Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/.github export-ignore
/tests export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/phpunit.xml.dist export-ignore
/art export-ignore
/node_modules export-ignore
/resources/js export-ignore
/package.json export-ignore
/package-lock.json export-ignore
59 changes: 59 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: ci
on:
push:
branches: [main]
pull_request:

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- statamic: "^5.0"
testbench: "9.*"
php: "8.2"
- statamic: "^5.0"
testbench: "10.*"
php: "8.3"
- statamic: "^6.0"
testbench: "10.*"
php: "8.3"
- statamic: "^6.0"
testbench: "11.*"
php: "8.4"
name: Statamic ${{ matrix.statamic }} / Testbench ${{ matrix.testbench }} / PHP ${{ matrix.php }}
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: intl, exif, gd
coverage: none
- name: Install
env:
COMPOSER_NO_SECURITY_BLOCKING: "1"
run: |
# Older Laravel and Statamic releases have security advisories, and
# Composer refuses those by default. They are tested on purpose;
# sites choose their own versions.
php -r '$c = json_decode(file_get_contents("composer.json"), true); $c["config"]["audit"]["block-insecure"] = false; $c["config"]["policy"]["advisories"]["block"] = false; file_put_contents("composer.json", json_encode($c, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));'
composer require "statamic/cms:${{ matrix.statamic }}" --no-interaction --no-update
composer require --dev "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --prefer-dist --no-interaction --no-progress --with-all-dependencies
- run: vendor/bin/phpunit

bundle:
runs-on: ubuntu-latest
name: dist is up to date
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- run: npm ci && npm run build
- run: git diff --exit-code dist
15 changes: 15 additions & 0 deletions .github/workflows/release-notify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Posts each published release of this repo to Slack, using the shared
# workflow in hibira-io/.github. Needs the org secret SLACK_WEBHOOK_URL;
# without it the job is a no-op.
name: release-notify

on:
release:
types: [published]

permissions: {}

jobs:
slack:
uses: hibira-io/.github/.github/workflows/release-slack.yml@main
secrets: inherit
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/vendor/
/composer.lock
/.phpunit.cache/
/.phpunit.result.cache
/workbench/
/testbench.yaml
/node_modules/
/tests/__fixtures__/
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Changelog

## 0.1.0

- Avatars of everyone who has the same entry open, and a warning when one
of them saves it.
- Live comments on entries, stored as one JSON file per entry: add,
resolve, reopen and delete, checked against Statamic's permissions.
- Live preview on other devices: a QR code and link of your live preview,
which reloads on every change.
- With `BROADCAST_CONNECTION=hibira`, Statamic's own control panel Echo
client connects to Hibira.
- Statamic 5 and 6. English, 繁體中文, 简体中文, 日本語, 한국어, ไทย and Tiếng Việt.
119 changes: 119 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# hibira-io/statamic

[![ci](https://github.com/hibira-io/statamic/actions/workflows/ci.yml/badge.svg)](https://github.com/hibira-io/statamic/actions/workflows/ci.yml)

Realtime teamwork for the [Statamic](https://statamic.com) control panel, on
[Hibira](https://hibira.io):

- **Who else is here.** The avatars of everyone who has the same entry open,
and a warning the moment one of them saves it, so nobody keeps editing an
old version.
- **Live comments.** Leave a question or a note on an entry. Everyone who has
it open sees new comments as they are written; resolve them when they are
done. Reviewers who may only view an entry can comment too.
- **Live preview on any device.** Scan a QR code to open your live preview on
your phone, or send the link to another browser. The page reloads every
time you change the entry, and keeps its scroll position.

Works with Statamic 5 and 6, flat file or database. Comments need no
database, and there is nothing to publish or build.

![The dock, comments and a saved warning](art/comments-light.png)

## Install

```sh
composer require hibira-io/statamic
php artisan hibira:install
```

`hibira:install` (from [hibira-io/laravel](https://github.com/hibira-io/laravel))
adds the `HIBIRA_*` settings to `.env`. Copy the app ID, key and secret from
your app page on [hibira.io/portal](https://hibira.io/portal) (the free plan
needs no card), and check them with `php artisan hibira:check`.

On the same app page, add your site's address (for example
`https://example.com`) to **Allowed origins**, so the control panel and
preview pages may connect.

Open an entry in two browsers, signed in as two users. The dock appears in
the bottom right corner.

![Live preview on another device, in dark mode](art/preview-dark.png)

## What it does

| | |
| --- | --- |
| Avatars | Everyone with the entry's edit page open. Hover for the name. |
| Saved warning | When someone else saves the entry, a card asks you to reload before you edit. Saves from the console (imports, scheduled publishing) are left out. |
| Comments | Plain text, up to 2,000 characters. Ctrl+Enter sends. Anyone who may view the entry can comment and resolve; the author or a super user can delete. |
| Live preview link | Open Live Preview on the entry once, then press the phone button for the QR code and link. The link works as long as Statamic's live preview token. |

People see only entries they may view: every channel subscription and
comment request is checked against Statamic's own permissions.

In English, 繁體中文, 简体中文, 日本語, 한국어, ไทย and Tiếng Việt, following
each user's control panel language.

## Options

Publish the config to change them:

```sh
php artisan vendor:publish --tag=hibira-statamic-config
```

| Setting | Default | |
| --- | --- | --- |
| `presence` | `true` | Avatars and saved warnings (`HIBIRA_STATAMIC_PRESENCE`) |
| `comments.enabled` | `true` | Comments (`HIBIRA_STATAMIC_COMMENTS`) |
| `comments.path` | `storage/statamic/hibira-comments` | One JSON file per entry. Point it inside `content/` to keep comments in git with your content. |
| `comments.max_length` | `2000` | Characters per comment |
| `live_preview` | `true` | Live preview on other devices (`HIBIRA_STATAMIC_LIVE_PREVIEW`) |
| `control_panel_echo` | `true` | See below (`HIBIRA_STATAMIC_CP_ECHO`) |

### Statamic's own broadcasting

Statamic's control panel has its own Echo client, which addons such as
[statamic/collaboration](https://github.com/statamic/collaboration) use.
Statamic only knows how to point it at Pusher or Reverb. With
`BROADCAST_CONNECTION=hibira`, this addon fills in the Hibira host, so those
addons run on Hibira with no more setup. That client opens a connection on
every control panel page, so set `HIBIRA_STATAMIC_CP_ECHO=false` if you
don't use such an addon.

## How it uses Hibira

- Each entry has a presence channel. The control panel signs subscriptions
on its own route, for users who may view the entry, so you don't have to
change your app's broadcasting setup.
- Comments are stored first, then sent to the others on the entry's channel.
A page that lost its connection fetches them again when it reconnects.
- A live preview page opened outside the control panel listens on a public
channel named after a keyed hash of its preview token, so only someone with
the link can find it, and its events carry no content. Events are sent only
while such a page is open.
- Each open edit page is one connection, and each preview page opened on
another device is one more.

## Testing

```sh
composer test
```

The browser code is in `resources/js`. After changing it, rebuild `dist/`
with `npm ci && npm run build`.

## License

MIT

## 中文摘要

在 Statamic 控制台加上即時協作:同一篇內容誰也開著(頭像),有人儲存時立刻提醒重新載入;
即時留言(可標記已解決,只能看不能改的審稿人也能留言);用手機掃 QR Code 開即時預覽,
每次修改內容手機頁面就自動重新載入。支援 Statamic 5 與 6,留言存成 JSON 檔不需要資料庫。
安裝:`composer require hibira-io/statamic`,`php artisan hibira:install` 填入
[hibira.io/portal](https://hibira.io/portal) 的 App ID、Key、Secret,並把網站網址加到 Allowed origins。
Binary file added art/comments-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added art/preview-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 77 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"name": "hibira-io/statamic",
"description": "Live comments, \"someone else is editing\" warnings and live preview on any device for the Statamic control panel, over Hibira WebSockets",
"type": "statamic-addon",
"keywords": [
"statamic",
"statamic-addon",
"laravel",
"comments",
"collaboration",
"presence",
"live-preview",
"realtime",
"websockets",
"hibira"
],
"homepage": "https://hibira.io",
"license": "MIT",
"authors": [
{
"name": "Hibira",
"homepage": "https://hibira.io"
}
],
"support": {
"issues": "https://github.com/hibira-io/statamic/issues",
"docs": "https://github.com/hibira-io/statamic#readme",
"email": "support@hibira.io"
},
"require": {
"php": "^8.2",
"hibira-io/laravel": "^0.2",
"pusher/pusher-php-server": "^7.2",
"statamic/cms": "^5.0|^6.0"
},
"require-dev": {
"mockery/mockery": "^1.6",
"orchestra/testbench": "^8.0|^9.0|^10.0|^11.0",
"phpunit/phpunit": "^10.0|^11.0|^12.0"
},
"autoload": {
"psr-4": {
"Hibira\\Statamic\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Hibira\\Statamic\\Tests\\": "tests/"
}
},
"extra": {
"statamic": {
"name": "Hibira Realtime",
"slug": "hibira-statamic",
"description": "Live comments, editing warnings and live preview on any device, over Hibira"
},
"laravel": {
"providers": [
"Hibira\\Statamic\\ServiceProvider"
]
},
"branch-alias": {
"dev-main": "0.1.x-dev"
}
},
"scripts": {
"test": "phpunit"
},
"config": {
"sort-packages": true,
"allow-plugins": {
"pixelfear/composer-dist-plugin": true
}
},
"minimum-stability": "stable",
"prefer-stable": true
}
61 changes: 61 additions & 0 deletions config/hibira-statamic.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

return [

/*
|--------------------------------------------------------------------------
| Who else is here
|--------------------------------------------------------------------------
|
| On an entry's edit page, show the people who have the same entry open,
| and warn when one of them saves it.
|
*/

'presence' => env('HIBIRA_STATAMIC_PRESENCE', true),

/*
|--------------------------------------------------------------------------
| Comments
|--------------------------------------------------------------------------
|
| Comments on entries, for everyone who may view the entry. They are
| stored as one JSON file per entry in this folder, so no database is
| needed. Commit the folder if you want comments to travel with your
| content.
|
*/

'comments' => [
'enabled' => env('HIBIRA_STATAMIC_COMMENTS', true),
'path' => storage_path('statamic/hibira-comments'),
'max_length' => 2000,
],

/*
|--------------------------------------------------------------------------
| Live preview on other devices
|--------------------------------------------------------------------------
|
| A live preview link opened on a phone or in another browser reloads
| when the entry is changed in the control panel. The link stays valid
| as long as Statamic's live preview token (about an hour of inactivity).
|
*/

'live_preview' => env('HIBIRA_STATAMIC_LIVE_PREVIEW', true),

/*
|--------------------------------------------------------------------------
| Statamic's own broadcasting
|--------------------------------------------------------------------------
|
| With BROADCAST_CONNECTION=hibira, point the control panel's own Echo
| client at Hibira as well, so addons that use it (such as
| statamic/collaboration) work without more setup.
|
*/

'control_panel_echo' => env('HIBIRA_STATAMIC_CP_ECHO', true),

];
262 changes: 262 additions & 0 deletions dist/cp.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/preview.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading