@glw907/cairn-cms 0.50.0 → 0.51.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.
- package/CHANGELOG.md +40 -0
- package/dist/components/EditPage.svelte +94 -16
- package/dist/components/EditPage.svelte.d.ts +4 -1
- package/dist/components/EditorToolbar.svelte +79 -8
- package/dist/components/EditorToolbar.svelte.d.ts +10 -2
- package/dist/components/MarkdownEditor.svelte +20 -2
- package/dist/components/cairn-admin.css +57 -9
- package/dist/components/editor-highlight.d.ts +1 -0
- package/dist/components/editor-highlight.js +31 -8
- package/dist/components/markdown-directives.d.ts +10 -0
- package/dist/components/markdown-directives.js +54 -1
- package/dist/components/preview-doc.d.ts +27 -0
- package/dist/components/preview-doc.js +64 -0
- package/dist/content/compose.js +1 -0
- package/dist/content/types.d.ts +33 -0
- package/dist/diagnostics/conditions.js +24 -0
- package/dist/doctor/bin.js +30 -12
- package/dist/doctor/check-floors.d.ts +15 -0
- package/dist/doctor/check-floors.js +107 -0
- package/dist/doctor/check-probe.d.ts +3 -0
- package/dist/doctor/check-probe.js +123 -0
- package/dist/doctor/checks-github.js +1 -1
- package/dist/doctor/checks-local.d.ts +1 -0
- package/dist/doctor/checks-local.js +28 -2
- package/dist/doctor/cloudflare-api.js +2 -2
- package/dist/doctor/index.d.ts +28 -3
- package/dist/doctor/index.js +47 -6
- package/dist/doctor/types.d.ts +2 -0
- package/dist/doctor/wrangler-config.d.ts +4 -0
- package/dist/doctor/wrangler-config.js +11 -0
- package/dist/env.d.ts +2 -1
- package/dist/env.js +9 -4
- package/dist/index.d.ts +1 -1
- package/dist/sveltekit/content-routes.d.ts +5 -1
- package/dist/sveltekit/content-routes.js +25 -17
- package/dist/sveltekit/guard.d.ts +8 -2
- package/dist/sveltekit/guard.js +3 -1
- package/dist/sveltekit/nav-routes.js +3 -9
- package/dist/vite/index.d.ts +16 -0
- package/dist/vite/index.js +57 -13
- package/package.json +2 -2
- package/src/lib/components/EditPage.svelte +94 -16
- package/src/lib/components/EditorToolbar.svelte +79 -8
- package/src/lib/components/MarkdownEditor.svelte +20 -2
- package/src/lib/components/cairn-admin.css +59 -0
- package/src/lib/components/editor-highlight.ts +32 -7
- package/src/lib/components/markdown-directives.ts +51 -1
- package/src/lib/components/preview-doc.ts +82 -0
- package/src/lib/content/compose.ts +1 -0
- package/src/lib/content/types.ts +32 -0
- package/src/lib/diagnostics/conditions.ts +24 -0
- package/src/lib/doctor/bin.ts +35 -10
- package/src/lib/doctor/check-floors.ts +124 -0
- package/src/lib/doctor/check-probe.ts +138 -0
- package/src/lib/doctor/checks-github.ts +3 -1
- package/src/lib/doctor/checks-local.ts +28 -2
- package/src/lib/doctor/cloudflare-api.ts +4 -2
- package/src/lib/doctor/index.ts +67 -6
- package/src/lib/doctor/types.ts +2 -0
- package/src/lib/doctor/wrangler-config.ts +11 -0
- package/src/lib/env.ts +9 -4
- package/src/lib/index.ts +2 -0
- package/src/lib/sveltekit/content-routes.ts +29 -17
- package/src/lib/sveltekit/guard.ts +4 -2
- package/src/lib/sveltekit/nav-routes.ts +3 -10
- package/src/lib/vite/index.ts +71 -17
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,46 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project are recorded here, most recent first.
|
|
4
4
|
|
|
5
|
+
## 0.51.0
|
|
6
|
+
|
|
7
|
+
The `svelte` peer dependency floor rises from `^5.0.0` to `^5.56.3`, turning the 0.40.0 advisory
|
|
8
|
+
into an enforced range: consumer sites compile the shipped `.svelte` sources, and svelte `5.56.1`
|
|
9
|
+
miscompiles parenthesized boolean groupings. `cairn-doctor` gains a `config.dependency-floors`
|
|
10
|
+
check in its default set, which compares the lockfile's resolved `svelte` and `@sveltejs/kit`
|
|
11
|
+
versions against the peer ranges the installed engine declares.
|
|
12
|
+
|
|
13
|
+
Consumers must: raise the `svelte` devDependency range to at least `^5.56.3` (and `@sveltejs/kit`
|
|
14
|
+
to `^2.12` where it sits lower) and reinstall so the lockfile re-resolves. A site pinning svelte
|
|
15
|
+
below the floor now draws an npm peer warning or resolution failure on install, and the doctor
|
|
16
|
+
reports the below-floor version as a blocker.
|
|
17
|
+
|
|
18
|
+
The edit page's preview now renders inside a sandboxed iframe whose document links the site's own
|
|
19
|
+
stylesheets, so an entry proofs in the site's real styling without that CSS ever touching the
|
|
20
|
+
admin document. The adapter gains an optional `preview` member naming the compiled CSS URLs (a
|
|
21
|
+
Vite `?url` import resolves the hashed asset) plus `bodyClass` and `containerClass` for the site's
|
|
22
|
+
body classes and content wrapper, and a `byConcept` map overrides either class per concept for a
|
|
23
|
+
site whose posts and pages wrap content differently. While Preview shows, the sidebar steps aside
|
|
24
|
+
so the document takes the full width, and a width menu on the Preview tab sizes the frame to
|
|
25
|
+
Desktop, Tablet, Phone, or Small phone, persisted per browser.
|
|
26
|
+
|
|
27
|
+
Consumers should: wire `preview` in the adapter, referencing the sheet only through `?url` and
|
|
28
|
+
linking the same URL from the site layout, the way
|
|
29
|
+
[the adapter guide](docs/guides/define-an-adapter-and-schema.md) shows. Without the knob the
|
|
30
|
+
preview renders unstyled markup behind a one-line hint.
|
|
31
|
+
|
|
32
|
+
The editor's directive highlighting now recognizes labeled and attributed `:::` openers and fences
|
|
33
|
+
of four or more colons, where before only bare closers matched, and nested containers step their
|
|
34
|
+
band and rail tint by depth. No consumer action.
|
|
35
|
+
|
|
36
|
+
`cairn-doctor` derives its missing inputs from the repo it runs in: the backend owner and repo
|
|
37
|
+
plus the sender address come from evaluating the site's config module through the manifest bin's
|
|
38
|
+
Vite machinery, and the Cloudflare account id comes from the wrangler config, with flags and
|
|
39
|
+
environment variables taking precedence. A new `--probe <url>` flag runs a zero-side-effect live
|
|
40
|
+
check against the deployed admin's sign-in surface: the login envelope, the CSRF cookie and field,
|
|
41
|
+
and the uniform non-leak answer to a stranger's sign-in request. Consumers may: drop the `--from`
|
|
42
|
+
and `--repo` flags from doctor invocations and run `npx cairn-doctor --probe <url>` after a
|
|
43
|
+
deploy.
|
|
44
|
+
|
|
5
45
|
## 0.50.0
|
|
6
46
|
|
|
7
47
|
The admin now mounts as one catch-all route. A new `createCairnAdmin(runtime, deps)` facade
|
|
@@ -6,13 +6,16 @@ markdown editor and a live, design-accurate preview. The whole surface is one fo
|
|
|
6
6
|
remaining fields group in the sidebar under Details, Visibility (the draft boolean as the Hidden
|
|
7
7
|
toggle), and Address (the slug with the Change URL trigger). The toolbar's Write/Preview tabs
|
|
8
8
|
swap the editing surface for the rendered preview inside the same card; every visit lands on
|
|
9
|
-
Write.
|
|
9
|
+
Write. Preview renders inside a sandboxed iframe that links the site's own stylesheets (the
|
|
10
|
+
adapter's `preview` knob), takes the full content width (the sidebar hides until Write), and
|
|
11
|
+
sizes to a persisted device width picked from the toolbar's capsule. A sticky glass header
|
|
12
|
+
carries the breadcrumb, the status badges, the save-state indicator,
|
|
10
13
|
and the lifecycle actions: Save, Publish (riding the same form via formaction while edits are
|
|
11
14
|
pending), and an overflow menu for Discard and Delete. One feedback strip under the header carries the
|
|
12
15
|
transient flashes, and the editor card's footer holds the word count and the Markdown help.
|
|
13
16
|
-->
|
|
14
17
|
<script lang="ts">
|
|
15
|
-
import { untrack } from 'svelte';
|
|
18
|
+
import { flushSync, untrack } from 'svelte';
|
|
16
19
|
import { beforeNavigate } from '$app/navigation';
|
|
17
20
|
import { page } from '$app/state';
|
|
18
21
|
import CsrfField from './CsrfField.svelte';
|
|
@@ -26,6 +29,7 @@ transient flashes, and the editor card's footer holds the word count and the Mar
|
|
|
26
29
|
import MarkdownHelpDialog from './MarkdownHelpDialog.svelte';
|
|
27
30
|
import { cairnLinkCompletionSource } from './link-completion.js';
|
|
28
31
|
import { unwrapCairnLink, type FormatKind } from './markdown-format.js';
|
|
32
|
+
import { buildPreviewDoc, deviceLabel, previewDevice, previewDevices, type PreviewDeviceId } from './preview-doc.js';
|
|
29
33
|
import { directiveLineKind, findInlineDirectives } from './markdown-directives.js';
|
|
30
34
|
import type { ComponentRegistry } from '../render/registry.js';
|
|
31
35
|
import type { IconSet } from '../render/glyph.js';
|
|
@@ -97,6 +101,16 @@ transient flashes, and the editor card's footer holds the word count and the Mar
|
|
|
97
101
|
// The edit form element, for the Ctrl/Cmd+S shortcut's requestSubmit.
|
|
98
102
|
let editForm = $state<HTMLFormElement | null>(null);
|
|
99
103
|
|
|
104
|
+
// A required sidebar field hidden by Preview cannot take the browser's validation report: an
|
|
105
|
+
// invisible control is unfocusable, so the browser cancels the save silently with no message.
|
|
106
|
+
// This capture-phase invalid listener flips back to Write first, and flushSync forces the pane
|
|
107
|
+
// swap inside the event, so the report that follows the invalid events lands on a visible
|
|
108
|
+
// control and the author sees what blocked the save.
|
|
109
|
+
function onFormInvalid() {
|
|
110
|
+
if (mode === 'write') return;
|
|
111
|
+
flushSync(() => (mode = 'write'));
|
|
112
|
+
}
|
|
113
|
+
|
|
100
114
|
// The SvelteKit half of the leave guard. Registered at component init (beforeNavigate wraps
|
|
101
115
|
// onMount, so it must run synchronously here) and auto-unregistered on destroy. A submit's own
|
|
102
116
|
// navigation passes through because busy flips before it starts, and a non-edit POST's because
|
|
@@ -150,6 +164,24 @@ transient flashes, and the editor card's footer holds the word count and the Mar
|
|
|
150
164
|
let previewHtml = $state('');
|
|
151
165
|
// True after a render call threw, so the preview pane can say so instead of going blank.
|
|
152
166
|
let previewFailed = $state(false);
|
|
167
|
+
// The preview frame's device width, a per-browser preference under its own key (the legacy
|
|
168
|
+
// 'cairn-admin:preview' key from the removed split-pane preview stays untouched). Desktop is
|
|
169
|
+
// the default; the storage read sits in an effect so it never runs during SSR, and it tracks
|
|
170
|
+
// nothing reactive, so it runs once.
|
|
171
|
+
const deviceStorageKey = 'cairn-editor-preview-device';
|
|
172
|
+
let device = $state<PreviewDeviceId>('desktop');
|
|
173
|
+
$effect(() => {
|
|
174
|
+
const stored = localStorage.getItem(deviceStorageKey);
|
|
175
|
+
if (previewDevices.some((d) => d.id === stored)) device = stored as PreviewDeviceId;
|
|
176
|
+
});
|
|
177
|
+
function setDevice(id: PreviewDeviceId) {
|
|
178
|
+
device = id;
|
|
179
|
+
localStorage.setItem(deviceStorageKey, id);
|
|
180
|
+
}
|
|
181
|
+
const activeDevice = $derived(previewDevice(device));
|
|
182
|
+
// The iframe document around the rendered html: the site's stylesheets from the adapter's
|
|
183
|
+
// preview knob, or a styleless document (behind the hint below) when the site sets none.
|
|
184
|
+
const previewDoc = $derived(buildPreviewDoc(previewHtml, data.preview));
|
|
153
185
|
let insert = $state.raw<(text: string) => void>(() => {});
|
|
154
186
|
let insertLink = $state.raw<(href: string, title: string) => void>(() => {});
|
|
155
187
|
// The editor's current selection, registered by MarkdownEditor on mount; the web link dialog
|
|
@@ -388,7 +420,13 @@ transient flashes, and the editor card's footer holds the word count and the Mar
|
|
|
388
420
|
}
|
|
389
421
|
}
|
|
390
422
|
}, 150);
|
|
391
|
-
return () =>
|
|
423
|
+
return () => {
|
|
424
|
+
clearTimeout(handle);
|
|
425
|
+
// Every re-run and the final teardown invalidate the in-flight render. The entry-key reset
|
|
426
|
+
// above cannot reach this counter, so without the bump a slow render for entry A could
|
|
427
|
+
// resolve after a same-route hop and write A's html into entry B's pane.
|
|
428
|
+
previewRun++;
|
|
429
|
+
};
|
|
392
430
|
});
|
|
393
431
|
|
|
394
432
|
// Coerce a frontmatter value to a string for text/date/textarea inputs.
|
|
@@ -575,7 +613,8 @@ transient flashes, and the editor card's footer holds the word count and the Mar
|
|
|
575
613
|
bind:this={editForm}
|
|
576
614
|
onsubmit={onEditSubmit}
|
|
577
615
|
oninput={onFormInput}
|
|
578
|
-
|
|
616
|
+
oninvalidcapture={onFormInvalid}
|
|
617
|
+
class={mode === 'preview' ? '' : 'lg:grid lg:grid-cols-[1fr_20rem] lg:gap-6'}
|
|
579
618
|
>
|
|
580
619
|
<CsrfField />
|
|
581
620
|
{#if data.isNew}<input type="hidden" name="new" value="1" />{/if}
|
|
@@ -602,7 +641,7 @@ transient flashes, and the editor card's footer holds the word count and the Mar
|
|
|
602
641
|
role="group"
|
|
603
642
|
aria-label="Editor"
|
|
604
643
|
>
|
|
605
|
-
<EditorToolbar {format} {mode} onMode={setMode}>
|
|
644
|
+
<EditorToolbar {format} {mode} onMode={setMode} {device} onDevice={setDevice}>
|
|
606
645
|
{#snippet insertControls()}
|
|
607
646
|
<!-- Plain triggers only: the dialogs they open hold their own <form> elements, so the
|
|
608
647
|
dialogs themselves mount outside the edit form at the bottom of this component. -->
|
|
@@ -668,16 +707,53 @@ transient flashes, and the editor card's footer holds the word count and the Mar
|
|
|
668
707
|
/>
|
|
669
708
|
</div>
|
|
670
709
|
{#if mode === 'preview'}
|
|
671
|
-
<!--
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
710
|
+
<!-- The preview ground: recessed under the floating frame card so the page reads as a
|
|
711
|
+
sheet on the desk. tabindex 0 only while a message shows in place of the iframe;
|
|
712
|
+
with the iframe up the frame itself is the pane's focusable content (the tabpanel
|
|
713
|
+
pattern's completeness requirement). -->
|
|
714
|
+
<div
|
|
715
|
+
id="cairn-pane-preview"
|
|
716
|
+
role="tabpanel"
|
|
717
|
+
aria-labelledby="cairn-tab-preview"
|
|
718
|
+
tabindex={previewHtml && !previewFailed ? undefined : 0}
|
|
719
|
+
class="bg-base-200 px-4 py-6 lg:px-8"
|
|
720
|
+
>
|
|
721
|
+
<!-- The frame column: centered, sized by the picked device (capped at the pane), with
|
|
722
|
+
the width eased; the admin sheet's prefers-reduced-motion rule squashes the move. -->
|
|
723
|
+
<div
|
|
724
|
+
class="cairn-preview-frame mx-auto max-w-full transition-[width] duration-300"
|
|
725
|
+
style:width={activeDevice.width === null ? '100%' : `${activeDevice.width}px`}
|
|
726
|
+
>
|
|
727
|
+
{#if activeDevice.width !== null}
|
|
728
|
+
<p class="mb-2 text-right text-[0.6875rem] font-semibold uppercase tracking-[0.08em] text-[var(--color-muted)]">
|
|
729
|
+
{deviceLabel(activeDevice)}
|
|
730
|
+
</p>
|
|
731
|
+
{/if}
|
|
732
|
+
{#if !data.preview}
|
|
733
|
+
<p class="mb-2 text-xs text-[var(--color-muted)]">
|
|
734
|
+
Preview shows unstyled markup until the adapter's preview option names the site's stylesheets.
|
|
735
|
+
</p>
|
|
736
|
+
{/if}
|
|
737
|
+
<div class="rounded-box border border-[var(--cairn-card-border)] bg-base-100 overflow-hidden shadow-[var(--cairn-shadow)]">
|
|
738
|
+
{#if previewFailed}
|
|
739
|
+
<p class="p-4 text-sm text-[var(--color-muted)]">The preview could not render this content.</p>
|
|
740
|
+
{:else if !previewHtml}
|
|
741
|
+
<p class="p-4 text-sm text-[var(--color-muted)]">Nothing to preview yet.</p>
|
|
742
|
+
{:else}
|
|
743
|
+
<!-- The site's render pipeline already sanitized the html (the floor strips
|
|
744
|
+
scripts and handlers); the empty sandbox is belt and braces on top. The
|
|
745
|
+
frame document's base tag targets every link at a new tab, which the
|
|
746
|
+
sandbox (no allow-popups) blocks, so a proofing click never navigates the
|
|
747
|
+
admin or the frame itself. tabindex 0 keeps the scrollable preview
|
|
748
|
+
keyboard-reachable (an iframe is not a sequential tab stop by itself); on
|
|
749
|
+
a link-heavy page that one inert Tab stop is a deliberate tradeoff. The
|
|
750
|
+
a11y rule reads any tabindex on a non-interactive element as a smell, but
|
|
751
|
+
a scrollable region is the recognized exception. -->
|
|
752
|
+
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
|
|
753
|
+
<iframe sandbox="" tabindex="0" title="Page preview" srcdoc={previewDoc} class="block h-[70vh] w-full"></iframe>
|
|
754
|
+
{/if}
|
|
755
|
+
</div>
|
|
756
|
+
</div>
|
|
681
757
|
</div>
|
|
682
758
|
{/if}
|
|
683
759
|
<!-- The card footer, part of the same instrument frame. It stays up in Preview too, so the
|
|
@@ -696,7 +772,9 @@ transient flashes, and the editor card's footer holds the word count and the Mar
|
|
|
696
772
|
</div>
|
|
697
773
|
</div>
|
|
698
774
|
|
|
699
|
-
|
|
775
|
+
<!-- Preview takes the full surface: the sidebar hides (never unmounts, so the uncontrolled
|
|
776
|
+
field edits survive the round trip) and the editor column above spans the whole width. -->
|
|
777
|
+
<aside class="lg:order-2 mt-4 lg:mt-0" class:hidden={mode === 'preview'}>
|
|
700
778
|
<!-- One sidebar card, three labeled groups. Each group is its own fieldset so its eyebrow is
|
|
701
779
|
a real legend that screen readers announce with the fields it holds. -->
|
|
702
780
|
<div class="rounded-box border border-[var(--cairn-card-border)] bg-base-100 flex flex-col gap-5 p-4 shadow-[var(--cairn-shadow)]">
|
|
@@ -27,7 +27,10 @@ interface Props {
|
|
|
27
27
|
* remaining fields group in the sidebar under Details, Visibility (the draft boolean as the Hidden
|
|
28
28
|
* toggle), and Address (the slug with the Change URL trigger). The toolbar's Write/Preview tabs
|
|
29
29
|
* swap the editing surface for the rendered preview inside the same card; every visit lands on
|
|
30
|
-
* Write.
|
|
30
|
+
* Write. Preview renders inside a sandboxed iframe that links the site's own stylesheets (the
|
|
31
|
+
* adapter's `preview` knob), takes the full content width (the sidebar hides until Write), and
|
|
32
|
+
* sizes to a persisted device width picked from the toolbar's capsule. A sticky glass header
|
|
33
|
+
* carries the breadcrumb, the status badges, the save-state indicator,
|
|
31
34
|
* and the lifecycle actions: Save, Publish (riding the same form via formaction while edits are
|
|
32
35
|
* pending), and an overflow menu for Discard and Delete. One feedback strip under the header carries the
|
|
33
36
|
* transient flashes, and the editor card's footer holds the word count and the Markdown help.
|
|
@@ -3,12 +3,15 @@
|
|
|
3
3
|
The editor card's instrument strip. Three button groups divided by hairlines (Text, Structure with a
|
|
4
4
|
More overflow menu, then the host's Insert controls) and the Write/Preview segmented control pinned
|
|
5
5
|
right. Format buttons ask the host to transform the editor's current selection; the host supplies the
|
|
6
|
-
Insert group through the `insertControls` snippet so the strip stays free of picker wiring.
|
|
7
|
-
|
|
6
|
+
Insert group through the `insertControls` snippet so the strip stays free of picker wiring. While
|
|
7
|
+
Preview shows, a device trigger joins the segmented capsule and opens a popover menu of preview
|
|
8
|
+
widths, reported to the host through `onDevice`. The glyphs are stroke SVG icons in the admin's
|
|
9
|
+
house style (24x24 viewBox, `currentColor`, round caps).
|
|
8
10
|
-->
|
|
9
11
|
<script lang="ts">
|
|
10
12
|
import type { Snippet } from 'svelte';
|
|
11
13
|
import type { FormatKind } from './markdown-format.js';
|
|
14
|
+
import { deviceLabel, previewDevice, previewDevices, type PreviewDeviceId } from './preview-doc.js';
|
|
12
15
|
|
|
13
16
|
interface Props {
|
|
14
17
|
/** Apply a markdown transform to the editor's current selection. */
|
|
@@ -17,11 +20,16 @@ are stroke SVG icons in the admin's house style (24x24 viewBox, `currentColor`,
|
|
|
17
20
|
mode: 'write' | 'preview';
|
|
18
21
|
/** Ask the host to switch panes. */
|
|
19
22
|
onMode: (m: 'write' | 'preview') => void;
|
|
23
|
+
/** The active preview-frame device, shown on the device trigger. Desktop when absent. */
|
|
24
|
+
device?: PreviewDeviceId;
|
|
25
|
+
/** Pick a preview-frame width. When set, a device trigger joins the Write/Preview capsule
|
|
26
|
+
* while Preview shows. */
|
|
27
|
+
onDevice?: (id: PreviewDeviceId) => void;
|
|
20
28
|
/** The host's Insert controls (link picker, component insert, image), rendered in the Insert group. */
|
|
21
29
|
insertControls?: Snippet;
|
|
22
30
|
}
|
|
23
31
|
|
|
24
|
-
let { format, mode, onMode, insertControls }: Props = $props();
|
|
32
|
+
let { format, mode, onMode, device = 'desktop', onDevice, insertControls }: Props = $props();
|
|
25
33
|
|
|
26
34
|
// Each icon is a set of stroke `<path>` d-strings rendered into the shared 24x24 svg below, so the
|
|
27
35
|
// markup stays declarative (no per-icon raw html). Paths follow the house outline style.
|
|
@@ -89,6 +97,19 @@ are stroke SVG icons in the admin's house style (24x24 viewBox, `currentColor`,
|
|
|
89
97
|
if (moreMenu?.matches(':popover-open')) moreMenu.hidePopover();
|
|
90
98
|
}
|
|
91
99
|
|
|
100
|
+
// The device menu's popover element and its open state, mirrored from the toggle event into
|
|
101
|
+
// aria-expanded on the trigger (the More menu's pattern).
|
|
102
|
+
let deviceMenu = $state<HTMLUListElement | null>(null);
|
|
103
|
+
let deviceOpen = $state(false);
|
|
104
|
+
const activeDevice = $derived(previewDevice(device));
|
|
105
|
+
// Whether the device trigger renders as the capsule's third segment.
|
|
106
|
+
const showDeviceTrigger = $derived(mode === 'preview' && !!onDevice);
|
|
107
|
+
|
|
108
|
+
function pickDevice(id: PreviewDeviceId) {
|
|
109
|
+
onDevice?.(id);
|
|
110
|
+
if (deviceMenu?.matches(':popover-open')) deviceMenu.hidePopover();
|
|
111
|
+
}
|
|
112
|
+
|
|
92
113
|
let toolbarEl = $state<HTMLDivElement | null>(null);
|
|
93
114
|
// The roving tab stop's position among the strip's enabled top-level controls. The Write/Preview
|
|
94
115
|
// tabs join the toolbar's roving order instead of managing their own arrow keys: the ARIA toolbar
|
|
@@ -156,13 +177,20 @@ are stroke SVG icons in the admin's house style (24x24 viewBox, `currentColor`,
|
|
|
156
177
|
{/snippet}
|
|
157
178
|
|
|
158
179
|
{#snippet tab(m: 'write' | 'preview', label: string)}
|
|
180
|
+
<!-- The capsule look is manual rounding, not daisyUI's .join: join radii follow direct
|
|
181
|
+
children, and the device trigger must sit outside the tablist (ARIA required children),
|
|
182
|
+
so the segments square their shared edges themselves. Preview squares its right edge only
|
|
183
|
+
while the trigger extends the capsule. -->
|
|
159
184
|
<button
|
|
160
185
|
type="button"
|
|
161
186
|
role="tab"
|
|
162
187
|
id={`cairn-tab-${m}`}
|
|
163
188
|
aria-selected={mode === m}
|
|
164
189
|
aria-controls={`cairn-pane-${m}`}
|
|
165
|
-
class="
|
|
190
|
+
class="btn btn-sm {mode === m ? 'btn-active' : 'btn-ghost'}"
|
|
191
|
+
class:rounded-r-none={m === 'write' || showDeviceTrigger}
|
|
192
|
+
class:rounded-l-none={m === 'preview'}
|
|
193
|
+
class:-ml-px={m === 'preview'}
|
|
166
194
|
onclick={() => onMode(m)}
|
|
167
195
|
>
|
|
168
196
|
{label}
|
|
@@ -230,9 +258,52 @@ are stroke SVG icons in the admin's house style (24x24 viewBox, `currentColor`,
|
|
|
230
258
|
{/if}
|
|
231
259
|
|
|
232
260
|
<!-- The host renders the matching tabpanels (#cairn-pane-write and #cairn-pane-preview) below
|
|
233
|
-
the strip inside the same editor card.
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
261
|
+
the strip inside the same editor card. The tablist wrapper holds ONLY the two tabs (ARIA
|
|
262
|
+
required children: anything else in a tablist makes assistive tech miscount the tabs).
|
|
263
|
+
While Preview shows, the device trigger reads as the capsule's third segment from the
|
|
264
|
+
flex row right after the wrapper; it is a plain button, not a tab. -->
|
|
265
|
+
<div class="ml-auto flex items-center">
|
|
266
|
+
<div role="tablist" aria-label="Editor view" class="flex items-center">
|
|
267
|
+
{@render tab('write', 'Write')}
|
|
268
|
+
{@render tab('preview', 'Preview')}
|
|
269
|
+
</div>
|
|
270
|
+
{#if showDeviceTrigger}
|
|
271
|
+
<button
|
|
272
|
+
type="button"
|
|
273
|
+
class="btn btn-sm btn-ghost gap-1 rounded-l-none -ml-px"
|
|
274
|
+
title="Preview width"
|
|
275
|
+
aria-expanded={deviceOpen}
|
|
276
|
+
popovertarget="cairn-preview-device-menu"
|
|
277
|
+
style="anchor-name:--cairn-preview-device"
|
|
278
|
+
>
|
|
279
|
+
<span class="sr-only">Preview width:</span>
|
|
280
|
+
{activeDevice.label}
|
|
281
|
+
{@render strokeIcon(['m6 9 6 6 6-6'])}
|
|
282
|
+
</button>
|
|
283
|
+
{/if}
|
|
237
284
|
</div>
|
|
285
|
+
{#if showDeviceTrigger}
|
|
286
|
+
<!-- The device list mirrors the More menu exactly: a DaisyUI v5 popover dropdown of plain
|
|
287
|
+
buttons, with the active pick carried by aria-pressed and the check glyph. Deliberately
|
|
288
|
+
NOT the ARIA menu pattern: menu roles promise interactions this list does not have. -->
|
|
289
|
+
<ul
|
|
290
|
+
bind:this={deviceMenu}
|
|
291
|
+
popover="auto"
|
|
292
|
+
id="cairn-preview-device-menu"
|
|
293
|
+
style="position-anchor:--cairn-preview-device"
|
|
294
|
+
ontoggle={(e) => (deviceOpen = e.newState === 'open')}
|
|
295
|
+
class="dropdown dropdown-end menu menu-sm bg-base-100 rounded-box w-44 border border-[var(--cairn-card-border)] p-1 shadow-[var(--cairn-shadow)]"
|
|
296
|
+
>
|
|
297
|
+
{#each previewDevices as d (d.id)}
|
|
298
|
+
<li>
|
|
299
|
+
<button type="button" aria-pressed={device === d.id} onclick={() => pickDevice(d.id)}>
|
|
300
|
+
<span class="grow">{deviceLabel(d)}</span>
|
|
301
|
+
{#if device === d.id}
|
|
302
|
+
{@render strokeIcon(['M20 6 9 17l-5-5'])}
|
|
303
|
+
{/if}
|
|
304
|
+
</button>
|
|
305
|
+
</li>
|
|
306
|
+
{/each}
|
|
307
|
+
</ul>
|
|
308
|
+
{/if}
|
|
238
309
|
</div>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
import type { FormatKind } from './markdown-format.js';
|
|
3
|
+
import { type PreviewDeviceId } from './preview-doc.js';
|
|
3
4
|
interface Props {
|
|
4
5
|
/** Apply a markdown transform to the editor's current selection. */
|
|
5
6
|
format: (kind: FormatKind) => void;
|
|
@@ -7,6 +8,11 @@ interface Props {
|
|
|
7
8
|
mode: 'write' | 'preview';
|
|
8
9
|
/** Ask the host to switch panes. */
|
|
9
10
|
onMode: (m: 'write' | 'preview') => void;
|
|
11
|
+
/** The active preview-frame device, shown on the device trigger. Desktop when absent. */
|
|
12
|
+
device?: PreviewDeviceId;
|
|
13
|
+
/** Pick a preview-frame width. When set, a device trigger joins the Write/Preview capsule
|
|
14
|
+
* while Preview shows. */
|
|
15
|
+
onDevice?: (id: PreviewDeviceId) => void;
|
|
10
16
|
/** The host's Insert controls (link picker, component insert, image), rendered in the Insert group. */
|
|
11
17
|
insertControls?: Snippet;
|
|
12
18
|
}
|
|
@@ -14,8 +20,10 @@ interface Props {
|
|
|
14
20
|
* The editor card's instrument strip. Three button groups divided by hairlines (Text, Structure with a
|
|
15
21
|
* More overflow menu, then the host's Insert controls) and the Write/Preview segmented control pinned
|
|
16
22
|
* right. Format buttons ask the host to transform the editor's current selection; the host supplies the
|
|
17
|
-
* Insert group through the `insertControls` snippet so the strip stays free of picker wiring.
|
|
18
|
-
*
|
|
23
|
+
* Insert group through the `insertControls` snippet so the strip stays free of picker wiring. While
|
|
24
|
+
* Preview shows, a device trigger joins the segmented capsule and opens a popover menu of preview
|
|
25
|
+
* widths, reported to the host through `onDevice`. The glyphs are stroke SVG icons in the admin's
|
|
26
|
+
* house style (24x24 viewBox, `currentColor`, round caps).
|
|
19
27
|
*/
|
|
20
28
|
declare const EditorToolbar: import("svelte").Component<Props, {}, "">;
|
|
21
29
|
type EditorToolbar = ReturnType<typeof EditorToolbar>;
|
|
@@ -61,9 +61,16 @@ through the adapter's render. Swapping the editor stays a one-file change.
|
|
|
61
61
|
// Mirror the admin theme into CodeMirror's own dark flag, so its base chrome (the autocomplete
|
|
62
62
|
// tooltip above all) renders dark-on-dark instead of light-on-dark.
|
|
63
63
|
const isDark = host.closest('[data-theme]')?.getAttribute('data-theme')?.includes('dark') ?? false;
|
|
64
|
-
// The directive machinery
|
|
64
|
+
// The directive machinery treatment. The fence bands and content rails step their alpha by
|
|
65
|
+
// nesting depth through the per-theme vars in cairn-admin.css; the fallbacks are the light
|
|
66
|
+
// values, so the editor still renders sensibly outside an admin theme wrapper. The deeper
|
|
67
|
+
// bands swap in a darker ink (--cairn-directive-ink-N) to hold AA on their own tint.
|
|
68
|
+
const band = (depth: number, fallback: string) =>
|
|
69
|
+
`color-mix(in oklab, var(--color-accent) var(--cairn-directive-band-${depth}, ${fallback}), transparent)`;
|
|
70
|
+
const rail = (depth: number, fallback: string) =>
|
|
71
|
+
`inset 2px 0 0 0 color-mix(in oklab, var(--color-accent) var(--cairn-directive-rail-${depth}, ${fallback}), transparent)`;
|
|
65
72
|
const directiveInk = {
|
|
66
|
-
backgroundColor:
|
|
73
|
+
backgroundColor: band(1, '8%'),
|
|
67
74
|
color: 'var(--color-accent)',
|
|
68
75
|
};
|
|
69
76
|
const theme = EditorView.theme(
|
|
@@ -90,6 +97,17 @@ through the adapter's render. Swapping the editor stays a one-file change.
|
|
|
90
97
|
},
|
|
91
98
|
'.cm-line': { padding: '0' },
|
|
92
99
|
'.cm-cairn-directive-fence': directiveInk,
|
|
100
|
+
'.cm-cairn-directive-fence.cm-cairn-depth-2': {
|
|
101
|
+
backgroundColor: band(2, '14%'),
|
|
102
|
+
color: 'var(--cairn-directive-ink-2, oklch(50% 0.16 300))',
|
|
103
|
+
},
|
|
104
|
+
'.cm-cairn-directive-fence.cm-cairn-depth-3': {
|
|
105
|
+
backgroundColor: band(3, '20%'),
|
|
106
|
+
color: 'var(--cairn-directive-ink-3, oklch(48% 0.16 300))',
|
|
107
|
+
},
|
|
108
|
+
'.cm-cairn-directive-content.cm-cairn-depth-1': { boxShadow: rail(1, '75%') },
|
|
109
|
+
'.cm-cairn-directive-content.cm-cairn-depth-2': { boxShadow: rail(2, '82%') },
|
|
110
|
+
'.cm-cairn-directive-content.cm-cairn-depth-3': { boxShadow: rail(3, '90%') },
|
|
93
111
|
'.cm-cairn-directive-leaf': directiveInk,
|
|
94
112
|
'.cm-cairn-directive-inline': directiveInk,
|
|
95
113
|
},
|
|
@@ -176,6 +176,14 @@
|
|
|
176
176
|
outline-offset: -1px;
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
+
:where([data-theme="cairn-admin"], [data-theme="cairn-admin-dark"]) .menu li > button:not(.btn) {
|
|
180
|
+
font: inherit;
|
|
181
|
+
color: inherit;
|
|
182
|
+
text-align: start;
|
|
183
|
+
background-color: #0000;
|
|
184
|
+
border: 0 solid;
|
|
185
|
+
}
|
|
186
|
+
|
|
179
187
|
:where([data-theme="cairn-admin"], [data-theme="cairn-admin-dark"]) :is(a, button, input, textarea, select, summary, [tabindex]) {
|
|
180
188
|
scroll-margin-top: 8.5rem;
|
|
181
189
|
}
|
|
@@ -3400,15 +3408,6 @@
|
|
|
3400
3408
|
}
|
|
3401
3409
|
}
|
|
3402
3410
|
|
|
3403
|
-
:where([data-theme='cairn-admin'], [data-theme='cairn-admin-dark']) .join-item:where(:not(:first-child, :disabled, [disabled], .btn-disabled)) {
|
|
3404
|
-
margin-block-start: 0;
|
|
3405
|
-
margin-inline-start: calc(var(--border, 1px) * -1);
|
|
3406
|
-
}
|
|
3407
|
-
|
|
3408
|
-
:where([data-theme='cairn-admin'], [data-theme='cairn-admin-dark']) .join-item:where(:is(:disabled, [disabled], .btn-disabled)) {
|
|
3409
|
-
border-width: var(--border, 1px) 0 var(--border, 1px) var(--border, 1px);
|
|
3410
|
-
}
|
|
3411
|
-
|
|
3412
3411
|
@layer daisyui.l1.l2.l3 {
|
|
3413
3412
|
:where([data-theme='cairn-admin'], [data-theme='cairn-admin-dark']) .modal-action {
|
|
3414
3413
|
justify-content: flex-end;
|
|
@@ -3503,6 +3502,10 @@
|
|
|
3503
3502
|
margin-bottom: calc(var(--spacing) * 7);
|
|
3504
3503
|
}
|
|
3505
3504
|
|
|
3505
|
+
:where([data-theme='cairn-admin'], [data-theme='cairn-admin-dark']) .-ml-px {
|
|
3506
|
+
margin-left: -1px;
|
|
3507
|
+
}
|
|
3508
|
+
|
|
3506
3509
|
:where([data-theme='cairn-admin'], [data-theme='cairn-admin-dark']) .ml-1 {
|
|
3507
3510
|
margin-left: calc(var(--spacing) * 1);
|
|
3508
3511
|
}
|
|
@@ -3919,6 +3922,10 @@
|
|
|
3919
3922
|
height: calc(var(--spacing) * 16);
|
|
3920
3923
|
}
|
|
3921
3924
|
|
|
3925
|
+
:where([data-theme='cairn-admin'], [data-theme='cairn-admin-dark']) .h-\[70vh\] {
|
|
3926
|
+
height: 70vh;
|
|
3927
|
+
}
|
|
3928
|
+
|
|
3922
3929
|
:where([data-theme='cairn-admin'], [data-theme='cairn-admin-dark']) .max-h-\[60vh\] {
|
|
3923
3930
|
max-height: 60vh;
|
|
3924
3931
|
}
|
|
@@ -4037,6 +4044,10 @@
|
|
|
4037
4044
|
max-width: 30%;
|
|
4038
4045
|
}
|
|
4039
4046
|
|
|
4047
|
+
:where([data-theme='cairn-admin'], [data-theme='cairn-admin-dark']) .max-w-full {
|
|
4048
|
+
max-width: 100%;
|
|
4049
|
+
}
|
|
4050
|
+
|
|
4040
4051
|
:where([data-theme='cairn-admin'], [data-theme='cairn-admin-dark']) .max-w-md {
|
|
4041
4052
|
max-width: var(--container-md);
|
|
4042
4053
|
}
|
|
@@ -4337,6 +4348,16 @@
|
|
|
4337
4348
|
border-radius: var(--radius-xl);
|
|
4338
4349
|
}
|
|
4339
4350
|
|
|
4351
|
+
:where([data-theme='cairn-admin'], [data-theme='cairn-admin-dark']) .rounded-l-none {
|
|
4352
|
+
border-top-left-radius: 0;
|
|
4353
|
+
border-bottom-left-radius: 0;
|
|
4354
|
+
}
|
|
4355
|
+
|
|
4356
|
+
:where([data-theme='cairn-admin'], [data-theme='cairn-admin-dark']) .rounded-r-none {
|
|
4357
|
+
border-top-right-radius: 0;
|
|
4358
|
+
border-bottom-right-radius: 0;
|
|
4359
|
+
}
|
|
4360
|
+
|
|
4340
4361
|
:where([data-theme='cairn-admin'], [data-theme='cairn-admin-dark']) .border {
|
|
4341
4362
|
border-style: var(--tw-border-style);
|
|
4342
4363
|
border-width: 1px;
|
|
@@ -4996,6 +5017,12 @@
|
|
|
4996
5017
|
transition-duration: var(--tw-duration, var(--default-transition-duration));
|
|
4997
5018
|
}
|
|
4998
5019
|
|
|
5020
|
+
:where([data-theme='cairn-admin'], [data-theme='cairn-admin-dark']) .transition-\[width\] {
|
|
5021
|
+
transition-property: width;
|
|
5022
|
+
transition-timing-function: var(--tw-ease, var(--default-transition-timing-function));
|
|
5023
|
+
transition-duration: var(--tw-duration, var(--default-transition-duration));
|
|
5024
|
+
}
|
|
5025
|
+
|
|
4999
5026
|
:where([data-theme='cairn-admin'], [data-theme='cairn-admin-dark']) .transition-all {
|
|
5000
5027
|
transition-property: all;
|
|
5001
5028
|
transition-timing-function: var(--tw-ease, var(--default-transition-timing-function));
|
|
@@ -5418,6 +5445,14 @@
|
|
|
5418
5445
|
--color-secondary-content: oklch(98% .004 75);
|
|
5419
5446
|
--color-accent: oklch(54% .16 300);
|
|
5420
5447
|
--color-accent-content: oklch(98% .012 300);
|
|
5448
|
+
--cairn-directive-band-1: 8%;
|
|
5449
|
+
--cairn-directive-band-2: 14%;
|
|
5450
|
+
--cairn-directive-band-3: 20%;
|
|
5451
|
+
--cairn-directive-ink-2: oklch(50% .16 300);
|
|
5452
|
+
--cairn-directive-ink-3: oklch(48% .16 300);
|
|
5453
|
+
--cairn-directive-rail-1: 75%;
|
|
5454
|
+
--cairn-directive-rail-2: 82%;
|
|
5455
|
+
--cairn-directive-rail-3: 90%;
|
|
5421
5456
|
--color-neutral: oklch(32% .012 75);
|
|
5422
5457
|
--color-neutral-content: oklch(96% .004 75);
|
|
5423
5458
|
--color-info: oklch(52% .12 240);
|
|
@@ -5459,6 +5494,14 @@
|
|
|
5459
5494
|
--color-secondary-content: oklch(20% .008 75);
|
|
5460
5495
|
--color-accent: oklch(70% .14 300);
|
|
5461
5496
|
--color-accent-content: oklch(20% .04 300);
|
|
5497
|
+
--cairn-directive-band-1: 10%;
|
|
5498
|
+
--cairn-directive-band-2: 16%;
|
|
5499
|
+
--cairn-directive-band-3: 22%;
|
|
5500
|
+
--cairn-directive-ink-2: oklch(74% .14 300);
|
|
5501
|
+
--cairn-directive-ink-3: oklch(78% .14 300);
|
|
5502
|
+
--cairn-directive-rail-1: 65%;
|
|
5503
|
+
--cairn-directive-rail-2: 75%;
|
|
5504
|
+
--cairn-directive-rail-3: 85%;
|
|
5462
5505
|
--color-neutral: oklch(80% .01 75);
|
|
5463
5506
|
--color-neutral-content: oklch(22% .008 75);
|
|
5464
5507
|
--color-info: oklch(72% .12 240);
|
|
@@ -5487,6 +5530,11 @@
|
|
|
5487
5530
|
box-sizing: border-box;
|
|
5488
5531
|
}
|
|
5489
5532
|
|
|
5533
|
+
:where([data-theme="cairn-admin"], [data-theme="cairn-admin-dark"]) .menu li > :is(button, a):focus-visible {
|
|
5534
|
+
outline: 2px solid var(--color-primary);
|
|
5535
|
+
outline-offset: -2px;
|
|
5536
|
+
}
|
|
5537
|
+
|
|
5490
5538
|
@media (prefers-reduced-motion: reduce) {
|
|
5491
5539
|
[data-theme="cairn-admin"] *, [data-theme="cairn-admin-dark"] * {
|
|
5492
5540
|
scroll-behavior: auto !important;
|
|
@@ -5,5 +5,6 @@ export declare function cairnHighlightStyle(): HighlightStyle;
|
|
|
5
5
|
/** Line and mark decorations flagging remark-directive machinery. */
|
|
6
6
|
export declare function cairnDirectivePlugin(): ViewPlugin<{
|
|
7
7
|
decorations: DecorationSet;
|
|
8
|
+
depths: (number | null)[];
|
|
8
9
|
update(update: ViewUpdate): void;
|
|
9
10
|
}, undefined>;
|