studio-engine 0.137.0 → 0.139.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +38 -0
- data/README.md +86 -1
- data/app/assets/tailwind/studio_engine/engine.css +235 -0
- data/app/controllers/concerns/studio/connection_flow.rb +1 -1
- data/app/controllers/sessions_controller.rb +12 -3
- data/app/controllers/studio/integrations_controller.rb +43 -0
- data/app/controllers/studio/local_reviews_controller.rb +12 -0
- data/app/javascript/studio/carousel.js +109 -0
- data/app/javascript/studio/controllers/carousel_captions_controller.js +42 -0
- data/app/javascript/studio/controllers/carousel_controller.js +243 -1
- data/app/javascript/studio/stimulus.js +3 -1
- data/app/models/concerns/studio/account.rb +143 -0
- data/app/models/concerns/studio/omniauth_user.rb +9 -17
- data/app/models/error_log.rb +14 -5
- data/app/views/studio/_carousel.html.erb +74 -14
- data/app/views/studio/integrations/_card.html.erb +50 -0
- data/app/views/studio/integrations/index.html.erb +22 -0
- data/app/views/studio/integrations/show.html.erb +24 -0
- data/app/views/style/_tricks.html.erb +38 -0
- data/config/studio_tricks.yml +7 -0
- data/db/migrate/20261006120001_ensure_error_logs_table.rb +3 -1
- data/db/migrate/20261006120002_ensure_theme_settings_table.rb +3 -2
- data/db/migrate/20261108160000_require_slugs_on_engine_tables.rb +119 -0
- data/db/migrate/20261108160001_add_engine_state_checks.rb +94 -0
- data/db/migrate/20261108170000_add_users_role_known_check.rb +69 -0
- data/lib/generators/studio/connections/connections_generator.rb +10 -0
- data/lib/studio/connections.rb +53 -12
- data/lib/studio/integrations/egnyte.rb +69 -0
- data/lib/studio/integrations/microsoft_365.rb +63 -0
- data/lib/studio/integrations/quickbooks.rb +86 -0
- data/lib/studio/integrations.rb +265 -0
- data/lib/studio/node_tooling/README.md +9 -1
- data/lib/studio/node_tooling/e2e_helpers.js +93 -1
- data/lib/studio/node_tooling/playwright_base.js +51 -4
- data/lib/studio/roles.rb +17 -0
- data/lib/studio/version.rb +1 -1
- data/lib/studio.rb +59 -1
- metadata +16 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a9937bbeb00f70902af7404d9ded16f10216e7123dba4d929eef0d04fe8c1f80
|
|
4
|
+
data.tar.gz: ff26fdac225b730cc611af898fe0fc786ee968545a5ee674f89131cfe183f035
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d3721562277466c4af36db5835ad05ad5fba414d4a091c9a447787f95d5d8bbe8ae053b5ff0a0563422a732169130aedd77e2bf5f721e6026b099e99172b7e6f
|
|
7
|
+
data.tar.gz: 2b2405866b62361954dc69c30d66b5dbcd56536ef40b9e26d5b64094d3ed7a07bfb36cda26483ae872cc370f95a1f7f69a7a79dd4c24c4744c1d2ce1a59a8504
|
data/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,44 @@ The format is [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). This pro
|
|
|
4
4
|
|
|
5
5
|
## Unreleased
|
|
6
6
|
|
|
7
|
+
## 0.139.0 — 2026-11-08
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- **`studio/_carousel` dispatches `studio:carousel:change`.** Every style (standard, spotlight, cascade) dispatches it from the region, bubbling, once each time the open slide changes, after `data-current` has moved. `event.detail` is `{ index, previous, slide, total }`. A host that follows the open slide (a caption under the row, a counter) listens for it instead of a `MutationObserver` on `data-current`. The first paint's slide fires nothing; a looping row fires once, for the real slide, when it lands home off the seam copy.
|
|
12
|
+
- **`studio/_carousel` takes `dots:`.** `dots: false` draws no dot group, so nothing for Tab or a screen reader to meet; the arrows, keys, swipe and status line stay. The default, `dots: true`, renders byte for byte what leaving it out does (render digests for standard, spotlight and cascade). A host that hid the dots with CSS passes `dots: false` instead.
|
|
13
|
+
- **The image-only cascade pattern is documented and on `/admin/style`.** Each card is only its picture, the open card wears a ring (`in-data-current:`), and one caption under the stack follows the open card. The new lazy `carousel-captions` controller does the following: wrap the row and its captions in `data-studio-controller="carousel-captions"` and mark each caption `data-carousel-captions-target="caption"`; no page script. The README gives the markup to copy.
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
|
|
17
|
+
- **A cascade press released off the track no longer hijacks Enter.** A mouse press on a side card that let go outside the track left its card recorded, so Enter on the front card's link later moved the stack to that card instead of following the link. A click with no press (Enter or Space) now reads only the card it lands in, and the next press replaces a stale one.
|
|
18
|
+
- **A cascade card that crosses a looping stack's seam fades in on every move.** Next then Previous on a five-card loop took the same card round the seam twice, and the second jump did not fade in. The fade now replays each time and leaves no finished animation behind.
|
|
19
|
+
- **A narrow cascade fades its side cards at the track's edge** instead of cutting them hard; a wide stack and a failed controller's scrolling row keep no mask.
|
|
20
|
+
- **The cascade's Tab wording is exact.** The partial, the controller and the README now say that Tab skips the cards past the window, and that a cascade which does not loop and opens mid-row reaches the cards before the window by Shift+Tab, Home, the arrow keys, Previous and the dots.
|
|
21
|
+
|
|
22
|
+
## 0.138.0 — 2026-11-08
|
|
23
|
+
|
|
24
|
+
### Added
|
|
25
|
+
|
|
26
|
+
- **`studio/_carousel` takes `style: :cascade`, a 3D stacked carousel.** The open slide sits in front at full size; the slides either side step back behind it, each step smaller, deeper and dimmer, turned a little toward the centre. `visible: 5` (the default) shows two each side, `visible: 3` one, and a region under 36rem wide shows one whatever it asks. Arrows, dots, keys, swipe or drag, a click on a side slide and keyboard focus bring a slide to the front; `loop:`, `start:`, `autoplay:` and `caption:` work as on the spotlight, and a looping cascade needs no clones. Reduced motion lays it flat as a spotlight row. `:standard` and `:spotlight` render byte for byte as before. A host adopts it by changing `style: :spotlight` to `style: :cascade`; `visible:` on any other style raises.
|
|
27
|
+
- **Shared reveal waits for page transition specs.** `e2e_helpers.js` adds `watchReveal`, `revealed`, `settled`, `arrivalSettled`, `frames`, `sessionLog` and `logOnRed`, moved from the engine's full-load spec. They wait on the new page's `pagereveal` and its view transition, never on a pause, and a red prints and attaches the event log. A host's own transition spec can drop its copies and require these from `node_modules/.studio-engine/e2e_helpers.js`.
|
|
28
|
+
- **Integrations registry: QuickBooks, Egnyte and Microsoft 365 connection definitions, and an admin page.** The engine now ships a connection definition for each (URLs, scopes, token behaviour, a one-call describe of the account; no reader). QuickBooks keeps its access token until 5 minutes before it expires or a 401, then refreshes once under the row lock and stores the rotated refresh token; it captures Intuit's `intuit_tid` header on every call (new generic `trace_header:` provider option: logged per call, `provider.last_trace_id`, and on every raised error as `trace_id` and in its message). A host enables one in an initializer with `Studio.enable_integration :quickbooks, env: { client_id: "...", client_secret: "..." }`, naming its own env vars, and mounts `Studio.draw_integrations_routes(self)`: `/admin/integrations` lists each status and Connect, and `/admin/integrations/<key>` shows its connections, Disconnect, the redirect URI to register (`/admin/integrations/<key>/callback`) and the host's own panel (`panel:`). Stand-ins walk a connect end to end in development and test. See `docs/INTEGRATIONS.md`.
|
|
29
|
+
- **`Studio::Account`, the engine-owned account contract.** `include Studio::Account` in `User` gives `admin?`, a default `display_name`, `normalizes :email` (blank stored as NULL), `validates :role, inclusion:` against the new `Studio::Roles` (`viewer`, `member`, `admin`; a host may narrow it with `studio_roles`, never widen it), `Sluggable` and `Studio::OmniauthUser`. `Studio::Account.find_by_email` is the one safe lookup by address (blank finds nobody, `LOWER(email)`), and `Studio::Account.race_winner` is the race rescue for a host's own `from_omniauth` (verified address only; logs to `ErrorLog.capture!` when nothing matches). The new host migration `AddUsersRoleKnownCheck` installs CHECK `users_role_known` and NOT NULL, skips an app that already has the CHECK, and refuses on a stray role. Nothing changes until an app includes the concern or installs the migration. See docs/USER_CONTRACT.md, "The account concern". (The audit called it `Studio::User`; that name would shadow the host's `User` inside `module Studio`.)
|
|
30
|
+
|
|
31
|
+
### Changed
|
|
32
|
+
|
|
33
|
+
- **A local-review provisioning miss is logged to ErrorLog.** `Studio::LocalReviewsController` still mints the link when it cannot provision the reviewer, and now records the reason with `ErrorLog.capture!` as well as the Rails log. The likeliest cause after `Studio::Account`: `Studio.local_review_role` names a role the app's list refuses.
|
|
34
|
+
- **The engine's own tables meet the hub's database standard.** Two new migrations, for every host. `RequireSlugsOnEngineTables` makes `slug` NOT NULL with a unique index on `error_logs`, `theme_settings`, `studio_geo_settings` and `studio_site_identities`. It first fills a NULL or blank slug the way the model writes one (`error-log-<id>`, `theme-<app>`, `geo-<app>`, `site-identity-<app>`), and gives a duplicate after the first `-<id>`. `AddEngineStateChecks` adds CHECK `studio_links_kind_known` (`Studio::LinkToken::KINDS`) and `studio_knowledge_docs_status_known` (`Studio::KnowledgeDoc::STATUSES`), and stops with the stray values named if a row holds another value. Production held no NULL slug, no duplicate and no stray value on 2026-11-08. `ErrorLog` now includes `Sluggable`, so a bare `ErrorLog.create!` gets `error-log-<id>` too, and a host's own `update_column(:slug, "error-log-#{log.id}")` after a create may go. To adopt, use two releases, model first. Release one bumps the gem only: the new `ErrorLog` writes a slug on the old nullable column. Release two runs `bin/rails studio_engine:install:migrations && bin/rails db:migrate` and commits `db/schema.rb`. In one release, old dynos insert a NULL slug until the restart, and a failed release or a `heroku rollback` leaves old code on the NOT NULL column, so every `ErrorLog` write fails; undo it with `bin/rails db:migrate:down VERSION=20261108160000` before the rollback. A host whose own state registry lists `studio_knowledge_docs.status` as unconstrained (the hub's `StringStates`) moves it to a checked entry.
|
|
35
|
+
|
|
36
|
+
### Fixed
|
|
37
|
+
|
|
38
|
+
- **A local e2e run no longer reuses another tree's server.** `playwright_base.js` reuses a server already on the e2e port only when its working directory (read with `lsof`) is inside this tree. A sibling desk's server on the shared default port is refused, with a warning that names its root; give the run its own port with `E2E_PORT`. CI is unchanged: it never reuses a server.
|
|
39
|
+
- **Connect's refusal of a mistyped account now reads "That is not a valid <label> account."** It read "not a Egnyte account" for a label that starts with a vowel. A host test that matched the old text matches the new one.
|
|
40
|
+
|
|
41
|
+
### Security
|
|
42
|
+
|
|
43
|
+
- **The engine's sign-in doors find nobody for a blank email.** `SessionsController#create` and the SSO "Continue as" path looked the account up with `User.find_by(email: ...)`. With no address that is `find_by(email: nil)`, which matches any account without an email (a wallet or guest sign-up): the password door handed that account to `authenticate`, and the SSO path signed it in. Both now use `Studio::Account.find_by_email`, which also matches case-insensitively. Nothing for a consumer to change.
|
|
44
|
+
|
|
7
45
|
## 0.137.0 — 2026-11-08
|
|
8
46
|
|
|
9
47
|
### Added
|
data/README.md
CHANGED
|
@@ -51,7 +51,8 @@ resolved.
|
|
|
51
51
|
- **Voice profile**: an opt-in row on `/profile` ("Set up your voice"): the person reads three phrases with a live level meter, their device turns each take into a speaker embedding (WeSpeaker via transformers.js), and only the averaged vector is saved on their user, never audio. `Studio::VoiceMatch.identify(embedding, among: User.all, model:)` answers who is speaking. Turn it on with `config.voice_profile = true` after installing the migration. See [`docs/VOICE_PROFILE.md`](docs/VOICE_PROFILE.md).
|
|
52
52
|
- **Voice capture**: the microphone chip (names the microphone a page records from, picks another, Chrome help dialog), one level meter, and a record button that refuses a silent take and hands a heard one to the page as a `studio:voice-recorder:take` event with the blob; it uploads nothing. Render `studio/voice/microphone_chip` and `studio/voice/recorder`. See [`docs/VOICE_CAPTURE.md`](docs/VOICE_CAPTURE.md).
|
|
53
53
|
- **Voice transcription**: `POST /voice/takes` (opt-in, `config.voice_transcription = true`) turns a signed-in user's take into `{text, speaker, score}`: a mock-first transcriber (OpenAI `gpt-4o-transcribe` in production, a mock elsewhere, a no-live-calls trap in every test environment) and `Studio::VoiceMatch` against the user's own saved voice. Nothing is kept. See [`docs/VOICE_TRANSCRIPTION.md`](docs/VOICE_TRANSCRIPTION.md).
|
|
54
|
-
- **Connections**: generic OAuth 2.0 tooling to connect a third-party account. A host declares each provider with `Studio.define_connection` (endpoints, static or per-account; scopes; form or HTTP Basic client auth; a rotating, cached or client-credentials refresh policy). The engine gives it `Studio::Connection` (one table, tokens encrypted, `bin/rails g studio:connections`), the connect, callback and disconnect actions (`Studio::ConnectionFlow`) behind the host's admin guard, `Studio.draw_connection_routes`, an exact-key log filter, and a stand-in for the e2e lane. The
|
|
54
|
+
- **Connections**: generic OAuth 2.0 tooling to connect a third-party account. A host declares each provider with `Studio.define_connection` (endpoints, static or per-account; scopes; form or HTTP Basic client auth; a rotating, cached or client-credentials refresh policy). The engine gives it `Studio::Connection` (one table, tokens encrypted, `bin/rails g studio:connections`), the connect, callback and disconnect actions (`Studio::ConnectionFlow`) behind the host's admin guard, `Studio.draw_connection_routes`, an exact-key log filter, and a stand-in for the e2e lane. The tooling names no provider; the engine's own definitions are the Integrations below. See [`docs/CONNECTIONS.md`](docs/CONNECTIONS.md).
|
|
55
|
+
- **Integrations**: ready connection definitions on that tooling for QuickBooks, Egnyte and Microsoft 365: the URLs, scopes, token behaviour and a minimal describe, never a reader. A host turns one on with `Studio.enable_integration :quickbooks, env: { client_id: "...", client_secret: "..." }` (env var names) and mounts the admin page with `Studio.draw_integrations_routes(self)`: a list with each status and Connect, and one page per integration with Disconnect and a host panel for the host's own live read. See [`docs/INTEGRATIONS.md`](docs/INTEGRATIONS.md).
|
|
55
56
|
- **Surveys**: define a survey in app code (`config/surveys/*.rb`, `Studio.define_survey`) with six question types — emoji scale, 1–5 rating, single and multiple choice, short and long text — and the engine serves it at `/surveys/:slug`: one question per screen, autosave, resume, keyboard shortcuts, and a no-JavaScript fallback. `config.on_survey_completed` and `config.survey_ref_resolver` let the app fire its own goals and attribute email arrivals. An admin panel at `/admin/surveys` breaks results down per question and exports CSV. Opt in with `config.draw_survey_routes = true` and `config.draw_admin_survey_routes = true`. See [`docs/SURVEYS.md`](docs/SURVEYS.md).
|
|
56
57
|
|
|
57
58
|
## Tailwind
|
|
@@ -257,6 +258,8 @@ Set `Studio.draw_survey_routes = true` to add the public survey pages (`/surveys
|
|
|
257
258
|
|
|
258
259
|
For each connection provider a host declares, `Studio.draw_connection_routes(self, :files, path: "admin/files")` adds its connect (`GET`/`POST /admin/files/connect`), callback (`GET /admin/files/callback`, the redirect URI to register) and disconnect (`DELETE /admin/files/connections/:id`) routes. Nothing is drawn for a provider the host has not declared. They need the `studio_connections` table (`bin/rails g studio:connections`; [`docs/CONNECTIONS.md`](docs/CONNECTIONS.md)).
|
|
259
260
|
|
|
261
|
+
`Studio.draw_integrations_routes(self)` draws the admin integrations page at `GET /admin/integrations` and, for each integration enabled with `Studio.enable_integration`, its page (`GET /admin/integrations/<key>`) and its connection routes under that path. QuickBooks's callback is then `/admin/integrations/quickbooks/callback` ([`docs/INTEGRATIONS.md`](docs/INTEGRATIONS.md)).
|
|
262
|
+
|
|
260
263
|
**Magic links need the `studio_links` table.** Install it with `bin/rails studio_engine:install:migrations && bin/rails db:migrate` (install all of them) before enabling `:magic_link` — never by hand-copying the migration, which collides with the task's own copy on `class CreateStudioLinks`. Without the table, the first sign-in raises `Studio::Link::MissingTable`.
|
|
261
264
|
|
|
262
265
|
Set `Studio.agent_chat_souls = %w[alex]` to add the shared agent chat's proxy (`POST /agent_chat/messages`, `GET /agent_chat/turns`), which forwards to the McRitchie Studio hub with the app's `AGENT_CHAT_TOKEN`; then `render "studio/agent_chat/chat", soul: "alex", name: "Alex", portrait: ...` on any page, with `voice: true` for hold to talk in the composer ([`docs/AGENT_CHAT.md`](docs/AGENT_CHAT.md)). To open that chat in a modal from any button, render `studio/agent_chat/talk_modal` once and mark the buttons with `studio_talk_to_agent_link` ([`docs/AGENT_CHAT.md`](docs/AGENT_CHAT.md), "Talk to an agent in a modal").
|
|
@@ -347,6 +350,10 @@ as a layout; the block draws each slide. `per_view:` is the wide row's count
|
|
|
347
350
|
|
|
348
351
|
`caption:` (a callable on the item) writes a small line under each slide.
|
|
349
352
|
|
|
353
|
+
`dots: false` draws no dots: the row has no dot group in the tab order or the
|
|
354
|
+
accessibility tree, and the arrows, keys, swipe and status line stay. The default,
|
|
355
|
+
`dots: true`, renders exactly what leaving it out does.
|
|
356
|
+
|
|
350
357
|
`style: :spotlight` snaps each slide to the centre: the centred slide is full size and
|
|
351
358
|
colour, with its caption under it (the spotlight shows the centred slide's only), and its
|
|
352
359
|
neighbours are smaller, faded and grey. The arrows ("Previous slide", "Next slide") and
|
|
@@ -395,6 +402,84 @@ again from the first.
|
|
|
395
402
|
<% end %>
|
|
396
403
|
```
|
|
397
404
|
|
|
405
|
+
`style: :cascade` is a 3D stack. The open slide sits in front at full size, and the slides
|
|
406
|
+
either side step back behind it: each step further aside, smaller, deeper (`perspective`,
|
|
407
|
+
`translateZ`), dimmer and turned a little toward the centre, with the open slide on top.
|
|
408
|
+
`visible: 5` (the default) shows two each side and `visible: 3` one; a region under 36rem
|
|
409
|
+
wide shows one each side whatever it asks, so a phone keeps its cards legible. `visible:`
|
|
410
|
+
on another style raises. The row does not scroll: each slide wears `data-cascade-step`
|
|
411
|
+
(`-2` to `2` in view, `before` and `after` past the window, hidden), which the partial writes
|
|
412
|
+
for the first paint and the controller rewrites on a move. The arrows, dots, keys
|
|
413
|
+
(arrows, Home, End), a swipe or drag, autoplay, a click on a side slide (which opens
|
|
414
|
+
nothing) and keyboard focus landing in a side slide bring that slide to the front, and the
|
|
415
|
+
status line says "Slide N of M". `start:`, `caption:` (under the open slide only),
|
|
416
|
+
`autoplay:` and `loop:` behave as on the spotlight; a looping cascade needs no clones,
|
|
417
|
+
since the steps wrap round the set. Under reduced motion the stack lays flat as a spotlight
|
|
418
|
+
row, the neighbours only dimmed, and a move swaps at once. A controller that fails leaves
|
|
419
|
+
a plain scrolling row. A region under 36rem wide fades its side cards at the track's edge
|
|
420
|
+
instead of cutting them, and a card that crosses a looping stack round the seam fades in at
|
|
421
|
+
its new place on every move.
|
|
422
|
+
|
|
423
|
+
Tab skips the cards past the window (they are hidden). Tab from the track lands on the
|
|
424
|
+
first card in view and brings it to the front, and each Tab after moves one card on. A
|
|
425
|
+
cascade that does not loop and opens mid-row (the default) has cards before the window that
|
|
426
|
+
forward Tab never reaches: Shift+Tab from the first card in view, Home, the arrow keys,
|
|
427
|
+
Previous and the dots reach them.
|
|
428
|
+
|
|
429
|
+
```erb
|
|
430
|
+
<%= render layout: "studio/carousel",
|
|
431
|
+
locals: { label: "Portfolio", items: @apps, style: :cascade, autoplay: 6, loop: true } do |app| %>
|
|
432
|
+
<%= render "apps/card", app: app %>
|
|
433
|
+
<% end %>
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
**The change event.** Every style dispatches `studio:carousel:change` from the region
|
|
437
|
+
(`section.carousel`), bubbling, once each time the open slide changes, after the
|
|
438
|
+
controller has moved `data-current`. `event.detail` is `{ index, previous, slide, total }`:
|
|
439
|
+
the open slide's index among the real slides (from 0), the one open before, its element
|
|
440
|
+
(never a looping row's copy) and the count. Follow the open slide with it; do not observe
|
|
441
|
+
`data-current`. The first paint's slide fires nothing, and a row that opens elsewhere
|
|
442
|
+
when its controller connects (a `#fragment`, a restored scroll) fires once. A cascade
|
|
443
|
+
fires once per move. A scrolling row (standard or spotlight) fires for each slide its
|
|
444
|
+
glide passes, as its `data-current` moves; a looping one fires for the real slide once it
|
|
445
|
+
has jumped home off the seam copy. A standard row's open slide is the one at its first
|
|
446
|
+
stop, and it marks none `data-current`.
|
|
447
|
+
|
|
448
|
+
**The image-only pattern** (the hub Portfolio, `/lab/carousel_cascade`, `/admin/style`):
|
|
449
|
+
each card is only its picture, filling the card; the open card wears a ring; and one caption
|
|
450
|
+
sits under the stack and follows the open card. A caption inside each slide would ride the
|
|
451
|
+
slide's 3D move, so the captions live outside the row, one per item in item order, all in one
|
|
452
|
+
grid cell. The engine's `carousel-captions` controller (lazy) marks the open one
|
|
453
|
+
`data-current` and the rest `aria-hidden` on each change event; the page needs no script:
|
|
454
|
+
|
|
455
|
+
```erb
|
|
456
|
+
<div data-studio-controller="carousel-captions">
|
|
457
|
+
<%= render layout: "studio/carousel",
|
|
458
|
+
locals: { label: "Portfolio", items: @apps, style: :cascade, loop: true, dots: false,
|
|
459
|
+
slide_label: ->(app) { app.name } } do |app| %>
|
|
460
|
+
<%= link_to app.url, aria: { label: app.name },
|
|
461
|
+
class: "block aspect-[4/3] overflow-hidden rounded-2xl transition-shadow duration-300 in-data-current:ring-2 in-data-current:ring-primary" do %>
|
|
462
|
+
<%= image_tag app.image, alt: "", class: "h-full w-full object-cover" %>
|
|
463
|
+
<% end %>
|
|
464
|
+
<% end %>
|
|
465
|
+
<div class="grid pt-4 text-center">
|
|
466
|
+
<% @apps.each_with_index do |app, index| %>
|
|
467
|
+
<div class="col-start-1 row-start-1 opacity-0 invisible transition-opacity data-current:opacity-100 data-current:visible"
|
|
468
|
+
data-carousel-captions-target="caption"<%= " data-current".html_safe if index.zero? %><%= ' aria-hidden="true"'.html_safe unless index.zero? %>>
|
|
469
|
+
<h2 class="type-h4 text-heading"><%= app.name %></h2>
|
|
470
|
+
<p class="text-sm text-secondary"><%= app.blurb %></p>
|
|
471
|
+
</div>
|
|
472
|
+
<% end %>
|
|
473
|
+
</div>
|
|
474
|
+
</div>
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
The server marks the caption of the slide the row opens on (`start:`; index 0 for a
|
|
478
|
+
looping row). The ring keys on `data-current`, which the cascade and the spotlight set on
|
|
479
|
+
the open slide (`in-data-current:` matches the card inside it). The row's status line
|
|
480
|
+
already says which slide is open, so the caption stack is not a live region. A host that
|
|
481
|
+
needs more than a caption listens for `studio:carousel:change` itself.
|
|
482
|
+
|
|
398
483
|
### The "at" time stamp — `at_time_tag`
|
|
399
484
|
|
|
400
485
|
Stamps WHEN something happened, on the reader's own clock: `at 3:53p`, gaining a
|
|
@@ -1112,6 +1112,241 @@ body.modal-open .studio-app-banner {
|
|
|
1112
1112
|
}
|
|
1113
1113
|
}
|
|
1114
1114
|
|
|
1115
|
+
/* -- The cascade carousel (studio/_carousel, style: :cascade) ----------------------
|
|
1116
|
+
A 3D stack. The open slide sits in front at full size; the slides either side step
|
|
1117
|
+
back behind it, each step further aside, smaller, deeper and dimmer, turned a
|
|
1118
|
+
little toward the centre. visible: 5 (the default) shows two each side, visible: 3
|
|
1119
|
+
one; a region under 36rem wide shows one each side whatever it asks, so a phone
|
|
1120
|
+
keeps its cards legible.
|
|
1121
|
+
|
|
1122
|
+
THE ROW DOES NOT SCROLL. Every slide sits in one grid cell, so the cell is as tall
|
|
1123
|
+
as the tallest slide, and each wears data-cascade-step: its place from the open
|
|
1124
|
+
slide, -2 to 2 in view, "before" and "after" past the window (hidden). The partial
|
|
1125
|
+
writes the first paint's steps and the controller rewrites them on a move; this
|
|
1126
|
+
block maps a step to --cascade-x (signed) and --cascade-d (its depth) and lays the
|
|
1127
|
+
slide out from the two, with a transition. The track clips sideways, so the stack
|
|
1128
|
+
never widens the page. --carousel-cascade-reach tells the controller how many
|
|
1129
|
+
steps each side are in view.
|
|
1130
|
+
|
|
1131
|
+
A slide that crosses the stack round a looping set's seam (data-cascade-jump)
|
|
1132
|
+
takes no glide; it fades in at its new place. A drag nudges the stack after the
|
|
1133
|
+
pointer (--carousel-cascade-drag) and settles on release.
|
|
1134
|
+
|
|
1135
|
+
UNDER REDUCED MOTION nothing turns, deepens, scales or glides: the stack lays flat
|
|
1136
|
+
as a spotlight row does, the neighbours only dimmed, and a move swaps at once.
|
|
1137
|
+
|
|
1138
|
+
IF THE CONTROLLER FAILS (data-studio-controller-failed) the stack is a plain
|
|
1139
|
+
scrolling row, so every slide can still be reached. */
|
|
1140
|
+
@keyframes carousel-cascade-in {
|
|
1141
|
+
from {
|
|
1142
|
+
opacity: 0;
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
@utility carousel-cascade {
|
|
1147
|
+
& > .carousel-track {
|
|
1148
|
+
--carousel-cascade-reach: 2;
|
|
1149
|
+
--cascade-w: min(34cqi, 22rem);
|
|
1150
|
+
--cascade-shift: 0.52;
|
|
1151
|
+
--cascade-scale: 0.12;
|
|
1152
|
+
--cascade-depth: 6rem;
|
|
1153
|
+
--cascade-turn: 10deg;
|
|
1154
|
+
--cascade-dim: 0.22;
|
|
1155
|
+
display: grid;
|
|
1156
|
+
grid-template-columns: minmax(0, 1fr);
|
|
1157
|
+
justify-items: center;
|
|
1158
|
+
align-items: start;
|
|
1159
|
+
gap: 0;
|
|
1160
|
+
overflow: visible;
|
|
1161
|
+
overflow-x: clip;
|
|
1162
|
+
scroll-snap-type: none;
|
|
1163
|
+
perspective: 1400px;
|
|
1164
|
+
perspective-origin: 50% 40%;
|
|
1165
|
+
touch-action: pan-y;
|
|
1166
|
+
padding-block: 0.5rem 0.75rem;
|
|
1167
|
+
-webkit-mask-image: none;
|
|
1168
|
+
mask-image: none;
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
&[data-carousel-visible="3"] > .carousel-track {
|
|
1172
|
+
--carousel-cascade-reach: 1;
|
|
1173
|
+
--cascade-w: min(46cqi, 26rem);
|
|
1174
|
+
--cascade-shift: 0.62;
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
/* A narrow region shows one each side, on wider cards. Those side cards run past
|
|
1178
|
+
the track's edge, so the edge fades them out instead of cutting them hard. */
|
|
1179
|
+
@container (width < 36rem) {
|
|
1180
|
+
& > .carousel-track {
|
|
1181
|
+
--carousel-cascade-reach: 1;
|
|
1182
|
+
--cascade-w: 64cqi;
|
|
1183
|
+
--cascade-shift: 0.44;
|
|
1184
|
+
--cascade-depth: 3.5rem;
|
|
1185
|
+
-webkit-mask-image: linear-gradient(to right, transparent, #000 var(--carousel-cascade-fade, 10%), #000 calc(100% - var(--carousel-cascade-fade, 10%)), transparent);
|
|
1186
|
+
mask-image: linear-gradient(to right, transparent, #000 var(--carousel-cascade-fade, 10%), #000 calc(100% - var(--carousel-cascade-fade, 10%)), transparent);
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
&[data-carousel-dragging] > .carousel-track {
|
|
1191
|
+
cursor: grabbing;
|
|
1192
|
+
user-select: none;
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
& > .carousel-track > .carousel-slide {
|
|
1196
|
+
--cascade-x: 0;
|
|
1197
|
+
--cascade-d: 0;
|
|
1198
|
+
grid-area: 1 / 1;
|
|
1199
|
+
flex: none;
|
|
1200
|
+
width: var(--cascade-w);
|
|
1201
|
+
scroll-snap-align: none;
|
|
1202
|
+
display: flex;
|
|
1203
|
+
flex-direction: column;
|
|
1204
|
+
z-index: calc(10 - var(--cascade-d));
|
|
1205
|
+
transform:
|
|
1206
|
+
translateX(calc(var(--cascade-x) * var(--cascade-w) * var(--cascade-shift)))
|
|
1207
|
+
translateZ(calc(var(--cascade-d) * -1 * var(--cascade-depth)))
|
|
1208
|
+
rotateY(calc(var(--cascade-x) * -1 * var(--cascade-turn)))
|
|
1209
|
+
scale(calc(1 - var(--cascade-d) * var(--cascade-scale)));
|
|
1210
|
+
translate: var(--carousel-cascade-drag, 0px) 0;
|
|
1211
|
+
opacity: 1;
|
|
1212
|
+
transition:
|
|
1213
|
+
transform 480ms cubic-bezier(0.22, 0.8, 0.26, 1),
|
|
1214
|
+
translate 480ms cubic-bezier(0.22, 0.8, 0.26, 1),
|
|
1215
|
+
opacity 320ms ease,
|
|
1216
|
+
visibility 0s linear 0s;
|
|
1217
|
+
-webkit-user-drag: none;
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
& > .carousel-track > .carousel-slide :is(a, img) {
|
|
1221
|
+
-webkit-user-drag: none;
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
/* A side slide is a target: a click brings it to the front. */
|
|
1225
|
+
&[data-carousel-ready] > .carousel-track > .carousel-slide:not([data-current]) {
|
|
1226
|
+
cursor: pointer;
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
&[data-carousel-dragging] > .carousel-track > .carousel-slide {
|
|
1230
|
+
transition-property: transform, opacity, visibility;
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
& > .carousel-track > [data-cascade-step="-1"] { --cascade-x: -1; --cascade-d: 1; }
|
|
1234
|
+
& > .carousel-track > [data-cascade-step="1"] { --cascade-x: 1; --cascade-d: 1; }
|
|
1235
|
+
& > .carousel-track > [data-cascade-step="-2"] { --cascade-x: -2; --cascade-d: 2; }
|
|
1236
|
+
& > .carousel-track > [data-cascade-step="2"] { --cascade-x: 2; --cascade-d: 2; }
|
|
1237
|
+
|
|
1238
|
+
/* Past the window: one more step out, hidden. visibility waits for the fade. */
|
|
1239
|
+
& > .carousel-track > :is([data-cascade-step="before"], [data-cascade-step="after"]) {
|
|
1240
|
+
--cascade-d: 3;
|
|
1241
|
+
opacity: 0;
|
|
1242
|
+
visibility: hidden;
|
|
1243
|
+
pointer-events: none;
|
|
1244
|
+
transition-delay: 0s, 0s, 0s, 320ms;
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
& > .carousel-track > [data-cascade-step="before"] { --cascade-x: -3; }
|
|
1248
|
+
& > .carousel-track > [data-cascade-step="after"] { --cascade-x: 3; }
|
|
1249
|
+
|
|
1250
|
+
/* Three in view: the second step out is past the window too. */
|
|
1251
|
+
&[data-carousel-visible="3"] > .carousel-track > :is([data-cascade-step="-2"], [data-cascade-step="2"]) {
|
|
1252
|
+
opacity: 0;
|
|
1253
|
+
visibility: hidden;
|
|
1254
|
+
pointer-events: none;
|
|
1255
|
+
transition-delay: 0s, 0s, 0s, 320ms;
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1258
|
+
@container (width < 36rem) {
|
|
1259
|
+
& > .carousel-track > :is([data-cascade-step="-2"], [data-cascade-step="2"]) {
|
|
1260
|
+
opacity: 0;
|
|
1261
|
+
visibility: hidden;
|
|
1262
|
+
pointer-events: none;
|
|
1263
|
+
transition-delay: 0s, 0s, 0s, 320ms;
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1267
|
+
/* Round the seam: no glide across the stack, a fade in at the new place. */
|
|
1268
|
+
& > .carousel-track > .carousel-slide[data-cascade-jump] {
|
|
1269
|
+
transition: none;
|
|
1270
|
+
/* backwards, not both: a fade that has ended leaves nothing running, so the
|
|
1271
|
+
slide holds no finished animation until its next move. */
|
|
1272
|
+
animation: carousel-cascade-in 320ms ease backwards;
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
& > .carousel-track > .carousel-slide[data-cascade-jump]:is([data-cascade-step="before"], [data-cascade-step="after"]) {
|
|
1276
|
+
animation: none;
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1279
|
+
/* The dim: brightness and colour fall with depth, so a step back reads as further
|
|
1280
|
+
away on a light page and a dark one, glass or solid, and nothing behind shows
|
|
1281
|
+
through the card in front. */
|
|
1282
|
+
& .carousel-cascade-body {
|
|
1283
|
+
flex: 1 1 auto;
|
|
1284
|
+
min-height: 0;
|
|
1285
|
+
filter: brightness(calc(1 - var(--cascade-d) * var(--cascade-dim))) saturate(calc(1 - var(--cascade-d) * 0.3));
|
|
1286
|
+
transition: filter 320ms ease;
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
& .carousel-slide[data-current] .carousel-cascade-body {
|
|
1290
|
+
filter: none;
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1293
|
+
& .carousel-caption {
|
|
1294
|
+
margin-top: 0.75rem;
|
|
1295
|
+
text-align: center;
|
|
1296
|
+
@apply text-sm text-body;
|
|
1297
|
+
transition: opacity 300ms ease;
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
& .carousel-slide:not([data-current]) .carousel-caption {
|
|
1301
|
+
opacity: 0;
|
|
1302
|
+
}
|
|
1303
|
+
|
|
1304
|
+
@media (prefers-reduced-motion: reduce) {
|
|
1305
|
+
& > .carousel-track > .carousel-slide {
|
|
1306
|
+
transform: translateX(calc(var(--cascade-x) * (var(--cascade-w) + 0.75rem)));
|
|
1307
|
+
translate: none;
|
|
1308
|
+
transition: none !important;
|
|
1309
|
+
animation: none !important;
|
|
1310
|
+
}
|
|
1311
|
+
|
|
1312
|
+
& .carousel-cascade-body,
|
|
1313
|
+
& .carousel-caption {
|
|
1314
|
+
transition: none !important;
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
& .carousel-slide:not([data-current]) .carousel-cascade-body {
|
|
1318
|
+
filter: none;
|
|
1319
|
+
opacity: 0.45;
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
/* A controller that failed leaves a plain scrolling row: every slide in reach. */
|
|
1324
|
+
&[data-studio-controller-failed] > .carousel-track {
|
|
1325
|
+
display: flex;
|
|
1326
|
+
gap: 1rem;
|
|
1327
|
+
overflow-x: auto;
|
|
1328
|
+
scroll-snap-type: x mandatory;
|
|
1329
|
+
perspective: none;
|
|
1330
|
+
-webkit-mask-image: none;
|
|
1331
|
+
mask-image: none;
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1334
|
+
&[data-studio-controller-failed] > .carousel-track > .carousel-slide {
|
|
1335
|
+
flex: 0 0 var(--cascade-w);
|
|
1336
|
+
scroll-snap-align: center;
|
|
1337
|
+
transform: none;
|
|
1338
|
+
translate: none;
|
|
1339
|
+
opacity: 1;
|
|
1340
|
+
visibility: visible;
|
|
1341
|
+
pointer-events: auto;
|
|
1342
|
+
transition: none;
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
&[data-studio-controller-failed] .carousel-cascade-body {
|
|
1346
|
+
filter: none;
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1115
1350
|
/* -- The section header (studio/_section_header, docs/PAGE_HEADER.md) --------
|
|
1116
1351
|
A section's title that sticks under the rest of the stack, inside its own <section>,
|
|
1117
1352
|
so the next section's header takes its place with no scroll script. At rest it reads as
|
|
@@ -49,7 +49,7 @@ module Studio
|
|
|
49
49
|
account = nil
|
|
50
50
|
if provider.account_source == :connect
|
|
51
51
|
account = provider.normalize_account(params[provider.account_param]) or
|
|
52
|
-
return redirect_to(back, alert: "That is not a #{provider.label} account. Check what you entered, then press Connect again.")
|
|
52
|
+
return redirect_to(back, alert: "That is not a valid #{provider.label} account. Check what you entered, then press Connect again.")
|
|
53
53
|
end
|
|
54
54
|
url = provider.authorize_url(redirect_uri: connection_callback_url, state: new_connection_state, account:)
|
|
55
55
|
session[connection_session_key(:account)] = account
|
|
@@ -5,7 +5,10 @@ class SessionsController < ApplicationController
|
|
|
5
5
|
end
|
|
6
6
|
|
|
7
7
|
def create
|
|
8
|
-
|
|
8
|
+
# Studio::Account.find_by_email, never find_by(email:): a form posted with
|
|
9
|
+
# no address made that find_by(email: nil), which matches any account with
|
|
10
|
+
# no email (a wallet or guest sign-up) and handed it to `authenticate`.
|
|
11
|
+
user = Studio::Account.find_by_email(User, params[:email])
|
|
9
12
|
if user&.authenticate(params[:password])
|
|
10
13
|
set_app_session(user)
|
|
11
14
|
redirect_to root_path, notice: "Welcome back, #{user.display_name}!"
|
|
@@ -49,10 +52,16 @@ class SessionsController < ApplicationController
|
|
|
49
52
|
private
|
|
50
53
|
|
|
51
54
|
def authenticate_sso_user!
|
|
52
|
-
|
|
55
|
+
# sso_continue checks the address is present first; this method does not
|
|
56
|
+
# trust that. A blank one finds nobody and signs nobody in: find_by(email:
|
|
57
|
+
# nil) would match any account without an email and sign in as it.
|
|
58
|
+
email = Studio::Account.normalize_email(session[:sso_email])
|
|
59
|
+
return redirect_to(login_path, alert: "Could not continue session. Please log in.") unless email
|
|
60
|
+
|
|
61
|
+
user = Studio::Account.find_by_email(User, email)
|
|
53
62
|
unless user
|
|
54
63
|
user = User.new(
|
|
55
|
-
email:
|
|
64
|
+
email: email,
|
|
56
65
|
name: session[:sso_name],
|
|
57
66
|
provider: session[:sso_provider],
|
|
58
67
|
uid: session[:sso_uid]
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Studio
|
|
4
|
+
# The admin integrations page (docs/INTEGRATIONS.md): every integration the
|
|
5
|
+
# host enabled with Studio.enable_integration, its status and its Connect,
|
|
6
|
+
# and one page per integration with its connections, Disconnect, and the
|
|
7
|
+
# host's own panel. Studio.draw_integrations_routes points here.
|
|
8
|
+
#
|
|
9
|
+
# It includes Studio::ConnectionFlow, so connect, callback and disconnect are
|
|
10
|
+
# the connection tooling's own, and the host's admin guard
|
|
11
|
+
# (Studio.connection_admin_guard) runs before EVERY action here, the list
|
|
12
|
+
# and the pages included. It inherits the host's ApplicationController: its
|
|
13
|
+
# layout, session, current_user and Studio::ErrorHandling apply.
|
|
14
|
+
class IntegrationsController < ::ApplicationController
|
|
15
|
+
include Studio::ConnectionFlow
|
|
16
|
+
|
|
17
|
+
helper_method :integration_path_for, :integration_connect_path, :integration_callback_url,
|
|
18
|
+
:integration_disconnect_path, :integrations_index_path
|
|
19
|
+
|
|
20
|
+
def index
|
|
21
|
+
@integrations = Studio::Integrations.all
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def show
|
|
25
|
+
@integration = Studio::Integrations.fetch(params[:studio_connection])
|
|
26
|
+
@connections = @integration.connections
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def integration_route(integration) = Studio::Connections.route(integration.key)
|
|
32
|
+
|
|
33
|
+
def integration_path_for(integration) = public_send(:"#{integration_route(integration).as}_path")
|
|
34
|
+
def integration_connect_path(integration) = public_send(:"#{integration_route(integration).as}_connect_path")
|
|
35
|
+
def integration_callback_url(integration) = public_send(:"#{integration_route(integration).as}_callback_url")
|
|
36
|
+
|
|
37
|
+
def integration_disconnect_path(integration, connection)
|
|
38
|
+
public_send(:"#{integration_route(integration).as}_disconnect_path", connection)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def integrations_index_path = "/#{Studio::Integrations.mount_path}"
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -115,9 +115,21 @@ module Studio
|
|
|
115
115
|
Rails.logger.warn(
|
|
116
116
|
"[Studio::LocalReviewsController] could not provision #{email}: #{e.class}: #{e.message}"
|
|
117
117
|
)
|
|
118
|
+
# An ErrorLog too, so the miss is on the page an operator reads. The
|
|
119
|
+
# likeliest cause: Studio.local_review_role names a role this app's
|
|
120
|
+
# Studio::Account list refuses.
|
|
121
|
+
log_provisioning_failure(e)
|
|
118
122
|
nil
|
|
119
123
|
end
|
|
120
124
|
|
|
125
|
+
# Best-effort as well: a host whose error_logs table is missing or broken
|
|
126
|
+
# must not turn a logged miss into a failed mint.
|
|
127
|
+
def log_provisioning_failure(error)
|
|
128
|
+
ErrorLog.capture!(error) if defined?(::ErrorLog) && ::ErrorLog.respond_to?(:capture!)
|
|
129
|
+
rescue StandardError => e
|
|
130
|
+
Rails.logger.warn("[Studio::LocalReviewsController] could not log the miss: #{e.class}")
|
|
131
|
+
end
|
|
132
|
+
|
|
121
133
|
# A brand-new reviewer goes through the host's own new-user hook first, so
|
|
122
134
|
# the account this endpoint creates is shaped like every other account in
|
|
123
135
|
# the app (usernames, defaults, associations) — then the role is stamped on
|
|
@@ -246,3 +246,112 @@ export function loopPositionText(first, shown, total) {
|
|
|
246
246
|
const head = first + 1 === total ? `Slides ${total}` : `Slides ${first + 1} to ${total}`
|
|
247
247
|
return `${head} and ${over === 1 ? "1" : `1 to ${over}`} of ${total}`
|
|
248
248
|
}
|
|
249
|
+
|
|
250
|
+
// THE CASCADE (style: :cascade, class carousel-cascade). The row does not scroll:
|
|
251
|
+
// every slide sits in one grid cell and wears data-cascade-step, its place from the
|
|
252
|
+
// open slide, which engine.css turns into the 3D stack. A STEP is signed: 0 is the
|
|
253
|
+
// open slide, -1 and 1 its neighbours, and so on. CASCADE_REACH steps either side
|
|
254
|
+
// are in view; past them a slide's slot is "before" or "after", hidden.
|
|
255
|
+
//
|
|
256
|
+
// app/views/studio/_carousel.html.erb writes the first paint's slots with the same
|
|
257
|
+
// rule, so the two must agree (test/views/carousel_render_test.rb pins the partial).
|
|
258
|
+
export const CASCADE_REACH = 2
|
|
259
|
+
|
|
260
|
+
// A slide's step from the open one. A looping set has no ends, so the step is the
|
|
261
|
+
// short way round; a tie (an even set's far side) goes to the later side.
|
|
262
|
+
export function cascadeStep(index, active, total, loop = false) {
|
|
263
|
+
const step = index - active
|
|
264
|
+
if (!loop || !(total > 1)) return step
|
|
265
|
+
const round = wrapIndex(step, total)
|
|
266
|
+
return round > total / 2 ? round - total : round
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// Every slide's step, in row order.
|
|
270
|
+
export function cascadeSteps(total, active, loop = false) {
|
|
271
|
+
return Array.from({ length: Math.max(0, total) }, (_, index) => cascadeStep(index, active, total, loop))
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// The data-cascade-step a step is written as: the step itself in view, "before" or
|
|
275
|
+
// "after" past the reach.
|
|
276
|
+
export function cascadeSlot(step, reach = CASCADE_REACH) {
|
|
277
|
+
if (step < -reach) return "before"
|
|
278
|
+
if (step > reach) return "after"
|
|
279
|
+
return String(step)
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// The cascade's reach from its view: 5 slides in view reach 2 each side, 3 reach 1.
|
|
283
|
+
export function cascadeReach(visible) {
|
|
284
|
+
return Number(visible) === 3 ? 1 : CASCADE_REACH
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// Which slides JUMP on a move from one set of steps to the next: the ones that cross
|
|
288
|
+
// round a looping set's seam (the far left slide becoming the far right one) instead
|
|
289
|
+
// of shifting with the rest. They take no glide across the stack. Every other slide
|
|
290
|
+
// moves by the same shift, the open slide's old step turned round.
|
|
291
|
+
export function cascadeJumps(before, after, active) {
|
|
292
|
+
const shift = -(before[active] ?? 0)
|
|
293
|
+
return after.map((step, index) => step - before[index] !== shift)
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// How many slides a drag of `dx` pixels moves, against `width` pixels a step: none
|
|
297
|
+
// under the threshold, else at least one, the open slide following the pointer
|
|
298
|
+
// (a drag to the left brings the next slides in, so it moves forward).
|
|
299
|
+
export const DRAG_THRESHOLD = 40
|
|
300
|
+
export function dragSteps(dx, width) {
|
|
301
|
+
if (!(Math.abs(dx) >= DRAG_THRESHOLD)) return 0
|
|
302
|
+
const per = width > 0 ? width : 1
|
|
303
|
+
const count = Math.max(1, Math.round(Math.abs(dx) / per))
|
|
304
|
+
return dx < 0 ? count : -count
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// The slide a drag or a click takes a cascade to, from the open one: held to the
|
|
308
|
+
// ends of a set that does not loop, round the set on one that does.
|
|
309
|
+
export function cascadeTarget(active, by, total, loop = false) {
|
|
310
|
+
if (!(total > 0)) return 0
|
|
311
|
+
const to = active + by
|
|
312
|
+
if (loop) return wrapIndex(to, total)
|
|
313
|
+
return Math.min(total - 1, Math.max(0, to))
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// -- the change event ----------------------------------------------------------
|
|
317
|
+
//
|
|
318
|
+
// THE CHANGE EVENT: the region dispatches CHANGE_EVENT once each time its open slide
|
|
319
|
+
// changes, on every style, after the controller has moved data-current (a spotlight
|
|
320
|
+
// and a cascade mark the open slide; a standard row marks none). It bubbles, so a
|
|
321
|
+
// host listens on the region or the document and needs no MutationObserver:
|
|
322
|
+
//
|
|
323
|
+
// region.addEventListener("studio:carousel:change", ({ detail }) => {
|
|
324
|
+
// detail.index // the open slide, 0-based among the real slides
|
|
325
|
+
// detail.previous // the one open before
|
|
326
|
+
// detail.slide // that slide's element (never a looping row's copy)
|
|
327
|
+
// detail.total // the real slides
|
|
328
|
+
// })
|
|
329
|
+
//
|
|
330
|
+
// A standard row's "open slide" is the one at its first stop. The first paint's
|
|
331
|
+
// slide (start:) fires nothing; a row that opens elsewhere when its controller
|
|
332
|
+
// connects (a #fragment, a restored scroll) fires once. A looping row's glide round
|
|
333
|
+
// the seam fires once, for the real slide, when the row has jumped home onto it, not
|
|
334
|
+
// for the copy it rests on first. A scrolling row's glide across several slides fires
|
|
335
|
+
// for each slide it passes, as data-current moves; a cascade does not glide, so a dot
|
|
336
|
+
// or End fires once.
|
|
337
|
+
export const CHANGE_EVENT = "studio:carousel:change"
|
|
338
|
+
|
|
339
|
+
// The event's detail when the open slide moved from `previous` to `index`, else null.
|
|
340
|
+
export function changeDetail(previous, index, slides) {
|
|
341
|
+
if (!Number.isInteger(index) || index < 0 || index === previous) return null
|
|
342
|
+
const list = slides || []
|
|
343
|
+
if (index >= list.length) return null
|
|
344
|
+
return { index, previous: Number.isInteger(previous) ? previous : null, slide: list[index], total: list.length }
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// -- the cascade's press --------------------------------------------------------
|
|
348
|
+
|
|
349
|
+
// The slide a click on a cascade belongs to. A mouse press on a side slide records
|
|
350
|
+
// it (pressed), since a link whose focus already moved the stack still counts as a
|
|
351
|
+
// side slide's. A click with no press (detail 0: Enter or Space on a focused link, or
|
|
352
|
+
// a script's click()) never reads a record a press left behind: it is the slide it
|
|
353
|
+
// lands in, so Enter on the open card follows its link.
|
|
354
|
+
export function clickedSlide(pressed, detail, hit) {
|
|
355
|
+
if (detail === 0) return hit
|
|
356
|
+
return pressed ?? hit
|
|
357
|
+
}
|