@jant/core 0.6.14 → 0.6.15
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/bin/commands/import-site.js +81 -13
- package/bin/commands/migrate.js +55 -0
- package/bin/commands/posts/rebuild-html.js +184 -0
- package/bin/commands/site/snapshot/import.js +14 -10
- package/bin/lib/d1-query.js +23 -5
- package/bin/lib/migration-runner.js +29 -7
- package/bin/lib/node-database.js +32 -0
- package/bin/lib/site-snapshot.js +347 -46
- package/bin/lib/sql-export.js +1 -1
- package/bin/lib/thread-collection-migration.js +326 -0
- package/dist/app-BxCOR3Uc.js +6 -0
- package/dist/{app-2i7-WQHg.js → app-C-oi_t8W.js} +7408 -6343
- package/dist/client/.vite/manifest.json +3 -3
- package/dist/client/_assets/client-B_eGKN5p.css +2 -0
- package/dist/client/_assets/{client-BvID5ucz.js → client-DxY5BFe8.js} +58 -37
- package/dist/client/_assets/client-auth-CakPESv9.js +5533 -0
- package/dist/{export-DWn149b7.js → export-CsFx6F_M.js} +1259 -125
- package/dist/{github-sync-Ckk0sJxK.js → github-sync-Cq1pzzOI.js} +1 -1
- package/dist/{github-sync-C0zyF6XS.js → github-sync-ppWXN3jb.js} +2 -2
- package/dist/index.js +3 -3
- package/dist/node.js +5 -5
- package/package.json +11 -10
- package/src/__tests__/bin/posts-rebuild-html.test.ts +137 -0
- package/src/__tests__/dev-navigation-defaults.test.ts +22 -0
- package/src/__tests__/export-hugo-build.test.ts +63 -4
- package/src/__tests__/export-import-roundtrip.test.ts +6 -4
- package/src/__tests__/export-service.test.ts +142 -9
- package/src/__tests__/helpers/app.ts +3 -0
- package/src/__tests__/helpers/export-fixtures.ts +2 -0
- package/src/__tests__/import-site-command.test.ts +65 -0
- package/src/__tests__/vite-config.test.ts +45 -0
- package/src/app.tsx +16 -3
- package/src/client/__tests__/collection-created-notice.test.ts +36 -0
- package/src/client/__tests__/collection-form-bridge.test.ts +10 -1
- package/src/client/__tests__/collection-page-actions.test.ts +71 -2
- package/src/client/__tests__/compose-bridge.test.ts +64 -0
- package/src/client/__tests__/feed-video-player.test.ts +16 -1
- package/src/client/__tests__/footnote-rail.test.ts +472 -0
- package/src/client/__tests__/hydrate-partial.test.ts +3 -0
- package/src/client/__tests__/toast.test.ts +18 -1
- package/src/client/collection-created-notice.ts +66 -0
- package/src/client/collection-form-bridge.ts +17 -0
- package/src/client/collection-navigation.ts +44 -0
- package/src/client/collection-page-actions.ts +57 -1
- package/src/client/components/__tests__/jant-collection-directory.test.ts +155 -6
- package/src/client/components/__tests__/jant-compose-dialog.test.ts +370 -5
- package/src/client/components/__tests__/jant-compose-editor.test.ts +97 -0
- package/src/client/components/__tests__/jant-compose-fullscreen.test.ts +104 -0
- package/src/client/components/__tests__/jant-config-editor.test.ts +405 -0
- package/src/client/components/__tests__/jant-media-lightbox.test.ts +121 -0
- package/src/client/components/__tests__/jant-nav-manager.test.ts +538 -2
- package/src/client/components/__tests__/jant-post-form.test.ts +2 -2
- package/src/client/components/__tests__/jant-post-menu.test.ts +47 -5
- package/src/client/components/__tests__/jant-settings-avatar.test.ts +2 -2
- package/src/client/components/__tests__/jant-settings-general.test.ts +3 -3
- package/src/client/components/collection-manager-types.ts +9 -3
- package/src/client/components/compose-types.ts +8 -0
- package/src/client/components/jant-collection-directory.ts +165 -30
- package/src/client/components/jant-command-palette.ts +2 -1
- package/src/client/components/jant-compose-dialog.ts +85 -21
- package/src/client/components/jant-compose-editor.ts +13 -7
- package/src/client/components/jant-compose-fullscreen.ts +24 -4
- package/src/client/components/jant-config-editor.ts +722 -0
- package/src/client/components/jant-media-lightbox.ts +100 -18
- package/src/client/components/jant-nav-manager.ts +1283 -54
- package/src/client/components/jant-post-form.ts +3 -3
- package/src/client/components/jant-post-menu.ts +86 -74
- package/src/client/components/nav-manager-types.ts +51 -2
- package/src/client/components/post-form-types.ts +1 -1
- package/src/client/compose-bridge.ts +4 -1
- package/src/client/feed-video-player.ts +62 -2
- package/src/client/footnote-rail.ts +478 -0
- package/src/client/hydrate-partial.ts +2 -0
- package/src/client/media-lightbox-events.ts +63 -0
- package/src/client/site-header-fragment.ts +38 -0
- package/src/client/tiptap/__tests__/blockquote-editing.test.ts +201 -0
- package/src/client/tiptap/__tests__/clear-formatting.test.ts +168 -0
- package/src/client/tiptap/__tests__/list-editing.test.ts +447 -0
- package/src/client/tiptap/__tests__/markdown-clipboard.test.ts +727 -4
- package/src/client/tiptap/__tests__/table-controls.test.ts +263 -0
- package/src/client/tiptap/__tests__/table-size-picker.test.ts +179 -0
- package/src/client/tiptap/bubble-menu.ts +88 -10
- package/src/client/tiptap/continuous-lists.ts +102 -0
- package/src/client/tiptap/create-editor.ts +3 -0
- package/src/client/tiptap/extensions.ts +14 -5
- package/src/client/tiptap/markdown-clipboard.ts +608 -11
- package/src/client/tiptap/slash-commands.ts +8 -1
- package/src/client/tiptap/structural-keymap.ts +211 -0
- package/src/client/tiptap/tab-indent.ts +8 -22
- package/src/client/tiptap/table-control-labels.ts +30 -0
- package/src/client/tiptap/table-controls.ts +537 -0
- package/src/client/tiptap/table-size-picker.ts +254 -0
- package/src/client/toast.ts +8 -6
- package/src/client-auth.ts +1 -0
- package/src/client.ts +1 -0
- package/src/db/__tests__/d1-query.test.ts +43 -1
- package/src/db/__tests__/migration-runner.test.ts +63 -0
- package/src/db/__tests__/migrations.test.ts +469 -0
- package/src/db/__tests__/thread-collection-migration.test.ts +364 -0
- package/src/db/migrations/0027_old_blue_blade.sql +39 -0
- package/src/db/migrations/0028_superb_post.sql +2 -0
- package/src/db/migrations/0029_boring_magma.sql +1 -0
- package/src/db/migrations/0030_typical_vivisector.sql +50 -0
- package/src/db/migrations/meta/0027_snapshot.json +2511 -0
- package/src/db/migrations/meta/0028_snapshot.json +2511 -0
- package/src/db/migrations/meta/0029_snapshot.json +2519 -0
- package/src/db/migrations/meta/0030_snapshot.json +2541 -0
- package/src/db/migrations/meta/_journal.json +28 -0
- package/src/db/migrations/pg/0025_moaning_epoch.sql +39 -0
- package/src/db/migrations/pg/0026_talented_killer_shrike.sql +2 -0
- package/src/db/migrations/pg/0027_short_cannonball.sql +1 -0
- package/src/db/migrations/pg/0028_perfect_sharon_carter.sql +27 -0
- package/src/db/migrations/pg/meta/0025_snapshot.json +3204 -0
- package/src/db/migrations/pg/meta/0026_snapshot.json +3204 -0
- package/src/db/migrations/pg/meta/0027_snapshot.json +3211 -0
- package/src/db/migrations/pg/meta/0028_snapshot.json +3248 -0
- package/src/db/migrations/pg/meta/_journal.json +28 -0
- package/src/db/pg/schema.ts +28 -20
- package/src/db/rehearsal-fixtures/demo-current.json +39 -4
- package/src/db/rehearsal-fixtures/demo-current.sql +121 -6
- package/src/db/schema.ts +28 -20
- package/src/i18n/__tests__/detect.test.ts +8 -2
- package/src/i18n/detect.ts +14 -5
- package/src/i18n/locales/public/en.po +133 -30
- package/src/i18n/locales/public/en.ts +1 -1
- package/src/i18n/locales/public/zh-Hans.po +128 -25
- package/src/i18n/locales/public/zh-Hans.ts +1 -1
- package/src/i18n/locales/public/zh-Hant.po +128 -25
- package/src/i18n/locales/public/zh-Hant.ts +1 -1
- package/src/i18n/locales/settings/en.po +513 -10
- package/src/i18n/locales/settings/en.ts +1 -1
- package/src/i18n/locales/settings/zh-Hans.po +515 -12
- package/src/i18n/locales/settings/zh-Hans.ts +1 -1
- package/src/i18n/locales/settings/zh-Hant.po +515 -12
- package/src/i18n/locales/settings/zh-Hant.ts +1 -1
- package/src/lib/__tests__/api-settings.test.ts +299 -0
- package/src/lib/__tests__/constants.test.ts +5 -0
- package/src/lib/__tests__/feed-policy.test.ts +25 -0
- package/src/lib/__tests__/footnotes-upgrade.test.ts +181 -0
- package/src/lib/__tests__/markdown-roundtrip-embed.test.ts +61 -0
- package/src/lib/__tests__/markdown-to-tiptap.test.ts +32 -4
- package/src/lib/__tests__/markdown.test.ts +8 -6
- package/src/lib/__tests__/navigation.test.ts +59 -2
- package/src/lib/__tests__/post-body-html.test.ts +176 -0
- package/src/lib/__tests__/post-display.test.ts +64 -0
- package/src/lib/__tests__/resolve-config.test.ts +113 -1
- package/src/lib/__tests__/summary.test.ts +82 -0
- package/src/lib/__tests__/timeline.test.ts +109 -70
- package/src/lib/__tests__/timezones.test.ts +31 -3
- package/src/lib/__tests__/tiptap-render.test.ts +268 -9
- package/src/lib/__tests__/tiptap-to-markdown.test.ts +6 -0
- package/src/lib/__tests__/view.test.ts +53 -0
- package/src/lib/__tests__/worker-response-cache.test.ts +18 -1
- package/src/lib/api-settings.ts +239 -12
- package/src/lib/collection-sort.ts +7 -5
- package/src/lib/constants.ts +2 -0
- package/src/lib/feed-path.ts +25 -0
- package/src/lib/feed-policy.ts +64 -0
- package/src/lib/footnotes.ts +264 -0
- package/src/lib/github-sync-site-config.ts +2 -0
- package/src/lib/hugo-markdown.ts +10 -3
- package/src/lib/jant-branding.ts +1 -0
- package/src/lib/markdown-manager.ts +188 -5
- package/src/lib/markdown.ts +10 -3
- package/src/lib/navigation.ts +16 -3
- package/src/lib/post-body-html.ts +131 -0
- package/src/lib/post-display.ts +7 -1
- package/src/lib/render.tsx +9 -2
- package/src/lib/resolve-config.ts +100 -16
- package/src/lib/schemas.ts +133 -1
- package/src/lib/settings-paths.ts +5 -0
- package/src/lib/site-skill.ts +78 -0
- package/src/lib/summary.ts +16 -5
- package/src/lib/timeline.ts +98 -122
- package/src/lib/timezones.ts +54 -14
- package/src/lib/tiptap-render.ts +355 -81
- package/src/lib/view.ts +30 -20
- package/src/lib/worker-response-cache.ts +11 -18
- package/src/middleware/__tests__/public-content-access.test.ts +91 -0
- package/src/middleware/config.ts +2 -2
- package/src/middleware/public-content-access.ts +87 -0
- package/src/node/__tests__/cli-export.test.ts +14 -0
- package/src/node/__tests__/cli-migrate.test.ts +6 -0
- package/src/node/__tests__/cli-site-snapshot.test.ts +205 -2
- package/src/node/__tests__/cli-snapshot-meta.test.ts +100 -0
- package/src/node/index.ts +2 -1
- package/src/preset.css +16 -2
- package/src/routes/__tests__/compose.test.ts +51 -0
- package/src/routes/__tests__/site-skill.test.ts +112 -0
- package/src/routes/api/__tests__/collections.test.ts +91 -19
- package/src/routes/api/__tests__/mcp.test.ts +65 -1
- package/src/routes/api/__tests__/nav-items.test.ts +91 -0
- package/src/routes/api/__tests__/public-access.test.ts +81 -0
- package/src/routes/api/__tests__/settings.test.ts +217 -0
- package/src/routes/api/collections.ts +22 -26
- package/src/routes/api/export.ts +2 -0
- package/src/routes/api/internal/__tests__/post-body-html.test.ts +163 -0
- package/src/routes/api/internal/__tests__/sites.test.ts +35 -2
- package/src/routes/api/internal/post-body-html.ts +43 -0
- package/src/routes/api/internal/sites.ts +24 -0
- package/src/routes/api/nav-items.ts +24 -1
- package/src/routes/api/posts.ts +2 -2
- package/src/routes/api/public/__tests__/archive.test.ts +35 -0
- package/src/routes/api/public/__tests__/posts.test.ts +208 -0
- package/src/routes/api/public/archive.ts +4 -0
- package/src/routes/api/public/posts.ts +41 -24
- package/src/routes/api/search.ts +3 -0
- package/src/routes/api/settings.ts +33 -0
- package/src/routes/auth/__tests__/setup.test.ts +7 -4
- package/src/routes/compose.tsx +2 -1
- package/src/routes/dash/settings.tsx +45 -2
- package/src/routes/feed/__tests__/feed.test.ts +210 -6
- package/src/routes/feed/feed.ts +23 -14
- package/src/routes/pages/__tests__/archive-params.test.ts +92 -3
- package/src/routes/pages/__tests__/collection-routing.test.ts +63 -5
- package/src/routes/pages/__tests__/collections.test.ts +9 -9
- package/src/routes/pages/__tests__/preview.test.ts +174 -0
- package/src/routes/pages/__tests__/search.test.ts +69 -0
- package/src/routes/pages/archive.tsx +27 -7
- package/src/routes/pages/collection.tsx +32 -19
- package/src/routes/pages/collections.tsx +6 -1
- package/src/routes/pages/page.tsx +83 -11
- package/src/routes/site-skill.ts +18 -0
- package/src/services/__tests__/auth.test.ts +7 -5
- package/src/services/__tests__/collection.test.ts +159 -44
- package/src/services/__tests__/navigation.test.ts +229 -21
- package/src/services/__tests__/post-timeline.test.ts +109 -30
- package/src/services/__tests__/post.test.ts +567 -5
- package/src/services/__tests__/search.test.ts +48 -1
- package/src/services/__tests__/settings.test.ts +8 -0
- package/src/services/__tests__/site-admin.test.ts +121 -1
- package/src/services/auth.ts +2 -2
- package/src/services/bootstrap.ts +3 -2
- package/src/services/collection.ts +226 -167
- package/src/services/export-theme/assets/client-site.css +1 -1
- package/src/services/export-theme/assets/client-site.js +46 -25
- package/src/services/export-theme/layouts/_default/list.html +18 -4
- package/src/services/export-theme/layouts/_default/rss.xml +8 -12
- package/src/services/export-theme/layouts/featured/list.html +5 -4
- package/src/services/export-theme/layouts/partials/featured-thread.html +56 -0
- package/src/services/export-theme/layouts/partials/footer.html +1 -1
- package/src/services/export-theme/layouts/partials/media-gallery.html +1 -0
- package/src/services/export-theme/styles/main.css +30 -2
- package/src/services/export.ts +91 -80
- package/src/services/mcp.ts +37 -27
- package/src/services/media.ts +1 -1
- package/src/services/navigation.ts +185 -46
- package/src/services/post.ts +874 -271
- package/src/services/search.ts +8 -2
- package/src/services/settings.ts +2 -10
- package/src/services/site-admin.ts +63 -43
- package/src/style-cjk-jp.css +1 -1
- package/src/style-cjk-kr.css +1 -1
- package/src/style-cjk-tc.css +1 -1
- package/src/style-cjk.css +1 -1
- package/src/styles/components.css +540 -0
- package/src/styles/site-media.css +111 -19
- package/src/styles/tokens.css +14 -9
- package/src/styles/ui.css +829 -29
- package/src/types/bindings.ts +3 -0
- package/src/types/config.ts +243 -12
- package/src/types/constants.ts +22 -1
- package/src/types/entities.ts +9 -8
- package/src/types/operations.ts +18 -10
- package/src/types/props.ts +8 -2
- package/src/types/raw-assets.d.ts +5 -0
- package/src/types/views.ts +16 -4
- package/src/ui/__tests__/font-themes.test.ts +42 -30
- package/src/ui/compose/ComposeDialog.tsx +92 -2
- package/src/ui/dash/appearance/NavigationContent.tsx +332 -4
- package/src/ui/dash/appearance/__tests__/NavigationContent.test.tsx +23 -0
- package/src/ui/dash/settings/ConfigEditorContent.tsx +578 -0
- package/src/ui/dash/settings/GeneralContent.tsx +15 -5
- package/src/ui/dash/settings/SettingsRootContent.tsx +21 -1
- package/src/ui/dash/settings/__tests__/ConfigEditorContent.test.tsx +98 -0
- package/src/ui/dash/settings/__tests__/SettingsRootContent.test.tsx +15 -0
- package/src/ui/feed/CuratedThreadPreview.tsx +16 -4
- package/src/ui/feed/LinkCard.tsx +2 -12
- package/src/ui/feed/NoteCard.tsx +10 -20
- package/src/ui/feed/QuoteCard.tsx +2 -12
- package/src/ui/feed/ThreadPreview.tsx +26 -34
- package/src/ui/feed/TimelineFeed.tsx +2 -2
- package/src/ui/feed/__tests__/thread-preview.test.ts +197 -56
- package/src/ui/feed/__tests__/timeline-cards.test.ts +178 -3
- package/src/ui/feed/thread-preview-state.ts +5 -7
- package/src/ui/font-themes.ts +74 -26
- package/src/ui/layouts/BaseLayout.tsx +22 -8
- package/src/ui/layouts/__tests__/BaseLayout.test.tsx +64 -1
- package/src/ui/pages/CollectionPage.tsx +101 -22
- package/src/ui/pages/CollectionsPage.tsx +3 -1
- package/src/ui/pages/PostPage.tsx +39 -12
- package/src/ui/pages/SearchPage.tsx +6 -14
- package/src/ui/pages/__tests__/ArchivePage.test.tsx +7 -0
- package/src/ui/pages/__tests__/PostPage.test.tsx +88 -0
- package/src/ui/shared/CollectionDirectory.tsx +13 -9
- package/src/ui/shared/CollectionsManager.tsx +17 -7
- package/src/ui/shared/DraftPreviewBar.tsx +33 -0
- package/src/ui/shared/HomePageBranding.tsx +2 -2
- package/src/ui/shared/MediaGallery.tsx +1 -0
- package/src/ui/shared/PostFooter.tsx +3 -1
- package/src/ui/shared/__tests__/home-page-branding.test.tsx +1 -1
- package/src/ui/shared/__tests__/media-gallery.test.ts +1 -0
- package/src/ui/shared/__tests__/navigation-labels.test.ts +2 -2
- package/src/ui/shared/__tests__/post-footer.test.ts +15 -0
- package/src/ui/shared/collection-management-labels.ts +33 -2
- package/src/ui/shared/navigation-labels.ts +2 -4
- package/src/ui/shared/post-article-attributes.ts +46 -0
- package/dist/app-DZDlmh7C.js +0 -6
- package/dist/client/_assets/client-Cevfpm8H.css +0 -2
- package/dist/client/_assets/client-auth-v3yvhbgZ.js +0 -4736
- package/src/client/tiptap/wrapping-input-rules.ts +0 -102
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
|
|
3
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
4
|
+
import "../jant-config-editor.js";
|
|
5
|
+
import type { JantConfigEditor } from "../jant-config-editor.js";
|
|
6
|
+
|
|
7
|
+
const fields = [
|
|
8
|
+
{
|
|
9
|
+
key: "ENABLE_FEATURE",
|
|
10
|
+
mode: "edit",
|
|
11
|
+
type: "boolean",
|
|
12
|
+
value: "false",
|
|
13
|
+
fallbackValue: "false",
|
|
14
|
+
modified: false,
|
|
15
|
+
locked: false,
|
|
16
|
+
label: "Enable feature",
|
|
17
|
+
description: "Turns the feature on.",
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
key: "SITE_TITLE",
|
|
21
|
+
mode: "edit",
|
|
22
|
+
type: "string",
|
|
23
|
+
value: "Original",
|
|
24
|
+
fallbackValue: "Default",
|
|
25
|
+
modified: true,
|
|
26
|
+
locked: false,
|
|
27
|
+
maxLength: 120,
|
|
28
|
+
label: "Site title",
|
|
29
|
+
description: "Names the site.",
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
key: "ITEM_COUNT",
|
|
33
|
+
mode: "edit",
|
|
34
|
+
type: "number",
|
|
35
|
+
value: "5",
|
|
36
|
+
fallbackValue: "5",
|
|
37
|
+
modified: false,
|
|
38
|
+
locked: false,
|
|
39
|
+
min: 1,
|
|
40
|
+
max: 20,
|
|
41
|
+
step: 1,
|
|
42
|
+
label: "Item count",
|
|
43
|
+
description: "Controls the number of items.",
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
key: "SEARCH_COUNT",
|
|
47
|
+
mode: "edit",
|
|
48
|
+
type: "number",
|
|
49
|
+
value: "5",
|
|
50
|
+
fallbackValue: "5",
|
|
51
|
+
fallbackKey: "ITEM_COUNT",
|
|
52
|
+
modified: false,
|
|
53
|
+
locked: false,
|
|
54
|
+
min: 1,
|
|
55
|
+
max: 20,
|
|
56
|
+
step: 1,
|
|
57
|
+
label: "Search count",
|
|
58
|
+
description: "Inherits the item count.",
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
key: "DISPLAY_MODE",
|
|
62
|
+
mode: "edit",
|
|
63
|
+
type: "enum",
|
|
64
|
+
value: "full",
|
|
65
|
+
fallbackValue: "quiet",
|
|
66
|
+
modified: false,
|
|
67
|
+
locked: false,
|
|
68
|
+
options: ["quiet", "full"],
|
|
69
|
+
optionLabels: { quiet: "Quiet", full: "Full" },
|
|
70
|
+
label: "Display mode",
|
|
71
|
+
description: "Chooses how much detail to show.",
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
key: "THEME",
|
|
75
|
+
mode: "link",
|
|
76
|
+
type: "string",
|
|
77
|
+
value: "paper",
|
|
78
|
+
fallbackValue: "tufte",
|
|
79
|
+
modified: true,
|
|
80
|
+
locked: false,
|
|
81
|
+
resettable: true,
|
|
82
|
+
description: "Chooses the active color theme.",
|
|
83
|
+
settingsPath: "/settings/color-theme",
|
|
84
|
+
display: "value",
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
key: "CUSTOM_CSS",
|
|
88
|
+
mode: "link",
|
|
89
|
+
type: "string",
|
|
90
|
+
value: "false",
|
|
91
|
+
fallbackValue: "false",
|
|
92
|
+
modified: false,
|
|
93
|
+
locked: false,
|
|
94
|
+
description: "Add site-wide CSS in the dedicated editor.",
|
|
95
|
+
settingsPath: "/settings/custom-css",
|
|
96
|
+
display: "configured",
|
|
97
|
+
},
|
|
98
|
+
];
|
|
99
|
+
|
|
100
|
+
function rowFor(element: HTMLElement, key: string): HTMLElement {
|
|
101
|
+
const row = Array.from(
|
|
102
|
+
element.querySelectorAll<HTMLElement>(".config-editor-row"),
|
|
103
|
+
).find((candidate) => candidate.textContent?.includes(key));
|
|
104
|
+
if (!row) throw new Error(`Missing row for ${key}`);
|
|
105
|
+
return row;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async function createEditor(): Promise<JantConfigEditor> {
|
|
109
|
+
const element = document.createElement(
|
|
110
|
+
"jant-config-editor",
|
|
111
|
+
) as JantConfigEditor;
|
|
112
|
+
element.setAttribute("endpoint", "/api/settings");
|
|
113
|
+
element.setAttribute("initial-data", JSON.stringify({ fields }));
|
|
114
|
+
element.setAttribute("labels", JSON.stringify({}));
|
|
115
|
+
const fallback = document.createElement("div");
|
|
116
|
+
fallback.className = "config-editor-fallback";
|
|
117
|
+
fallback.textContent = "Server-rendered fallback";
|
|
118
|
+
element.appendChild(fallback);
|
|
119
|
+
document.body.appendChild(element);
|
|
120
|
+
await element.updateComplete;
|
|
121
|
+
return element;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
describe("jant-config-editor", () => {
|
|
125
|
+
beforeEach(() => {
|
|
126
|
+
document.body.innerHTML = "";
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
afterEach(() => {
|
|
130
|
+
vi.unstubAllGlobals();
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("renders all four control types, linked settings, and live search", async () => {
|
|
134
|
+
const element = await createEditor();
|
|
135
|
+
|
|
136
|
+
expect(element.querySelector(".config-editor-fallback")).toBeNull();
|
|
137
|
+
|
|
138
|
+
expect(
|
|
139
|
+
rowFor(element, "ENABLE_FEATURE").querySelector('[role="switch"]'),
|
|
140
|
+
).not.toBeNull();
|
|
141
|
+
expect(
|
|
142
|
+
rowFor(element, "ENABLE_FEATURE")
|
|
143
|
+
.querySelector('[role="switch"]')
|
|
144
|
+
?.getAttribute("name"),
|
|
145
|
+
).toBe("ENABLE_FEATURE");
|
|
146
|
+
expect(
|
|
147
|
+
rowFor(element, "SITE_TITLE").querySelector('input[type="text"]'),
|
|
148
|
+
).not.toBeNull();
|
|
149
|
+
expect(
|
|
150
|
+
rowFor(element, "ITEM_COUNT").querySelector('input[type="number"]'),
|
|
151
|
+
).not.toBeNull();
|
|
152
|
+
expect(
|
|
153
|
+
rowFor(element, "ITEM_COUNT")
|
|
154
|
+
.querySelector(".config-editor-control-row")
|
|
155
|
+
?.classList.contains("config-editor-control-row-number"),
|
|
156
|
+
).toBe(true);
|
|
157
|
+
expect(
|
|
158
|
+
rowFor(element, "DISPLAY_MODE").querySelector("select"),
|
|
159
|
+
).not.toBeNull();
|
|
160
|
+
const displayModeSelect = rowFor(element, "DISPLAY_MODE").querySelector(
|
|
161
|
+
"select",
|
|
162
|
+
) as { value?: string } | null;
|
|
163
|
+
expect(displayModeSelect?.value).toBe("full");
|
|
164
|
+
expect(
|
|
165
|
+
rowFor(element, "DISPLAY_MODE")
|
|
166
|
+
.querySelector(".config-editor-control-row")
|
|
167
|
+
?.classList.contains("config-editor-control-row-select"),
|
|
168
|
+
).toBe(true);
|
|
169
|
+
expect(
|
|
170
|
+
rowFor(element, "CUSTOM_CSS")
|
|
171
|
+
.querySelector<HTMLAnchorElement>(".config-editor-open-control")
|
|
172
|
+
?.getAttribute("href"),
|
|
173
|
+
).toBe("/settings/custom-css");
|
|
174
|
+
expect(
|
|
175
|
+
rowFor(element, "CUSTOM_CSS")
|
|
176
|
+
.querySelector<HTMLAnchorElement>(".config-editor-open-control")
|
|
177
|
+
?.hasAttribute("target"),
|
|
178
|
+
).toBe(false);
|
|
179
|
+
expect(rowFor(element, "CUSTOM_CSS").textContent).toContain(
|
|
180
|
+
"Not configured",
|
|
181
|
+
);
|
|
182
|
+
expect(element.querySelector(".config-editor-save")).toBeNull();
|
|
183
|
+
expect(element.querySelector(".config-editor-row-footer")).toBeNull();
|
|
184
|
+
|
|
185
|
+
const search = element.querySelector<HTMLInputElement>(
|
|
186
|
+
'.config-editor-search input[type="search"]',
|
|
187
|
+
);
|
|
188
|
+
if (!search) throw new Error("Missing search input");
|
|
189
|
+
search.value = "display";
|
|
190
|
+
search.dispatchEvent(new Event("input", { bubbles: true }));
|
|
191
|
+
await element.updateComplete;
|
|
192
|
+
|
|
193
|
+
const visibleRows = element.querySelectorAll(".config-editor-row");
|
|
194
|
+
expect(visibleRows).toHaveLength(1);
|
|
195
|
+
expect(visibleRows[0]?.textContent).toContain("DISPLAY_MODE");
|
|
196
|
+
|
|
197
|
+
search.dispatchEvent(
|
|
198
|
+
new KeyboardEvent("keydown", { key: "Escape", bubbles: true }),
|
|
199
|
+
);
|
|
200
|
+
await element.updateComplete;
|
|
201
|
+
expect(element.querySelectorAll(".config-editor-row")).toHaveLength(7);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("updates unmodified dependent values when their fallback changes", async () => {
|
|
205
|
+
const fetchMock = vi.fn().mockResolvedValue(
|
|
206
|
+
new Response(
|
|
207
|
+
JSON.stringify({
|
|
208
|
+
settings: { ITEM_COUNT: "10", SEARCH_COUNT: "10" },
|
|
209
|
+
}),
|
|
210
|
+
{ status: 200, headers: { "Content-Type": "application/json" } },
|
|
211
|
+
),
|
|
212
|
+
);
|
|
213
|
+
vi.stubGlobal("fetch", fetchMock);
|
|
214
|
+
const element = await createEditor();
|
|
215
|
+
const input = rowFor(element, "ITEM_COUNT").querySelector<HTMLInputElement>(
|
|
216
|
+
'input[type="number"]',
|
|
217
|
+
);
|
|
218
|
+
if (!input) throw new Error("Missing number setting input");
|
|
219
|
+
|
|
220
|
+
input.value = "10";
|
|
221
|
+
input.dispatchEvent(new Event("input", { bubbles: true }));
|
|
222
|
+
await element.updateComplete;
|
|
223
|
+
input.dispatchEvent(
|
|
224
|
+
new KeyboardEvent("keydown", { key: "Enter", bubbles: true }),
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
await vi.waitFor(() =>
|
|
228
|
+
expect(
|
|
229
|
+
rowFor(element, "SEARCH_COUNT").querySelector<HTMLInputElement>(
|
|
230
|
+
'input[type="number"]',
|
|
231
|
+
)?.value,
|
|
232
|
+
).toBe("10"),
|
|
233
|
+
);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it("can show only modified settings", async () => {
|
|
237
|
+
const element = await createEditor();
|
|
238
|
+
const checkbox = element.querySelector<HTMLInputElement>(
|
|
239
|
+
".config-editor-modified-filter input",
|
|
240
|
+
);
|
|
241
|
+
if (!checkbox) throw new Error("Missing modified-only checkbox");
|
|
242
|
+
checkbox.checked = true;
|
|
243
|
+
checkbox.dispatchEvent(new Event("change", { bubbles: true }));
|
|
244
|
+
await element.updateComplete;
|
|
245
|
+
|
|
246
|
+
const rows = element.querySelectorAll(".config-editor-row");
|
|
247
|
+
expect(rows).toHaveLength(2);
|
|
248
|
+
expect(Array.from(rows).map((row) => row.textContent)).toEqual(
|
|
249
|
+
expect.arrayContaining([
|
|
250
|
+
expect.stringContaining("SITE_TITLE"),
|
|
251
|
+
expect.stringContaining("THEME"),
|
|
252
|
+
]),
|
|
253
|
+
);
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
it("saves text on Enter and resets the stored override", async () => {
|
|
257
|
+
const fetchMock = vi.fn(async (...[, init]: Parameters<typeof fetch>) => {
|
|
258
|
+
if (init?.method === "DELETE") {
|
|
259
|
+
return new Response(
|
|
260
|
+
JSON.stringify({ settings: { SITE_TITLE: "Default" } }),
|
|
261
|
+
{ status: 200, headers: { "Content-Type": "application/json" } },
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
return new Response(
|
|
265
|
+
JSON.stringify({ settings: { SITE_TITLE: "Changed" } }),
|
|
266
|
+
{ status: 200, headers: { "Content-Type": "application/json" } },
|
|
267
|
+
);
|
|
268
|
+
});
|
|
269
|
+
vi.stubGlobal("fetch", fetchMock);
|
|
270
|
+
const element = await createEditor();
|
|
271
|
+
const input = rowFor(element, "SITE_TITLE").querySelector<HTMLInputElement>(
|
|
272
|
+
'input[type="text"]',
|
|
273
|
+
);
|
|
274
|
+
if (!input) throw new Error("Missing text setting input");
|
|
275
|
+
|
|
276
|
+
input.value = "Changed";
|
|
277
|
+
input.dispatchEvent(new Event("input", { bubbles: true }));
|
|
278
|
+
await element.updateComplete;
|
|
279
|
+
input.dispatchEvent(
|
|
280
|
+
new KeyboardEvent("keydown", { key: "Enter", bubbles: true }),
|
|
281
|
+
);
|
|
282
|
+
|
|
283
|
+
await vi.waitFor(() => expect(fetchMock).toHaveBeenCalledTimes(1));
|
|
284
|
+
expect(fetchMock.mock.calls[0]?.[1]).toMatchObject({ method: "PUT" });
|
|
285
|
+
await vi.waitFor(() =>
|
|
286
|
+
expect(rowFor(element, "SITE_TITLE").textContent).toContain("Saved"),
|
|
287
|
+
);
|
|
288
|
+
|
|
289
|
+
const reset = rowFor(
|
|
290
|
+
element,
|
|
291
|
+
"SITE_TITLE",
|
|
292
|
+
).querySelector<HTMLButtonElement>(".config-editor-reset");
|
|
293
|
+
if (!reset) throw new Error("Missing reset action");
|
|
294
|
+
reset.click();
|
|
295
|
+
|
|
296
|
+
await vi.waitFor(() => expect(fetchMock).toHaveBeenCalledTimes(2));
|
|
297
|
+
expect(fetchMock.mock.calls[1]?.[0]).toBe("/api/settings/SITE_TITLE");
|
|
298
|
+
expect(fetchMock.mock.calls[1]?.[1]).toMatchObject({ method: "DELETE" });
|
|
299
|
+
await vi.waitFor(() =>
|
|
300
|
+
expect(
|
|
301
|
+
rowFor(element, "SITE_TITLE").querySelector<HTMLInputElement>(
|
|
302
|
+
'input[type="text"]',
|
|
303
|
+
)?.value,
|
|
304
|
+
).toBe("Default"),
|
|
305
|
+
);
|
|
306
|
+
expect(rowFor(element, "SITE_TITLE").textContent).not.toContain("Modified");
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
it("saves a changed text value on blur", async () => {
|
|
310
|
+
const fetchMock = vi.fn().mockResolvedValue(
|
|
311
|
+
new Response(JSON.stringify({ settings: { SITE_TITLE: "Changed" } }), {
|
|
312
|
+
status: 200,
|
|
313
|
+
headers: { "Content-Type": "application/json" },
|
|
314
|
+
}),
|
|
315
|
+
);
|
|
316
|
+
vi.stubGlobal("fetch", fetchMock);
|
|
317
|
+
const element = await createEditor();
|
|
318
|
+
const input = rowFor(element, "SITE_TITLE").querySelector<HTMLInputElement>(
|
|
319
|
+
'input[type="text"]',
|
|
320
|
+
);
|
|
321
|
+
if (!input) throw new Error("Missing text setting input");
|
|
322
|
+
|
|
323
|
+
input.value = "Changed";
|
|
324
|
+
input.dispatchEvent(new Event("input", { bubbles: true }));
|
|
325
|
+
await element.updateComplete;
|
|
326
|
+
input.dispatchEvent(new Event("blur"));
|
|
327
|
+
|
|
328
|
+
await vi.waitFor(() => expect(fetchMock).toHaveBeenCalledTimes(1));
|
|
329
|
+
expect(fetchMock.mock.calls[0]?.[1]).toMatchObject({ method: "PUT" });
|
|
330
|
+
await vi.waitFor(() =>
|
|
331
|
+
expect(rowFor(element, "SITE_TITLE").textContent).toContain("Saved"),
|
|
332
|
+
);
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
it("rolls back an immediate boolean edit when saving fails", async () => {
|
|
336
|
+
vi.stubGlobal(
|
|
337
|
+
"fetch",
|
|
338
|
+
vi.fn().mockResolvedValue(
|
|
339
|
+
new Response(JSON.stringify({ error: "The setting is locked." }), {
|
|
340
|
+
status: 400,
|
|
341
|
+
headers: { "Content-Type": "application/json" },
|
|
342
|
+
}),
|
|
343
|
+
),
|
|
344
|
+
);
|
|
345
|
+
const element = await createEditor();
|
|
346
|
+
const toggle = rowFor(
|
|
347
|
+
element,
|
|
348
|
+
"ENABLE_FEATURE",
|
|
349
|
+
).querySelector<HTMLInputElement>('[role="switch"]');
|
|
350
|
+
if (!toggle) throw new Error("Missing boolean setting switch");
|
|
351
|
+
|
|
352
|
+
toggle.checked = true;
|
|
353
|
+
toggle.dispatchEvent(new Event("change", { bubbles: true }));
|
|
354
|
+
|
|
355
|
+
await vi.waitFor(() => expect(toggle.checked).toBe(false));
|
|
356
|
+
expect(rowFor(element, "ENABLE_FEATURE").textContent).toContain(
|
|
357
|
+
"The setting is locked.",
|
|
358
|
+
);
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
it("resets safe linked values without exposing reset for specialized content", async () => {
|
|
362
|
+
const fetchMock = vi.fn().mockResolvedValue(
|
|
363
|
+
new Response(
|
|
364
|
+
JSON.stringify({
|
|
365
|
+
settings: {},
|
|
366
|
+
setting: {
|
|
367
|
+
key: "THEME",
|
|
368
|
+
mode: "link",
|
|
369
|
+
type: "string",
|
|
370
|
+
value: "tufte",
|
|
371
|
+
fallbackValue: "tufte",
|
|
372
|
+
modified: false,
|
|
373
|
+
locked: false,
|
|
374
|
+
resettable: true,
|
|
375
|
+
settingsPath: "/settings/color-theme",
|
|
376
|
+
display: "value",
|
|
377
|
+
},
|
|
378
|
+
}),
|
|
379
|
+
{ status: 200, headers: { "Content-Type": "application/json" } },
|
|
380
|
+
),
|
|
381
|
+
);
|
|
382
|
+
vi.stubGlobal("fetch", fetchMock);
|
|
383
|
+
const element = await createEditor();
|
|
384
|
+
const themeRow = rowFor(element, "THEME");
|
|
385
|
+
const reset = themeRow.querySelector<HTMLButtonElement>(
|
|
386
|
+
".config-editor-reset",
|
|
387
|
+
);
|
|
388
|
+
|
|
389
|
+
expect(reset).not.toBeNull();
|
|
390
|
+
expect(
|
|
391
|
+
rowFor(element, "CUSTOM_CSS").querySelector(".config-editor-reset"),
|
|
392
|
+
).toBeNull();
|
|
393
|
+
reset?.click();
|
|
394
|
+
|
|
395
|
+
await vi.waitFor(() => expect(fetchMock).toHaveBeenCalledTimes(1));
|
|
396
|
+
expect(fetchMock.mock.calls[0]?.[0]).toBe("/api/settings/THEME");
|
|
397
|
+
await vi.waitFor(() =>
|
|
398
|
+
expect(rowFor(element, "THEME").textContent).toContain("tufte"),
|
|
399
|
+
);
|
|
400
|
+
expect(rowFor(element, "THEME").textContent).not.toContain("Modified");
|
|
401
|
+
expect(
|
|
402
|
+
rowFor(element, "THEME").querySelector(".config-editor-reset"),
|
|
403
|
+
).toBeNull();
|
|
404
|
+
});
|
|
405
|
+
});
|
|
@@ -4,6 +4,11 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
4
4
|
import "../jant-media-lightbox.js";
|
|
5
5
|
import type { JantMediaLightbox } from "../jant-media-lightbox.js";
|
|
6
6
|
import { shouldUseScrollableLightboxImage } from "../jant-media-lightbox.js";
|
|
7
|
+
import {
|
|
8
|
+
MEDIA_VIDEO_PLAYBACK_INTENT_EVENT,
|
|
9
|
+
setMediaVideoPlaybackPaused,
|
|
10
|
+
type MediaVideoPlaybackIntentDetail,
|
|
11
|
+
} from "../../media-lightbox-events.js";
|
|
7
12
|
|
|
8
13
|
function installDialogShim() {
|
|
9
14
|
Object.defineProperty(HTMLDialogElement.prototype, "open", {
|
|
@@ -278,10 +283,126 @@ describe("JantMediaLightbox", () => {
|
|
|
278
283
|
const muteButton = el.querySelector<HTMLButtonElement>(
|
|
279
284
|
".media-lightbox-short-mute",
|
|
280
285
|
);
|
|
286
|
+
const playbackButton = el.querySelector<HTMLButtonElement>(
|
|
287
|
+
".media-lightbox-short-playback",
|
|
288
|
+
);
|
|
281
289
|
|
|
282
290
|
expect(video?.hasAttribute("controls")).toBe(false);
|
|
283
291
|
expect(progress).not.toBeNull();
|
|
284
292
|
expect(muteButton).not.toBeNull();
|
|
293
|
+
expect(playbackButton?.getAttribute("aria-label")).toBe("Pause video");
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
it("publishes explicit pause and play intent for the matching feed video", async () => {
|
|
297
|
+
const el = await createElement();
|
|
298
|
+
const intents: MediaVideoPlaybackIntentDetail[] = [];
|
|
299
|
+
const handleIntent = (event: Event) => {
|
|
300
|
+
intents.push(
|
|
301
|
+
(event as CustomEvent<MediaVideoPlaybackIntentDetail>).detail,
|
|
302
|
+
);
|
|
303
|
+
};
|
|
304
|
+
document.addEventListener(MEDIA_VIDEO_PLAYBACK_INTENT_EVENT, handleIntent);
|
|
305
|
+
|
|
306
|
+
el.open(
|
|
307
|
+
[
|
|
308
|
+
{
|
|
309
|
+
id: "media-clip",
|
|
310
|
+
url: "https://example.com/clip.mp4",
|
|
311
|
+
alt: "",
|
|
312
|
+
mimeType: "video/mp4",
|
|
313
|
+
durationSeconds: 12,
|
|
314
|
+
size: 2_000_000,
|
|
315
|
+
},
|
|
316
|
+
],
|
|
317
|
+
0,
|
|
318
|
+
);
|
|
319
|
+
await flush(el);
|
|
320
|
+
|
|
321
|
+
const video = el.querySelector<HTMLVideoElement>(".media-lightbox-video");
|
|
322
|
+
if (!video) throw new Error("expected short video");
|
|
323
|
+
|
|
324
|
+
let paused = false;
|
|
325
|
+
Object.defineProperty(video, "paused", {
|
|
326
|
+
configurable: true,
|
|
327
|
+
get: () => paused,
|
|
328
|
+
});
|
|
329
|
+
Object.defineProperty(video, "pause", {
|
|
330
|
+
configurable: true,
|
|
331
|
+
value: vi.fn(() => {
|
|
332
|
+
paused = true;
|
|
333
|
+
video.dispatchEvent(new Event("pause"));
|
|
334
|
+
}),
|
|
335
|
+
});
|
|
336
|
+
Object.defineProperty(video, "play", {
|
|
337
|
+
configurable: true,
|
|
338
|
+
value: vi.fn(() => {
|
|
339
|
+
paused = false;
|
|
340
|
+
video.dispatchEvent(new Event("play"));
|
|
341
|
+
return Promise.resolve();
|
|
342
|
+
}),
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
video.click();
|
|
346
|
+
await flush(el);
|
|
347
|
+
|
|
348
|
+
expect(video.pause).toHaveBeenCalledOnce();
|
|
349
|
+
expect(intents).toEqual([{ mediaId: "media-clip", paused: true }]);
|
|
350
|
+
expect(
|
|
351
|
+
el
|
|
352
|
+
.querySelector(".media-lightbox-short-playback")
|
|
353
|
+
?.getAttribute("aria-label"),
|
|
354
|
+
).toBe("Play video");
|
|
355
|
+
|
|
356
|
+
el.querySelector<HTMLButtonElement>(
|
|
357
|
+
".media-lightbox-short-playback",
|
|
358
|
+
)?.click();
|
|
359
|
+
await flush(el);
|
|
360
|
+
|
|
361
|
+
expect(video.play).toHaveBeenCalledOnce();
|
|
362
|
+
expect(intents).toEqual([
|
|
363
|
+
{ mediaId: "media-clip", paused: true },
|
|
364
|
+
{ mediaId: "media-clip", paused: false },
|
|
365
|
+
]);
|
|
366
|
+
expect(
|
|
367
|
+
el
|
|
368
|
+
.querySelector(".media-lightbox-short-playback")
|
|
369
|
+
?.getAttribute("aria-label"),
|
|
370
|
+
).toBe("Pause video");
|
|
371
|
+
|
|
372
|
+
document.removeEventListener(
|
|
373
|
+
MEDIA_VIDEO_PLAYBACK_INTENT_EVENT,
|
|
374
|
+
handleIntent,
|
|
375
|
+
);
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
it("reopens explicitly paused media without autoplaying it", async () => {
|
|
379
|
+
const el = await createElement();
|
|
380
|
+
setMediaVideoPlaybackPaused("media-paused", true);
|
|
381
|
+
|
|
382
|
+
el.open(
|
|
383
|
+
[
|
|
384
|
+
{
|
|
385
|
+
id: "media-paused",
|
|
386
|
+
url: "https://example.com/clip.mp4",
|
|
387
|
+
alt: "",
|
|
388
|
+
mimeType: "video/mp4",
|
|
389
|
+
durationSeconds: 12,
|
|
390
|
+
size: 2_000_000,
|
|
391
|
+
},
|
|
392
|
+
],
|
|
393
|
+
0,
|
|
394
|
+
);
|
|
395
|
+
await flush(el);
|
|
396
|
+
|
|
397
|
+
const video = el.querySelector<HTMLVideoElement>(".media-lightbox-video");
|
|
398
|
+
expect(video?.hasAttribute("autoplay")).toBe(false);
|
|
399
|
+
expect(
|
|
400
|
+
el
|
|
401
|
+
.querySelector(".media-lightbox-short-playback")
|
|
402
|
+
?.getAttribute("aria-label"),
|
|
403
|
+
).toBe("Play video");
|
|
404
|
+
|
|
405
|
+
setMediaVideoPlaybackPaused("media-paused", false);
|
|
285
406
|
});
|
|
286
407
|
|
|
287
408
|
it("scrubs the video on arrow keys instead of switching items", async () => {
|