@jant/core 0.6.16 → 0.7.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/README.md +11 -11
- package/bin/commands/assets/upload.js +192 -15
- package/bin/commands/import-site.js +60 -4
- package/bin/commands/reset-password.js +21 -8
- package/bin/commands/site/snapshot/export.js +1 -1
- package/bin/commands/site/snapshot/import.js +1 -1
- package/bin/lib/d1-query.js +5 -16
- package/bin/lib/node-env.js +40 -4
- package/bin/lib/site-selection.js +85 -29
- package/bin/lib/wrangler-cli.js +28 -2
- package/bin/lib/wrangler-json.js +35 -0
- package/dist/{app-C7_4oab9.js → app-K_Aa1MMn.js} +52476 -13330
- package/dist/client/.vite/manifest.json +255 -90
- package/dist/client/_assets/chunks/confirm-D7GrwsCN.js +45 -0
- package/dist/client/_assets/chunks/create-editor-CD3FhrOB.js +257 -0
- package/dist/client/_assets/chunks/{native-DpcrFAPh.js → emoji-mart-C4RpRKcU.js} +716 -1
- package/dist/client/_assets/chunks/footnote-rail-CmeoVtnU.js +1 -0
- package/dist/client/_assets/chunks/heic-to-CuP2Qlsw.js +1 -0
- package/dist/client/_assets/chunks/jant-locale-picker-DL6mIOT5.js +69 -0
- package/dist/client/_assets/chunks/lit-DW8VmJAT.js +2 -0
- package/dist/client/_assets/chunks/mediabunny-DRaCQ1r-.js +31 -0
- package/dist/client/_assets/chunks/rolldown-runtime-hePW80VL.js +1 -0
- package/dist/client/_assets/chunks/settings-paths-BcdySNx6.js +84 -0
- package/dist/client/_assets/chunks/site-header-nav-DzXsFk05.js +1 -0
- package/dist/client/_assets/chunks/slug-format-CRXO1AL5.js +1 -0
- package/dist/client/_assets/chunks/slugify-373citbs.js +1 -0
- package/dist/client/_assets/chunks/sortable-list-CgaL2jCs.js +2 -0
- package/dist/client/_assets/chunks/types-D5iF3H1a.js +1 -0
- package/dist/client/_assets/chunks/unsafe-html-B5ZEXaxg.js +1 -0
- package/dist/client/_assets/chunks/unsafe-svg-0QCkP0vZ.js +2 -0
- package/dist/client/_assets/client-GiYENVw8.css +2 -0
- package/dist/client/_assets/client-VnFxJN7G.js +295 -0
- package/dist/client/_assets/client-auth-k8gJ6QJj.js +828 -0
- package/dist/client/_assets/client-author-DQ8R-8KR.css +2 -0
- package/dist/client/_assets/client-compose-B_kDtWkW.js +2004 -0
- package/dist/client/_assets/client-manage-M90aSTOk.js +2170 -0
- package/dist/client/_assets/client-settings-DfYs9n1F.js +1112 -0
- package/dist/{export-Dl5KCiEs.js → github-sync-BPAvT999.js} +2254 -107
- package/dist/index.js +2 -5
- package/dist/node.js +5 -7
- package/package.json +3 -3
- package/src/__tests__/auth-session-freshness.test.ts +57 -0
- package/src/__tests__/basecoat-variants.test.ts +121 -0
- package/src/__tests__/bin/assets-upload.test.ts +68 -0
- package/src/__tests__/export-hugo-build.test.ts +260 -0
- package/src/__tests__/export-service.test.ts +231 -0
- package/src/__tests__/helpers/component-css.ts +91 -0
- package/src/__tests__/helpers/db.ts +33 -0
- package/src/__tests__/helpers/export-fixtures.ts +3 -0
- package/src/__tests__/stylesheet-audience.test.ts +159 -0
- package/src/__tests__/stylesheet-breakpoints.test.ts +183 -0
- package/src/app.tsx +71 -16
- package/src/auth.ts +18 -1
- package/src/client/__tests__/collection-page-actions.test.ts +51 -2
- package/src/client/__tests__/compose-bridge-image-upload.test.ts +196 -0
- package/src/client/__tests__/compose-bridge-video-poster.test.ts +159 -0
- package/src/client/__tests__/compose-bridge.test.ts +272 -0
- package/src/client/__tests__/compose-launch.test.ts +62 -1
- package/src/client/__tests__/compose-shortcuts.test.ts +38 -9
- package/src/client/__tests__/compose-triggers.test.ts +90 -0
- package/src/client/__tests__/copy-field.test.ts +162 -0
- package/src/client/__tests__/custom-url-menu.test.ts +127 -6
- package/src/client/__tests__/image-processor.test.ts +324 -2
- package/src/client/__tests__/lazy-entries.test.ts +92 -0
- package/src/client/__tests__/media-scroll-hint.test.ts +155 -0
- package/src/client/__tests__/runtime-paths.test.ts +84 -0
- package/src/client/__tests__/smart-collection-page-actions.test.ts +158 -0
- package/src/client/__tests__/toast.test.ts +23 -0
- package/src/client/__tests__/video-processor-probe.test.ts +175 -0
- package/src/client/__tests__/video-processor.test.ts +181 -0
- package/src/client/audio-processor.ts +24 -15
- package/src/client/audio-waveform.ts +49 -0
- package/src/client/collection-dialog-host.ts +72 -0
- package/src/client/collection-navigation.ts +51 -16
- package/src/client/collection-page-actions.ts +26 -0
- package/src/client/components/__tests__/jant-collection-dialog.test.ts +329 -0
- package/src/client/components/__tests__/jant-collection-directory.test.ts +274 -10
- package/src/client/components/__tests__/jant-collection-form.test.ts +59 -178
- package/src/client/components/__tests__/jant-command-palette.test.ts +28 -0
- package/src/client/components/__tests__/jant-compose-dialog-draft-storage.test.ts +340 -0
- package/src/client/components/__tests__/jant-compose-dialog.test.ts +1250 -53
- package/src/client/components/__tests__/jant-compose-editor.test.ts +544 -40
- package/src/client/components/__tests__/jant-compose-fullscreen.test.ts +0 -1
- package/src/client/components/__tests__/jant-locale-picker.test.ts +207 -0
- package/src/client/components/__tests__/jant-nav-manager.test.ts +234 -15
- package/src/client/components/__tests__/jant-post-menu.test.ts +413 -2
- package/src/client/components/__tests__/jant-post-picker.test.ts +197 -0
- package/src/client/components/__tests__/jant-settings-avatar.test.ts +15 -12
- package/src/client/components/__tests__/jant-settings-general.test.ts +541 -172
- package/src/client/components/__tests__/jant-settings-language.test.ts +851 -0
- package/src/client/components/__tests__/jant-smart-collection-dialog.test.ts +665 -0
- package/src/client/components/collection-dialog-types.ts +49 -0
- package/src/client/components/collection-manager-types.ts +32 -1
- package/src/client/components/collection-types.ts +1 -15
- package/src/client/components/compose-types.ts +75 -1
- package/src/client/components/jant-collection-dialog.ts +722 -0
- package/src/client/components/jant-collection-directory.ts +567 -182
- package/src/client/components/jant-collection-form.ts +53 -232
- package/src/client/components/jant-command-palette.ts +100 -49
- package/src/client/components/jant-compose-dialog.ts +1486 -707
- package/src/client/components/jant-compose-editor.ts +673 -336
- package/src/client/components/jant-compose-fullscreen.ts +51 -43
- package/src/client/components/jant-config-editor.ts +65 -53
- package/src/client/components/jant-confirm-dialog.ts +13 -11
- package/src/client/components/jant-locale-picker.ts +418 -0
- package/src/client/components/jant-media-lightbox.ts +146 -136
- package/src/client/components/jant-nav-manager.ts +690 -366
- package/src/client/components/jant-post-menu.ts +1086 -282
- package/src/client/components/jant-post-picker.ts +324 -0
- package/src/client/components/jant-repo-picker.ts +138 -106
- package/src/client/components/jant-settings-avatar.ts +31 -27
- package/src/client/components/jant-settings-general.ts +617 -543
- package/src/client/components/jant-settings-language.ts +1087 -0
- package/src/client/components/jant-smart-collection-dialog.ts +1021 -0
- package/src/client/components/jant-text-preview.ts +94 -86
- package/src/client/components/nav-manager-types.ts +62 -1
- package/src/client/components/settings-types.ts +14 -29
- package/src/client/components/smart-collection-conditions.ts +285 -0
- package/src/client/components/smart-collection-dialog-types.ts +68 -0
- package/src/client/compose-bridge.ts +214 -141
- package/src/client/compose-launch.ts +76 -2
- package/src/client/compose-shortcuts.ts +6 -8
- package/src/client/compose-triggers.ts +50 -0
- package/src/client/copy-field.ts +108 -0
- package/src/client/custom-url-menu.ts +60 -4
- package/src/client/icons.ts +14 -0
- package/src/client/image-plan.ts +165 -0
- package/src/client/image-processor.ts +195 -117
- package/src/client/image-worker-client.ts +45 -0
- package/src/client/image-worker.ts +135 -0
- package/src/client/lazy-entries.ts +95 -0
- package/src/client/lazy-slugify.ts +2 -2
- package/src/client/media-scroll-hint.ts +43 -2
- package/src/client/mediabunny.ts +29 -0
- package/src/client/post-picker.ts +41 -0
- package/src/client/runtime-paths.ts +74 -1
- package/src/client/settings-bridge.ts +4 -10
- package/src/client/site-header-nav.js +18 -6
- package/src/client/smart-collection-dialog-host.ts +116 -0
- package/src/client/smart-collection-page-actions.ts +208 -0
- package/src/client/tiptap/__tests__/bubble-menu.test.ts +110 -0
- package/src/client/tiptap/__tests__/floating-position.test.ts +136 -1
- package/src/client/tiptap/__tests__/inline-image-upload.test.ts +37 -0
- package/src/client/tiptap/bubble-menu.ts +47 -16
- package/src/client/tiptap/floating-position.ts +216 -2
- package/src/client/tiptap/inline-image-upload.ts +7 -3
- package/src/client/tiptap/link-toolbar.ts +22 -9
- package/src/client/toast.ts +13 -0
- package/src/client/types/vite-worker.d.ts +12 -0
- package/src/client/upload-with-metadata.ts +3 -13
- package/src/client/video-processor.ts +351 -107
- package/src/client-auth.ts +14 -31
- package/src/client-compose.ts +19 -0
- package/src/client-manage.ts +13 -0
- package/src/client-settings.ts +14 -0
- package/src/client-site.ts +10 -3
- package/src/client.ts +4 -0
- package/src/db/__tests__/backfill-nav-label-mirrors.test.ts +149 -0
- package/src/db/__tests__/schema-enum-sources.test.ts +33 -0
- package/src/db/__tests__/smart-collection-placement.test.ts +402 -0
- package/src/db/backfills/0006_clear_mirrored_page_nav_labels.sql +31 -0
- package/src/db/migrations/0032_married_tomas.sql +3 -0
- package/src/db/migrations/0033_busy_johnny_storm.sql +198 -0
- package/src/db/migrations/0034_cheerful_rumiko_fujikawa.sql +35 -0
- package/src/db/migrations/meta/0032_snapshot.json +2582 -0
- package/src/db/migrations/meta/0033_snapshot.json +2816 -0
- package/src/db/migrations/meta/0034_snapshot.json +2816 -0
- package/src/db/migrations/meta/_journal.json +21 -0
- package/src/db/migrations/pg/0030_abandoned_nighthawk.sql +3 -0
- package/src/db/migrations/pg/0031_strong_ultimatum.sql +128 -0
- package/src/db/migrations/pg/0032_furry_multiple_man.sql +6 -0
- package/src/db/migrations/pg/meta/0030_snapshot.json +3329 -0
- package/src/db/migrations/pg/meta/0031_snapshot.json +3660 -0
- package/src/db/migrations/pg/meta/0032_snapshot.json +3660 -0
- package/src/db/migrations/pg/meta/_journal.json +21 -0
- package/src/db/pg/schema.ts +195 -27
- package/src/db/post-visibility.ts +117 -0
- package/src/db/schema.ts +222 -27
- package/src/i18n/__tests__/detect.test.ts +26 -81
- package/src/i18n/__tests__/supported-locales.test.ts +83 -0
- package/src/i18n/context.tsx +12 -2
- package/src/i18n/detect.ts +7 -66
- package/src/i18n/locales/glossary.zh-Hans.yml +44 -4
- package/src/i18n/locales/glossary.zh-Hant.yml +44 -4
- package/src/i18n/locales/public/en.po +490 -158
- package/src/i18n/locales/public/en.ts +1 -1
- package/src/i18n/locales/public/zh-Hans.po +487 -155
- package/src/i18n/locales/public/zh-Hans.ts +1 -1
- package/src/i18n/locales/public/zh-Hant.po +487 -155
- package/src/i18n/locales/public/zh-Hant.ts +1 -1
- package/src/i18n/locales/settings/en.po +551 -69
- package/src/i18n/locales/settings/en.ts +1 -1
- package/src/i18n/locales/settings/zh-Hans.po +597 -115
- package/src/i18n/locales/settings/zh-Hans.ts +1 -1
- package/src/i18n/locales/settings/zh-Hant.po +610 -128
- package/src/i18n/locales/settings/zh-Hant.ts +1 -1
- package/src/i18n/locales.ts +94 -0
- package/src/i18n/middleware.ts +12 -2
- package/src/i18n/supported-locales.ts +80 -0
- package/src/lib/__tests__/api-settings.test.ts +11 -2
- package/src/lib/__tests__/asset-path.test.ts +92 -0
- package/src/lib/__tests__/deferred.test.ts +90 -0
- package/src/lib/__tests__/discover-ping.test.ts +89 -0
- package/src/lib/__tests__/discover.test.ts +410 -0
- package/src/lib/__tests__/feed-policy.test.ts +26 -0
- package/src/lib/__tests__/feed.test.ts +1526 -15
- package/src/lib/__tests__/filter-dimensions.test.ts +341 -0
- package/src/lib/__tests__/hosted-signin.test.ts +1 -1
- package/src/lib/__tests__/http-cache.test.ts +162 -0
- package/src/lib/__tests__/jant-docs-dev.test.ts +21 -0
- package/src/lib/__tests__/jant-docs.test.ts +23 -0
- package/src/lib/__tests__/lang-detect.test.ts +231 -0
- package/src/lib/__tests__/media-helpers.test.ts +81 -0
- package/src/lib/__tests__/navigation.test.ts +135 -1
- package/src/lib/__tests__/resolve-config.test.ts +64 -3
- package/src/lib/__tests__/schemas.test.ts +42 -4
- package/src/lib/__tests__/site-unavailable-page.test.ts +25 -0
- package/src/lib/__tests__/slug.test.ts +70 -0
- package/src/lib/__tests__/slugify.test.ts +85 -0
- package/src/lib/__tests__/storage.test.ts +32 -0
- package/src/lib/__tests__/thread-fold.test.ts +113 -0
- package/src/lib/__tests__/upload-sideload.test.ts +14 -0
- package/src/lib/__tests__/url-fetch.test.ts +1 -2
- package/src/lib/__tests__/url.test.ts +78 -72
- package/src/lib/__tests__/view-language.test.ts +413 -0
- package/src/lib/__tests__/worker-response-cache.test.ts +90 -0
- package/src/lib/address.ts +57 -0
- package/src/lib/api-posts.ts +12 -0
- package/src/lib/asset-path.ts +98 -1
- package/src/lib/build-env.ts +16 -0
- package/src/lib/collection-groups.ts +5 -1
- package/src/lib/collection-paths.ts +3 -10
- package/src/lib/constants.ts +28 -3
- package/src/lib/copy-field.ts +36 -0
- package/src/lib/crypto.ts +40 -0
- package/src/lib/csp-builder.ts +2 -1
- package/src/lib/deferred.ts +79 -0
- package/src/lib/discover-ping.ts +141 -0
- package/src/lib/discover.ts +437 -0
- package/src/lib/env.ts +134 -0
- package/src/lib/errors.ts +33 -0
- package/src/lib/feed-policy.ts +236 -2
- package/src/lib/feed.ts +926 -73
- package/src/lib/filter-dimensions.ts +1349 -0
- package/src/lib/github-sync-site-config.ts +3 -0
- package/src/lib/hosted-signin.ts +1 -1
- package/src/lib/http-cache.ts +148 -0
- package/src/lib/hugo-markdown.ts +16 -0
- package/src/lib/icons.ts +9 -2
- package/src/lib/ids.ts +3 -0
- package/src/lib/jant-docs.ts +42 -0
- package/src/lib/lang-detect.ts +308 -0
- package/src/lib/media-helpers.ts +13 -1
- package/src/lib/navigation.ts +78 -11
- package/src/lib/pagination.ts +28 -24
- package/src/lib/per-language-surfaces.ts +67 -0
- package/src/lib/post-meta.ts +19 -0
- package/src/lib/render.tsx +55 -7
- package/src/lib/resolve-config.ts +53 -5
- package/src/lib/schemas.ts +201 -10
- package/src/lib/site-header-fragment.tsx +2 -1
- package/src/lib/site-unavailable-page.ts +47 -0
- package/src/lib/slug.ts +51 -7
- package/src/lib/slugify.ts +113 -0
- package/src/lib/startup-config.ts +4 -6
- package/src/lib/storage.ts +7 -0
- package/src/lib/summary.ts +50 -0
- package/src/lib/thread-fold.ts +161 -0
- package/src/lib/time.ts +32 -0
- package/src/lib/timeline.ts +42 -1
- package/src/lib/tiptap-render.ts +1 -2
- package/src/lib/upload.ts +16 -13
- package/src/lib/url.ts +139 -86
- package/src/lib/version.ts +10 -8
- package/src/lib/view-language.ts +436 -0
- package/src/lib/view.ts +51 -23
- package/src/lib/viewer-context.ts +62 -0
- package/src/middleware/__tests__/auth.test.ts +70 -2
- package/src/middleware/__tests__/cache-control.test.ts +71 -3
- package/src/middleware/__tests__/onboarding.test.ts +76 -5
- package/src/middleware/__tests__/secure-headers.test.ts +1 -1
- package/src/middleware/__tests__/session.test.ts +181 -33
- package/src/middleware/auth.ts +50 -31
- package/src/middleware/cache-control.ts +75 -10
- package/src/middleware/config.ts +6 -6
- package/src/middleware/error-handler.ts +12 -0
- package/src/middleware/onboarding.ts +32 -10
- package/src/middleware/secure-headers.ts +1 -1
- package/src/middleware/session.ts +96 -8
- package/src/node/__tests__/cli-migrate.test.ts +21 -19
- package/src/node/__tests__/cli-reset-password.test.ts +81 -8
- package/src/node/__tests__/cli-runtime-target.test.ts +48 -1
- package/src/node/__tests__/cli-site-selection.test.ts +128 -38
- package/src/node/__tests__/runtime.test.ts +37 -0
- package/src/node/index.ts +1 -0
- package/src/preset.css +76 -22
- package/src/routes/__tests__/feed-validator.test.ts +156 -0
- package/src/routes/api/__tests__/collections.test.ts +114 -0
- package/src/routes/api/__tests__/discover.test.ts +222 -0
- package/src/routes/api/__tests__/nav-items.test.ts +212 -2
- package/src/routes/api/__tests__/post-translations.test.ts +829 -0
- package/src/routes/api/__tests__/settings.test.ts +24 -3
- package/src/routes/api/__tests__/telegram.test.ts +6 -5
- package/src/routes/api/collections.ts +49 -6
- package/src/routes/api/custom-urls.ts +0 -1
- package/src/routes/api/discover.ts +95 -0
- package/src/routes/api/export.ts +3 -0
- package/src/routes/api/internal/__tests__/sites.test.ts +42 -2
- package/src/routes/api/nav-items.ts +55 -8
- package/src/routes/api/posts.ts +159 -0
- package/src/routes/api/public/__tests__/archive.test.ts +111 -0
- package/src/routes/api/public/archive.ts +77 -81
- package/src/routes/api/public/posts.ts +23 -6
- package/src/routes/api/smart-collections.ts +132 -0
- package/src/routes/api/telegram.ts +2 -40
- package/src/routes/api/uploads.ts +1 -2
- package/src/routes/auth/__tests__/setup-auth.test.ts +137 -0
- package/src/routes/auth/__tests__/setup-discover.test.ts +204 -0
- package/src/routes/auth/__tests__/setup-flow.test.ts +270 -0
- package/src/routes/auth/__tests__/setup-page.test.tsx +329 -0
- package/src/routes/auth/__tests__/setup-steps.test.ts +310 -0
- package/src/routes/auth/__tests__/setup.test.ts +278 -26
- package/src/routes/auth/__tests__/signin.test.ts +135 -0
- package/src/routes/auth/setup.tsx +934 -186
- package/src/routes/auth/signin.tsx +10 -8
- package/src/routes/compose.tsx +5 -0
- package/src/routes/dash/__tests__/custom-urls-archive.test.ts +44 -0
- package/src/routes/dash/__tests__/custom-urls-page.test.ts +49 -0
- package/src/routes/dash/__tests__/delete-account.test.ts +106 -0
- package/src/routes/dash/__tests__/settings-discover.test.ts +213 -0
- package/src/routes/dash/custom-urls.tsx +1 -37
- package/src/routes/dash/settings.tsx +502 -41
- package/src/routes/discover-announce.ts +96 -0
- package/src/routes/feed/__tests__/feed.test.ts +165 -2
- package/src/routes/feed/feed.ts +69 -40
- package/src/routes/feed/sitemap.ts +95 -11
- package/src/routes/pages/__tests__/archive-indexing.test.ts +200 -0
- package/src/routes/pages/__tests__/archive-params.test.ts +370 -6
- package/src/routes/pages/__tests__/collection-routing.test.ts +16 -0
- package/src/routes/pages/__tests__/collections-feed-links.test.ts +72 -0
- package/src/routes/pages/__tests__/collections.test.ts +9 -3
- package/src/routes/pages/__tests__/custom-archive-url.test.ts +119 -0
- package/src/routes/pages/__tests__/feed-autodiscovery.test.ts +148 -0
- package/src/routes/pages/__tests__/language-routing.test.ts +679 -0
- package/src/routes/pages/__tests__/post-preview-partial.test.ts +96 -0
- package/src/routes/pages/__tests__/smart-collection.test.ts +298 -0
- package/src/routes/pages/__tests__/subscribe.test.ts +248 -0
- package/src/routes/pages/archive.tsx +471 -369
- package/src/routes/pages/collection.tsx +94 -96
- package/src/routes/pages/collections.tsx +38 -50
- package/src/routes/pages/featured.tsx +32 -13
- package/src/routes/pages/home.tsx +25 -6
- package/src/routes/pages/language.tsx +113 -0
- package/src/routes/pages/latest.tsx +26 -16
- package/src/routes/pages/new.tsx +3 -0
- package/src/routes/pages/page.tsx +178 -17
- package/src/routes/pages/partials.tsx +41 -0
- package/src/routes/pages/search.tsx +18 -3
- package/src/routes/pages/smart-collection.tsx +340 -0
- package/src/routes/pages/subscribe.tsx +182 -0
- package/src/runtime/__tests__/index.test.ts +19 -0
- package/src/runtime/__tests__/node.test.ts +129 -4
- package/src/runtime/cloudflare.ts +21 -2
- package/src/runtime/index.ts +27 -1
- package/src/runtime/node.ts +18 -1
- package/src/runtime/site.ts +95 -24
- package/src/services/__tests__/auth.test.ts +116 -7
- package/src/services/__tests__/collection.test.ts +108 -4
- package/src/services/__tests__/language.test.ts +495 -0
- package/src/services/__tests__/navigation.test.ts +213 -10
- package/src/services/__tests__/path.test.ts +180 -0
- package/src/services/__tests__/post-language.test.ts +830 -0
- package/src/services/__tests__/post.test.ts +46 -9
- package/src/services/__tests__/settings.test.ts +228 -17
- package/src/services/__tests__/site-admin.test.ts +5 -5
- package/src/services/__tests__/smart-collection.test.ts +651 -0
- package/src/services/about-page.ts +22 -1
- package/src/services/auth.ts +51 -49
- package/src/services/bootstrap.ts +188 -38
- package/src/services/collection-directory-position.ts +76 -0
- package/src/services/collection.ts +331 -46
- package/src/services/custom-url.ts +27 -22
- package/src/services/export-theme/assets/client-site.css +1 -1
- package/src/services/export-theme/assets/client-site.js +123 -123
- package/src/services/export-theme/layouts/_default/rss.xml +77 -1
- package/src/services/export-theme/layouts/partials/feed-post-content.xml +105 -2
- package/src/services/export-theme/layouts/partials/media-gallery.html +35 -21
- package/src/services/export-theme/layouts/partials/pagination.html +14 -13
- package/src/services/export-theme/layouts/partials/post-card.html +8 -4
- package/src/services/export-theme/layouts/partials/reply.html +2 -1
- package/src/services/export-theme/layouts/partials/thread-preview.html +40 -30
- package/src/services/export-theme/styles/main.css +13 -1
- package/src/services/export.ts +278 -19
- package/src/services/index.ts +34 -3
- package/src/services/language.ts +412 -0
- package/src/services/mcp.ts +3 -1
- package/src/services/media.ts +14 -6
- package/src/services/navigation.ts +429 -67
- package/src/services/path.ts +221 -6
- package/src/services/post.ts +1021 -152
- package/src/services/search.ts +39 -2
- package/src/services/settings.ts +238 -43
- package/src/services/site-admin.ts +24 -7
- package/src/services/site.ts +77 -1
- package/src/services/smart-collection.ts +636 -0
- package/src/services/telegram.ts +20 -22
- package/src/services/upload-session.ts +1 -3
- package/src/style-author.css +27 -0
- package/src/styles/components-author.css +1622 -0
- package/src/styles/components.css +24 -1571
- package/src/styles/site-media.css +16 -2
- package/src/styles/tokens.css +82 -12
- package/src/styles/ui-author.css +7602 -0
- package/src/styles/ui.css +1087 -7219
- package/src/types/app-context.ts +7 -0
- package/src/types/bindings.ts +3 -0
- package/src/types/config.ts +94 -15
- package/src/types/constants.ts +188 -16
- package/src/types/entities.ts +87 -1
- package/src/types/operations.ts +64 -2
- package/src/types/props.ts +157 -31
- package/src/types/views.ts +55 -1
- package/src/ui/__tests__/font-themes.test.ts +52 -12
- package/src/ui/compose/ComposeDialog.tsx +201 -7
- package/src/ui/compose/ComposePrompt.tsx +1 -5
- package/src/ui/compose/__tests__/ComposeDialog.test.tsx +125 -0
- package/src/ui/dash/appearance/AdvancedContent.tsx +2 -2
- package/src/ui/dash/appearance/CodeInjectionContent.tsx +12 -16
- package/src/ui/dash/appearance/NavigationContent.tsx +117 -16
- package/src/ui/dash/appearance/__tests__/NavigationContent.test.tsx +33 -11
- package/src/ui/dash/appearance/__tests__/system-nav-descriptions.test.ts +44 -0
- package/src/ui/dash/appearance/system-nav-descriptions.ts +75 -0
- package/src/ui/dash/settings/AccountMenuContent.tsx +2 -2
- package/src/ui/dash/settings/ApiTokensContent.tsx +2 -1
- package/src/ui/dash/settings/ConfigEditorContent.tsx +35 -16
- package/src/ui/dash/settings/GeneralContent.tsx +275 -113
- package/src/ui/dash/settings/LanguageContent.tsx +409 -0
- package/src/ui/dash/settings/SettingsRootContent.tsx +19 -1
- package/src/ui/dash/settings/__tests__/GeneralContent.test.tsx +324 -4
- package/src/ui/dash/settings/__tests__/LanguageContent.test.tsx +144 -0
- package/src/ui/dash/settings/__tests__/discover-copy.test.ts +66 -0
- package/src/ui/dash/settings/discover-copy.ts +116 -0
- package/src/ui/feed/LinkCard.tsx +55 -45
- package/src/ui/feed/NoteCard.tsx +9 -4
- package/src/ui/feed/PostStatusBadges.tsx +90 -43
- package/src/ui/feed/QuoteCard.tsx +55 -30
- package/src/ui/feed/ThreadPreview.tsx +6 -2
- package/src/ui/feed/__tests__/thread-preview.test.ts +13 -16
- package/src/ui/feed/__tests__/timeline-cards.test.ts +314 -49
- package/src/ui/feed/thread-preview-state.ts +20 -6
- package/src/ui/font-themes.ts +39 -29
- package/src/ui/layouts/BaseLayout.tsx +155 -10
- package/src/ui/layouts/SiteLayout.tsx +192 -34
- package/src/ui/layouts/__tests__/BaseLayout.test.tsx +196 -17
- package/src/ui/layouts/__tests__/SiteLayout.test.tsx +109 -85
- package/src/ui/pages/ArchivePage.tsx +282 -289
- package/src/ui/pages/CollectionPage.tsx +86 -76
- package/src/ui/pages/CollectionsPage.tsx +5 -0
- package/src/ui/pages/ComposePage.tsx +8 -0
- package/src/ui/pages/PostPage.tsx +47 -0
- package/src/ui/pages/SearchPage.tsx +3 -3
- package/src/ui/pages/SmartCollectionPage.tsx +434 -0
- package/src/ui/pages/SubscribePage.tsx +236 -0
- package/src/ui/pages/__tests__/ArchivePage.test.tsx +65 -9
- package/src/ui/pages/__tests__/collections-directory-rows.test.tsx +92 -0
- package/src/ui/pages/__tests__/collections-view-links.test.tsx +81 -0
- package/src/ui/shared/CollectionDirectory.tsx +178 -3
- package/src/ui/shared/CollectionsManager.tsx +70 -17
- package/src/ui/shared/CopyField.tsx +127 -0
- package/src/ui/shared/EmptyPostContent.tsx +23 -0
- package/src/ui/shared/MediaGallery.tsx +125 -46
- package/src/ui/shared/Pagination.tsx +20 -5
- package/src/ui/shared/PostFooter.tsx +20 -11
- package/src/ui/shared/__tests__/archive-labels.test.ts +100 -0
- package/src/ui/shared/__tests__/media-gallery.test.ts +210 -2
- package/src/ui/shared/__tests__/navigation-labels.test.ts +16 -22
- package/src/ui/shared/__tests__/pagination.test.ts +38 -24
- package/src/ui/shared/__tests__/post-footer.test.ts +32 -0
- package/src/ui/shared/archive-labels.ts +98 -0
- package/src/ui/shared/collection-management-labels.ts +94 -16
- package/src/ui/shared/navigation-labels.ts +45 -71
- package/src/ui/shared/post-article-attributes.ts +2 -0
- package/src/ui/shared/smart-collection-labels.ts +343 -0
- package/dist/app-C75Zc8dD.js +0 -6
- package/dist/client/_assets/chunks/heic-to-DUUaO23q.js +0 -1
- package/dist/client/_assets/chunks/module-DcsAZQZ_.js +0 -716
- package/dist/client/_assets/chunks/url-CU9pEbk5.js +0 -1
- package/dist/client/_assets/client-Bq0vre8Y.js +0 -296
- package/dist/client/_assets/client-D3VZyG4L.css +0 -2
- package/dist/client/_assets/client-auth-F2rb9WfF.js +0 -5571
- package/dist/env-BPYViDJJ.js +0 -281
- package/dist/github-api-BNF35Lkx.js +0 -176
- package/dist/github-app-DdiD-bC4.js +0 -275
- package/dist/github-sync-Bqg62IvV.js +0 -4
- package/dist/github-sync-HdK2EgvJ.js +0 -431
- package/dist/url-CbLAtlZe.js +0 -900
- package/src/client/__tests__/collection-created-notice.test.ts +0 -36
- package/src/client/__tests__/collection-form-bridge.test.ts +0 -216
- package/src/client/__tests__/post-form-bridge.test.ts +0 -82
- package/src/client/collection-created-notice.ts +0 -66
- package/src/client/collection-form-bridge.ts +0 -191
- package/src/client/components/__tests__/jant-post-form.test.ts +0 -193
- package/src/client/components/jant-post-form.ts +0 -422
- package/src/client/components/post-form-template.ts +0 -352
- package/src/client/components/post-form-types.ts +0 -96
- package/src/client/media-metadata.ts +0 -247
- package/src/client/post-form-bridge.ts +0 -193
- package/src/ui/pages/CollectionEditorPage.tsx +0 -175
|
@@ -0,0 +1,2004 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["_assets/chunks/emoji-mart-C4RpRKcU.js","_assets/chunks/rolldown-runtime-hePW80VL.js","_assets/chunks/mediabunny-DRaCQ1r-.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{b as e,c as t,f as n,h as r,i,l as a,n as o,s,t as c,u as l}from"./chunks/lit-DW8VmJAT.js";import{r as u}from"./chunks/footnote-rail-CmeoVtnU.js";import{n as d}from"./chunks/unsafe-html-B5ZEXaxg.js";import{c as f,i as p,n as m,o as h,r as g,s as _,t as v}from"./chunks/unsafe-svg-0QCkP0vZ.js";import{i as y,r as b,t as x}from"./chunks/slug-format-CRXO1AL5.js";import{_ as S,p as C}from"./chunks/types-D5iF3H1a.js";import{a as w,f as ee,i as te,n as T,o as E,r as D,s as ne,t as O,u as re}from"./chunks/sortable-list-CgaL2jCs.js";import{_ as ie,a as k,c as A,d as j,f as M,g as N,h as ae,i as oe,l as se,m as ce,n as le,o as ue,p as de,s as fe,u as pe}from"./chunks/create-editor-CD3FhrOB.js";var P=e=>e??o;function me(e){let t=e.trim().toLowerCase();if(!t)return;let n=t.split(`-`)[0];if(n===`zh`){let e=t.slice(3);return e===`hant`||e===`tw`||e===`hk`||e===`mo`?`zh-Hant`:`zh-Hans`}if(n===`ja`)return`ja`;if(n===`ko`)return`ko`}var he=`们这会说对时国学个来过现发经应关点无义与从门问间东车长马鸟鱼见贝页风飞头语话认识讲论议记让试该请读谁调谈变边达运还进远连适选递邮释钟银错锁闭开闻阅队阶阳阴陆陈险隐难静韩须顾频颜题类飘饭饮饰馆驻驾验骑骗体处备够夺奋妇妈宁宝实宽宾寻导尔尘尝尽层属岁岂岛币帅帮归当录彻忆态怀恋恶悬惊惧惨愤愿战户扩扫扬担拟挂挤挥换据摄击敌断旧显术机杀杂权条极构柜标树桥检楼欢欧残毁气汉汤沟泪洁济浏浅浆涛润涨渐渔渗湾湿满滨滤灭灯灵灾炉烦烧热营爱状犹狮独狱猎猪献猫环电画畅疗疯皱监盘矿码确础礼祸种积称稳穷窃竞笔筹简签粮紧纪纯纲纳纵纷纸线组细织终绍结绕绘给络绝统继绩绪续维综绿缓编缘缩缴网罗罚罢习联声职聪肃肠胀脑脱腊舰艰节苏药荐荡获萧蓝虏虚虽蚀蜡补装观规觉计订讨训讯词译诉诊证评诚误诸课谅谓谢谱贡财责贤败货质贩贪购贯贱贴贵贷贸费贺资赏赐赔赖赚赛赢赠赶趋践轨转轮软载较辅辈辉输辐辑辞迁迈违迟逊遗邓邻郑针钉钓钙钝钞钢钥钦钩钱钻铁铃铅铜铝铺链销锋锐锦键镇镜闪闯闲闷闹阀阁阵际隶随雾项顶预领颇颈颗颠饥饱饼馈驰驱驶骂骄鲁鲜鸡鸣鸦鸭鸽鹅鹰麦黄齐齿龄龙龟儿优传伤侦侧俭债倾偿储兰兴军农决净减凤凭则刘创剑剧劝办务动励劳势勋医华单卖卫厅历压厌厨参叶号叹吗启呐员呜响哑唤啸喷嘱团园围图圆场坏块坚坛垒垦堕墙壮壳复`,ge=`們這會說對時國學後個來過現發經應關點無義與從門問間東車長馬鳥魚見貝頁風飛頭語話認識講論議記讓試該請讀誰調談變邊達運還進遠連適選遞郵釋鐘銀錯鎖閉開聞閱隊階陽陰陸陳險隱難靜韓須顧頻顏題類飄飯飲飾館駐駕驗騎騙體處備夠奪奮婦媽寧寶實寬賓尋導爾塵嘗盡層屬歲豈島幣帥幫歸當錄徹憶態懷戀惡懸驚懼慘憤願戰戶擴掃揚擔擬掛擠揮換據攝擊敵斷舊顯術機殺雜權條極構櫃標樹橋檢樓歡歐殘毀氣漢湯溝淚潔濟瀏淺漿濤潤漲漸漁滲灣濕滿濱濾滅燈靈災爐煩燒熱營愛狀猶獅獨獄獵豬獻貓環電畫暢療瘋皺監盤礦碼確礎禮禍種積稱穩窮竊競筆籌簡簽糧緊紀純綱納縱紛紙線組細織終紹結繞繪給絡絕統繼績緒續維綜綠緩編緣縮繳網羅罰罷習聯聲職聰肅腸脹腦脫臘艦艱節蘇藥薦蕩獲蕭藍虜虛雖蝕蠟補裝觀規覺計訂討訓訊詞譯訴診證評誠誤諸課諒謂謝譜貢財責賢敗貨質販貪購貫賤貼貴貸貿費賀資賞賜賠賴賺賽贏贈趕趨踐軌轉輪軟載較輔輩輝輸輻輯辭遷邁違遲遜遺鄧鄰鄭針釘釣鈣鈍鈔鋼鑰欽鉤錢鑽鐵鈴鉛銅鋁鋪鏈銷鋒銳錦鍵鎮鏡閃闖閒悶鬧閥閣陣際隸隨霧項頂預領頗頸顆顛飢飽餅饋馳驅駛罵驕魯鮮雞鳴鴉鴨鴿鵝鷹麥黃齊齒齡龍龜兒優傳傷偵側儉債傾償儲蘭興軍農衝決淨減鳳憑劃則劉創劍劇勸辦務動勵勞勢勳醫華單賣衛廳歷壓厭廚參疊隻臺葉號嘆嗎啟吶員嗚響啞喚嘯噴囑團園圍圖圓場壞塊堅壇壘墾墮牆壯殼複`,_e=new Set(he),ve=new Set(ge);function ye(e){let t={hangul:0,kana:0,han:0,latin:0,simplified:0,traditional:0};for(let n of e){let e=n.codePointAt(0);if(e!==void 0){if(e>=44032&&e<=55203||e>=4352&&e<=4607||e>=12592&&e<=12687){t.hangul++;continue}if(e>=12352&&e<=12447||e>=12448&&e<=12543||e>=12784&&e<=12799){t.kana++;continue}if(e>=19968&&e<=40959||e>=13312&&e<=19903||e>=63744&&e<=64255){t.han++,_e.has(n)?t.simplified++:ve.has(n)&&t.traditional++;continue}(e>=65&&e<=90||e>=97&&e<=122||e>=192&&e<=591)&&t.latin++}}return t}var be=3,xe=10;function Se(e){let t=ye(e),n=(t.hangul+t.kana+t.han)*be;return n>=t.latin&&n>=xe?t.hangul>0?`ko`:t.kana>0?`ja`:t.simplified>t.traditional?`zh-Hans`:t.traditional>t.simplified?`zh-Hant`:`han`:t.latin>=xe?`latin`:null}function Ce(e,t){let{languages:n}=t;if(n.length===0)return null;let r=Se(e);if(!r)return null;if(r===`latin`){let e=n.filter(e=>!me(e));return e.length===1?e[0]:null}if(r===`han`){let e=n.filter(e=>{let t=me(e);return t===`zh-Hans`||t===`zh-Hant`});return e.length===1?e[0]:null}return n.find(e=>me(e)===r)??null}var we=/^—\s*(.*?)(?:\s+(https?:\/\/\S+))?\s*$/;function Te(e){return e?JSON.parse(JSON.stringify(e)):null}function Ee(e){return e?typeof e.text==`string`?e.text:Array.isArray(e.content)?e.content.map(Ee).join(``):``:``}function De(e,t=2){return{type:`heading`,attrs:{level:t},content:[{type:`text`,text:e}]}}function Oe(e){return e?{type:`paragraph`,content:[{type:`text`,text:e}]}:{type:`paragraph`}}function ke(e){return{type:`paragraph`,content:[{type:`text`,text:e,marks:[{type:`link`,attrs:{href:e}}]}]}}function Ae(e){let t=we.exec(e.trim());return t?{author:t[1].trim(),url:t[2]??null}:{author:``,url:null}}function je(e){if(!e)return null;if(Array.isArray(e.marks)){let t=e.marks.find(e=>e.type===`link`)?.attrs?.href;if(typeof t==`string`&&t)return t}if(Array.isArray(e.content))for(let t of e.content){let e=je(t);if(e)return e}return null}function Me(e,t){let n=e.trim(),r=t?.trim()??``;if(!n&&!r)return null;let i=e=>({type:`text`,text:e,marks:[{type:`link`,attrs:{href:r}}]});return n&&r?{type:`paragraph`,content:[{type:`text`,text:`— `},i(n)]}:n?{type:`paragraph`,content:[{type:`text`,text:`— ${n}`}]}:{type:`paragraph`,content:[{type:`text`,text:`— `},i(r)]}}function Ne(e,t){let n=e.split(`
|
|
3
|
+
`).map(e=>Oe(e));return t&&n.push(t),{type:`blockquote`,content:n}}function Pe(e,t,n){if(e===t)return n;let r={...n},i=Te(n.bodyJson),a=Array.isArray(i?.content)?[...i.content]:[];if(t===`link`&&r.url===``){let e=a[0],t=je(e);t&&e?.type===`paragraph`&&Array.isArray(e.content)&&e.content.length===1&&Ee(e)===t&&(r.url=t,a.shift())}if(t===`quote`&&r.quoteText===``&&a[0]?.type===`blockquote`){let e=Array.isArray(a[0].content)?[...a[0].content]:[],t=e[e.length-1],n=Ee(t);if(e.length>0&&/^—/.test(n.trim())){let i=Ae(n),a=je(t)??i.url,o=i.author===a?``:i.author;o&&(r.quoteAuthor=r.quoteAuthor||o),a&&r.url===``&&(r.url=a),e.pop()}r.quoteText=e.map(Ee).join(`
|
|
4
|
+
`).trim(),a.shift()}let o=[];if(t===`quote`&&r.title.trim()!==``&&(o.push(De(r.title.trim())),r.title=``),t!==`quote`&&r.quoteText.trim()!==``){let e=t===`note`?r.url:null;o.push(Ne(r.quoteText,Me(r.quoteAuthor,e))),r.quoteText=``,r.quoteAuthor=``,t===`note`&&(r.url=``)}else t===`note`&&r.url.trim()!==``&&(o.push(ke(r.url.trim())),r.url=``);return o.length&&a.unshift(...o),r.bodyJson=a.length?{type:`doc`,content:a}:null,t===`note`&&r.title.trim().length>0&&(r.showTitle=!0),r}var Fe=[`image/jpeg`,`image/png`,`image/gif`,`image/webp`,`image/svg+xml`,`image/avif`,`image/bmp`,`image/x-icon`],Ie=[`video/mp4`,`video/webm`,`video/quicktime`,`video/x-msvideo`,`video/x-matroska`,`video/mpeg`,`video/3gpp`,`video/x-flv`,`video/ogg`],Le=[`audio/mpeg`,`audio/ogg`,`audio/wav`,`audio/mp4`,`audio/x-m4a`,`audio/flac`,`audio/aac`,`audio/webm`,`audio/x-aiff`,`audio/opus`,`audio/3gpp`,`audio/midi`],Re=[`application/pdf`,`application/epub+zip`,`application/x-mobipocket-ebook`,`application/vnd.amazon.ebook`],ze=[`application/msword`,`application/vnd.openxmlformats-officedocument.wordprocessingml.document`,`application/vnd.ms-excel`,`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`,`application/vnd.ms-powerpoint`,`application/vnd.openxmlformats-officedocument.presentationml.presentation`,`application/vnd.oasis.opendocument.text`,`application/vnd.oasis.opendocument.spreadsheet`,`application/vnd.oasis.opendocument.presentation`,`application/vnd.apple.pages`,`application/vnd.apple.numbers`,`application/vnd.apple.keynote`],Be=[`text/plain`,`text/markdown`,`text/csv`,`text/html`,`text/css`,`text/javascript`,`text/xml`,`text/rtf`,`text/tab-separated-values`,`text/calendar`,`application/json`,`application/xml`,`application/yaml`,`application/toml`],Ve=[`application/zip`,`application/x-tar`,`application/gzip`,`application/x-bzip2`,`application/x-7z-compressed`,`application/x-rar-compressed`,`application/zstd`],He=[`font/ttf`,`font/otf`,`font/woff`,`font/woff2`],Ue=[`model/gltf+json`,`model/gltf-binary`,`model/obj`,`application/x-figma`,`image/vnd.dxf`],We=[`application/sql`,`application/wasm`,`application/x-ipynb+json`,`application/x-sh`,`application/x-python-code`],Ge=new Map([...Fe.map(e=>[e,`image`]),...Ie.map(e=>[e,`video`]),...Le.map(e=>[e,`audio`]),...Re.map(e=>[e,`document`]),...ze.map(e=>[e,`office`]),...Be.map(e=>[e,`text`]),...Ve.map(e=>[e,`archive`]),...He.map(e=>[e,`font`]),...Ue.map(e=>[e,`3d`]),...We.map(e=>[e,`code`])]);function F(e){return Ge.get(e)||(e.startsWith(`image/`)?`image`:e.startsWith(`video/`)?`video`:e.startsWith(`audio/`)?`audio`:e.startsWith(`font/`)?`font`:e.startsWith(`model/`)?`3d`:e.startsWith(`text/`)?`text`:`archive`)}function Ke(e){return e.startsWith(`image/`)}new Set(Fe);var qe=new Set([`heic`,`heix`,`hevc`,`hevx`,`mif1`,`msf1`]);function Je(e){if(e.length>=3&&e[0]===255&&e[1]===216&&e[2]===255)return`image/jpeg`;if(e.length>=8&&e[0]===137&&I(e,1,3)===`PNG`)return`image/png`;if(e.length>=6&&/^GIF8[79]a$/.test(I(e,0,6)))return`image/gif`;if(e.length>=12&&I(e,0,4)===`RIFF`&&I(e,8,4)===`WEBP`)return`image/webp`;if(e.length>=12&&I(e,4,4)===`ftyp`){let t=I(e,8,4);if(t===`avif`||t===`avis`)return`image/avif`;if(qe.has(t))return`image/heic`}return e.length>=2&&e[0]===66&&e[1]===77?`image/bmp`:e.length>=4&&e[0]===0&&e[1]===0&&e[2]===1&&e[3]===0?`image/x-icon`:new TextDecoder().decode(e.subarray(0,1024)).toLowerCase().includes(`<svg`)?`image/svg+xml`:null}function Ye(e,t){return Xe(e.type,e.size,t)}function Xe(e,t,n){if(n?.imagesOnly&&!Ke(e))return`File type not allowed.`;let r=n.maxFileSizeMB;return t>r*1024*1024?`File too large (max ${r}MB).`:null}function I(e,t,n){return new TextDecoder(`ascii`).decode(e.slice(t,t+n))}var L=()=>typeof crypto<`u`&&typeof crypto.randomUUID==`function`?crypto.randomUUID():`xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx`.replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e===`x`?t:t&3|8).toString(16)}),Ze=`[data-editor-floating-ui]`,Qe=`single`,$e=`(max-width: 700px), (max-height: 760px), (hover: none) and (pointer: coarse)`,et={drafts:`
|
|
5
|
+
<rect x="3.85" y="3.45" width="7.85" height="8.35" rx="2.35" />
|
|
6
|
+
<rect
|
|
7
|
+
x="6.15"
|
|
8
|
+
y="5.75"
|
|
9
|
+
width="7.85"
|
|
10
|
+
height="8.35"
|
|
11
|
+
rx="2.35"
|
|
12
|
+
fill="var(--compose-icon-paper-fill)"
|
|
13
|
+
stroke="none"
|
|
14
|
+
/>
|
|
15
|
+
<rect x="6.15" y="5.75" width="7.85" height="8.35" rx="2.35" />
|
|
16
|
+
<path d="M8.55 8.55h3.2" stroke-width="1.2" />
|
|
17
|
+
<path d="M8.55 10.8h3.95" stroke-width="1.2" />
|
|
18
|
+
<path d="M8.55 13.05h2.45" stroke-width="1.2" />
|
|
19
|
+
`,saveDraft:`
|
|
20
|
+
<path d="M6.65 3.6h4.7a2 2 0 0 1 2 2v8.7L9 11.75l-4.35 2.55V5.6a2 2 0 0 1 2-2Z" />
|
|
21
|
+
`},tt={public:`
|
|
22
|
+
<circle cx="8" cy="8" r="5.15" />
|
|
23
|
+
<path d="M3.85 8h8.3" />
|
|
24
|
+
<path d="M8 2.85c1.22 1.32 1.95 3.08 1.95 5.15S9.22 11.83 8 13.15" />
|
|
25
|
+
<path d="M8 2.85C6.78 4.17 6.05 5.93 6.05 8S6.78 11.83 8 13.15" />
|
|
26
|
+
`,latest_hidden:`
|
|
27
|
+
<path
|
|
28
|
+
d="M2.55 8c1.38-2.18 3.44-3.4 5.45-3.4S12.07 5.82 13.45 8c-1.38 2.18-3.44 3.4-5.45 3.4S3.93 10.18 2.55 8Z"
|
|
29
|
+
/>
|
|
30
|
+
<path d="M4.35 11.1 11.65 4.9" />
|
|
31
|
+
`,private:`
|
|
32
|
+
<rect x="4.05" y="7.05" width="7.9" height="5.4" rx="1.75" />
|
|
33
|
+
<path d="M5.95 7.05V5.9A2.05 2.05 0 0 1 8 3.85a2.05 2.05 0 0 1 2.05 2.05v1.15" />
|
|
34
|
+
`},R={check:`
|
|
35
|
+
<path d="M3.75 7.25 6 9.5l4.25-4.25" />
|
|
36
|
+
`,caretRight:`
|
|
37
|
+
<path d="M5.65 4.5 8.15 7l-2.5 2.5" />
|
|
38
|
+
`,calendar:`
|
|
39
|
+
<rect x="2.5" y="3.5" width="9" height="8" rx="2" stroke-width="1" />
|
|
40
|
+
<path d="M4.5 2.5v2" stroke-width="1" />
|
|
41
|
+
<path d="M9.5 2.5v2" stroke-width="1" />
|
|
42
|
+
<path d="M2.5 6.5h9" stroke-width="1" />
|
|
43
|
+
`,options:`
|
|
44
|
+
<path d="M4 8.5h3.4" stroke-width="1.8" />
|
|
45
|
+
<path d="M12.6 8.5H20" stroke-width="1.8" />
|
|
46
|
+
<circle cx="10" cy="8.5" r="2.2" stroke-width="1.8" />
|
|
47
|
+
<path d="M4 15.5h7.4" stroke-width="1.8" />
|
|
48
|
+
<path d="M16.6 15.5H20" stroke-width="1.8" />
|
|
49
|
+
<circle cx="14" cy="15.5" r="2.2" stroke-width="1.8" />
|
|
50
|
+
`},nt=`
|
|
51
|
+
<circle cx="12" cy="12" r="10" />
|
|
52
|
+
<path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20" />
|
|
53
|
+
<path d="M2 12h20" />
|
|
54
|
+
`,z={collection:`
|
|
55
|
+
<path d="M2.5 6.3 8 3.5l5.5 2.8L8 9.1 2.5 6.3Z" />
|
|
56
|
+
<path d="M2.5 9.7 8 12.5l5.5-2.8" />
|
|
57
|
+
`,search:`
|
|
58
|
+
<circle cx="7.1" cy="7.1" r="3.65" />
|
|
59
|
+
<path d="m10.1 10.1 2.45 2.45" />
|
|
60
|
+
`,plus:`
|
|
61
|
+
<path d="M8 3.5v9" />
|
|
62
|
+
<path d="M3.5 8h9" />
|
|
63
|
+
`,plusCircle:`
|
|
64
|
+
<circle cx="8" cy="8" r="5.7" />
|
|
65
|
+
<path d="M8 5.55v4.9" />
|
|
66
|
+
<path d="M5.55 8h4.9" />
|
|
67
|
+
`};function rt(e){return i`<svg
|
|
68
|
+
class="compose-sheet-row-icon"
|
|
69
|
+
width="18"
|
|
70
|
+
height="18"
|
|
71
|
+
viewBox="0 0 18 18"
|
|
72
|
+
fill="none"
|
|
73
|
+
stroke="currentColor"
|
|
74
|
+
stroke-width="1.25"
|
|
75
|
+
stroke-linecap="round"
|
|
76
|
+
stroke-linejoin="round"
|
|
77
|
+
aria-hidden="true"
|
|
78
|
+
>
|
|
79
|
+
${v(e)}
|
|
80
|
+
</svg>`}function it(e,t){return i`<span class=${t} aria-hidden="true">
|
|
81
|
+
<svg
|
|
82
|
+
class="compose-publish-visibility-svg"
|
|
83
|
+
width="16"
|
|
84
|
+
height="16"
|
|
85
|
+
viewBox="0 0 16 16"
|
|
86
|
+
fill="none"
|
|
87
|
+
stroke="currentColor"
|
|
88
|
+
stroke-width="1.35"
|
|
89
|
+
stroke-linecap="round"
|
|
90
|
+
stroke-linejoin="round"
|
|
91
|
+
>
|
|
92
|
+
${v(e)}
|
|
93
|
+
</svg>
|
|
94
|
+
</span>`}function B(e,t){return i`<svg
|
|
95
|
+
class=${t}
|
|
96
|
+
width="16"
|
|
97
|
+
height="16"
|
|
98
|
+
viewBox="0 0 16 16"
|
|
99
|
+
fill="none"
|
|
100
|
+
stroke="currentColor"
|
|
101
|
+
stroke-width="1.35"
|
|
102
|
+
stroke-linecap="round"
|
|
103
|
+
stroke-linejoin="round"
|
|
104
|
+
aria-hidden="true"
|
|
105
|
+
>
|
|
106
|
+
${v(e)}
|
|
107
|
+
</svg>`}function V(e,t){return i`<svg
|
|
108
|
+
class=${t}
|
|
109
|
+
width="14"
|
|
110
|
+
height="14"
|
|
111
|
+
viewBox="0 0 14 14"
|
|
112
|
+
fill="none"
|
|
113
|
+
stroke="currentColor"
|
|
114
|
+
stroke-width="1.35"
|
|
115
|
+
stroke-linecap="round"
|
|
116
|
+
stroke-linejoin="round"
|
|
117
|
+
aria-hidden="true"
|
|
118
|
+
>
|
|
119
|
+
${v(e)}
|
|
120
|
+
</svg>`}function at(e){return Array.isArray(e)?e.flatMap(e=>{if(!e||typeof e!=`object`)return[];let t=Reflect.get(e,`id`),n=Reflect.get(e,`title`),r=Reflect.get(e,`slug`);return typeof t!=`string`||typeof n!=`string`?[]:[{id:t,title:n,slug:typeof r==`string`?r:``}]}):[]}function ot(e){return!e.content||e.content.length===0||e.content.every(e=>e.type===`paragraph`&&(!e.content||e.content.length===0))}function H(e){return e?ot(e)?null:e:null}function st(e){return String(e).padStart(2,`0`)}function ct(e){let t=new Date(e*1e3);return`${t.getFullYear()}-${st(t.getMonth()+1)}-${st(t.getDate())}`}function U(e){let t=e.trim();if(!t)return null;let n=/^(\d{4})-(\d{2})-(\d{2})$/.exec(t);if(!n)return null;let r=Number(n[1]),i=Number(n[2]),a=Number(n[3]),o=new Date(r,i-1,a);return Number.isNaN(o.getTime())||o.getFullYear()!==r||o.getMonth()!==i-1||o.getDate()!==a?null:{year:r,monthIndex:i-1,day:a}}function W(e){let t=new Date(e*1e3);return t.getHours()*60+t.getMinutes()}function lt(e,t){let n=U(e);if(!n)return null;let r=Math.min(Math.max(t,0),1439),i=Math.floor(r/60),a=r%60;return Math.floor(new Date(n.year,n.monthIndex,n.day,i,a,0,0).getTime()/1e3)}async function ut(e){let t=e.filter(e=>e.type===`media`),n=e.filter(e=>e.type===`text`);return{media:t.map(e=>({id:e.id,previewUrl:e.previewUrl,posterUrl:e.posterUrl??null,alt:e.alt,mimeType:e.mimeType,originalName:e.originalName,summary:e.summary,chars:e.chars})),textAttachments:await Promise.all(n.map(async e=>{try{let t=await fetch(e.contentUrl);if(t.ok){let n=await t.json(),r=n.contentFormat===`markdown`&&n.content?n.content:``,i=r?ie(r):null;if(i)return{bodyJson:JSON.stringify(i),bodyHtml:``,summary:e.summary??``,mediaId:e.id}}}catch{}return{bodyJson:JSON.stringify({type:`doc`,content:[{type:`paragraph`}]}),bodyHtml:``,summary:e.summary??``,mediaId:e.id}})),attachmentOrder:e.map(e=>e.id)}}var dt=class e extends c{static _lastNewPostVisibility=`public`;_sourceCollectionId=null;static _collectionVisibilityKey(e){return`jant:collection-visibility:${e}`}static _getCollectionVisibility(t){try{let n=globalThis.localStorage.getItem(e._collectionVisibilityKey(t));if(n===`public`||n===`latest_hidden`||n===`private`)return n}catch{}return null}static _setCollectionVisibility(t,n){try{globalThis.localStorage.setItem(e._collectionVisibilityKey(t),n)}catch{}}static _NOTE_TITLE_KEY=`jant:compose-note-title`;static _getNoteTitleDefault(){try{return globalThis.localStorage.getItem(e._NOTE_TITLE_KEY)!==`0`}catch{return!0}}static _setNoteTitleDefault(t){try{globalThis.localStorage.setItem(e._NOTE_TITLE_KEY,t?`1`:`0`)}catch{}}static properties={collections:{type:Array},languages:{type:Array},contextLanguage:{type:String,attribute:`context-language`},labels:{type:Object},uploadMaxFileSize:{type:Number,attribute:`upload-max-file-size`},pageMode:{type:Boolean,attribute:`page-mode`},closeHref:{type:String,attribute:`close-href`},autoRestoreDraft:{type:Boolean,attribute:`auto-restore-draft`},slashCommandDiscovered:{type:Boolean,attribute:`slash-command-discovered`},_format:{state:!0},_status:{state:!0},_loading:{state:!0},_openingEdit:{state:!0},_collectionIds:{state:!0},_showCollection:{state:!0},_collectionSearch:{state:!0},_altPanelOpen:{state:!0},_altPanelIndex:{state:!0},_attachedPanelOpen:{state:!0},_attachedTextIndex:{state:!0},_confirmPanelOpen:{state:!0},_editPostId:{state:!0},_draftSourceId:{state:!0},_draftsPanelOpen:{state:!0},_drafts:{state:!0},_draftsLoading:{state:!0},_draftsError:{state:!0},_draftMenuOpenId:{state:!0},_addCollectionPanelOpen:{state:!0},_replyToId:{state:!0},_replyToData:{state:!0},_replyParentPosition:{state:!0},_replyExpanded:{state:!0},_threadItems:{state:!0},_rowStatus:{state:!0},_focusedThreadIndex:{state:!0},_slug:{state:!0},_publishedAtInput:{state:!0},_visibility:{state:!0},_showPublishPanel:{state:!0},_postMetaIndex:{state:!0},_publishPanelFullscreen:{state:!0},_suggestedSlug:{state:!0},_suggestedSlugLoading:{state:!0},_slugCheckLoading:{state:!0},_slugTaken:{state:!0},_visibilityLocked:{state:!0},_quietReply:{state:!0},_language:{state:!0},_showLanguagePicker:{state:!0},_translationOf:{state:!0},_translationCollapsed:{state:!0}};_attachedEditor=null;_attachedTextSnapshot=null;_seededFromSource=!1;_confirmForDrafts=!1;_confirmForAttachedText=!1;_draftSaveTimer=null;_draftRestored=!1;_hasOwnedContent=!1;_reportedStorageFailure=!1;_initialSnapshot=null;_pageFocusApplied=!1;_pageLeaveRequested=!1;_replyThreadRootId=null;_replyRefreshKind=null;_replyRefreshId=null;_publishedAtTimeMinutes=null;_originalPublishedAt=null;_initialPublishedAtTimeMinutes=null;_initialPublishedAtInput=``;_initialSlug=``;_slugCheckTimer=null;_slugSuggestTimer=null;_slugSuggestRequestId=0;_slugCheckRequestId=0;_slugSuggestionKey=``;_suppressBeforeUnload=!1;_dialogEl=null;_mousedownOnBackdrop=!1;_mousedownPos=null;_filePickerActive=!1;_ignoreNextEscapeClose=!1;_openEditRequestId=0;_collectionPickerOrder=[];_suppressCollectionOptionClickUntil=0;_suppressedCollectionOptionId=null;createRenderRoot(){return this.innerHTML=``,this}constructor(){super(),this.collections=[],this.languages=[],this.contextLanguage=``,this.labels={},this.uploadMaxFileSize=1024,this.pageMode=!1,this.closeHref=`/`,this.autoRestoreDraft=!1,this.slashCommandDiscovered=!1,this._format=`note`,this._status=`published`,this._loading=!1,this._openingEdit=!1,this._collectionIds=[],this._showCollection=!1,this._collectionSearch=``,this._altPanelOpen=!1,this._altPanelIndex=0,this._attachedPanelOpen=!1,this._attachedTextIndex=0,this._confirmPanelOpen=!1,this._editPostId=null,this._draftSourceId=null,this._draftsPanelOpen=!1,this._drafts=[],this._draftsLoading=!1,this._draftsError=null,this._draftMenuOpenId=null,this._addCollectionPanelOpen=!1,this._replyToId=null,this._replyToData=null,this._replyExpanded=!1,this._threadItems=[],this._rowStatus=new Map,this._focusedThreadIndex=0,this._replyThreadRootId=null,this._replyParentPosition=null,this._replyRefreshKind=null,this._replyRefreshId=null,this._slug=``,this._publishedAtInput=``,this._publishedAtTimeMinutes=null,this._originalPublishedAt=null,this._initialPublishedAtTimeMinutes=null,this._initialPublishedAtInput=``,this._initialSlug=``,this._visibility=e._lastNewPostVisibility,this._sourceCollectionId=null,this._showPublishPanel=!1,this._publishPanelFullscreen=!1,this._postMetaIndex=null,this._suggestedSlug=``,this._suggestedSlugLoading=!1,this._slugCheckLoading=!1,this._slugTaken=!1,this._visibilityLocked=!1,this._quietReply=!1,this._language=null,this._showLanguagePicker=!1,this._translationOf=null,this._translationCollapsed=!1,this._seededFromSource=!1}get _editor(){return this.querySelector(`jant-compose-editor`)}get _rowIds(){return this._threadItems.length>0?this._threadItems.map(e=>e.id):[Qe]}_handleRowStatus(e,t){let n=this._rowStatus.get(e);if(n?.hasContent===t.hasContent&&n?.publishable===t.publishable)return;let r=new Map(this._rowStatus);r.set(e,t),this._rowStatus=r}willUpdate(e){if(super.willUpdate(e),e.has(`_threadItems`)){let e=new Set(this._rowIds);[...this._rowStatus.keys()].some(t=>!e.has(t))&&(this._rowStatus=new Map([...this._rowStatus].filter(([t])=>e.has(t))))}}updated(e){super.updated(e),this._initialSnapshot===null&&this._editor&&this._captureInitialSnapshot(),this._adoptTranslationPreview(),e.has(`labels`)&&this._dialogEl&&this.labels&&this._dialogEl.setAttribute(`aria-label`,this.labels.composeDialogLabel),e.has(`_addCollectionPanelOpen`)&&this._addCollectionPanelOpen&&this.updateComplete.then(()=>{let e=this.querySelector(`[data-collection-quick-dialog] [data-collection-title-input]`);e?.focus(),e?.select()}),e.has(`_showCollection`)&&this._showCollection&&this._scheduleCollectionPickerAutofocus(),(e.has(`_collectionIds`)||e.has(`_slug`)||e.has(`_publishedAtInput`)||e.has(`_visibility`))&&(this._draftSourceId||this._scheduleDraftSave()),this._showPublishPanel&&this._updatePublishPanelLayout(),this._showCollection&&this._updateCollectionPopoverSide(),this._postMetaIndex!==null&&this._updatePostMetaPanelLayout()}reset(){this._openEditRequestId+=1,this._format=`note`,this._status=`published`,this._loading=!1,this._openingEdit=!1,this._collectionIds=[],this._closeCollectionPicker(),this._altPanelOpen=!1,this._altPanelIndex=0,this._attachedPanelOpen=!1,this._attachedTextIndex=0,this._confirmPanelOpen=!1,this._editPostId=null,this._draftSourceId=null,this._draftsPanelOpen=!1,this._drafts=[],this._draftsLoading=!1,this._draftsError=null,this._draftMenuOpenId=null,this._addCollectionPanelOpen=!1,this._replyToId=null,this._replyToData=null,this._replyExpanded=!1,this._threadItems=[],this._rowStatus=new Map,this._focusedThreadIndex=0,this._replyThreadRootId=null,this._replyParentPosition=null,this._replyRefreshKind=null,this._replyRefreshId=null,this._slug=``,this._publishedAtInput=``,this._publishedAtTimeMinutes=null,this._originalPublishedAt=null,this._initialPublishedAtTimeMinutes=null,this._initialPublishedAtInput=``,this._initialSlug=``,this._visibility=e._lastNewPostVisibility,this._sourceCollectionId=null,this._showPublishPanel=!1,this._suggestedSlug=``,this._suggestedSlugLoading=!1,this._slugCheckLoading=!1,this._slugTaken=!1,this._slugSuggestionKey=``,this._visibilityLocked=!1,this._quietReply=!1,this._language=null,this._showLanguagePicker=!1,this._translationOf=null,this._translationCollapsed=!1,this._seededFromSource=!1,this._confirmForDrafts=!1,this._confirmForAttachedText=!1,this._initialSnapshot=null,this._hasOwnedContent=!1,this._reportedStorageFailure=!1,this._pageFocusApplied=!1,this._pageLeaveRequested=!1,this._slugSuggestRequestId+=1,this._slugCheckRequestId+=1,this._suppressBeforeUnload=!1,this._filePickerActive=!1,this._ignoreNextEscapeClose=!1,this._cancelSlugTimers(),this._destroyAttachedEditor(),this._editor?.reset(),this._captureInitialSnapshot()}async refreshCollections(){try{let e=await fetch(`/api/collections?view=compose`,{cache:`no-store`,headers:{Accept:`application/json`}});if(!e.ok)return!1;let t=await e.json().catch(()=>null);return Array.isArray(t?.collections)?(this.collections=at(t.collections),!0):!1}catch{return!1}}async openEdit(e,t){this.reset();let n=++this._openEditRequestId;this._openingEdit=!0,this._editPostId=e;let r=this.closest(`dialog`);r&&!r.open&&r.showModal(),await this.updateComplete,this._focusDialogShell();try{let r=await fetch(`/api/posts/${e}`);if(!r.ok)throw Error(`Failed to load post`);let i=await r.json();if(n!==this._openEditRequestId||(this._format=i.format,this._slug=i.slug??``,this._slugTaken=!1,this._slugCheckLoading=!1,this._suggestedSlug=``,this._suggestedSlugLoading=!1,this._slugSuggestionKey=``,this._publishedAtInput=i.publishedAt?ct(i.publishedAt):``,this._publishedAtTimeMinutes=i.publishedAt?W(i.publishedAt):null,this._originalPublishedAt=i.publishedAt??null,this._initialPublishedAtTimeMinutes=this._publishedAtTimeMinutes,this._initialPublishedAtInput=this._publishedAtInput,this._initialSlug=this._slug.trim(),this._visibility=i.visibility??`public`,this._visibilityLocked=!!i.replyToId,this._language=i.language??null,i.replyToId&&(this._replyToId=i.replyToId,await this._fetchReplyContext(i.replyToId),n!==this._openEditRequestId)))return;!i.replyToId&&i.collectionIds?.length&&(this._collectionIds=i.collectionIds);let{media:a,textAttachments:o,attachmentOrder:s}=await ut(i.attachments??[]);if(n!==this._openEditRequestId||(this._openingEdit=!1,await this.updateComplete,n!==this._openEditRequestId))return;this._restoreEditDraftIfAvailable(e,t?.restoreToast)||this._editor?.populate({format:i.format,title:i.format===`quote`?void 0:i.title??void 0,bodyJson:i.body??void 0,url:i.format===`quote`?i.sourceUrl??void 0:i.url??void 0,quoteText:i.quoteText??void 0,quoteAuthor:i.format===`quote`?i.sourceName??void 0:void 0,rating:i.rating??void 0,media:a,textAttachments:o,attachmentOrder:s}),globalThis.requestAnimationFrame(()=>{n===this._openEditRequestId&&(this._focusDialogShell(),this._captureInitialSnapshot())})}catch{if(n!==this._openEditRequestId)return;this._openingEdit=!1,this._closeDialog(),this.reset(),l(this.labels.loadPostFailed,`error`)}}async openDraft(e){let t=this.closest(`dialog`);t&&!t.open&&t.showModal(),await this.updateComplete,this._focusDialogShell(),await this._loadDraft(e)}async openNew(t){this.reset(),this._editor?.setTitleDefault(e._getNoteTitleDefault());let n=`none`;if(t?.restoreDraft!==!1&&(n=await this.restoreLocalDraft({notify:t?.restoreToast,extraMedia:t?.restoreMedia})),t?.initialFormat&&(this._format=t.initialFormat),t?.collectionId&&!this._collectionIds.includes(t.collectionId)&&(this._collectionIds=[t.collectionId,...this._collectionIds]),t?.collectionId){this._sourceCollectionId=t.collectionId;let r=n===`restored`?null:e._getCollectionVisibility(t.collectionId);r&&(this._visibility=r)}this.closest(`dialog`)?.showModal(),await this.updateComplete,this._editor?.focusInput(),this._captureInitialSnapshot()}async openTranslation(t,n){this.reset(),this._editor?.setTitleDefault(e._getNoteTitleDefault()),this.languages.some(e=>e.tag===n)&&(this._language=n),this.closest(`dialog`)?.showModal(),await this.updateComplete,this._editor?.focusInput(),this._captureInitialSnapshot(),await this._loadTranslationSource(t,{seed:!0})}async openReply(e,t,n,r,i){this.reset(),this._replyToId=e,this._replyThreadRootId=n??e,this._replyRefreshKind=r?.kind??null,this._replyRefreshId=r?.id??null,this._replyToData=t??null,this._visibilityLocked=!0,this._format=i?.initialFormat??`note`,i?.restoreDraft!==!1&&await this.restoreLocalDraft({expectedReplyToId:e,notify:i?.restoreToast,extraMedia:i?.restoreMedia}),this._collectionIds=[],this.closest(`dialog`)?.showModal(),await this.updateComplete,this._editor?.focusInput(),this._captureInitialSnapshot(),this._loadReplyParentPosition(e)}async _loadReplyParentPosition(e){try{let t=await fetch(`/api/posts/${e}`);if(!t.ok)return;let n=await t.json();if(this._replyToId!==e)return;this._replyParentPosition=n.threadPosition??null}catch{}}async _fetchReplyContext(e){try{let t=await fetch(`/api/posts/${e}`);if(!t.ok)return;let n=await t.json();this._replyThreadRootId=n.replyToId?n.threadId:n.id,this._replyParentPosition=n.threadPosition??null;let r=n.publishedAt?new Date(n.publishedAt*1e3).toLocaleDateString(void 0,{month:`short`,day:`numeric`}):``,i=(n.attachments??[]).filter(e=>e.type===`media`).map(e=>({url:e.url??e.previewUrl,previewUrl:e.previewUrl,alt:e.alt,mimeType:e.mimeType,width:e.width,height:e.height}));this._replyToData={contentHtml:n.bodyHtml??``,dateText:r,media:i.length>0?i:void 0}}catch{}}set loading(e){this._loading=e}_closeDialog(){let e=this.closest(`dialog`);if(e){e.close(),document.activeElement?.blur();return}this.pageMode&&(this._suppressBeforeUnload=!0,globalThis.location.assign(this.closeHref||r(`/`)))}requestCloseAndLeave(){this._pageLeaveRequested=!0,this.requestClose()}consumePageLeaveRequest(){let e=this._pageLeaveRequested;return this._pageLeaveRequested=!1,e}preparePageLeave(){this._suppressBeforeUnload=!0}_clearFilePickerEscapeState(){this._filePickerActive=!1,this._ignoreNextEscapeClose=!1}_shouldIgnoreEscapeClose(){return this._filePickerActive||this._ignoreNextEscapeClose?(this._clearFilePickerEscapeState(),!0):!1}_hasContent(){return this._rowIds.some(e=>this._rowStatus.get(e)?.hasContent===!0)}_hasWorkToLose(){return this._hasContent()?!this._seededFromSource||this._hasUnsavedChanges():!1}_buildSnapshot(){let e=this._editor;if(!e)return null;let t=e.getData(),n=e.getEffectiveAttachedTexts(),r=t.rating>0&&e._showRating;return{format:this._format,collectionIds:[...this._collectionIds],slug:this._slug,publishedAtInput:this._publishedAtInput,publishedAtTimeMinutes:this._publishedAtTimeMinutes,visibility:this._visibility,language:this._language,title:t.title,bodyJson:e.getNormalizedBodyJson(),url:t.url,quoteText:t.quoteText,quoteAuthor:t.quoteAuthor,rating:t.rating,showRating:r,attachments:e._attachments.map(e=>({clientId:e.clientId,mediaId:e.mediaId,previewUrl:e.previewUrl,mimeType:e.file.type,alt:e.alt,status:e.status,summary:e.summary,chars:e.chars})),attachedTexts:n.map(e=>({clientId:e.clientId,mediaId:e.mediaId??null,bodyJson:e.bodyJson,bodyHtml:e.bodyHtml,summary:e.summary})),attachmentOrder:e.getEffectiveAttachmentOrder()}}_serializeSnapshot(e){return e?JSON.stringify(e):null}_captureInitialSnapshot(){this._initialSnapshot=this._serializeSnapshot(this._buildSnapshot())}_hasUnsavedChanges(){let e=this._serializeSnapshot(this._buildSnapshot());return e===null||!this._editPostId&&!this._draftSourceId&&!this._hasContent()?!1:this._initialSnapshot===null?this._hasContent():e!==this._initialSnapshot}requestClose(){if(!this._loading){if(this._showCollection&&this._closeCollectionPicker(),this._showPublishPanel&&=!1,this._showLanguagePicker=!1,this._confirmPanelOpen){let e=this._confirmForAttachedText;this._confirmPanelOpen=!1,this._confirmForDrafts=!1,this._confirmForAttachedText=!1,this._pageLeaveRequested=!1,this.updateComplete.then(()=>{if(e){this._attachedEditor?.commands.focus();return}this._editor?.focusInput()});return}if(this._editPostId){this._hasUnsavedChanges()?(this._confirmForDrafts=!1,this._confirmForAttachedText=!1,this._confirmPanelOpen=!0):(this._closeDialog(),this.reset());return}this._hasWorkToLose()?(this._confirmForDrafts=!1,this._confirmForAttachedText=!1,this._confirmPanelOpen=!0):(this._closeDialog(),this.reset())}}_discardAndClose(){if(this._draftSourceId){let e=this._draftSourceId;fetch(`/api/posts/${e}`,{method:`DELETE`}).catch(()=>{}),l(this.labels.draftDeleted)}this._clearDraftFromStorage(),this._confirmPanelOpen=!1,this._confirmForAttachedText=!1,this._closeDialog(),this.reset()}_discardAttachedPanel(){this._confirmForAttachedText=!1,this._destroyAttachedEditor(),this._attachedPanelOpen=!1,this._editor?.closeAttachedPanel(this._attachedTextIndex)}_handleConfirmSave(){this._confirmForAttachedText?(this._confirmPanelOpen=!1,this._confirmForAttachedText=!1,this._doneAttachedPanel()):this._confirmForDrafts?(this._confirmPanelOpen=!1,this._editor?.hasPendingInlineImageUploads()?this._saveDraftAndOpenDrafts():this._finishDraftSaveAndOpenDrafts()):this._editPostId?(this._confirmPanelOpen=!1,this._submit(`published`)):(this._confirmPanelOpen=!1,this._submit(`draft`))}_handleConfirmDiscard(){if(this._confirmForAttachedText)this._confirmPanelOpen=!1,this._discardAttachedPanel();else if(this._confirmForDrafts){if(this._draftSourceId){let e=this._draftSourceId;fetch(`/api/posts/${e}`,{method:`DELETE`}).catch(()=>{}),l(this.labels.draftDeleted)}this._confirmPanelOpen=!1,this.reset(),this._openDraftsPanel()}else this._discardAndClose()}_buildEditorPostDetail(e,t,n,r){e.promoteLeadingH1Title({force:!0});let i=e.getData(),a=new Map((i.attachments??[]).map(e=>[e.clientId,e])),o=new Map(i.attachedTexts.map(e=>[e.clientId,e])),s=[];for(let e of i.attachmentOrder){let t=a.get(e);if(t){s.push({type:`media`,clientId:e,mediaId:t.mediaId,alt:t.alt||void 0});continue}let n=o.get(e);n?.bodyJson&&s.push({type:`text`,clientId:e,bodyJson:n.bodyJson,summary:n.summary,mediaId:n.mediaId,originalBodyJson:H(n.originalBodyJson??null)})}let c=n===0;return{format:t,title:i.title,body:i.body,url:i.url,quoteText:i.quoteText,quoteAuthor:i.quoteAuthor,status:r,slug:this._getPostSlug(n).trim()||void 0,publishedAt:this._getPostPublishedAtSubmitValue(n,r),visibility:c?this._visibilityLocked?void 0:this._visibility:void 0,rating:i.rating,collectionIds:c&&!this._replyToId?[...this._collectionIds]:[],attachments:s,replyToId:c?this._replyToId??void 0:void 0,quietReply:c&&this._canReplyQuietly()&&this._quietReply||void 0,replyThreadRootId:c?this._replyThreadRootId??void 0:void 0,replyRefreshKind:c?this._replyRefreshKind??void 0:void 0,replyRefreshId:c?this._replyRefreshId??void 0:void 0,language:c&&!this._replyToId?this._effectiveLanguage()??void 0:void 0,translationOfId:c?this._translationOf?.id:void 0}}_buildSubmitDetail(e){let t=this._editor;return t?{...this._buildEditorPostDetail(t,this._format,0,e),editPostId:this._editPostId??this._draftSourceId??void 0,draftSourceId:this._draftSourceId??void 0}:null}_focusBlockedSubmitField(e){if(e===`published`){let e=Math.max(1,this._threadItems.length);for(let t=0;t<e;t++)if(this._getPostPublishedAtValidationMessage(t)!==null)return this._revealPublishedAtField(t),!0}{let e=Math.max(1,this._threadItems.length);for(let t=0;t<e;t++)if(this._getPostSlugValidationMessage(t))return this._revealSlugField(t),!0}if(this._threadItems.length>0){let e=Array.from(this.querySelectorAll(`jant-compose-editor`));for(let t=0;t<this._threadItems.length;t++){let n=this._threadItems[t],r=e[t];if(r){if(r.getUrlValidationMessage())return r.revealUrlValidation(),r.focusUrlInput(`end`),!0;if(r.getLinkTitleValidationMessage())return r.revealLinkTitleValidation(),r.focusLinkTitleInput(`end`),!0;if(n.format===`quote`&&!r._quoteText.trim())return r.focusInput(`end`),!0}}return!1}let t=this._editor;return t?t.getUrlValidationMessage()?(t.revealUrlValidation(),t.focusUrlInput(`end`),!0):t.getLinkTitleValidationMessage()?(t.revealLinkTitleValidation(),t.focusLinkTitleInput(`end`),!0):this._format===`quote`&&!t._quoteText.trim()&&(t.focusInput(`end`),!0):!1}_dispatchSubmit(e){if(this._loading||this._focusBlockedSubmitField(e))return!1;if(this._draftSourceId||(this._cancelDraftSaveTimer(),this._saveDraftToStorage()),this._threadItems.length>0){if(this._threadItems.length>20)return l(this._getThreadLimitMessage(),`error`),!1;let t=Array.from(this.querySelectorAll(`jant-compose-editor`));if(t.length!==this._threadItems.length)return!1;let n=[],r=[];for(let i=0;i<this._threadItems.length;i++){let a=this._threadItems[i],o=t[i];if(!o)return!1;n.push(this._buildEditorPostDetail(o,a.format,i,e)),r.push(...(o._attachments??[]).filter(e=>e.status===`pending`||e.status===`processing`||e.status===`uploading`))}return this.dispatchEvent(new CustomEvent(`jant:compose-submit-deferred`,{bubbles:!0,detail:{...n[0],editPostId:this._editPostId??this._draftSourceId??void 0,draftSourceId:this._draftSourceId??void 0,threadPosts:n,pendingAttachments:r}})),!0}let t=this._editor;if(!t)return!1;let n=this._buildSubmitDetail(e);if(!n)return!1;let r=(t._attachments??[]).filter(e=>e.status===`pending`||e.status===`processing`||e.status===`uploading`);return this.dispatchEvent(new CustomEvent(`jant:compose-submit-deferred`,{bubbles:!0,detail:{...n,pendingAttachments:r}})),!0}_saveDraftAndOpenDrafts(){this._finishDraftSaveAndOpenDrafts()}_finishDraftSaveAndOpenDrafts(){if(!this._dispatchSubmit(`draft`))return;this.reset();let e=()=>{clearTimeout(t),this.isConnected&&this._openDraftsPanel()},t=globalThis.setTimeout(()=>{document.removeEventListener(`jant:compose-submit-complete`,e)},1e4);document.addEventListener(`jant:compose-submit-complete`,e,{once:!0})}_finishSubmit(e){if(this._dispatchSubmit(e)){if(this.pageMode){this._loading=!0;return}this._closeDialog(),this.reset()}}_submit(e){this._showPublishPanel=!1,this._finishSubmit(e)}_toggleCollection(e){this._collectionIds=this._collectionIds.includes(e)?this._collectionIds.filter(t=>t!==e):[...this._collectionIds,e]}_selectedCollectionLabel(e){let t=this._collectionIds,n=e.find(e=>e.id===t[0]);if(!n)return``;if(t.length===1)return n.title;if(t.length===2){let r=e.find(e=>e.id===t[1]);return r?`${n.title}, ${r.title}`:n.title}return this.labels.collectionCountLabel.replace(`%name%`,n.title).replace(`%count%`,String(t.length-1))}_prepareCollectionPickerOrder(){this._collectionPickerOrder=p(this.collections??[],this._collectionIds)}_focusCollectionPickerInitialTarget(){this.querySelector(`.compose-collection-search-input, .compose-collection-option, .compose-collection-add-action`)?.focus()}_focusCollectionSearchInput(){let e=this.querySelector(`.compose-collection-search-input`);if(!e)return!1;e.focus();let t=e.value.length;return e.setSelectionRange(t,t),!0}_closeCollectionPicker(e){if(this._showCollection=!1,this._collectionSearch=``,this._suppressedCollectionOptionId=null,this._suppressCollectionOptionClickUntil=0,e?.restoreFocus===`trigger`){this.updateComplete.then(()=>{this.querySelector(`.compose-collection-trigger`)?.focus()});return}e?.restoreFocus===`editor`&&this._restorePageEditorFocus()}_suppressNextCollectionOptionClick(e){this._suppressedCollectionOptionId=e,this._suppressCollectionOptionClickUntil=Date.now()+250}_isTouchViewport(){return globalThis.matchMedia?.(`(hover: none) and (pointer: coarse)`)?.matches??!1}_shouldAutofocusCollectionPicker(){return!this._isTouchViewport()}_shouldAutofocusFormatInput(){return!this._isTouchViewport()}_scheduleCollectionPickerAutofocus(){this._shouldAutofocusCollectionPicker()&&globalThis.requestAnimationFrame(()=>{this._showCollection&&this._focusCollectionPickerInitialTarget()})}_scheduleCollectionSearchFocus(){globalThis.requestAnimationFrame(()=>{this._showCollection&&(this._focusCollectionSearchInput()||this._focusCollectionPickerInitialTarget())})}_isPrintableCollectionSearchKey(e){return e.length===1&&e.trim().length>0}_handleCollectionTriggerKeydown=e=>{if(!(e.defaultPrevented||e.isComposing||e.altKey||e.ctrlKey||e.metaKey)){if(e.key===`ArrowDown`){e.preventDefault(),this._scheduleCollectionSearchFocus();return}this._showCollection&&this._isPrintableCollectionSearchKey(e.key)&&(e.preventDefault(),this._collectionSearch+=e.key,this._scheduleCollectionSearchFocus())}};_getCollectionOptionElements(){return Array.from(this.querySelectorAll(`.compose-collection-option`))}_handleCollectionSearchKeydown=e=>{if(e.defaultPrevented||e.isComposing||e.altKey||e.ctrlKey||e.metaKey)return;if(e.key===`Enter`){e.preventDefault(),this._closeCollectionPicker({restoreFocus:`trigger`});return}if(e.key!==`ArrowDown`)return;let[t]=this._getCollectionOptionElements(),n=this.querySelector(`.compose-collection-add-action`),r=t??n;r&&(e.preventDefault(),r.focus())};_handleCollectionOptionKeydown=(e,t)=>{if(e.defaultPrevented||e.isComposing||e.altKey||e.ctrlKey||e.metaKey)return;let n=this._getCollectionOptionElements(),r=e.currentTarget,i=r?n.indexOf(r):-1;if(e.key===`ArrowDown`){let t=this.querySelector(`.compose-collection-add-action`),r=i>=0?n[i+1]??t:n[0];if(!r)return;e.preventDefault(),r.focus();return}if(e.key===`ArrowUp`){let t=this.querySelector(`.compose-collection-search-input`),r=i>0?n[i-1]:t;if(!r)return;e.preventDefault(),r.focus();return}if(e.key===` `||e.key===`Spacebar`){e.preventDefault(),this._suppressNextCollectionOptionClick(t),this._toggleCollection(t);return}e.key===`Enter`&&(e.preventDefault(),this._suppressNextCollectionOptionClick(t),this._closeCollectionPicker({restoreFocus:`trigger`}))};_handleCollectionOptionClick=e=>{if(this._suppressedCollectionOptionId===e&&Date.now()<=this._suppressCollectionOptionClickUntil){this._suppressedCollectionOptionId=null,this._suppressCollectionOptionClickUntil=0;return}this._suppressedCollectionOptionId=null,this._suppressCollectionOptionClickUntil=0,this._toggleCollection(e)};_handleCollectionAddActionKeydown=e=>{if(e.defaultPrevented||e.isComposing||e.altKey||e.ctrlKey||e.metaKey||e.key!==`ArrowUp`)return;let t=this._getCollectionOptionElements(),n=this.querySelector(`.compose-collection-search-input`),r=t.at(-1)??n;r&&(e.preventDefault(),r.focus())};_updateCollectionPopoverSide(){let e=this.querySelector(`.compose-collection-trigger`),t=this.querySelector(`.compose-collection-popover[data-popover]`);if(!e||!t)return;let n=globalThis.visualViewport,r=n?.offsetTop??0,i=r+(n?.height??globalThis.innerHeight),a=e.getBoundingClientRect(),o=Math.max(0,i-12-a.bottom-4),s=Math.max(0,a.top-r-12-4);t.dataset.side=o>=s?`bottom`:`top`}_cancelSlugTimers(){this._slugCheckTimer!==null&&(clearTimeout(this._slugCheckTimer),this._slugCheckTimer=null),this._slugSuggestTimer!==null&&(clearTimeout(this._slugSuggestTimer),this._slugSuggestTimer=null)}_currentSlugOwnerId(){return this._editPostId??this._draftSourceId??void 0}_hasManualSlug(){return this._slug.trim().length>0}_currentSuggestionTitle(){return this._editor?.getData().title.trim()??``}_canSuggestSlug(){return this._currentSuggestionTitle().length>0}_currentSuggestionKey(){return`${this._currentSlugOwnerId()??``}::${this._currentSuggestionTitle()}`}_scheduleSuggestedSlugRefresh(e=!1){if(this._postMetaIndex!==0||this._hasManualSlug())return;if(!this._canSuggestSlug()){this._slugSuggestRequestId+=1,this._suggestedSlug=``,this._suggestedSlugLoading=!1,this._slugSuggestionKey=``;return}let t=this._currentSuggestionKey();if(this._slugSuggestionKey!==t&&(this._suggestedSlug=``),!e&&!this._suggestedSlugLoading&&this._suggestedSlug&&this._slugSuggestionKey===t)return;this._slugSuggestTimer!==null&&(clearTimeout(this._slugSuggestTimer),this._slugSuggestTimer=null);let n=()=>void this._refreshSuggestedSlug(t);if(e){n();return}this._slugSuggestTimer=setTimeout(n,250)}async _refreshSuggestedSlug(e){if(this._slugSuggestTimer=null,this._hasManualSlug()||!this._canSuggestSlug())return;let t=++this._slugSuggestRequestId;this._suggestedSlugLoading=!0;let n=new URLSearchParams({mode:`suggest`}),r=this._currentSuggestionTitle();r&&n.set(`title`,r);let i=this._currentSlugOwnerId();i&&n.set(`postId`,i);try{let r=await fetch(`/api/posts/slug?${n.toString()}`);if(!r.ok)return;let i=await r.json();if(t!==this._slugSuggestRequestId||this._hasManualSlug()||this._postMetaIndex!==0)return;this._suggestedSlug=i.slug?.trim()??``,this._slugSuggestionKey=e}catch{}finally{t===this._slugSuggestRequestId&&(this._suggestedSlugLoading=!1)}}_scheduleSlugAvailabilityCheck(e=0){if(!this._hasPostManualSlug(e)){this._setPostSlugTaken(e,!1),this._slugCheckLoading=!1;return}if(this._slugCheckTimer!==null&&(clearTimeout(this._slugCheckTimer),this._slugCheckTimer=null),this._getPostSlugSyncValidationMessage(e)){this._setPostSlugTaken(e,!1),this._slugCheckLoading=!1;return}this._slugCheckLoading=!0;let t=this._getPostSlug(e).trim();this._slugCheckTimer=setTimeout(()=>{this._checkSlugAvailability(t,e)},250)}async _checkSlugAvailability(e,t=0){this._slugCheckTimer=null;let n=++this._slugCheckRequestId,r=new URLSearchParams({mode:`check`,slug:e}),i=t===0?this._currentSlugOwnerId():this._threadItems[t]?.sourcePostId;i&&r.set(`postId`,i);try{let i=await fetch(`/api/posts/slug?${r.toString()}`);if(!i.ok)return;let a=await i.json();if(n!==this._slugCheckRequestId||this._getPostSlug(t).trim()!==e)return;this._setPostSlugTaken(t,a.available===!1)}catch{}finally{n===this._slugCheckRequestId&&(this._slugCheckLoading=!1)}}_useSuggestedSlug(){this._suggestedSlug&&(this._slug=this._suggestedSlug,this._slugTaken=!1,this._slugCheckLoading=!1,this.updateComplete.then(()=>{this.querySelector(`.compose-publish-slug-input`)?.focus()}))}_resetCustomSlug(e=0){this._setPostSlug(e,``),this._setPostSlugTaken(e,!1),this._slugCheckLoading=!1,this._scheduleSuggestedSlugRefresh(!0),this.updateComplete.then(()=>{this.querySelector(`.compose-publish-slug-input`)?.focus()})}connectedCallback(){super.connectedCallback(),this._syncPublishPanelPresentation(),this.addEventListener(`keydown`,this._handleKeydown),this.addEventListener(`jant:alt-panel-open`,this._handleAltPanelOpen),this.addEventListener(`jant:alt-panel-close`,this._handleAltPanelClose),this.addEventListener(`jant:attached-panel-open`,this._handleAttachedPanelOpen),this.addEventListener(`jant:compose-content-changed`,this._onContentChanged),this.addEventListener(`jant:title-toggle`,this._handleTitleToggle),this.addEventListener(`jant:file-picker-open`,this._handleFilePickerOpen),this.addEventListener(`jant:file-picker-close`,this._handleFilePickerClose),this.addEventListener(`jant:fullscreen-open`,this._handleFullscreenOpen),this.addEventListener(`pointerdown`,this._handlePointerDown),document.addEventListener(`jant:fullscreen-close`,this._handleFullscreenClose),window.addEventListener(`beforeunload`,this._onBeforeUnload),window.addEventListener(`resize`,this._handleViewportChange),window.addEventListener(`scroll`,this._handleViewportChange,{passive:!0}),document.addEventListener(`scroll`,this._handleAnyScroll,{capture:!0,passive:!0}),globalThis.visualViewport?.addEventListener(`resize`,this._handleViewportChange),globalThis.visualViewport?.addEventListener(`scroll`,this._handleViewportChange),this._dialogEl=this.closest(`dialog`),this._dialogEl&&(this._dialogEl.addEventListener(`cancel`,this._handleDialogCancel),this._dialogEl.addEventListener(`mousedown`,this._handleDialogMousedown),this._dialogEl.addEventListener(`click`,this._handleDialogClick)),this.pageMode&&this.updateComplete.then(()=>this._focusPageEditorOnMount())}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener(`keydown`,this._handleKeydown),this.removeEventListener(`jant:alt-panel-open`,this._handleAltPanelOpen),this.removeEventListener(`jant:alt-panel-close`,this._handleAltPanelClose),this.removeEventListener(`jant:attached-panel-open`,this._handleAttachedPanelOpen),this.removeEventListener(`jant:compose-content-changed`,this._onContentChanged),this.removeEventListener(`jant:title-toggle`,this._handleTitleToggle),this.removeEventListener(`jant:file-picker-open`,this._handleFilePickerOpen),this.removeEventListener(`jant:file-picker-close`,this._handleFilePickerClose),this.removeEventListener(`jant:fullscreen-open`,this._handleFullscreenOpen),this.removeEventListener(`pointerdown`,this._handlePointerDown),document.removeEventListener(`jant:fullscreen-close`,this._handleFullscreenClose),window.removeEventListener(`beforeunload`,this._onBeforeUnload),window.removeEventListener(`resize`,this._handleViewportChange),window.removeEventListener(`scroll`,this._handleViewportChange),document.removeEventListener(`scroll`,this._handleAnyScroll,{capture:!0}),globalThis.visualViewport?.removeEventListener(`resize`,this._handleViewportChange),globalThis.visualViewport?.removeEventListener(`scroll`,this._handleViewportChange),this._cancelSlugTimers(),this._destroyAttachedEditor(),this._cancelDraftSaveTimer(),this._dialogEl&&=(this._dialogEl.removeEventListener(`cancel`,this._handleDialogCancel),this._dialogEl.removeEventListener(`mousedown`,this._handleDialogMousedown),this._dialogEl.removeEventListener(`click`,this._handleDialogClick),null)}_handleFilePickerOpen=()=>{this._filePickerActive=!0,this._ignoreNextEscapeClose=!1};_handleFilePickerClose=e=>{this._filePickerActive=!1,this._ignoreNextEscapeClose=!!e.detail?.cancelled};_handlePointerDown=()=>{this._clearFilePickerEscapeState()};_syncPublishPanelPresentation(){let e=globalThis.matchMedia?.($e)?.matches??!1;e!==this._publishPanelFullscreen&&(this._publishPanelFullscreen=e)}_handleViewportChange=()=>{this._syncPublishPanelPresentation(),this._showPublishPanel&&this.updateComplete.then(()=>this._updatePublishPanelLayout()),this._showCollection&&this.updateComplete.then(()=>this._updateCollectionPopoverSide()),this._postMetaIndex!==null&&this.updateComplete.then(()=>this._updatePostMetaPanelLayout())};_handleAnyScroll=()=>{this._postMetaIndex!==null&&this._updatePostMetaPanelLayout()};_handleDialogCancel=e=>{e.preventDefault();let t=e;t.isComposing||t.keyCode===229||this._shouldIgnoreEscapeClose()||this._dismissEscapeOverlay()||this.requestClose()};_pointInOpenPopover(e,t){for(let n of document.querySelectorAll(`:popover-open`)){let r=n.getBoundingClientRect();if(e>=r.left&&e<=r.right&&t>=r.top&&t<=r.bottom)return!0}return!1}_handleDialogMousedown=e=>{let t=e;this._mousedownOnBackdrop=e.target===this._dialogEl&&!this._pointInOpenPopover(t.clientX,t.clientY),this._mousedownPos=this._mousedownOnBackdrop?{x:t.clientX,y:t.clientY}:null};_handleDialogClick=e=>{if(!this._dialogEl||e.target!==this._dialogEl||!this._mousedownOnBackdrop)return;let t=e;if(this._mousedownPos){let e=t.clientX-this._mousedownPos.x,n=t.clientY-this._mousedownPos.y;if(e*e+n*n>16)return}let n=document.getSelection();if(n&&!n.isCollapsed||this._pointInOpenPopover(t.clientX,t.clientY))return;let r=document.elementFromPoint(t.clientX,t.clientY);r instanceof globalThis.Element&&r.closest(Ze)||this.requestClose()};_focusDialogShell(){let e=this.querySelector(`.compose-dialog-inner`);if(e){e.focus();return}this._dialogEl?.focus()}_restorePageEditorFocus(){this.updateComplete.then(()=>this._editor?.focusInput())}_dismissEscapeOverlay(){return this._confirmPanelOpen?(this.requestClose(),!0):this._addCollectionPanelOpen?(this._closeAddCollectionPanel(),!0):this._editor?.isEmojiPickerOpen()?(this._editor.closeEmojiPicker({restoreFocus:!0}),!0):this._showLanguagePicker?(this._closeLanguagePicker(!0),!0):this._showCollection?(this._closeCollectionPicker({restoreFocus:`editor`}),!0):this._showPublishPanel?(this._closePublishPanel(!0),!0):this._postMetaIndex===null?this._altPanelOpen?(this._closeAltPanel(),this._restorePageEditorFocus(),!0):this._draftMenuOpenId?(this._draftMenuOpenId=null,!0):this._draftsPanelOpen?(this._closeDraftsPanel(),!0):this._attachedPanelOpen?(this._cancelAttachedPanel(),!0):!1:(this._closePostMeta(),!0)}_handleKeydown=t=>{let n=t;if(!(n.isComposing||n.keyCode===229)){if(n.key!==`Escape`&&this._clearFilePickerEscapeState(),n.key===`Escape`){if(n.preventDefault(),n.stopPropagation(),this._shouldIgnoreEscapeClose()||this._dismissEscapeOverlay())return;this.requestClose()}else if(n.key===`Enter`&&this._confirmPanelOpen)n.preventDefault(),this._handleConfirmSave();else if((n.metaKey||n.ctrlKey)&&n.key===`Enter`)t.preventDefault(),this._publishFromShortcut();else if((n.metaKey||n.ctrlKey)&&!n.altKey&&!n.shiftKey&&n.key>=`1`&&n.key<=String(e._FORMATS.length)){n.preventDefault();let t=e._FORMATS[Number(n.key)-1];this._threadItems.length>0?this.querySelectorAll(`jant-compose-editor`)[this._focusedThreadIndex]?.dispatchEvent(new CustomEvent(`jant:format-change`,{detail:{format:t},bubbles:!0})):this._switchFormat(t)}}};_publishFromShortcut(){if(this._attachedPanelOpen){this._doneAttachedPanel();return}if(!this._canPublish()){this._focusBlockedSubmitField(`published`);return}this._submit(`published`)}_handleAltPanelOpen=e=>{let t=e.detail;this._altPanelIndex=t.index,this._altPanelOpen=!0,this.updateComplete.then(()=>{this.querySelector(`.compose-alt-input`)?.focus()})};_handleAltPanelClose=()=>{this._altPanelOpen=!1};_getAltAttachment(){return this._editor?._attachments[this._altPanelIndex]??null}_onAltInput(e){let t=e.target.value;this._editor?.updateAlt(this._altPanelIndex,t)}_closeAltPanel(){this._altPanelOpen=!1}_handleFullscreenClose=e=>{let t=Array.from(this.querySelectorAll(`jant-compose-editor`))[e.detail.editorIndex??0]??this._editor;t&&(t.setEditorState(e.detail.json,e.detail.title,e.detail.showTitle,e.detail.selection),t.adoptPendingUploads(),e.detail.intent!==`publish`&&this.updateComplete.then(()=>t.focusSelection(e.detail.selection))),this._replyExpanded=e.detail.replyExpanded,e.detail.intent===`publish`&&this._publishFromShortcut()};_buildFullscreenReplyContext(){return!this._replyToId||!this._replyToData?null:{contentHtml:this._replyToData.contentHtml,dateText:this._replyToData.dateText,expanded:this._replyExpanded}}_handleFullscreenOpen=e=>{e.detail.replyContext=this._buildFullscreenReplyContext();let t=Array.from(this.querySelectorAll(`jant-compose-editor`)).indexOf(e.target);e.detail.editorIndex=t>=0?t:0};_handleAttachedPanelOpen=e=>{let t=e.detail;this._attachedTextIndex=t.index,this._attachedPanelOpen=!0,this.updateComplete.then(()=>{let e=this.querySelector(`.compose-attached-tiptap`);if(!e)return;let t=this._editor?._attachedTexts[this._attachedTextIndex]?.bodyJson??null;this._attachedTextSnapshot=t?JSON.parse(JSON.stringify(t)):null,this._attachedEditor=le({element:e,placeholder:this.labels.attachedTextPlaceholder,content:t,toolbarMode:`compose`,tableControlLabels:this.labels.tableControls}),this._focusAttachedEditorBoundary(t)})};_focusAttachedEditorBoundary(e){if(!this._attachedEditor)return;let t=H(e??this._attachedEditor.getJSON())?`end`:`start`;this._attachedEditor.commands.focus(t)}_isAttachedTextDirty(){return this._attachedEditor?JSON.stringify(H(this._attachedEditor.getJSON()))!==JSON.stringify(H(this._attachedTextSnapshot)):!1}_destroyAttachedEditor(){this._attachedEditor&&=(this._attachedEditor.destroy(),null),this._attachedTextSnapshot=null}_doneAttachedPanel(){if(this._attachedEditor){let e=this._attachedEditor.getJSON(),t=this._attachedEditor.getHTML();this._editor?.updateAttachedText(this._attachedTextIndex,e,t)}this._confirmForAttachedText=!1,this._destroyAttachedEditor(),this._attachedPanelOpen=!1,this._editor?.closeAttachedPanel(this._attachedTextIndex)}_cancelAttachedPanel(){if(this._isAttachedTextDirty()){this._confirmForDrafts=!1,this._confirmForAttachedText=!0,this._confirmPanelOpen=!0;return}this._discardAttachedPanel()}_handleAttachedEditorMouseDown(e){e.target===e.currentTarget&&(e.preventDefault(),this._focusAttachedEditorBoundary())}_handleDraftButtonClick(){this._loading||(this._hasWorkToLose()?(this._confirmForDrafts=!0,this._confirmPanelOpen=!0):this._openDraftsPanel())}async _openDraftsPanel(){this._draftsPanelOpen=!0,this._draftsLoading=!0,this._draftsError=null,this._draftMenuOpenId=null;try{let e=await fetch(`/api/posts?status=draft&limit=50`);if(!e.ok)throw Error(`Failed to load drafts`);let t=await e.json(),n=(Array.isArray(t)?t:t.posts??[]).map(e=>({id:e.id,slug:e.slug,format:e.format,title:(e.format===`quote`?e.sourceName:e.title)??null,bodyText:e.bodyText??null,bodyHtml:e.bodyHtml??null,url:(e.format===`quote`?e.sourceUrl:e.url)??null,quoteText:e.quoteText??null,replyToId:e.replyToId??null,updatedAt:e.updatedAt,mediaAttachments:(e.attachments??[]).filter(e=>e.type===`media`).map(e=>({id:e.id,previewUrl:e.previewUrl,alt:e.alt??null,mimeType:e.mimeType}))})),r=new Set(n.map(e=>e.id));this._drafts=n.filter(e=>!e.replyToId||!r.has(e.replyToId))}catch{this._draftsError=`Could not load drafts. Try again.`,this._drafts=[]}finally{this._draftsLoading=!1}}_closeDraftsPanel(){this._draftsPanelOpen=!1,this._draftMenuOpenId=null,this.updateComplete.then(()=>this._editor?.focusInput())}async _populateEditorFromPost(e,t){let{media:n,textAttachments:r,attachmentOrder:i}=await ut(t.attachments??[]);e.populate({format:t.format,title:t.format===`quote`?void 0:t.title??void 0,bodyJson:t.body??void 0,url:t.format===`quote`?t.sourceUrl??void 0:t.url??void 0,quoteText:t.quoteText??void 0,quoteAuthor:t.format===`quote`?t.sourceName??void 0:void 0,rating:t.rating??void 0,media:n,textAttachments:r,attachmentOrder:i})}async _loadDraft(e){this._draftsPanelOpen=!1,this._draftMenuOpenId=null,this.reset();let t=await fetch(`/api/posts/${e}`);if(!t.ok)return;let n=await t.json();if(this._draftSourceId=e,this._format=n.format,this._slug=n.slug??``,this._slugTaken=!1,this._slugCheckLoading=!1,this._suggestedSlug=``,this._suggestedSlugLoading=!1,this._slugSuggestionKey=``,this._publishedAtInput=n.publishedAt?ct(n.publishedAt):``,this._publishedAtTimeMinutes=n.publishedAt?W(n.publishedAt):null,this._originalPublishedAt=n.publishedAt??null,this._initialPublishedAtTimeMinutes=this._publishedAtTimeMinutes,this._initialPublishedAtInput=this._publishedAtInput,this._initialSlug=this._slug.trim(),this._visibility=n.visibility??`public`,this._visibilityLocked=!!n.replyToId,!n.replyToId&&n.collectionIds?.length&&(this._collectionIds=n.collectionIds),n.replyToId&&(this._replyToId=n.replyToId,await this._fetchReplyContext(n.replyToId)),n.threadId===n.id||n.threadId===void 0)try{let e=await fetch(`/api/posts?status=draft&limit=50`);if(e.ok){let t=await e.json(),r=(Array.isArray(t)?t:t.posts??[]).filter(e=>e.id!==n.id&&e.threadId===n.id&&e.status===`draft`).map(e=>({id:e.id,format:e.format,slug:e.slug??null,replyToId:e.replyToId??null,title:e.title??null,body:e.body??null,url:e.url??null,sourceUrl:e.sourceUrl??null,sourceName:e.sourceName??null,quoteText:e.quoteText??null,rating:e.rating??null,attachments:e.attachments??[],visibility:e.visibility??null}));if(r.length>0){let e=[],t=n.id;for(let n=0;n<r.length;n++){let n=r.find(e=>e.replyToId===t);if(!n)break;e.push(n),t=n.id}for(let t of r)e.includes(t)||e.push(t);this._threadItems=[{id:L(),format:n.format},...e.map(e=>({id:L(),format:e.format,slug:e.slug??``,sourcePostId:e.id}))],this._focusedThreadIndex=0,await this.updateComplete;let i=Array.from(this.querySelectorAll(`jant-compose-editor`)),a=i[0];a&&await this._populateEditorFromPost(a,n);for(let t=0;t<e.length;t++){let r=i[t+1];if(!r)continue;let a=e[t];await this._populateEditorFromPost(r,{id:a.id,threadId:n.id,format:a.format,replyToId:a.replyToId,title:a.title,body:a.body,url:a.url,sourceUrl:a.sourceUrl,sourceName:a.sourceName,quoteText:a.quoteText,rating:a.rating,attachments:a.attachments,visibility:a.visibility})}globalThis.requestAnimationFrame(()=>{i[0]?.focusInput(),this._captureInitialSnapshot()});return}}}catch{}await this.updateComplete;let r=this._editor;r&&await this._populateEditorFromPost(r,n),globalThis.requestAnimationFrame(()=>{this._editor?.focusInput(),this._captureInitialSnapshot()})}async _deleteDraft(e){this._draftMenuOpenId=null,this._drafts=this._drafts.filter(t=>t.id!==e);try{if(!(await fetch(`/api/posts/${e}`,{method:`DELETE`})).ok)throw Error();l(this.labels.draftDeleted)}catch{l(`Failed to delete draft. Try again.`,`error`),this._openDraftsPanel()}}_formatDraftDate(e){let t=Date.now()/1e3-e;return t<60?`now`:t<3600?`${Math.floor(t/60)}m`:t<86400?`${Math.floor(t/3600)}h`:t<604800?`${Math.floor(t/86400)}d`:new Date(e*1e3).toLocaleDateString(void 0,{month:`short`,day:`numeric`})}_getDraftPreview(e){return e.format===`quote`&&e.quoteText?e.quoteText:e.title?e.title:e.bodyText?e.bodyText:e.url?e.url:null}_getThreadLimitMessage(){return this.labels.threadLimitReached||`Threads can include up to 20 posts.`}static _DRAFT_KEY=`jant:compose-draft`;static _EDIT_DRAFT_KEY_PREFIX=`jant:compose-edit:`;static _DRAFT_MAX_AGE=6048e5;_currentDraftStorageKey(){return this._editPostId?e._EDIT_DRAFT_KEY_PREFIX+this._editPostId:e._DRAFT_KEY}_onContentChanged=()=>{this.requestUpdate(),this._hasManualSlug()||this._scheduleSuggestedSlugRefresh(),this._draftSourceId||this._scheduleDraftSave()};_handleTitleToggle=t=>{this._editPostId||this._draftSourceId||this._replyToId||t.target?.threadItem||e._setNoteTitleDefault(t.detail.showTitle)};_cancelDraftSaveTimer(){this._draftSaveTimer!==null&&(clearTimeout(this._draftSaveTimer),this._draftSaveTimer=null)}_scheduleDraftSave(){this._cancelDraftSaveTimer(),this._draftSaveTimer=setTimeout(()=>this._saveDraftToStorage(),1e3)}_onBeforeUnload=e=>{if(this._suppressBeforeUnload)return;this._draftSaveTimer!==null&&(this._cancelDraftSaveTimer(),this._saveDraftToStorage());let t=this.closest(`dialog`);this._hasUnsavedChanges()&&(this.pageMode||t?.open===!0)&&(e.preventDefault(),e.returnValue=``)};_saveDraftToStorage(){if(this._threadItems.length>0){let t=Array.from(this.querySelectorAll(`jant-compose-editor`));if(!t.some(e=>{let t=e.getData();return!!t.body||!!t.title.trim()||!!t.url.trim()||!!t.quoteText.trim()||t.rating>0||t.attachedTexts.length>0||t.attachments.length>0})){this._releaseStoredDraft();return}let n=this._threadItems.map((n,r)=>{let i=t[r];if(!i)return null;let a=i.getData();return{format:n.format,publishedAtInput:n.publishedAtInput,publishedAtTimeMinutes:n.publishedAtTimeMinutes,slug:n.slug,title:a.title,bodyJson:i.getNormalizedBodyJson(),url:a.url,quoteText:a.quoteText,quoteAuthor:a.quoteAuthor,rating:a.rating,showTitle:n.format===`note`&&i._showTitle,showRating:a.rating>0&&i._showRating,attachedTexts:a.attachedTexts.map(e=>({clientId:e.clientId,bodyJson:e.bodyJson,bodyHtml:e.bodyHtml,summary:e.summary})),attachmentOrder:[...a.attachmentOrder],mediaAttachments:e._mediaSnapshotFromAttachments(a.attachments)}}).filter(e=>e!==null),r={format:this._threadItems[0]?.format??this._format,title:``,bodyJson:null,url:``,quoteText:``,quoteAuthor:``,slug:this._slug,publishedAtInput:this._publishedAtInput,publishedAtTimeMinutes:this._publishedAtTimeMinutes,visibility:this._visibility,rating:0,showTitle:!1,showRating:!1,collectionIds:[...this._collectionIds],replyToId:this._replyToId,language:this._language,translationOfId:this._translationOf?.id??null,attachedTexts:[],attachmentOrder:[],threadItems:n,savedAt:Date.now()};this._writeStoredDraft(r);return}let t=this._editor;if(!t)return;if(!this._hasUnsavedChanges()){this._releaseStoredDraft();return}let n=t.getData();if(!(n.body||n.title.trim()||n.url.trim()||n.quoteText.trim()||n.quoteAuthor.trim()||n.rating>0||n.attachments.length>0||n.attachedTexts.length>0)){this._releaseStoredDraft();return}let r={format:this._format,title:n.title,bodyJson:t.getNormalizedBodyJson(),url:n.url,quoteText:n.quoteText,quoteAuthor:n.quoteAuthor,slug:this._slug,publishedAtInput:this._publishedAtInput,publishedAtTimeMinutes:this._publishedAtTimeMinutes,visibility:this._visibility,rating:n.rating,showTitle:this._format===`note`&&t._showTitle,showRating:n.rating>0&&t._showRating,collectionIds:[...this._collectionIds],replyToId:this._replyToId,language:this._language,translationOfId:this._translationOf?.id??null,attachedTexts:n.attachedTexts.map(e=>({clientId:e.clientId,bodyJson:e.bodyJson,bodyHtml:e.bodyHtml,summary:e.summary})),attachmentOrder:[...n.attachmentOrder],mediaAttachments:e._mediaSnapshotFromAttachments(n.attachments),savedAt:Date.now()};this._writeStoredDraft(r)}_writeStoredDraft(e){try{globalThis.localStorage.setItem(this._currentDraftStorageKey(),JSON.stringify(e)),this._hasOwnedContent=!0}catch(e){console.warn(`[jant] compose draft could not be stored`,e),this._reportedStorageFailure||(this._reportedStorageFailure=!0,l(this.labels.draftStoreFailed,`error`))}}_releaseStoredDraft(){this._hasOwnedContent&&(this._hasOwnedContent=!1,globalThis.localStorage.removeItem(this._currentDraftStorageKey()))}_clearDraftFromStorage(){this._cancelDraftSaveTimer(),this._hasOwnedContent=!1,globalThis.localStorage.removeItem(this._currentDraftStorageKey())}clearLocalDraftFromStorage(){this._clearDraftFromStorage()}clearEditDraftFromStorage(t){globalThis.localStorage.removeItem(e._EDIT_DRAFT_KEY_PREFIX+t)}static _mediaSnapshotFromAttachments(e){return e.flatMap(e=>e.status===`done`&&e.mediaId&&e.remoteUrl?[{clientId:e.clientId,mediaId:e.mediaId,url:e.remoteUrl,mimeType:e.file.type,name:e.file.name||void 0,alt:e.alt||void 0,summary:e.summary,chars:e.chars}]:[])}static _restoredMediaToPopulate(e){return e.map(e=>({id:e.mediaId,clientId:e.clientId,previewUrl:e.url,mimeType:e.mimeType,originalName:e.name,alt:e.alt,summary:e.summary??void 0,chars:e.chars??void 0}))}static _mergeRestoredMedia(e,t){let n=new Map;for(let t of e??[])n.set(t.clientId,t);for(let e of t??[])n.set(e.clientId,e);return n}async restoreLocalDraft(t){let n=e._DRAFT_KEY;if(this._editPostId||this._draftSourceId)return this._reportRestoreOutcome(`composer-busy`,n);if(this._hasContent())return this._reportRestoreOutcome(`composer-has-content`,n);let r;try{r=globalThis.localStorage.getItem(n)}catch{return`none`}if(!r)return`none`;let i;try{i=JSON.parse(r)}catch{return this._reportRestoreOutcome(`unreadable`,n,r)}if(Date.now()-i.savedAt>e._DRAFT_MAX_AGE)return this._reportRestoreOutcome(`expired`,n,r,i);if(t?.expectedReplyToId!==void 0&&i.replyToId!==t.expectedReplyToId)return this._reportRestoreOutcome(`other-reply`,n,r,i);if(this._collectionIds=i.replyToId?[]:[...i.collectionIds??[]],this._slug=i.slug??``,this._slugTaken=!1,this._slugCheckLoading=!1,this._suggestedSlug=``,this._suggestedSlugLoading=!1,this._slugSuggestionKey=``,this._publishedAtInput=i.publishedAtInput??``,this._publishedAtTimeMinutes=i.publishedAtTimeMinutes??null,this._visibility=i.visibility??`public`,this._language=i.language??null,i.translationOfId&&await this._loadTranslationSource(i.translationOfId),i.replyToId&&(this._replyToId=i.replyToId,this._visibilityLocked=!0,await this._fetchReplyContext(i.replyToId)),i.threadItems&&i.threadItems.length>=2){this._format=i.threadItems[0].format,this._threadItems=i.threadItems.map(e=>({id:L(),format:e.format,publishedAtInput:e.publishedAtInput,publishedAtTimeMinutes:e.publishedAtTimeMinutes,slug:e.slug})),this._focusedThreadIndex=0,await this.updateComplete;let n=Array.from(this.querySelectorAll(`jant-compose-editor`));for(let r=0;r<i.threadItems.length;r++){let a=i.threadItems[r],o=n[r];if(!o)continue;let s=a.attachedTexts?.flatMap(e=>{let t=H(e.bodyJson);return t?[{clientId:e.clientId,bodyJson:JSON.stringify(t),bodyHtml:e.bodyHtml,summary:e.summary}]:[]}),c=t?.extraMedia?.filter(e=>a.attachmentOrder?.includes(e.clientId)),l=[...e._mergeRestoredMedia(a.mediaAttachments,c).values()];o.populate({format:a.format,title:a.title||void 0,bodyJson:a.bodyJson?JSON.stringify(a.bodyJson):void 0,url:a.url||void 0,quoteText:a.quoteText||void 0,quoteAuthor:a.quoteAuthor||void 0,rating:a.rating||void 0,showTitle:a.showTitle,showRating:a.showRating,media:l.length?e._restoredMediaToPopulate(l):void 0,textAttachments:s?.length?s:void 0,attachmentOrder:a.attachmentOrder})}return this._draftRestored=!0,this._hasOwnedContent=!0,t?.notify!==!1&&l(this.labels.draftRestored),globalThis.requestAnimationFrame(()=>{this._captureInitialSnapshot()}),`restored`}this._format=i.format,await this.updateComplete;let a=i.attachedTexts?.flatMap(e=>{let t=H(e.bodyJson);return t?[{clientId:e.clientId,bodyJson:JSON.stringify(t),bodyHtml:e.bodyHtml,summary:e.summary}]:[]}),o=[...e._mergeRestoredMedia(i.mediaAttachments,t?.extraMedia).values()];return this._editor?.populate({format:i.format,title:i.title||void 0,bodyJson:i.bodyJson?JSON.stringify(i.bodyJson):void 0,url:i.url||void 0,quoteText:i.quoteText||void 0,quoteAuthor:i.quoteAuthor||void 0,rating:i.rating||void 0,showTitle:i.showTitle,showRating:i.showRating,media:o.length?e._restoredMediaToPopulate(o):void 0,textAttachments:a?.length?a:void 0,attachmentOrder:i.attachmentOrder}),this._draftRestored=!0,this._hasOwnedContent=!0,t?.notify!==!1&&l(this.labels.draftRestored),globalThis.requestAnimationFrame(()=>{this._captureInitialSnapshot()}),`restored`}_reportRestoreOutcome(e,t,n,r){if(e===`restored`||e===`none`)return e;let i=n;if(i===void 0)try{i=globalThis.localStorage.getItem(t)}catch{i=null}return i?(console.warn(`[jant] compose draft not restored: ${e}`,{key:t,bytes:i.length,savedAt:r?.savedAt?new Date(r.savedAt).toISOString():null,thread:r?.threadItems?.length??null}),e):`none`}_restoreEditDraftIfAvailable(t,n){let r=e._EDIT_DRAFT_KEY_PREFIX+t,i;try{i=globalThis.localStorage.getItem(r)}catch{return!1}if(!i)return!1;let a;try{a=JSON.parse(i)}catch{return this._reportRestoreOutcome(`unreadable`,r,i),!1}if(Date.now()-a.savedAt>e._DRAFT_MAX_AGE)return this._reportRestoreOutcome(`expired`,r,i,a),!1;this._format=a.format,this._collectionIds=this._replyToId?[]:[...a.collectionIds??[]],this._slug=a.slug??``,this._publishedAtInput=a.publishedAtInput??``,this._publishedAtTimeMinutes=a.publishedAtTimeMinutes??null,this._visibility=a.visibility??`public`,this._language=a.language??null;let o=a.attachedTexts?.flatMap(e=>{let t=H(e.bodyJson);return t?[{clientId:e.clientId,bodyJson:JSON.stringify(t),bodyHtml:e.bodyHtml,summary:e.summary}]:[]});return this._editor?.populate({format:a.format,title:a.title||void 0,bodyJson:a.bodyJson?JSON.stringify(a.bodyJson):void 0,url:a.url||void 0,quoteText:a.quoteText||void 0,quoteAuthor:a.quoteAuthor||void 0,rating:a.rating||void 0,showTitle:a.showTitle,showRating:a.showRating,textAttachments:o?.length?o:void 0,attachmentOrder:a.attachmentOrder}),this._draftRestored=!0,this._hasOwnedContent=!0,n!==!1&&l(this.labels.draftRestored),!0}async _applyTranslationRequestFromUrl(){let e=new URLSearchParams(globalThis.location?.search??``),t=e.get(`translationOf`);if(!t)return;let n=e.get(`lang`);n&&this.languages.some(e=>e.tag===n)&&(this._language=n),this._translationOf||await this._loadTranslationSource(t,{seed:!0})}async _focusPageEditorOnMount(){this._pageFocusApplied||(this.autoRestoreDraft&&await this.restoreLocalDraft(),await this._applyTranslationRequestFromUrl(),await this.updateComplete,globalThis.requestAnimationFrame(()=>{this._editor?.focusInput(),this._pageFocusApplied=!0}))}_renderDraftsPanel(){return this._draftsPanelOpen?i`
|
|
121
|
+
<div class="compose-drafts-panel">
|
|
122
|
+
<div class="compose-alt-header">
|
|
123
|
+
<button
|
|
124
|
+
type="button"
|
|
125
|
+
class="compose-attached-panel-back"
|
|
126
|
+
@click=${()=>this._closeDraftsPanel()}
|
|
127
|
+
>
|
|
128
|
+
<svg
|
|
129
|
+
class="icon-fine"
|
|
130
|
+
width="16"
|
|
131
|
+
height="16"
|
|
132
|
+
viewBox="0 0 16 16"
|
|
133
|
+
fill="none"
|
|
134
|
+
stroke="currentColor"
|
|
135
|
+
stroke-width="1.5"
|
|
136
|
+
stroke-linecap="round"
|
|
137
|
+
stroke-linejoin="round"
|
|
138
|
+
>
|
|
139
|
+
<path d="M11 3L6 8l5 5" />
|
|
140
|
+
</svg>
|
|
141
|
+
</button>
|
|
142
|
+
<span class="compose-alt-title">${this.labels.drafts}</span>
|
|
143
|
+
</div>
|
|
144
|
+
${this._draftsLoading?i`<div class="compose-drafts-loading">
|
|
145
|
+
<svg
|
|
146
|
+
class="animate-spin size-5"
|
|
147
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
148
|
+
viewBox="0 0 24 24"
|
|
149
|
+
fill="none"
|
|
150
|
+
stroke="currentColor"
|
|
151
|
+
stroke-width="2"
|
|
152
|
+
stroke-linecap="round"
|
|
153
|
+
stroke-linejoin="round"
|
|
154
|
+
>
|
|
155
|
+
<path d="M21 12a9 9 0 1 1-6.219-8.56" />
|
|
156
|
+
</svg>
|
|
157
|
+
</div>`:this._draftsError?i`<div class="compose-drafts-empty">
|
|
158
|
+
${this._draftsError}
|
|
159
|
+
</div>`:this._drafts.length===0?i`<div class="compose-drafts-empty">
|
|
160
|
+
${this.labels.draftsEmpty}
|
|
161
|
+
</div>`:i`<div class="compose-drafts-list">
|
|
162
|
+
${this._drafts.map((e,t)=>i`
|
|
163
|
+
${t>0?i`<div class="compose-drafts-divider"></div>`:o}
|
|
164
|
+
${this._renderDraftItem(e)}
|
|
165
|
+
`)}
|
|
166
|
+
</div>`}
|
|
167
|
+
</div>
|
|
168
|
+
`:o}_renderDraftItem(e){let t=this._getDraftPreview(e),n=this.labels[e.format],a=`draft-actions-${e.id}`,s=this._draftMenuOpenId===e.id;return i`
|
|
169
|
+
<div class="compose-draft-item" @click=${()=>this.openDraft(e.id)}>
|
|
170
|
+
<div class="compose-draft-content">
|
|
171
|
+
${t?i`<div class="compose-draft-preview">${t}</div>`:i`<div
|
|
172
|
+
class="compose-draft-preview compose-draft-preview-empty"
|
|
173
|
+
>
|
|
174
|
+
Empty draft
|
|
175
|
+
</div>`}
|
|
176
|
+
<div class="compose-draft-meta">
|
|
177
|
+
<span class="compose-draft-format">${n}</span>
|
|
178
|
+
<span aria-hidden="true">·</span>
|
|
179
|
+
${this._formatDraftDate(e.updatedAt)}
|
|
180
|
+
</div>
|
|
181
|
+
</div>
|
|
182
|
+
<div class="relative">
|
|
183
|
+
${s?i`<div
|
|
184
|
+
class="compose-dropdown-backdrop"
|
|
185
|
+
@click=${e=>{e.stopPropagation(),this._draftMenuOpenId=null}}
|
|
186
|
+
></div>`:o}
|
|
187
|
+
<button
|
|
188
|
+
type="button"
|
|
189
|
+
class="compose-draft-more"
|
|
190
|
+
aria-label=${this.labels.draftActions}
|
|
191
|
+
aria-haspopup="menu"
|
|
192
|
+
aria-expanded=${s?`true`:`false`}
|
|
193
|
+
aria-controls=${a}
|
|
194
|
+
@click=${t=>{t.stopPropagation(),this._draftMenuOpenId=this._draftMenuOpenId===e.id?null:e.id}}
|
|
195
|
+
>
|
|
196
|
+
<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor">
|
|
197
|
+
<circle cx="4" cy="8" r="1.2" />
|
|
198
|
+
<circle cx="8" cy="8" r="1.2" />
|
|
199
|
+
<circle cx="12" cy="8" r="1.2" />
|
|
200
|
+
</svg>
|
|
201
|
+
</button>
|
|
202
|
+
${s?i`
|
|
203
|
+
<div
|
|
204
|
+
id=${a}
|
|
205
|
+
class="compose-dropdown compose-dropdown-right"
|
|
206
|
+
role="menu"
|
|
207
|
+
>
|
|
208
|
+
<a
|
|
209
|
+
class="compose-dropdown-item"
|
|
210
|
+
href=${r(`/preview/${e.slug}`)}
|
|
211
|
+
target="_blank"
|
|
212
|
+
rel="noopener noreferrer"
|
|
213
|
+
role="menuitem"
|
|
214
|
+
@click=${e=>{e.stopPropagation(),this._draftMenuOpenId=null}}
|
|
215
|
+
>
|
|
216
|
+
${this.labels.previewDraft}
|
|
217
|
+
</a>
|
|
218
|
+
<div
|
|
219
|
+
class="compose-dropdown-separator"
|
|
220
|
+
role="separator"
|
|
221
|
+
></div>
|
|
222
|
+
<button
|
|
223
|
+
type="button"
|
|
224
|
+
class="compose-dropdown-item compose-dropdown-item-danger"
|
|
225
|
+
role="menuitem"
|
|
226
|
+
@click=${t=>{t.stopPropagation(),this._deleteDraft(e.id)}}
|
|
227
|
+
>
|
|
228
|
+
${this.labels.deleteDraft}
|
|
229
|
+
</button>
|
|
230
|
+
</div>
|
|
231
|
+
`:o}
|
|
232
|
+
</div>
|
|
233
|
+
</div>
|
|
234
|
+
`}_renderTranslationContext(){let e=this._translationOf;if(!e)return o;let t=this.languages.find(e=>e.tag===this._language)?.label??``,n=t?this.labels.translationContextInLanguage.replace(`{language}`,t):this.labels.translationContext,r=this._translationCollapsed;return i`
|
|
235
|
+
<div class="compose-translation-context">
|
|
236
|
+
${r?o:e.previewHtml?i`<div
|
|
237
|
+
class="compose-translation-original"
|
|
238
|
+
tabindex="0"
|
|
239
|
+
role="region"
|
|
240
|
+
aria-label=${this.labels.translationContextOriginal}
|
|
241
|
+
>
|
|
242
|
+
<div class="compose-translation-preview">
|
|
243
|
+
${d(e.previewHtml)}
|
|
244
|
+
</div>
|
|
245
|
+
</div>`:i`<p class="compose-translation-fallback">
|
|
246
|
+
${e.href?i`<a
|
|
247
|
+
href=${e.href}
|
|
248
|
+
target="_blank"
|
|
249
|
+
rel="noopener noreferrer"
|
|
250
|
+
title=${this.labels.translationContextOpen}
|
|
251
|
+
>${e.title}</a
|
|
252
|
+
>`:e.title}
|
|
253
|
+
</p>`}
|
|
254
|
+
<div class="compose-translation-seam">
|
|
255
|
+
<span class="compose-translation-seam-label">
|
|
256
|
+
${this._iconArrowDown()}${n}
|
|
257
|
+
</span>
|
|
258
|
+
<span class="compose-translation-seam-dot" aria-hidden="true">·</span>
|
|
259
|
+
<button
|
|
260
|
+
type="button"
|
|
261
|
+
class="compose-translation-seam-toggle"
|
|
262
|
+
aria-expanded=${r?`false`:`true`}
|
|
263
|
+
aria-label=${r?this.labels.translationContextShowLong:this.labels.translationContextHideLong}
|
|
264
|
+
@click=${()=>{this._translationCollapsed=!this._translationCollapsed}}
|
|
265
|
+
>
|
|
266
|
+
${r?this.labels.translationContextShow:this.labels.translationContextHide}
|
|
267
|
+
</button>
|
|
268
|
+
</div>
|
|
269
|
+
</div>
|
|
270
|
+
`}_adoptTranslationPreview(){let e=this.querySelector(`.compose-translation-preview:not([data-preview-adopted])`);if(e){e.dataset.previewAdopted=``;for(let t of e.querySelectorAll(`a[href]`))t.setAttribute(`target`,`_blank`),t.setAttribute(`rel`,`noopener noreferrer`);for(let t of e.querySelectorAll(`[data-post-id]`))delete t.dataset.postId,delete t.dataset.post,delete t.dataset.threadRootId,delete t.dataset.postMenuTarget,t.classList.remove(`post-menu-target`);for(let t of e.querySelectorAll(`[data-post-menu-trigger], [data-reply-trigger], [data-timeline-item]`))t.remove()}}_iconArrowDown(){return i`<svg
|
|
271
|
+
class="compose-translation-seam-icon"
|
|
272
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
273
|
+
viewBox="0 0 24 24"
|
|
274
|
+
fill="none"
|
|
275
|
+
stroke="currentColor"
|
|
276
|
+
stroke-width="1.9"
|
|
277
|
+
stroke-linecap="round"
|
|
278
|
+
stroke-linejoin="round"
|
|
279
|
+
aria-hidden="true"
|
|
280
|
+
>
|
|
281
|
+
<path d="M12 5v14" />
|
|
282
|
+
<path d="m19 12-7 7-7-7" />
|
|
283
|
+
</svg>`}_renderReplyContext(){if(!this._replyToId||!this._replyToData)return o;let{contentHtml:e,dateText:t,media:n}=this._replyToData,r=this._replyExpanded;return i`
|
|
284
|
+
<div class="compose-reply-row">
|
|
285
|
+
<div class="compose-thread-dot"></div>
|
|
286
|
+
<div
|
|
287
|
+
class=${b({"compose-reply-context":!0,expanded:r})}
|
|
288
|
+
>
|
|
289
|
+
<div class="compose-reply-context-body">
|
|
290
|
+
${d(e)}
|
|
291
|
+
${n?.length?i`<div
|
|
292
|
+
class="compose-reply-context-media"
|
|
293
|
+
data-post-media
|
|
294
|
+
data-lightbox-group=${JSON.stringify(n.map(e=>({url:e.url,alt:e.alt??``,width:e.width,height:e.height,mimeType:e.mimeType})))}
|
|
295
|
+
>
|
|
296
|
+
${n.map((e,t)=>i`
|
|
297
|
+
<a
|
|
298
|
+
href=${e.url}
|
|
299
|
+
data-lightbox-index=${t}
|
|
300
|
+
class="compose-reply-context-media-link"
|
|
301
|
+
>
|
|
302
|
+
<img
|
|
303
|
+
src=${e.previewUrl}
|
|
304
|
+
alt=${e.alt??``}
|
|
305
|
+
class="compose-reply-context-media-img"
|
|
306
|
+
loading="lazy"
|
|
307
|
+
/>
|
|
308
|
+
</a>
|
|
309
|
+
`)}
|
|
310
|
+
</div>`:o}
|
|
311
|
+
</div>
|
|
312
|
+
${r?o:i`<div class="compose-reply-fade"></div>`}
|
|
313
|
+
</div>
|
|
314
|
+
</div>
|
|
315
|
+
<div class="compose-reply-meta">
|
|
316
|
+
${t?i`<span>${t}</span><span>·</span>`:o}
|
|
317
|
+
<button
|
|
318
|
+
type="button"
|
|
319
|
+
class="compose-reply-toggle"
|
|
320
|
+
@click=${()=>{this._replyExpanded=!this._replyExpanded}}
|
|
321
|
+
>
|
|
322
|
+
${r?this.labels.showLess:this.labels.showMore}
|
|
323
|
+
</button>
|
|
324
|
+
</div>
|
|
325
|
+
`}static _FORMATS=[`note`,`link`,`quote`];_shouldConvertOnFormatSwitch(){return!!(this._editPostId||this._draftSourceId)}_convertForFormatSwitch(e,t,n){e&&t!==n&&this._shouldConvertOnFormatSwitch()&&e.applyConvertedFields(Pe(t,n,e.getConvertibleFields()))}_switchFormat(e){this._format!==e&&(this._convertForFormatSwitch(this._editor,this._format,e),this._cancelDraftSaveTimer(),this._format=e,this._showPublishPanel=!1,this._shouldAutofocusFormatInput()&&globalThis.requestAnimationFrame(()=>this._editor?.focusInput()))}_renderCloseComposeControl(){return this.pageMode||this._threadItems.length>0?o:i`
|
|
326
|
+
<button
|
|
327
|
+
type="button"
|
|
328
|
+
class="compose-close-btn"
|
|
329
|
+
aria-label=${this.labels.close}
|
|
330
|
+
title=${this.labels.close}
|
|
331
|
+
@click=${()=>this.requestClose()}
|
|
332
|
+
>
|
|
333
|
+
<svg
|
|
334
|
+
width="14"
|
|
335
|
+
height="14"
|
|
336
|
+
viewBox="0 0 16 16"
|
|
337
|
+
fill="none"
|
|
338
|
+
stroke="currentColor"
|
|
339
|
+
stroke-width="1.8"
|
|
340
|
+
stroke-linecap="round"
|
|
341
|
+
aria-hidden="true"
|
|
342
|
+
>
|
|
343
|
+
<path d="M4.5 4.5 11.5 11.5M11.5 4.5 4.5 11.5" />
|
|
344
|
+
</svg>
|
|
345
|
+
</button>
|
|
346
|
+
`}_renderCollectionSelector(){let e=this.collections??[],t=m(e,this._collectionPickerOrder),n=this._collectionSearch.trim().length>0,r=g(t,this._collectionSearch),a=this._collectionIds.length,s=a>0?this._selectedCollectionLabel(e):this.labels.collection,c=n?this.labels.noCollections:this.labels.emptyCollections;return i`
|
|
347
|
+
<div class="flex-1 min-w-0">
|
|
348
|
+
${this._showCollection?i`<div
|
|
349
|
+
class="compose-dropdown-backdrop"
|
|
350
|
+
@click=${()=>this._closeCollectionPicker()}
|
|
351
|
+
></div>`:o}
|
|
352
|
+
<div
|
|
353
|
+
class="select compose-collection-select"
|
|
354
|
+
data-select-initialized
|
|
355
|
+
data-open=${this._showCollection?`true`:o}
|
|
356
|
+
>
|
|
357
|
+
<button
|
|
358
|
+
type="button"
|
|
359
|
+
class="compose-collection-trigger"
|
|
360
|
+
aria-haspopup="listbox"
|
|
361
|
+
aria-expanded=${this._showCollection?`true`:`false`}
|
|
362
|
+
data-open=${this._showCollection?`true`:o}
|
|
363
|
+
data-selected=${a>0?`true`:o}
|
|
364
|
+
@keydown=${this._handleCollectionTriggerKeydown}
|
|
365
|
+
@click=${()=>{let e=!this._showCollection;this._showPublishPanel=!1,this._showLanguagePicker=!1,e&&this._prepareCollectionPickerOrder(),this._showCollection=e,e||this._closeCollectionPicker()}}
|
|
366
|
+
>
|
|
367
|
+
<!-- No chevron: the glyph already says "picker", and a second one
|
|
368
|
+
pointing down only made the control wider. -->
|
|
369
|
+
${B(z.collection,`compose-collection-trigger-svg`)}
|
|
370
|
+
<span class="compose-collection-label">${s}</span>
|
|
371
|
+
</button>
|
|
372
|
+
<div
|
|
373
|
+
class="compose-collection-popover"
|
|
374
|
+
data-popover
|
|
375
|
+
aria-hidden=${this._showCollection?`false`:`true`}
|
|
376
|
+
>
|
|
377
|
+
${e.length>0?i`<div class="compose-collection-popover-header">
|
|
378
|
+
<label class="compose-collection-search-shell">
|
|
379
|
+
${B(z.search,`compose-collection-search-icon`)}
|
|
380
|
+
<input
|
|
381
|
+
type="text"
|
|
382
|
+
role="combobox"
|
|
383
|
+
class="compose-collection-search-input"
|
|
384
|
+
placeholder=${this.labels.searchCollections}
|
|
385
|
+
autocomplete="off"
|
|
386
|
+
autocorrect="off"
|
|
387
|
+
spellcheck="false"
|
|
388
|
+
.value=${this._collectionSearch}
|
|
389
|
+
@keydown=${this._handleCollectionSearchKeydown}
|
|
390
|
+
@input=${e=>{this._collectionSearch=e.target.value}}
|
|
391
|
+
/>
|
|
392
|
+
</label>
|
|
393
|
+
</div>`:o}
|
|
394
|
+
<div
|
|
395
|
+
role="listbox"
|
|
396
|
+
class="compose-collection-options"
|
|
397
|
+
aria-multiselectable="true"
|
|
398
|
+
>
|
|
399
|
+
${r.length>0?r.map(e=>{let t=this._collectionIds.includes(e.id);return i`
|
|
400
|
+
<button
|
|
401
|
+
type="button"
|
|
402
|
+
class=${b({"compose-collection-option":!0,"compose-collection-option-selected":t})}
|
|
403
|
+
role="option"
|
|
404
|
+
data-value=${e.id}
|
|
405
|
+
aria-selected=${t?`true`:`false`}
|
|
406
|
+
@keydown=${t=>this._handleCollectionOptionKeydown(t,e.id)}
|
|
407
|
+
@click=${()=>this._handleCollectionOptionClick(e.id)}
|
|
408
|
+
>
|
|
409
|
+
<span class="compose-collection-option-label"
|
|
410
|
+
>${e.title}</span
|
|
411
|
+
>
|
|
412
|
+
<span
|
|
413
|
+
class=${b({"compose-collection-option-marker":!0,"compose-collection-option-marker-selected":t,"compose-collection-option-marker-add":!t})}
|
|
414
|
+
>
|
|
415
|
+
${t?i`<svg
|
|
416
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
417
|
+
class="compose-collection-option-check-circle"
|
|
418
|
+
viewBox="0 0 24 24"
|
|
419
|
+
fill="none"
|
|
420
|
+
aria-hidden="true"
|
|
421
|
+
>
|
|
422
|
+
<circle
|
|
423
|
+
cx="12"
|
|
424
|
+
cy="12"
|
|
425
|
+
r="10"
|
|
426
|
+
fill="currentColor"
|
|
427
|
+
/>
|
|
428
|
+
<path
|
|
429
|
+
d="M8 12.5 10.7 15.2 16.4 9.5"
|
|
430
|
+
stroke="var(--site-page-bg)"
|
|
431
|
+
stroke-width="2.3"
|
|
432
|
+
stroke-linecap="round"
|
|
433
|
+
stroke-linejoin="round"
|
|
434
|
+
/>
|
|
435
|
+
</svg>`:B(z.plusCircle,`compose-collection-option-plus-circle`)}
|
|
436
|
+
</span>
|
|
437
|
+
</button>
|
|
438
|
+
`}):i`<div class="compose-collection-empty">
|
|
439
|
+
${c}
|
|
440
|
+
</div>`}
|
|
441
|
+
</div>
|
|
442
|
+
<div class="compose-collection-footer">
|
|
443
|
+
<button
|
|
444
|
+
type="button"
|
|
445
|
+
class="compose-collection-add-action"
|
|
446
|
+
@keydown=${this._handleCollectionAddActionKeydown}
|
|
447
|
+
@click=${()=>{this._closeCollectionPicker(),this._addCollectionPanelOpen=!0}}
|
|
448
|
+
>
|
|
449
|
+
<span class="compose-collection-add-icon">
|
|
450
|
+
${B(z.plus,`compose-collection-add-svg`)}
|
|
451
|
+
</span>
|
|
452
|
+
${this.labels.addCollection}
|
|
453
|
+
</button>
|
|
454
|
+
</div>
|
|
455
|
+
</div>
|
|
456
|
+
</div>
|
|
457
|
+
</div>
|
|
458
|
+
`}_closeAddCollectionPanel(){this._addCollectionPanelOpen=!1,this.updateComplete.then(()=>{this.querySelector(`.compose-collection-trigger`)?.focus()})}async _handleAddCollectionSubmit(e){let t=e;t.stopPropagation();let n=t.detail;if(!n)return;let r=this.querySelector(`jant-collection-form`);r&&(r.loading=!0);try{let e=await fetch(`/api/collections`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(n.data)}),t=await e.json().catch(()=>null);if(!e.ok)throw Error(t?.error||`Couldn't create collection. Try again.`);if(!t?.id||!t.title)throw Error(`Couldn't create collection. Try again.`);let r={id:t.id,title:t.title,slug:t.slug??``};(!await this.refreshCollections()||!this.collections.some(e=>e.id===t.id))&&(this.collections=[...this.collections,r]),this._collectionIds=[...this._collectionIds,t.id],this._closeAddCollectionPanel(),l(this.labels.collectionFormLabels.createdLabel)}catch(e){l(e instanceof Error?e.message:`Couldn't create collection. Try again.`,`error`)}finally{r&&(r.loading=!1)}}_submitAddCollectionForm(){let e=this.querySelector(`[data-collection-quick-dialog] form`);e&&e.requestSubmit()}_renderAddCollectionPanel(){return this._addCollectionPanelOpen?i`
|
|
459
|
+
<div
|
|
460
|
+
class="collection-quick-dialog-backdrop"
|
|
461
|
+
@click=${()=>this._closeAddCollectionPanel()}
|
|
462
|
+
></div>
|
|
463
|
+
<div
|
|
464
|
+
class="collection-quick-dialog"
|
|
465
|
+
data-collection-quick-dialog
|
|
466
|
+
role="dialog"
|
|
467
|
+
aria-modal="true"
|
|
468
|
+
aria-label=${this.labels.addCollection}
|
|
469
|
+
@click=${e=>e.stopPropagation()}
|
|
470
|
+
>
|
|
471
|
+
<div class="collection-quick-dialog-header">
|
|
472
|
+
<div class="collection-quick-dialog-title-block">
|
|
473
|
+
<h2 class="collection-quick-dialog-title">
|
|
474
|
+
${this.labels.addCollection}
|
|
475
|
+
</h2>
|
|
476
|
+
<p class="collection-quick-dialog-note">
|
|
477
|
+
${this.labels.collectionFormLabels.quickHint}
|
|
478
|
+
</p>
|
|
479
|
+
</div>
|
|
480
|
+
<button
|
|
481
|
+
type="button"
|
|
482
|
+
class="collection-quick-dialog-cancel"
|
|
483
|
+
@click=${()=>this._closeAddCollectionPanel()}
|
|
484
|
+
>
|
|
485
|
+
${this.labels.collectionFormLabels.cancelLabel}
|
|
486
|
+
</button>
|
|
487
|
+
</div>
|
|
488
|
+
<div class="collection-quick-dialog-body">
|
|
489
|
+
<jant-collection-form
|
|
490
|
+
.labels=${this.labels.collectionFormLabels}
|
|
491
|
+
.initial=${{title:``,slug:``}}
|
|
492
|
+
action=${r(`/api/collections`)}
|
|
493
|
+
@jant:collection-submit=${e=>this._handleAddCollectionSubmit(e)}
|
|
494
|
+
></jant-collection-form>
|
|
495
|
+
</div>
|
|
496
|
+
<div class="collection-quick-dialog-footer">
|
|
497
|
+
<button
|
|
498
|
+
type="button"
|
|
499
|
+
class="compose-post-btn collection-quick-dialog-submit"
|
|
500
|
+
@click=${()=>this._submitAddCollectionForm()}
|
|
501
|
+
>
|
|
502
|
+
${this.labels.collectionFormLabels.quickSubmitLabel}
|
|
503
|
+
</button>
|
|
504
|
+
</div>
|
|
505
|
+
</div>
|
|
506
|
+
`:o}_renderAttachedPanel(){return this._attachedPanelOpen?i`
|
|
507
|
+
<div class="compose-attached-panel">
|
|
508
|
+
<div class="compose-alt-header">
|
|
509
|
+
<button
|
|
510
|
+
type="button"
|
|
511
|
+
class="compose-attached-cancel"
|
|
512
|
+
@click=${()=>this._cancelAttachedPanel()}
|
|
513
|
+
>
|
|
514
|
+
${this.labels.cancel}
|
|
515
|
+
</button>
|
|
516
|
+
<span class="compose-alt-title">${this.labels.attachedText}</span>
|
|
517
|
+
<button
|
|
518
|
+
type="button"
|
|
519
|
+
class="compose-attached-done"
|
|
520
|
+
@click=${()=>this._doneAttachedPanel()}
|
|
521
|
+
>
|
|
522
|
+
${this.labels.done}
|
|
523
|
+
</button>
|
|
524
|
+
</div>
|
|
525
|
+
<div class="flex-1 p-4 overflow-hidden flex flex-col">
|
|
526
|
+
<div
|
|
527
|
+
class="compose-attached-tiptap compose-tiptap-body"
|
|
528
|
+
@mousedown=${e=>this._handleAttachedEditorMouseDown(e)}
|
|
529
|
+
></div>
|
|
530
|
+
</div>
|
|
531
|
+
</div>
|
|
532
|
+
`:o}_renderAltPanel(){if(!this._altPanelOpen)return o;let e=this._getAltAttachment();if(!e)return o;let t=F(e.file.type);return i`
|
|
533
|
+
<div class="compose-alt-panel">
|
|
534
|
+
<div class="compose-alt-header">
|
|
535
|
+
<button
|
|
536
|
+
type="button"
|
|
537
|
+
class="compose-attached-panel-back"
|
|
538
|
+
@click=${()=>this._closeAltPanel()}
|
|
539
|
+
>
|
|
540
|
+
<svg
|
|
541
|
+
class="icon-fine"
|
|
542
|
+
width="16"
|
|
543
|
+
height="16"
|
|
544
|
+
viewBox="0 0 16 16"
|
|
545
|
+
fill="none"
|
|
546
|
+
stroke="currentColor"
|
|
547
|
+
stroke-width="1.5"
|
|
548
|
+
stroke-linecap="round"
|
|
549
|
+
stroke-linejoin="round"
|
|
550
|
+
>
|
|
551
|
+
<path d="M11 3L6 8l5 5" />
|
|
552
|
+
</svg>
|
|
553
|
+
</button>
|
|
554
|
+
<span class="compose-alt-title">${this.labels.addAltTitle}</span>
|
|
555
|
+
</div>
|
|
556
|
+
<div class="compose-alt-preview">
|
|
557
|
+
${t===`image`?i`<img
|
|
558
|
+
src=${e.previewUrl}
|
|
559
|
+
alt=""
|
|
560
|
+
class="compose-alt-preview-img"
|
|
561
|
+
/>`:t===`video`?i`<video
|
|
562
|
+
src=${e.previewUrl}
|
|
563
|
+
class="compose-alt-preview-img"
|
|
564
|
+
preload="metadata"
|
|
565
|
+
muted
|
|
566
|
+
></video>`:i`<span class="text-sm text-muted-foreground"
|
|
567
|
+
>${e.file.name}</span
|
|
568
|
+
>`}
|
|
569
|
+
</div>
|
|
570
|
+
<div class="compose-alt-input-row">
|
|
571
|
+
<input
|
|
572
|
+
type="text"
|
|
573
|
+
.value=${e.alt}
|
|
574
|
+
@input=${e=>this._onAltInput(e)}
|
|
575
|
+
class="compose-input compose-alt-input"
|
|
576
|
+
placeholder=${this.labels.altPlaceholder}
|
|
577
|
+
/>
|
|
578
|
+
</div>
|
|
579
|
+
<div class="compose-alt-footer">
|
|
580
|
+
<span class="text-xs text-muted-foreground"
|
|
581
|
+
>${this.labels.altHint}</span
|
|
582
|
+
>
|
|
583
|
+
<button
|
|
584
|
+
type="button"
|
|
585
|
+
class="compose-post-btn"
|
|
586
|
+
@click=${()=>this._closeAltPanel()}
|
|
587
|
+
>
|
|
588
|
+
${this.labels.done}
|
|
589
|
+
</button>
|
|
590
|
+
</div>
|
|
591
|
+
</div>
|
|
592
|
+
`}_renderConfirmPanel(){if(!this._confirmPanelOpen)return o;let e=!!this._editPostId,t=this._confirmForAttachedText?this.labels.confirmAttachedTitle:e?this.labels.confirmEditTitle:this.labels.confirmCloseTitle,n=this._confirmForAttachedText?this.labels.confirmAttachedSubtitle:e?this.labels.confirmEditSubtitle:this.labels.confirmCloseSubtitle,r=this._confirmForAttachedText?this.labels.confirmAttachedSave:e?this.labels.confirmEditPublish:this.labels.confirmCloseSave,a=this._confirmForAttachedText?this.labels.confirmAttachedDiscard:e?this.labels.confirmEditDiscard:this.labels.confirmCloseDiscard;return i`
|
|
593
|
+
<div class="compose-confirm-panel">
|
|
594
|
+
<div class="compose-confirm-sheet">
|
|
595
|
+
<div class="compose-confirm-header">
|
|
596
|
+
<p class="compose-confirm-title">${t}</p>
|
|
597
|
+
<p class="compose-confirm-subtitle">${n}</p>
|
|
598
|
+
</div>
|
|
599
|
+
<button
|
|
600
|
+
type="button"
|
|
601
|
+
class="compose-confirm-action compose-confirm-save"
|
|
602
|
+
@click=${()=>this._handleConfirmSave()}
|
|
603
|
+
>
|
|
604
|
+
${r}
|
|
605
|
+
</button>
|
|
606
|
+
<button
|
|
607
|
+
type="button"
|
|
608
|
+
class="compose-confirm-action compose-confirm-discard"
|
|
609
|
+
@click=${()=>this._handleConfirmDiscard()}
|
|
610
|
+
>
|
|
611
|
+
${a}
|
|
612
|
+
</button>
|
|
613
|
+
<button
|
|
614
|
+
type="button"
|
|
615
|
+
class="compose-confirm-action compose-confirm-cancel"
|
|
616
|
+
@click=${()=>this.requestClose()}
|
|
617
|
+
>
|
|
618
|
+
${this.labels.confirmCloseCancel}
|
|
619
|
+
</button>
|
|
620
|
+
</div>
|
|
621
|
+
</div>
|
|
622
|
+
`}_getSubmitLabel(){return this._editPostId?this.labels.update:this._replyToId?this._quietReply?this.labels.quietReplyLabel:this.labels.reply:this._visibility===`latest_hidden`?this.labels.postHiddenFromLatest:this._visibility===`private`?this.labels.postPrivately:this.labels.post}_getSlugSyncValidationMessage(){let e=x(this._slug);return e===`invalid`?this.labels.publishSlugInvalid:e===`reserved`?this.labels.publishSlugReserved:null}_getSlugValidationMessage(){return this._getSlugSyncValidationMessage()||(this._hasManualSlug()&&this._slugTaken?this.labels.publishSlugTaken:null)}_getSlugPreviewUrl(){if(!this._hasManualSlug()||this._getSlugValidationMessage())return null;let e=r(`/${this._slug.trim()}`),t=globalThis.location?.origin&&globalThis.location.origin!==`null`?globalThis.location.origin:`http://localhost`;return new URL(e,`${t}/`).toString()}_getSlugPreviewParts(){let e=this._getSlugPreviewUrl();if(!e)return null;let t=new URL(e);return{full:e,origin:t.origin,path:`${t.pathname}${t.search}${t.hash}`}}_getSlugStatusMessage(){return this._hasManualSlug()?this._getSlugValidationMessage()?this._getSlugValidationMessage():null:this._suggestedSlugLoading?this.labels.publishSlugGenerating:null}_getCurrentTimestamp(){return Math.floor(Date.now()/1e3)}_getPublishedAtMaxInput(){return ct(this._getCurrentTimestamp())}_getPublishedAtTimeMinutes(){return this._publishedAtTimeMinutes??W(this._getCurrentTimestamp())}_hasPublishedAtValue(){return this._publishedAtInput.trim().length>0}_getPublishedAtValidationMessage(){return this._hasPublishedAtValue()?U(this._publishedAtInput)===null?this.labels.publishDateInvalid:this._publishedAtInput>this._getPublishedAtMaxInput()?this.labels.publishDateFutureError:null:null}_getPublishedAtSummary(){if(this._editPostId||this._draftSourceId){if(this._publishedAtInput===this._initialPublishedAtInput)return null;if(!this._hasPublishedAtValue())return{input:``,text:this.labels.publishDateSummaryNow}}if(this._getPublishedAtValidationMessage()!==null)return null;let e=U(this._publishedAtInput);return e===null?null:{input:this._publishedAtInput,text:new Intl.DateTimeFormat(void 0,{month:`short`,day:`numeric`,year:`numeric`}).format(new Date(e.year,e.monthIndex,e.day))}}_getPostPublishedAtSubmitValue(e,t){if(e===0)return this._getPublishedAtSubmitValue(t);if(t===`draft`)return;let n=this._threadItems[e],r=n?.publishedAtInput??``;if(!r.trim())return;let i=lt(r,n?.publishedAtTimeMinutes??W(this._getCurrentTimestamp()));if(i!==null)return Math.min(i,this._getCurrentTimestamp())}_getPublishedAtSubmitValue(e){if(e===`draft`)return;let t=lt(this._publishedAtInput,this._getPublishedAtTimeMinutes());if(t!==null)return this._originalPublishedAt!==null&&this._publishedAtInput===this._initialPublishedAtInput&&this._publishedAtTimeMinutes===this._initialPublishedAtTimeMinutes?Math.min(this._originalPublishedAt,this._getCurrentTimestamp()):Math.min(t,this._getCurrentTimestamp());if(!(this._publishedAtInput.trim().length>0)&&this._editPostId)return this._getCurrentTimestamp()}_openPublishPanelAndFocus(e,t=0){this._showCollection=!1,this._collectionSearch=``,this._showPublishPanel=!1,this._showLanguagePicker=!1,this._postMetaIndex=t,this._confirmPanelOpen=!1,this._scheduleSuggestedSlugRefresh(!0),this._placeAndFocusPostMetaPanel(e)}_revealSlugField(e=0){this._openPublishPanelAndFocus(`.compose-publish-slug-input`,e)}_revealPublishedAtField(e=0){this._openPublishPanelAndFocus(`.compose-publish-date-input`,e)}_canPublish(){if(this._loading)return!1;let e=this._rowIds;for(let t=0;t<e.length;t++)if(this._getPostPublishedAtValidationMessage(t)||this._getPostSlugValidationMessage(t))return!1;return e.every(e=>this._rowStatus.get(e)?.publishable===!0)}_focusPublishPanelInitialField(){let e=this._visibilityLocked?`.compose-publish-date-input`:`.compose-publish-option[role='radio']`;this.querySelector(e)?.focus()}_closePublishPanel(e=!1){this._showPublishPanel&&(this._showPublishPanel=!1,e&&this.updateComplete.then(()=>this._restorePageEditorFocus()))}_togglePublishPanel(){this._showCollection=!1,this._collectionSearch=``,this._showLanguagePicker=!1;let e=!this._showPublishPanel;this._showPublishPanel=e,e&&(this._scheduleSuggestedSlugRefresh(!0),this.updateComplete.then(()=>this._focusPublishPanelInitialField()))}_setVisibility(t){this._visibilityLocked||(this._visibility=t,this._showPublishPanel&&this._closePublishPanel(!0),!this._editPostId&&!this._draftSourceId&&!this._replyToId&&(e._lastNewPostVisibility=t,this._sourceCollectionId&&e._setCollectionVisibility(this._sourceCollectionId,t)))}_onSlugInput(e,t=0){let n=e.target.value;if(this._setPostSlug(t,n.toLowerCase()),this._setPostSlugTaken(t,!1),this._slugCheckLoading=!1,this._hasPostManualSlug(t)){this._scheduleSlugAvailabilityCheck(t);return}this._scheduleSuggestedSlugRefresh()}_resetPublishedAt(e=0){let t=this._getCurrentTimestamp();this._setPostPublishedAtInput(e,ct(t)),this._setPostPublishedAtTimeMinutes(e,W(t)),this.updateComplete.then(()=>{this.querySelector(`.compose-publish-date-input`)?.focus()})}_renderVisibilityIcon(e,t=`menu`){let n=b({"compose-publish-visibility-icon":!0,"compose-publish-visibility-icon-toggle":t===`toggle`,"compose-publish-visibility-icon-public":e===`public`,"compose-publish-visibility-icon-latest_hidden":e===`latest_hidden`,"compose-publish-visibility-icon-private":e===`private`});return it(tt[e],n)}_renderVisibilityRow(e,t,n){let r=this._visibility===e;return i`
|
|
623
|
+
<button
|
|
624
|
+
type="button"
|
|
625
|
+
class=${b({"compose-sheet-row":!0,"compose-sheet-row-selected":r})}
|
|
626
|
+
role="radio"
|
|
627
|
+
aria-checked=${r?`true`:`false`}
|
|
628
|
+
?disabled=${this._visibilityLocked}
|
|
629
|
+
@click=${()=>this._setVisibility(e)}
|
|
630
|
+
>
|
|
631
|
+
${this._renderVisibilityIcon(e)}
|
|
632
|
+
<span class="compose-sheet-main">
|
|
633
|
+
<span class="compose-sheet-title">${t}</span>
|
|
634
|
+
<span class="compose-sheet-sub">${n}</span>
|
|
635
|
+
</span>
|
|
636
|
+
${r?i`<span class="compose-sheet-check" aria-hidden="true">
|
|
637
|
+
${V(R.check,`compose-sheet-check-icon`)}
|
|
638
|
+
</span>`:o}
|
|
639
|
+
</button>
|
|
640
|
+
`}async _loadTranslationSource(e,t={}){try{let n=await fetch(r(`/api/posts/${e}`),{credentials:`same-origin`});if(!n.ok)return;let i=await n.json();this._translationOf={id:i.id,title:i.displayTitle||i.slug||``,href:i.slug?r(`/${i.slug}`):``,previewHtml:await this._fetchTranslationPreview(i.id)},t.seed&&await this._seedFromTranslationSource(i)}catch{}}async _fetchTranslationPreview(e){try{let t=await fetch(r(`/_/post-preview/${encodeURIComponent(e)}`),{headers:{Accept:`text/html`},credentials:`same-origin`});return t.ok?await t.text():``}catch{return``}}async _seedFromTranslationSource(e){if(this._hasContent()||this._editPostId||this._draftSourceId)return;let t=e.format;this._format=t,e.collectionIds?.length&&(this._collectionIds=[...e.collectionIds]),e.visibility&&(this._visibility=e.visibility),await this.updateComplete,this._editor?.populate({format:t,url:t===`quote`?e.sourceUrl??void 0:e.url??void 0,quoteAuthor:t===`quote`?e.sourceName??void 0:void 0,rating:e.rating??void 0}),await this.updateComplete,this._seededFromSource=!0,this._captureInitialSnapshot()}_composeTextForDetection(){let e=this._editor;if(!e)return``;let t=e.getData(),n=t.body?re(t.body)??``:``;return[t.title,t.quoteText,n].filter(Boolean).join(` `)}_contextLanguageTag(){let e=this.languages.map(e=>e.tag);return e.length===0?null:e.includes(this.contextLanguage)?this.contextLanguage:e[0]}_readLanguage(){return Ce(this._composeTextForDetection(),{languages:this.languages.map(e=>e.tag)})}_effectiveLanguage(){return this._language??this._readLanguage()??this._contextLanguageTag()}_renderLanguageRow(e,t,n){let r=this._language===e;return i`
|
|
641
|
+
<button
|
|
642
|
+
type="button"
|
|
643
|
+
class=${b({"compose-sheet-row":!0,"compose-sheet-row-selected":r})}
|
|
644
|
+
role="radio"
|
|
645
|
+
aria-checked=${r?`true`:`false`}
|
|
646
|
+
lang=${P(e??void 0)}
|
|
647
|
+
data-compose-language-row
|
|
648
|
+
@click=${()=>{this._language=e,this._scheduleDraftSave(),this._closeLanguagePicker(!0)}}
|
|
649
|
+
>
|
|
650
|
+
<span class="compose-sheet-main">
|
|
651
|
+
<span class="compose-sheet-title">${t}</span>
|
|
652
|
+
${n?i`<span class="compose-sheet-sub">${n}</span>`:o}
|
|
653
|
+
</span>
|
|
654
|
+
${r?i`<span class="compose-sheet-check" aria-hidden="true">
|
|
655
|
+
${V(R.check,`compose-sheet-check-icon`)}
|
|
656
|
+
</span>`:o}
|
|
657
|
+
</button>
|
|
658
|
+
`}_closeLanguagePicker(e=!1){this._showLanguagePicker&&(this._showLanguagePicker=!1,e&&this.updateComplete.then(()=>{this.querySelector(`[data-compose-language-trigger]`)?.focus()}))}_toggleLanguagePicker(){if(this._showLanguagePicker){this._closeLanguagePicker(!0);return}this._showCollection=!1,this._collectionSearch=``,this._showPublishPanel=!1,this._postMetaIndex=null,this._showLanguagePicker=!0,this.updateComplete.then(()=>{let e=this.querySelectorAll(`[data-compose-language-row]`);(Array.from(e).find(e=>e.getAttribute(`aria-checked`)===`true`)??e[0])?.focus()})}_renderLanguageControl(){if(this._replyToId||this.languages.length<2)return o;let e=this._effectiveLanguage(),t=this.languages.find(t=>t.tag===e)?.label??``,n=this._language!==null,r=n||e!==this._contextLanguageTag(),a=this._showLanguagePicker,s=this.labels.languageTriggerLabel.replace(`{language}`,t);return i`
|
|
659
|
+
<div
|
|
660
|
+
class=${b({"compose-language":!0,"compose-language-open":a})}
|
|
661
|
+
>
|
|
662
|
+
${a?i`<div
|
|
663
|
+
class="compose-dropdown-backdrop"
|
|
664
|
+
@click=${()=>this._closeLanguagePicker(!0)}
|
|
665
|
+
></div>`:o}
|
|
666
|
+
<button
|
|
667
|
+
type="button"
|
|
668
|
+
class=${b({"compose-language-trigger":!0,"compose-language-trigger-bare":!r})}
|
|
669
|
+
data-compose-language-trigger
|
|
670
|
+
data-open=${a?`true`:o}
|
|
671
|
+
data-chosen=${n?`true`:o}
|
|
672
|
+
?disabled=${this._loading}
|
|
673
|
+
aria-haspopup="dialog"
|
|
674
|
+
aria-expanded=${a?`true`:`false`}
|
|
675
|
+
aria-label=${s}
|
|
676
|
+
title=${s}
|
|
677
|
+
@click=${()=>this._toggleLanguagePicker()}
|
|
678
|
+
>
|
|
679
|
+
<svg
|
|
680
|
+
class="compose-language-trigger-svg"
|
|
681
|
+
width="24"
|
|
682
|
+
height="24"
|
|
683
|
+
viewBox="0 0 24 24"
|
|
684
|
+
fill="none"
|
|
685
|
+
stroke="currentColor"
|
|
686
|
+
stroke-width="1.9"
|
|
687
|
+
stroke-linecap="round"
|
|
688
|
+
stroke-linejoin="round"
|
|
689
|
+
aria-hidden="true"
|
|
690
|
+
>
|
|
691
|
+
${v(nt)}
|
|
692
|
+
</svg>
|
|
693
|
+
${r?i`<span
|
|
694
|
+
class="compose-language-label"
|
|
695
|
+
lang=${P(e??void 0)}
|
|
696
|
+
>${t}</span
|
|
697
|
+
>`:o}
|
|
698
|
+
</button>
|
|
699
|
+
${a?this._renderLanguagePicker():o}
|
|
700
|
+
</div>
|
|
701
|
+
`}_renderLanguagePicker(){let e=e=>this.languages.find(t=>t.tag===e)?.label??``,t=this._readLanguage(),n=e(this._contextLanguageTag()),r=t?this.labels.languageAutoDetected.replace(`{language}`,e(t)):n?this.labels.languageAutoPending.replace(`{language}`,n):this.labels.languageAutoHint;return i`
|
|
702
|
+
<div
|
|
703
|
+
class="compose-language-popover"
|
|
704
|
+
role="dialog"
|
|
705
|
+
aria-label=${this.labels.languageLabel}
|
|
706
|
+
>
|
|
707
|
+
<p class="compose-sheet-label">${this.labels.languageLabel}</p>
|
|
708
|
+
${this._translationOf?i`<p class="compose-sheet-note">
|
|
709
|
+
${this.labels.translationOf.replace(`{title}`,this._translationOf.title)}
|
|
710
|
+
</p>`:o}
|
|
711
|
+
<div role="radiogroup" aria-label=${this.labels.languageLabel}>
|
|
712
|
+
${this._renderLanguageRow(null,this.labels.languageAuto,r)}
|
|
713
|
+
${this.languages.map(e=>this._renderLanguageRow(e.tag,e.label,``))}
|
|
714
|
+
</div>
|
|
715
|
+
</div>
|
|
716
|
+
`}_renderMetaFieldHead(e,t){return i`
|
|
717
|
+
<div class="compose-meta-field-head">
|
|
718
|
+
<span class="compose-meta-label">${e}</span>
|
|
719
|
+
${t}
|
|
720
|
+
</div>
|
|
721
|
+
`}_openDatePicker(e){let t=this.querySelectorAll(`.compose-publish-date-input`),n=t[e]??t[0];if(n){n.focus();try{n.showPicker()}catch{}}}_renderPublishDateSection(e){let t=this._getPostPublishedAtValidationMessage(e),n=this._hasPostPublishedAtValue(e);return i`
|
|
722
|
+
<div class="compose-meta-field compose-publish-date-field">
|
|
723
|
+
${this._renderMetaFieldHead(this.labels.publishDateLabel,n?i`<button
|
|
724
|
+
type="button"
|
|
725
|
+
class="compose-publish-section-action"
|
|
726
|
+
@click=${()=>this._resetPublishedAt(e)}
|
|
727
|
+
>
|
|
728
|
+
${this.labels.publishDateReset}
|
|
729
|
+
</button>`:o)}
|
|
730
|
+
<div class="compose-publish-date-input-wrap">
|
|
731
|
+
<input
|
|
732
|
+
type="date"
|
|
733
|
+
class=${b({"compose-input":!0,"compose-publish-date-input":!0,"compose-publish-date-input-empty":!n})}
|
|
734
|
+
.value=${this._getPostPublishedAtInput(e)}
|
|
735
|
+
max=${this._getPublishedAtMaxInput()}
|
|
736
|
+
aria-label=${this.labels.publishDateLabel}
|
|
737
|
+
aria-invalid=${t?`true`:`false`}
|
|
738
|
+
@input=${t=>this._setPostPublishedAtInput(e,t.target.value)}
|
|
739
|
+
/>
|
|
740
|
+
<button
|
|
741
|
+
type="button"
|
|
742
|
+
class="compose-publish-date-picker"
|
|
743
|
+
aria-label=${this.labels.publishDateSummaryAction}
|
|
744
|
+
data-compose-date-picker
|
|
745
|
+
@click=${()=>this._openDatePicker(e)}
|
|
746
|
+
>
|
|
747
|
+
${V(R.calendar,`compose-publish-date-picker-icon`)}
|
|
748
|
+
</button>
|
|
749
|
+
</div>
|
|
750
|
+
${t?i`<p
|
|
751
|
+
class="compose-publish-date-status compose-publish-date-status-error"
|
|
752
|
+
>
|
|
753
|
+
${t}
|
|
754
|
+
</p>`:n?o:i`<p class="compose-sheet-hint">
|
|
755
|
+
${this.labels.publishDateHint}
|
|
756
|
+
</p>`}
|
|
757
|
+
</div>
|
|
758
|
+
`}_renderPublishSlugSection(e){let t=e===0,n=this._getPostSlugValidationMessage(e),r=t?this._getSlugStatusMessage():n,a=t?this._getSlugPreviewParts():null,s=t&&!this._hasManualSlug()&&!this._suggestedSlugLoading&&!!this._suggestedSlug;return i`
|
|
759
|
+
<div class="compose-meta-field compose-publish-slug-field">
|
|
760
|
+
${this._renderMetaFieldHead(this.labels.publishSlugLabel,this._hasManualSlug()?i`<button
|
|
761
|
+
type="button"
|
|
762
|
+
class="compose-publish-section-action"
|
|
763
|
+
@click=${()=>this._resetCustomSlug()}
|
|
764
|
+
>
|
|
765
|
+
${this.labels.publishSlugReset}
|
|
766
|
+
</button>`:o)}
|
|
767
|
+
<div class="compose-publish-slug-input-wrap">
|
|
768
|
+
<span class="compose-publish-slug-prefix" aria-hidden="true">/</span>
|
|
769
|
+
<input
|
|
770
|
+
type="text"
|
|
771
|
+
class="compose-input compose-publish-slug-input"
|
|
772
|
+
.value=${this._getPostSlug(e)}
|
|
773
|
+
placeholder=${this.labels.publishSlugPlaceholder}
|
|
774
|
+
aria-label=${this.labels.publishSlugLabel}
|
|
775
|
+
aria-invalid=${n?`true`:`false`}
|
|
776
|
+
spellcheck="false"
|
|
777
|
+
autocapitalize="off"
|
|
778
|
+
autocomplete="off"
|
|
779
|
+
@input=${t=>this._onSlugInput(t,e)}
|
|
780
|
+
/>
|
|
781
|
+
</div>
|
|
782
|
+
${s?i`
|
|
783
|
+
<button
|
|
784
|
+
type="button"
|
|
785
|
+
class="compose-slug-suggestion"
|
|
786
|
+
@click=${()=>this._useSuggestedSlug()}
|
|
787
|
+
>
|
|
788
|
+
<span class="compose-slug-suggestion-label"
|
|
789
|
+
>${this.labels.publishSlugSuggested}</span
|
|
790
|
+
>
|
|
791
|
+
<span class="compose-slug-suggestion-value"
|
|
792
|
+
>/${this._suggestedSlug}</span
|
|
793
|
+
>
|
|
794
|
+
<span class="compose-slug-suggestion-icon" aria-hidden="true">
|
|
795
|
+
<svg
|
|
796
|
+
width="13"
|
|
797
|
+
height="13"
|
|
798
|
+
viewBox="0 0 14 14"
|
|
799
|
+
fill="none"
|
|
800
|
+
stroke="currentColor"
|
|
801
|
+
stroke-width="1.4"
|
|
802
|
+
stroke-linecap="round"
|
|
803
|
+
stroke-linejoin="round"
|
|
804
|
+
>
|
|
805
|
+
<path d="M3 7h8" />
|
|
806
|
+
<path d="m8 3 4 4-4 4" />
|
|
807
|
+
</svg>
|
|
808
|
+
</span>
|
|
809
|
+
</button>
|
|
810
|
+
`:o}
|
|
811
|
+
${r?i`<p
|
|
812
|
+
class=${b({"compose-publish-slug-status":!0,"compose-publish-slug-status-error":!!n})}
|
|
813
|
+
data-compose-slug-error=${n?`true`:o}
|
|
814
|
+
>
|
|
815
|
+
${r}
|
|
816
|
+
</p>`:a?i`<p
|
|
817
|
+
class="compose-publish-slug-preview"
|
|
818
|
+
data-compose-slug-preview
|
|
819
|
+
title=${a.full}
|
|
820
|
+
>
|
|
821
|
+
<span class="compose-publish-slug-preview-origin"
|
|
822
|
+
>${a.origin}</span
|
|
823
|
+
><span class="compose-publish-slug-preview-path"
|
|
824
|
+
>${a.path}</span
|
|
825
|
+
>
|
|
826
|
+
</p>`:this._hasPostManualSlug(e)?o:i`<p class="compose-sheet-hint">
|
|
827
|
+
${this.labels.publishSlugHint}
|
|
828
|
+
</p>`}
|
|
829
|
+
</div>
|
|
830
|
+
`}_canReplyQuietly(){return this._replyToId?!(this._editPostId||this._draftSourceId)||this._threadItems.length>=2:!1}_renderQuietReplySection(){return this._canReplyQuietly()?i`
|
|
831
|
+
<label class="compose-sheet-row compose-sheet-row-switch">
|
|
832
|
+
<span class="compose-sheet-main">
|
|
833
|
+
<span class="compose-sheet-title"
|
|
834
|
+
>${this.labels.quietReplyLabel}</span
|
|
835
|
+
>
|
|
836
|
+
<span class="compose-sheet-sub">${this.labels.quietReplyHint}</span>
|
|
837
|
+
</span>
|
|
838
|
+
<input
|
|
839
|
+
type="checkbox"
|
|
840
|
+
role="switch"
|
|
841
|
+
class="input"
|
|
842
|
+
.checked=${this._quietReply}
|
|
843
|
+
@change=${e=>{this._quietReply=e.target.checked}}
|
|
844
|
+
/>
|
|
845
|
+
</label>
|
|
846
|
+
`:o}_getPublishedAtRowValue(){let e=U(this._publishedAtInput);return e===null?this.labels.publishDateSummaryNow:new Intl.DateTimeFormat(void 0,{month:`short`,day:`numeric`,year:`numeric`}).format(new Date(e.year,e.monthIndex,e.day))}_getPostSlugRowValue(e){let t=this._getPostSlug(e).trim();return t?`/${t}`:this.labels.publishSlugSummaryAuto}_getPostSlug(e){return e===0?this._slug:this._threadItems[e]?.slug??``}_setPostSlug(e,t){if(e===0){this._slug=t;return}this._threadItems=this._threadItems.map((n,r)=>r===e?{...n,slug:t}:n)}_setPostSlugTaken(e,t){if(e===0){this._slugTaken=t;return}this._threadItems=this._threadItems.map((n,r)=>r===e?{...n,slugTaken:t}:n)}_hasPostManualSlug(e){return this._getPostSlug(e).trim().length>0}_getPostSlugSyncValidationMessage(e){let t=x(this._getPostSlug(e));return t===`invalid`?this.labels.publishSlugInvalid:t===`reserved`?this.labels.publishSlugReserved:null}_getPostSlugValidationMessage(e){let t=this._getPostSlugSyncValidationMessage(e);if(t)return t;let n=e===0?this._slugTaken:this._threadItems[e]?.slugTaken;return this._hasPostManualSlug(e)&&n?this.labels.publishSlugTaken:null}_getPostPublishedAtInput(e){return e===0?this._publishedAtInput:this._threadItems[e]?.publishedAtInput??``}_setPostPublishedAtInput(e,t){if(e===0){this._publishedAtInput=t;return}this._threadItems=this._threadItems.map((n,r)=>r===e?{...n,publishedAtInput:t}:n)}_setPostPublishedAtTimeMinutes(e,t){if(e===0){this._publishedAtTimeMinutes=t;return}this._threadItems=this._threadItems.map((n,r)=>r===e?{...n,publishedAtTimeMinutes:t}:n)}_hasPostPublishedAtValue(e){return this._getPostPublishedAtInput(e).trim().length>0}_getPostPublishedAtValidationMessage(e){let t=this._getPostPublishedAtInput(e);return t.trim()?U(t)===null?this.labels.publishDateInvalid:t>this._getPublishedAtMaxInput()?this.labels.publishDateFutureError:null:null}_getPostPublishedAtRowValue(e){let t=U(this._getPostPublishedAtInput(e));return t===null?e>0&&this._hasPublishedAtValue()?this._getPublishedAtRowValue():this.labels.publishDateSummaryNow:new Intl.DateTimeFormat(void 0,{month:`short`,day:`numeric`,year:`numeric`}).format(new Date(t.year,t.monthIndex,t.day))}_renderPostMetaControl(e){if(this._openingEdit)return o;let t=e===0,n=this._postMetaIndex===e,r=this._hasPostPublishedAtValue(e)||this._hasPostManualSlug(e);return i`
|
|
847
|
+
<div
|
|
848
|
+
class=${b({"compose-post-meta":!0,"compose-post-meta-set":r,"compose-post-meta-open":n})}
|
|
849
|
+
>
|
|
850
|
+
${n?i`<div
|
|
851
|
+
class="compose-dropdown-backdrop"
|
|
852
|
+
@click=${()=>this._closePostMeta()}
|
|
853
|
+
></div>`:o}
|
|
854
|
+
<button
|
|
855
|
+
type="button"
|
|
856
|
+
class="compose-post-meta-pill"
|
|
857
|
+
aria-haspopup="dialog"
|
|
858
|
+
aria-expanded=${n?`true`:`false`}
|
|
859
|
+
data-compose-post-meta-pill
|
|
860
|
+
data-post-index=${e}
|
|
861
|
+
@click=${()=>{if(n)return this._closePostMeta();this._showPublishPanel=!1,this._showCollection=!1,this._showLanguagePicker=!1,this._postMetaIndex=e,t&&this._scheduleSuggestedSlugRefresh(!0),this._placeAndFocusPostMetaPanel()}}
|
|
862
|
+
>
|
|
863
|
+
${V(R.calendar,`compose-post-meta-icon`)}
|
|
864
|
+
<span class="compose-post-meta-value"
|
|
865
|
+
>${this._getPostPublishedAtRowValue(e)}</span
|
|
866
|
+
>
|
|
867
|
+
<span class="compose-post-meta-sep" aria-hidden="true">·</span>
|
|
868
|
+
<!-- No link icon: the permalink already renders with its leading
|
|
869
|
+
slash, and two icons in a control this quiet read as clutter. -->
|
|
870
|
+
<span class="compose-post-meta-value compose-post-meta-value-slug"
|
|
871
|
+
>${this._getPostSlugRowValue(e)}</span
|
|
872
|
+
>
|
|
873
|
+
</button>
|
|
874
|
+
${n?i`<div
|
|
875
|
+
class="compose-post-meta-panel"
|
|
876
|
+
role="dialog"
|
|
877
|
+
aria-label=${this.labels.publishSettings}
|
|
878
|
+
tabindex="-1"
|
|
879
|
+
data-compose-post-meta-panel
|
|
880
|
+
>
|
|
881
|
+
${this._renderPublishDateSection(e)}
|
|
882
|
+
${this._renderPublishSlugSection(e)}
|
|
883
|
+
<div class="compose-post-meta-footer">
|
|
884
|
+
<button
|
|
885
|
+
type="button"
|
|
886
|
+
class="compose-publish-done"
|
|
887
|
+
data-compose-post-meta-done
|
|
888
|
+
@click=${()=>this._closePostMeta()}
|
|
889
|
+
>
|
|
890
|
+
${this.labels.done}
|
|
891
|
+
</button>
|
|
892
|
+
</div>
|
|
893
|
+
</div>`:o}
|
|
894
|
+
</div>
|
|
895
|
+
`}_placeAndFocusPostMetaPanel(e){this.updateComplete.then(()=>{this._updatePostMetaPanelLayout(),this.querySelector(e??`[data-compose-post-meta-panel]`)?.focus({preventScroll:!0})})}_updatePostMetaPanelLayout(){let e=this._postMetaIndex;if(e===null)return;let t=this.querySelector(`[data-compose-post-meta-panel]`),n=this.querySelector(`[data-compose-post-meta-pill][data-post-index="${e}"]`);if(!t||!n)return;let r=globalThis.visualViewport,i=r?.offsetTop??0,a=r?.offsetLeft??0,o=i+(r?.height??globalThis.innerHeight),s=a+(r?.width??globalThis.innerWidth),c=n.getBoundingClientRect(),l=Math.max(0,c.top-(i+12)-6),u=Math.max(0,o-12-c.bottom-6),d=u>=l?`down`:`up`,f=Math.max(1,Math.floor(d===`up`?l:u));t.style.top=`0px`,t.style.left=`0px`;let p=t.getBoundingClientRect(),m=p.width/(t.offsetWidth||p.width||1)||1;t.style.setProperty(`--compose-post-meta-panel-max-height`,`${f/m}px`);let h=t.offsetHeight*m,g=d===`down`?c.bottom+6:c.top-6-h,_=Math.min(Math.max(c.right-p.width,a+12),Math.max(s-12-p.width,a));t.style.top=`${(g-p.top)/m}px`,t.style.left=`${(_-p.left)/m}px`}_closePostMeta(){let e=this._postMetaIndex;if(e===null)return;let t=this.querySelector(`[data-compose-post-meta-panel]`)?.contains(document.activeElement)??!1;this._postMetaIndex=null,t&&this.updateComplete.then(()=>{let t=this.querySelectorAll(`jant-compose-editor`);(t[e]??t[0])?.focusInput()})}_hasPublishPanelContent(){return!this._visibilityLocked||this._replyToId&&this._renderQuietReplySection()!==o?!0:this._renderSaveDraftRow()!==o||this._renderDraftsRow()!==o}_renderPublishPanelSections(){let e=i`<div
|
|
896
|
+
class="compose-sheet-divider"
|
|
897
|
+
aria-hidden="true"
|
|
898
|
+
></div>`,t=this._renderSaveDraftRow(),n=this._renderDraftsRow(),r=t!==o||n!==o;return i`
|
|
899
|
+
<div class="compose-sheet">
|
|
900
|
+
${this._visibilityLocked?o:i`
|
|
901
|
+
<p class="compose-sheet-label">
|
|
902
|
+
${this.labels.publishVisibilityLabel}
|
|
903
|
+
</p>
|
|
904
|
+
<div
|
|
905
|
+
role="radiogroup"
|
|
906
|
+
aria-label=${this.labels.publishVisibilityLabel}
|
|
907
|
+
>
|
|
908
|
+
${this._renderVisibilityRow(`public`,this.labels.publishVisibilityPublic,this.labels.publishVisibilityPublicHint)}
|
|
909
|
+
${this._renderVisibilityRow(`latest_hidden`,this.labels.publishVisibilityHiddenFromLatest,this.labels.publishVisibilityHiddenFromLatestHint)}
|
|
910
|
+
${this._renderVisibilityRow(`private`,this.labels.publishVisibilityPrivate,this.labels.publishVisibilityPrivateHint)}
|
|
911
|
+
</div>
|
|
912
|
+
`}
|
|
913
|
+
${this._replyToId?i`${this._visibilityLocked?o:e}
|
|
914
|
+
${this._renderQuietReplySection()}`:o}
|
|
915
|
+
${r?i`${e} ${t} ${n}`:o}
|
|
916
|
+
</div>
|
|
917
|
+
`}_renderSaveDraftRow(){return this._editPostId||!this._hasWorkToLose()?o:i`
|
|
918
|
+
<button
|
|
919
|
+
type="button"
|
|
920
|
+
class="compose-sheet-row"
|
|
921
|
+
?disabled=${this._loading}
|
|
922
|
+
@click=${()=>{this._closePublishPanel(!1),this._submit(`draft`)}}
|
|
923
|
+
>
|
|
924
|
+
${rt(et.saveDraft)}
|
|
925
|
+
<span class="compose-sheet-main">
|
|
926
|
+
<span class="compose-sheet-title">${this.labels.saveAsDraft}</span>
|
|
927
|
+
</span>
|
|
928
|
+
</button>
|
|
929
|
+
`}_renderDraftsRow(){return this._editPostId?o:i`
|
|
930
|
+
<button
|
|
931
|
+
type="button"
|
|
932
|
+
class="compose-sheet-row"
|
|
933
|
+
?disabled=${this._loading}
|
|
934
|
+
@click=${()=>{this._closePublishPanel(!1),this._handleDraftButtonClick()}}
|
|
935
|
+
>
|
|
936
|
+
${rt(et.drafts)}
|
|
937
|
+
<span class="compose-sheet-main">
|
|
938
|
+
<span class="compose-sheet-title">${this.labels.drafts}</span>
|
|
939
|
+
</span>
|
|
940
|
+
${V(R.caretRight,`compose-sheet-caret`)}
|
|
941
|
+
</button>
|
|
942
|
+
`}_renderCloseComposeQuickAction(){return this.pageMode||this._threadItems.length===0?o:i`
|
|
943
|
+
<button
|
|
944
|
+
type="button"
|
|
945
|
+
class="compose-quick-actions-close"
|
|
946
|
+
?disabled=${this._loading}
|
|
947
|
+
@click=${()=>this.requestClose()}
|
|
948
|
+
>
|
|
949
|
+
${this.labels.close}
|
|
950
|
+
</button>
|
|
951
|
+
`}_renderDesktopPublishPanel(){return!this._showPublishPanel||this._publishPanelFullscreen?o:i`
|
|
952
|
+
<div
|
|
953
|
+
class="compose-publish-panel compose-publish-panel-desktop"
|
|
954
|
+
role="dialog"
|
|
955
|
+
aria-label=${this.labels.publishSettings}
|
|
956
|
+
data-position="up"
|
|
957
|
+
data-compose-publish-panel
|
|
958
|
+
data-compose-publish-panel-desktop
|
|
959
|
+
>
|
|
960
|
+
${this._renderPublishPanelSections()}
|
|
961
|
+
</div>
|
|
962
|
+
`}_renderMobilePublishPanel(){return!this._showPublishPanel||!this._publishPanelFullscreen?o:i`
|
|
963
|
+
<div
|
|
964
|
+
class="compose-publish-panel compose-publish-panel-mobile"
|
|
965
|
+
role="dialog"
|
|
966
|
+
aria-label=${this.labels.publishSettings}
|
|
967
|
+
aria-modal="true"
|
|
968
|
+
data-compose-publish-panel
|
|
969
|
+
data-compose-publish-panel-mobile
|
|
970
|
+
>
|
|
971
|
+
<div class="compose-alt-header compose-publish-mobile-header">
|
|
972
|
+
<button
|
|
973
|
+
type="button"
|
|
974
|
+
class="compose-attached-panel-back"
|
|
975
|
+
@click=${()=>this._closePublishPanel(!0)}
|
|
976
|
+
>
|
|
977
|
+
<svg
|
|
978
|
+
class="icon-fine"
|
|
979
|
+
width="16"
|
|
980
|
+
height="16"
|
|
981
|
+
viewBox="0 0 16 16"
|
|
982
|
+
fill="none"
|
|
983
|
+
stroke="currentColor"
|
|
984
|
+
stroke-width="1.5"
|
|
985
|
+
stroke-linecap="round"
|
|
986
|
+
stroke-linejoin="round"
|
|
987
|
+
>
|
|
988
|
+
<path d="M11 3L6 8l5 5" />
|
|
989
|
+
</svg>
|
|
990
|
+
</button>
|
|
991
|
+
<span class="compose-alt-title">${this.labels.publishSettings}</span>
|
|
992
|
+
<button
|
|
993
|
+
type="button"
|
|
994
|
+
class="compose-attached-cancel compose-publish-mobile-done"
|
|
995
|
+
@click=${()=>this._closePublishPanel(!0)}
|
|
996
|
+
>
|
|
997
|
+
${this.labels.done}
|
|
998
|
+
</button>
|
|
999
|
+
</div>
|
|
1000
|
+
<div class="compose-publish-mobile-body">
|
|
1001
|
+
${this._renderPublishPanelSections()}
|
|
1002
|
+
</div>
|
|
1003
|
+
</div>
|
|
1004
|
+
`}_updatePublishPanelLayout(){if(this._publishPanelFullscreen)return;let e=this.querySelector(`.compose-publish-group`),t=this.querySelector(`[data-compose-publish-panel-desktop]`);if(!e||!t)return;let n=globalThis.visualViewport,r=n?.offsetTop??0,i=r+(n?.height??globalThis.innerHeight),a=e.getBoundingClientRect(),o=r+12,s=i-12,c=Math.max(0,a.top-o-10),l=Math.max(0,s-a.bottom-10),u=l>=c?`down`:`up`,d=Math.max(1,Math.floor(u===`up`?c:l));t.dataset.position=u,t.style.setProperty(`--compose-publish-panel-max-height`,`${d}px`)}_renderPublishButton(){let e=i`<svg
|
|
1005
|
+
class="animate-spin size-4"
|
|
1006
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
1007
|
+
viewBox="0 0 24 24"
|
|
1008
|
+
fill="none"
|
|
1009
|
+
stroke="currentColor"
|
|
1010
|
+
stroke-width="2"
|
|
1011
|
+
stroke-linecap="round"
|
|
1012
|
+
stroke-linejoin="round"
|
|
1013
|
+
role="status"
|
|
1014
|
+
>
|
|
1015
|
+
<path d="M21 12a9 9 0 1 1-6.219-8.56" />
|
|
1016
|
+
</svg>`,t=this._canPublish();return i`
|
|
1017
|
+
<div class="compose-publish-shell">
|
|
1018
|
+
<div
|
|
1019
|
+
class=${b({"compose-publish-group":!0,"compose-publish-group-open":this._showPublishPanel})}
|
|
1020
|
+
>
|
|
1021
|
+
${this._showPublishPanel&&!this._publishPanelFullscreen?i`<div
|
|
1022
|
+
class="compose-dropdown-backdrop"
|
|
1023
|
+
@click=${()=>this._closePublishPanel(!0)}
|
|
1024
|
+
></div>`:o}
|
|
1025
|
+
<div
|
|
1026
|
+
role="group"
|
|
1027
|
+
class=${b({"compose-publish-buttons":!0,"compose-publish-buttons-inactive":!t&&!this._loading})}
|
|
1028
|
+
>
|
|
1029
|
+
<button
|
|
1030
|
+
type="button"
|
|
1031
|
+
class=${b({"compose-publish-main":!0,"compose-publish-main-loading":this._loading})}
|
|
1032
|
+
?disabled=${!t}
|
|
1033
|
+
@click=${()=>void this._submit(`published`)}
|
|
1034
|
+
>
|
|
1035
|
+
${this._loading?e:o} ${this._getSubmitLabel()}
|
|
1036
|
+
</button>
|
|
1037
|
+
</div>
|
|
1038
|
+
<!-- Options sits past Publish as its own control rather than a
|
|
1039
|
+
chevron welded to it: a split button reads as one button, which
|
|
1040
|
+
is why nobody found the settings. -->
|
|
1041
|
+
${this._hasPublishPanelContent()?i`<button
|
|
1042
|
+
type="button"
|
|
1043
|
+
class=${b({"compose-options-trigger":!0,"compose-options-trigger-open":this._showPublishPanel})}
|
|
1044
|
+
?disabled=${this._loading}
|
|
1045
|
+
aria-haspopup="dialog"
|
|
1046
|
+
aria-expanded=${this._showPublishPanel?`true`:`false`}
|
|
1047
|
+
aria-label=${this.labels.publishSettings}
|
|
1048
|
+
title=${this.labels.publishSettings}
|
|
1049
|
+
@click=${()=>this._togglePublishPanel()}
|
|
1050
|
+
>
|
|
1051
|
+
<svg
|
|
1052
|
+
class="compose-options-trigger-icon"
|
|
1053
|
+
width="22"
|
|
1054
|
+
height="22"
|
|
1055
|
+
viewBox="0 0 24 24"
|
|
1056
|
+
fill="none"
|
|
1057
|
+
stroke="currentColor"
|
|
1058
|
+
stroke-linecap="round"
|
|
1059
|
+
stroke-linejoin="round"
|
|
1060
|
+
aria-hidden="true"
|
|
1061
|
+
>
|
|
1062
|
+
${v(R.options)}
|
|
1063
|
+
</svg>
|
|
1064
|
+
</button>`:o}
|
|
1065
|
+
${this._renderDesktopPublishPanel()}
|
|
1066
|
+
</div>
|
|
1067
|
+
</div>
|
|
1068
|
+
`}_renderQuickActionsRow(){let e=this._renderCloseComposeQuickAction(),t=this._renderHideFromLatestQuickToggle(),n=this._renderQuietReplyQuickToggle();return e===o&&t===o&&n===o?o:i`
|
|
1069
|
+
<div class="compose-quick-actions-row">
|
|
1070
|
+
${e} ${t} ${n}
|
|
1071
|
+
</div>
|
|
1072
|
+
`}_renderQuietReplyQuickToggle(){return this._canReplyQuietly()?i`
|
|
1073
|
+
<label class="compose-publish-quick-toggle">
|
|
1074
|
+
<input
|
|
1075
|
+
type="checkbox"
|
|
1076
|
+
class="input compose-publish-quick-toggle-input"
|
|
1077
|
+
.checked=${this._quietReply}
|
|
1078
|
+
?disabled=${this._loading}
|
|
1079
|
+
@change=${e=>{this._quietReply=e.target.checked}}
|
|
1080
|
+
/>
|
|
1081
|
+
<span>${this.labels.quietReplyLabel}</span>
|
|
1082
|
+
</label>
|
|
1083
|
+
`:o}_renderHideFromLatestQuickToggle(){if(this._visibilityLocked||this._visibility===`private`)return o;let e=this._visibility===`latest_hidden`;return i`
|
|
1084
|
+
<label class="compose-publish-quick-toggle">
|
|
1085
|
+
<input
|
|
1086
|
+
type="checkbox"
|
|
1087
|
+
class="input compose-publish-quick-toggle-input"
|
|
1088
|
+
.checked=${e}
|
|
1089
|
+
?disabled=${this._loading}
|
|
1090
|
+
@change=${e=>{let t=e.target;this._setVisibility(t.checked?`latest_hidden`:`public`)}}
|
|
1091
|
+
/>
|
|
1092
|
+
<span>${this.labels.publishHideFromLatest}</span>
|
|
1093
|
+
</label>
|
|
1094
|
+
`}_renderEditLoadingState(){return i`
|
|
1095
|
+
<div
|
|
1096
|
+
class="compose-edit-loading"
|
|
1097
|
+
role="status"
|
|
1098
|
+
aria-live="polite"
|
|
1099
|
+
aria-busy="true"
|
|
1100
|
+
>
|
|
1101
|
+
<!-- The post header this normally rides on has not rendered yet, so the
|
|
1102
|
+
close control gets its own row rather than leaving a fetch with no
|
|
1103
|
+
way out on a phone, where there is no Escape key. -->
|
|
1104
|
+
<div class="compose-edit-loading-close">
|
|
1105
|
+
${this._renderCloseComposeControl()}
|
|
1106
|
+
</div>
|
|
1107
|
+
<div class="compose-edit-loading-status">
|
|
1108
|
+
<svg
|
|
1109
|
+
class="animate-spin size-5"
|
|
1110
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
1111
|
+
viewBox="0 0 24 24"
|
|
1112
|
+
fill="none"
|
|
1113
|
+
stroke="currentColor"
|
|
1114
|
+
stroke-width="2"
|
|
1115
|
+
stroke-linecap="round"
|
|
1116
|
+
stroke-linejoin="round"
|
|
1117
|
+
aria-hidden="true"
|
|
1118
|
+
>
|
|
1119
|
+
<path d="M21 12a9 9 0 1 1-6.219-8.56" />
|
|
1120
|
+
</svg>
|
|
1121
|
+
<span>${this.labels.loadingPost}</span>
|
|
1122
|
+
</div>
|
|
1123
|
+
<div class="compose-edit-loading-skeleton">
|
|
1124
|
+
<div class="skel-input compose-edit-loading-title"></div>
|
|
1125
|
+
<div class="skel-section-lg compose-edit-loading-body"></div>
|
|
1126
|
+
<div class="compose-edit-loading-footer">
|
|
1127
|
+
<div class="skel-input compose-edit-loading-chip"></div>
|
|
1128
|
+
<div class="skel-input compose-edit-loading-submit"></div>
|
|
1129
|
+
</div>
|
|
1130
|
+
</div>
|
|
1131
|
+
</div>
|
|
1132
|
+
`}_addThreadItem(){if((this._threadItems.length===0?2:this._threadItems.length+1)>20){l(this._getThreadLimitMessage(),`error`);return}let e=this._threadItems.length>0?this._threadItems[this._threadItems.length-1].format:this._format;if(this._threadItems.length===0){let t=this._editor;this._threadItems=[{id:L(),format:this._format},{id:L(),format:e}],this.updateComplete.then(()=>{let e=this.querySelector(`jant-compose-editor`);t&&e&&e.takeOver(t)})}else this._threadItems=[...this._threadItems,{id:L(),format:e}];this._focusedThreadIndex=this._threadItems.length-1,this.updateComplete.then(()=>{this.querySelectorAll(`jant-compose-editor`)[this._focusedThreadIndex]?.focusInput();let e=this.querySelector(`.compose-scroll`);e&&(e.scrollTop=e.scrollHeight)})}_removeThreadItem(e){if(this._threadItems.length<=1)return;let t=this._threadItems.filter((t,n)=>n!==e);if(e===0){let e=t[0];this._slug=e.slug??``,this._slugTaken=e.slugTaken??!1,this._publishedAtInput=e.publishedAtInput??``,this._publishedAtTimeMinutes=e.publishedAtTimeMinutes??null}if(t.length===1){let e=this.querySelector(`jant-compose-editor[data-thread-id="${t[0].id}"]`);this._threadItems=[],this._focusedThreadIndex=0,this._format=t[0].format,this.updateComplete.then(()=>{let t=this._editor;t&&(e&&t.takeOver(e),t.focusInput())})}else this._threadItems=t,this._focusedThreadIndex=Math.min(this._focusedThreadIndex,t.length-1)}_positionLabel(e){if(this._editPostId)return``;let t=!!(this._replyToId&&this._replyToData);if(t&&this._replyParentPosition===null)return``;let n=t?this._replyParentPosition??0:0,r=n+(this._threadItems.length||1);return r<2?``:`${n+e+1}/${r}`}_renderThreadPost(e,t,n,r){return i`
|
|
1133
|
+
<div
|
|
1134
|
+
class=${b({"compose-editor-row":!0,"compose-thread-post":!0,"is-current":t===this._focusedThreadIndex})}
|
|
1135
|
+
data-thread-index=${t}
|
|
1136
|
+
@focusin=${()=>{this._focusedThreadIndex=t}}
|
|
1137
|
+
@jant:format-change=${n=>{n.stopPropagation(),this._convertForFormatSwitch(n.target,e.format,n.detail.format),this._threadItems=this._threadItems.map((e,r)=>r===t?{...e,format:n.detail.format}:e),this._format=n.detail.format,this._shouldAutofocusFormatInput()&&this.updateComplete.then(()=>{let e=this.querySelectorAll(`jant-compose-editor`)[t];e?.updateComplete.then(()=>e.focusInput())})}}
|
|
1138
|
+
@jant:thread-remove=${e=>{e.stopPropagation(),this._removeThreadItem(t)}}
|
|
1139
|
+
@jant:compose-status=${t=>{t.stopPropagation(),this._handleRowStatus(e.id,t.detail)}}
|
|
1140
|
+
>
|
|
1141
|
+
<div class="compose-thread-dot"></div>
|
|
1142
|
+
<jant-compose-editor
|
|
1143
|
+
.format=${e.format}
|
|
1144
|
+
.labels=${this.labels}
|
|
1145
|
+
.uploadMaxFileSize=${this.uploadMaxFileSize}
|
|
1146
|
+
.threadItem=${!0}
|
|
1147
|
+
.removable=${n}
|
|
1148
|
+
.titleByDefault=${r}
|
|
1149
|
+
.positionLabel=${this._positionLabel(t)}
|
|
1150
|
+
.headerExtra=${this._renderPostMetaControl(t)}
|
|
1151
|
+
.slashCommandDiscovered=${this.slashCommandDiscovered}
|
|
1152
|
+
data-thread-id=${e.id}
|
|
1153
|
+
></jant-compose-editor>
|
|
1154
|
+
</div>
|
|
1155
|
+
`}_renderAddToThreadRow(){let e=this._rowIds,t=e[e.length-1],n=!this._rowStatus.get(t)?.hasContent,r=this._threadItems.length>=20;return i`
|
|
1156
|
+
<div class="compose-thread-add-row">
|
|
1157
|
+
<div class="compose-thread-add-dot"></div>
|
|
1158
|
+
<button
|
|
1159
|
+
type="button"
|
|
1160
|
+
class="compose-thread-add-btn"
|
|
1161
|
+
?disabled=${n||r}
|
|
1162
|
+
@click=${()=>this._addThreadItem()}
|
|
1163
|
+
>
|
|
1164
|
+
Add to thread
|
|
1165
|
+
</button>
|
|
1166
|
+
</div>
|
|
1167
|
+
`}_renderThreadComposeLayout(){let e=!!(this._replyToId&&this._replyToData),t=this._threadItems,n=t.length>1;return i`
|
|
1168
|
+
<div
|
|
1169
|
+
class=${b({"compose-thread-layout":!0,"compose-thread-compose-layout":!0,"compose-reply-compose-layout":e})}
|
|
1170
|
+
@jant:compose-content-changed=${()=>this._scheduleDraftSave()}
|
|
1171
|
+
>
|
|
1172
|
+
${e?this._renderReplyContext():this._renderTranslationContext()}
|
|
1173
|
+
<!-- Keyed by row id, not by position: an editor holds its own content,
|
|
1174
|
+
so an unkeyed list would reuse elements by position and drop the
|
|
1175
|
+
last one when a middle post is removed — taking that post's text
|
|
1176
|
+
with it, and pairing the survivors with the wrong dates and
|
|
1177
|
+
permalinks. -->
|
|
1178
|
+
${ee(t,e=>e.id,(t,r)=>this._renderThreadPost(t,r,n,r===0&&!e))}
|
|
1179
|
+
${this._renderAddToThreadRow()}
|
|
1180
|
+
</div>
|
|
1181
|
+
`}_renderAddThreadTrigger(e){let t=!this._hasWorkToLose(),n=i`
|
|
1182
|
+
<button
|
|
1183
|
+
type="button"
|
|
1184
|
+
class="compose-thread-add-btn"
|
|
1185
|
+
?disabled=${t}
|
|
1186
|
+
@click=${()=>this._addThreadItem()}
|
|
1187
|
+
>
|
|
1188
|
+
Add to thread
|
|
1189
|
+
</button>
|
|
1190
|
+
`;return e?i`
|
|
1191
|
+
<div class="compose-thread-add-row">
|
|
1192
|
+
<div class="compose-thread-add-dot"></div>
|
|
1193
|
+
${n}
|
|
1194
|
+
</div>
|
|
1195
|
+
`:i`<div class="compose-add-thread-trigger">${n}</div>`}render(){let t=!!(this._replyToId&&this._replyToData),n=this._threadItems.length>0,r=this._openingEdit,a=i`<jant-compose-editor
|
|
1196
|
+
.format=${this._format}
|
|
1197
|
+
.labels=${this.labels}
|
|
1198
|
+
.uploadMaxFileSize=${this.uploadMaxFileSize}
|
|
1199
|
+
.inlineFormat=${t}
|
|
1200
|
+
.titleByDefault=${!t&&e._getNoteTitleDefault()}
|
|
1201
|
+
.positionLabel=${this._positionLabel(0)}
|
|
1202
|
+
.badgeLabel=${this._editPostId?this.labels.editing:``}
|
|
1203
|
+
.headerExtra=${i`${this._renderPostMetaControl(0)}
|
|
1204
|
+
${this._renderCloseComposeControl()}`}
|
|
1205
|
+
.slashCommandDiscovered=${this.slashCommandDiscovered}
|
|
1206
|
+
@jant:format-change=${e=>{e.stopPropagation(),this._switchFormat(e.detail.format)}}
|
|
1207
|
+
@jant:compose-status=${e=>{e.stopPropagation(),this._handleRowStatus(Qe,e.detail)}}
|
|
1208
|
+
></jant-compose-editor>`,s=r||n||this._editPostId?o:this._renderAddThreadTrigger(t);return i`
|
|
1209
|
+
<div
|
|
1210
|
+
class=${b({"compose-dialog-inner":!0,"compose-dialog-inner-page":this.pageMode,"compose-dialog-inner-suspended":this._addCollectionPanelOpen})}
|
|
1211
|
+
tabindex="-1"
|
|
1212
|
+
aria-hidden=${this._addCollectionPanelOpen?`true`:`false`}
|
|
1213
|
+
?inert=${this._addCollectionPanelOpen}
|
|
1214
|
+
>
|
|
1215
|
+
<div class="compose-scroll">
|
|
1216
|
+
${r?this._renderEditLoadingState():n?this._renderThreadComposeLayout():t?i`
|
|
1217
|
+
<div
|
|
1218
|
+
class="compose-thread-layout compose-reply-compose-layout"
|
|
1219
|
+
>
|
|
1220
|
+
${this._renderReplyContext()}
|
|
1221
|
+
<div class="compose-editor-row is-current">
|
|
1222
|
+
<div class="compose-thread-dot"></div>
|
|
1223
|
+
${a}
|
|
1224
|
+
</div>
|
|
1225
|
+
${s}
|
|
1226
|
+
</div>
|
|
1227
|
+
`:i`${this._renderTranslationContext()}${a}${s}`}
|
|
1228
|
+
</div>
|
|
1229
|
+
${r?o:i`<div
|
|
1230
|
+
class=${b({"compose-action-row":!0,"compose-action-row-without-collection":!!this._replyToId,"compose-action-row-overlay-open":this._showPublishPanel||this._showCollection||this._showLanguagePicker})}
|
|
1231
|
+
>
|
|
1232
|
+
${this._replyToId?o:this._renderCollectionSelector()}
|
|
1233
|
+
${this._renderLanguageControl()}
|
|
1234
|
+
${this._renderPublishButton()}
|
|
1235
|
+
</div>
|
|
1236
|
+
${this._renderQuickActionsRow()}`}
|
|
1237
|
+
${this._renderMobilePublishPanel()} ${this._renderAttachedPanel()}
|
|
1238
|
+
${this._renderAltPanel()} ${this._renderDraftsPanel()}
|
|
1239
|
+
${this._renderConfirmPanel()}
|
|
1240
|
+
</div>
|
|
1241
|
+
${this._renderAddCollectionPanel()}
|
|
1242
|
+
`}};customElements.define(`jant-compose-dialog`,dt);function ft(e){return typeof e.text==`string`?e.text:e.content?e.content.map(ft).join(``):e.type===`hardBreak`?` `:``}function pt(e){return!e.content||e.content.length===0||e.content.every(e=>e.type===`text`?!e.text?.trim():e.type===`hardBreak`)}function mt(e){return(e.type===`paragraph`||e.type===`heading`)&&pt(e)}function ht(e){return e.replace(/\s+/g,` `).trim()}function gt(e){let t=e?.content;if(!e||!t?.length)return null;let n=t.findIndex(e=>!mt(e));if(n<0)return null;let r=t[n];if(r?.type!==`heading`||r.attrs?.level!==1)return null;let i=ht(ft(r));if(!i)return null;let a=t.slice(n+1);return a.length===0?{title:i,bodyJson:null,headingIndex:n}:{title:i,bodyJson:{...e,content:a},headingIndex:n}}var _t=`0 0 96 96`,vt=[`M24.4 10.5C16.9 17.7 11.5 26.8 8.2 37.7C4.9 48.7 4.8 58.9 7.8 68.2C10.3 75.7 15.4 79.5 22.9 79.5C28 79.5 32.2 77.8 35.4 74.2C38.6 70.7 40.2 66.5 40.2 61.4C40.2 56.5 38.8 52.6 36 49.6C33.3 46.6 29.7 45.1 25.2 45.1C23.4 45.1 21.8 45.3 20.2 45.8C22.2 37.3 26.7 29.2 33.6 21.4L24.4 10.5Z`,`M60.8 10.5C53.3 17.7 47.9 26.8 44.6 37.7C41.3 48.7 41.2 58.9 44.2 68.2C46.7 75.7 51.8 79.5 59.3 79.5C64.4 79.5 68.6 77.8 71.8 74.2C75 70.7 76.6 66.5 76.6 61.4C76.6 56.5 75.2 52.6 72.4 49.6C69.7 46.6 66.1 45.1 61.6 45.1C59.8 45.1 58.2 45.3 56.6 45.8C58.6 37.3 63.1 29.2 70 21.4L60.8 10.5Z`].map(e=>`<path fill="currentColor" d="${e}" />`).join(``),yt=`jant.slashCommandDiscovery`,bt=`/api/settings/discovery/slash-command`,xt=600,St=3,G=`compose-slash-discovery-visible`,Ct=!1,wt=null,K=null;function Tt(){try{return globalThis.localStorage!==void 0}catch{return!1}}function Et(){if(!Tt())return{shownCount:0,completed:!1};let e=globalThis.localStorage.getItem(yt);if(!e)return{shownCount:0,completed:!1};try{let t=JSON.parse(e);return{shownCount:typeof t.shownCount==`number`&&t.shownCount>=0?t.shownCount:0,completed:t.completed===!0}}catch{return globalThis.localStorage.removeItem(yt),{shownCount:0,completed:!1}}}function Dt(e){if(Tt())try{globalThis.localStorage.setItem(yt,JSON.stringify(e))}catch{}}function Ot(){wt!==null&&(clearTimeout(wt),wt=null)}function kt(){return typeof globalThis.matchMedia==`function`&&globalThis.matchMedia(`(min-width: 700px)`).matches}function At(e){return Et().completed?!0:e.dataset.slashCommandDiscovered===`true`}function jt(){document.querySelectorAll(`jant-compose-editor`).forEach(e=>{e.dataset.slashCommandDiscovered=`true`,e.classList.remove(G)})}function Mt(){let e=Et();e.completed||Ct||e.shownCount>=St||(Ct=!0,Dt({...e,shownCount:e.shownCount+1}))}function Nt(e){return!kt()||At(e)?!1:Et().shownCount<St||Ct}function Pt(e){Ot(),e?e.classList.remove(G):K&&K.classList.remove(G),(!e||e===K)&&(K=null)}function Ft(e){Nt(e)&&(Pt(K),K=e,e.classList.add(G),Mt())}function It(e){Nt(e)&&(e.classList.contains(G)||(Ot(),wt=setTimeout(()=>{Ft(e)},xt)))}function Lt(){let e=Et();e.completed||Dt({shownCount:Math.max(e.shownCount,St),completed:!0}),jt(),Pt(K),typeof globalThis.fetch==`function`&&globalThis.fetch(bt,{method:`POST`,headers:{Accept:`application/json`},credentials:`same-origin`}).catch(()=>{})}function Rt(e){let t={};return e.brokenImageUnavailable&&(t.unavailable=e.brokenImageUnavailable),e.brokenImageDelete&&(t.delete=e.brokenImageDelete),e.brokenImageReplace&&(t.replace=e.brokenImageReplace),e.brokenImageOpen&&(t.open=e.brokenImageOpen),t}var q={media:`
|
|
1243
|
+
<rect x="2.75" y="3" width="12.5" height="11.25" rx="3" />
|
|
1244
|
+
<circle cx="6.15" cy="6.85" r="0.85" fill="currentColor" stroke="none" />
|
|
1245
|
+
<path d="M3.6 11.95 6.75 8.8c.42-.42 1.11-.42 1.53 0l1.4 1.4" />
|
|
1246
|
+
<path d="m8.95 10.2 1.38-1.38c.46-.46 1.21-.46 1.67 0l2.4 2.4" />
|
|
1247
|
+
`,attachedText:`
|
|
1248
|
+
<rect x="3" y="2.75" width="12" height="12.5" rx="3.1" />
|
|
1249
|
+
<path d="M5.85 6.35h6.3" />
|
|
1250
|
+
<path d="M5.85 9h6.3" />
|
|
1251
|
+
<path d="M5.85 11.65h4.35" />
|
|
1252
|
+
`,emoji:`
|
|
1253
|
+
<circle cx="9" cy="9" r="6.8" />
|
|
1254
|
+
<path d="M6.2 10.55c.52 1.08 1.46 1.8 2.8 1.8s2.28-.72 2.8-1.8" />
|
|
1255
|
+
<circle cx="6.5" cy="7.15" r="0.7" fill="currentColor" stroke="none" />
|
|
1256
|
+
<circle cx="11.5" cy="7.15" r="0.7" fill="currentColor" stroke="none" />
|
|
1257
|
+
`,rate:`
|
|
1258
|
+
<path
|
|
1259
|
+
d="m9 1.95 2.08 4.21 4.65.67-3.36 3.29.8 4.63L9 12.55l-4.17 2.2.8-4.63-3.36-3.29 4.65-.67z"
|
|
1260
|
+
fill="currentColor"
|
|
1261
|
+
fill-opacity="0.12"
|
|
1262
|
+
stroke="none"
|
|
1263
|
+
/>
|
|
1264
|
+
<path
|
|
1265
|
+
d="m9 1.95 2.08 4.21 4.65.67-3.36 3.29.8 4.63L9 12.55l-4.17 2.2.8-4.63-3.36-3.29 4.65-.67z"
|
|
1266
|
+
/>
|
|
1267
|
+
`,title:`
|
|
1268
|
+
<rect
|
|
1269
|
+
x="3.35"
|
|
1270
|
+
y="3.37"
|
|
1271
|
+
width="11.3"
|
|
1272
|
+
height="1.72"
|
|
1273
|
+
rx="0.6"
|
|
1274
|
+
fill="currentColor"
|
|
1275
|
+
stroke="none"
|
|
1276
|
+
/>
|
|
1277
|
+
<rect
|
|
1278
|
+
x="7.99"
|
|
1279
|
+
y="4.6"
|
|
1280
|
+
width="2.02"
|
|
1281
|
+
height="9.45"
|
|
1282
|
+
rx="0.68"
|
|
1283
|
+
fill="currentColor"
|
|
1284
|
+
stroke="none"
|
|
1285
|
+
/>
|
|
1286
|
+
<rect
|
|
1287
|
+
x="6.75"
|
|
1288
|
+
y="13.32"
|
|
1289
|
+
width="4.5"
|
|
1290
|
+
height="0.95"
|
|
1291
|
+
rx="0.48"
|
|
1292
|
+
fill="currentColor"
|
|
1293
|
+
stroke="none"
|
|
1294
|
+
/>
|
|
1295
|
+
`,fullscreen:`
|
|
1296
|
+
<path d="M5.85 3H3v2.85" />
|
|
1297
|
+
<path d="M12.15 3H15v2.85" />
|
|
1298
|
+
<path d="M3 12.15V15h2.85" />
|
|
1299
|
+
<path d="M15 12.15V15h-2.85" />
|
|
1300
|
+
`};function J(e){return i`<svg
|
|
1301
|
+
class="compose-tool-icon"
|
|
1302
|
+
width="18"
|
|
1303
|
+
height="18"
|
|
1304
|
+
viewBox="0 0 18 18"
|
|
1305
|
+
fill="none"
|
|
1306
|
+
stroke="currentColor"
|
|
1307
|
+
stroke-linecap="round"
|
|
1308
|
+
stroke-linejoin="round"
|
|
1309
|
+
aria-hidden="true"
|
|
1310
|
+
>
|
|
1311
|
+
${v(e)}
|
|
1312
|
+
</svg>`}function zt(e){return i`<span
|
|
1313
|
+
class=${`decorative-quote-mark ${e}`}
|
|
1314
|
+
aria-hidden="true"
|
|
1315
|
+
>
|
|
1316
|
+
<svg
|
|
1317
|
+
viewBox=${_t}
|
|
1318
|
+
role="presentation"
|
|
1319
|
+
focusable="false"
|
|
1320
|
+
>
|
|
1321
|
+
${v(vt)}
|
|
1322
|
+
</svg>
|
|
1323
|
+
</span>`}function Bt(e,t){let n=e.state.doc.content.size,r=Math.max(1,Math.min(t.from,n));return{from:r,to:Math.max(r,Math.min(t.to,n))}}var Vt=class t extends c{static properties={format:{type:String},labels:{type:Object},uploadMaxFileSize:{type:Number},threadItem:{type:Boolean,attribute:`thread-item`},removable:{type:Boolean},inlineFormat:{type:Boolean,attribute:`inline-format`},titleByDefault:{type:Boolean,attribute:`title-by-default`},positionLabel:{type:String,attribute:`position-label`},badgeLabel:{type:String,attribute:`badge-label`},headerExtra:{attribute:!1},slashCommandDiscovered:{type:Boolean},_title:{state:!0},_bodyJson:{state:!0},_url:{state:!0},_quoteText:{state:!0},_quoteAuthor:{state:!0},_rating:{state:!0},_showTitle:{state:!0},_showRating:{state:!0},_attachedTexts:{state:!0},_attachments:{state:!0},_attachmentOrder:{state:!0},_failedAttachmentPreviews:{state:!0},_showAltPanel:{state:!0},_altPanelIndex:{state:!0},_showEmojiPicker:{state:!0},_showUrlValidation:{state:!0},_showLinkTitleValidation:{state:!0}};_editor=null;_fileInput=null;_lastFocusedField=null;_lastEditorSelection=null;_emojiPickerEl=null;_emojiContainer=null;_urlStatusId=`compose-url-status-${L()}`;_onDocClickBound=this._onDocumentClick.bind(this);_filePickerCleanup=null;_suppressAttachedTextOpenUntil=0;_suppressContentChangedOnce=!1;#e=!1;#t=0;#n=new Set;#r=0;#i;#a=null;#o=null;#s=null;#c;createRenderRoot(){return this}constructor(){super(),this.format=`note`,this.labels={},this.uploadMaxFileSize=1024,this.threadItem=!1,this.removable=!1,this.inlineFormat=!1,this.titleByDefault=!0,this.positionLabel=``,this.badgeLabel=``,this.headerExtra=null,this.slashCommandDiscovered=!1,this._title=``,this._bodyJson=null,this._url=``,this._quoteText=``,this._quoteAuthor=``,this._rating=0,this._showTitle=!0,this._showRating=!1,this._attachedTexts=[],this._attachments=[],this._attachmentOrder=[],this._failedAttachmentPreviews=[],this._showAltPanel=!1,this._altPanelIndex=0,this._showEmojiPicker=!1,this._showUrlValidation=!1,this._showLinkTitleValidation=!1}connectedCallback(){super.connectedCallback(),document.addEventListener(`jant:slash-image`,this._onSlashImage),document.addEventListener(`jant:slash-command-discovered`,this._onSlashCommandDiscovered),this.addEventListener(`dragenter`,this._onDragEnter),this.addEventListener(`dragover`,this._onDragOver,!0),this.addEventListener(`dragleave`,this._onDragLeave),this.addEventListener(`drop`,this._onDrop),this.#b()?.addEventListener(`change`,this._onPointerTypeChange)}disconnectedCallback(){super.disconnectedCallback(),this.#h(),this._editor?.destroy(),this._editor=null,this.#a?.destroy(),this.#a=null,document.removeEventListener(`jant:slash-image`,this._onSlashImage),document.removeEventListener(`jant:slash-command-discovered`,this._onSlashCommandDiscovered),document.removeEventListener(`click`,this._onDocClickBound),this.removeEventListener(`dragenter`,this._onDragEnter),this.removeEventListener(`dragover`,this._onDragOver,!0),this.removeEventListener(`dragleave`,this._onDragLeave),this.removeEventListener(`drop`,this._onDrop),Pt(this),this._emojiContainer?.remove(),this._emojiPickerEl=null,this._filePickerCleanup?.(),this._filePickerCleanup=null,this.#b()?.removeEventListener(`change`,this._onPointerTypeChange)}#l=0;#u(e){let t=e.dataTransfer?.types;return t?Array.from(t).includes(`Files`):!1}_onDragEnter=e=>{this.#u(e)&&(this.#l+=1,this.classList.add(`compose-editor-dragover`))};_onDragOver=e=>{this.#u(e)&&(e.stopPropagation(),e.preventDefault(),e.dataTransfer&&(e.dataTransfer.dropEffect=`copy`))};_onDragLeave=e=>{this.#u(e)&&(this.#l=Math.max(0,this.#l-1),this.#l===0&&this.classList.remove(`compose-editor-dragover`))};_onDrop=e=>{if(this.#l=0,this.classList.remove(`compose-editor-dragover`),e.defaultPrevented)return;let t=ue(e.dataTransfer);if(t.length===0)return;e.preventDefault();let n=[],r=[];for(let e of t)this._editor&&this._shouldPasteInlineImage(e)?n.push(e):r.push(e);for(let e of n)this._uploadAndInsertImage(e);r.length>0&&this.addFiles(r)};_onSlashCommandDiscovered=()=>{Lt()};_onSlashImage=()=>{document.querySelector(`.compose-fullscreen-dialog[open]`)||this._editor&&this._triggerSlashImagePicker()};_slashImageInput=null;_triggerSlashImagePicker(){this._slashImageInput||(this._slashImageInput=document.createElement(`input`),this._slashImageInput.type=`file`,this._slashImageInput.accept=`image/*`,this._slashImageInput.style.display=`none`,this._slashImageInput.addEventListener(`change`,()=>{let e=this._slashImageInput?.files?.[0];e&&this._editor&&this._uploadAndInsertImage(e),this._slashImageInput&&(this._slashImageInput.value=``)}),document.body.appendChild(this._slashImageInput)),this._trackFilePickerSession(this._slashImageInput),this._slashImageInput.click()}_uploadAndInsertImage(e){let t=this._editor;if(!t)return Promise.resolve();let n=this.#t,r=M(t,e).finally(()=>{n===this.#t&&this.#n.delete(r)});return this.#n.add(r),r}#d(e){if(e.startsWith(`data:`))return!0;if(!/^https?:\/\//i.test(e))return!1;let t;try{t=new URL(e).origin}catch{return!1}if(t===window.location.origin)return!1;let n=document.documentElement.dataset.mediaBase;return!(n&&e.startsWith(n))}#f(e){let t=this._editor;if(!t){k(e);return}let n=e.startsWith(`data:`)?async()=>{let t=await(await fetch(e)).blob(),n=new File([t],`pasted-image`,{type:t.type||`image/png`});return(await de(n)).url}:async()=>(await j(e)).url,r=async()=>{try{return await n()}catch(e){throw this.#p(),e}},i=this.#t,a=se(t,e,r).finally(()=>{k(e),i===this.#t&&this.#n.delete(a)});this.#n.add(a)}#p(){this.#r+=1,this.#i===void 0&&(this.#i=setTimeout(()=>{this.#m()},800))}#m(){this.#i=void 0;let e=this.#r;if(this.#r=0,e<=0||!this.isConnected)return;let t=e===1?this.labels.imageNotRehosted??`An image couldn't be saved to your library — its original link was kept.`:(this.labels.imagesNotRehosted??`{count} images couldn't be saved to your library — their original links were kept.`).replace(`{count}`,String(e));l(t,`error`)}hasPendingInlineImageUploads(){return this.#n.size>0}async waitForPendingInlineImageUploads(){let e=this.#t;for(;e===this.#t&&this.#n.size>0;)await Promise.allSettled(Array.from(this.#n))}#h(){this.#t+=1,this.#n.clear(),this.#i!==void 0&&(clearTimeout(this.#i),this.#i=void 0),this.#r=0}adoptPendingUploads(){if(!this._editor)return;let e=this.#t,t=fe(this._editor);for(let n of t){let t=n.finally(()=>{e===this.#t&&this.#n.delete(t)});this.#n.add(t)}}_dispatchFilePickerEvent(e,t){this.dispatchEvent(new CustomEvent(e,{bubbles:!0,composed:!0,detail:t}))}_trackFilePickerSession(e){this._filePickerCleanup?.();let t=!1,n=e=>{t||(t=!0,o(),this._dispatchFilePickerEvent(`jant:file-picker-close`,{cancelled:e}))},r=()=>n(!1),i=()=>n(!0),a=()=>{globalThis.setTimeout(()=>{n(!(e.files&&e.files.length>0))},0)},o=()=>{e.removeEventListener(`change`,r),e.removeEventListener(`cancel`,i),window.removeEventListener(`focus`,a),this._filePickerCleanup===o&&(this._filePickerCleanup=null)};this._filePickerCleanup=o,e.addEventListener(`change`,r,{once:!0}),e.addEventListener(`cancel`,i,{once:!0}),window.addEventListener(`focus`,a,{once:!0}),this._dispatchFilePickerEvent(`jant:file-picker-open`)}_isEmptyDoc(e){return!e.content||e.content.length===0||e.content.every(e=>e.type===`paragraph`&&(!e.content||e.content.length===0||e.content.every(e=>e.type===`hardBreak`)))}_normalizeDocJson(e){return e?this._isEmptyDoc(e)?null:e:null}_isSelectionInsideTopLevelBlock(e){let t=this._editor;return t?t.state.selection.$from.index(0)===e:!1}_removedTopLevelSize(e){let t=this._editor?.state.doc;if(!t)return 0;let n=0;for(let r=0;r<=e.headingIndex;r+=1)n+=t.child(r)?.nodeSize??0;return n}promoteLeadingH1Title(e={}){if(this.format!==`note`||this._title.trim())return!1;let t=gt(this._editor?.getJSON()??this._bodyJson);if(!t||!e.force&&this._isSelectionInsideTopLevelBlock(t.headingIndex))return!1;let n=this._editor,r=!!n?.isFocused,i=n?.state.selection.from??null,a=this._removedTopLevelSize(t);if(this._title=t.title,this._showTitle=!0,this._bodyJson=t.bodyJson,n&&(t.bodyJson?n.commands.setContent(t.bodyJson):n.commands.clearContent(),r&&i!==null)){let e=n.state.doc.content.size;e>0&&(n.commands.setTextSelection(Math.max(1,Math.min(i-a,e))),n.commands.focus())}return!0}getNormalizedBodyJson(){return this._normalizeDocJson(this._bodyJson)}getEffectiveAttachedTexts(){return this._attachedTexts.flatMap(e=>{let t=this._normalizeDocJson(e.bodyJson);return t?[{...e,bodyJson:t,originalBodyJson:this._normalizeDocJson(e.originalBodyJson??null)}]:[]})}getEffectiveAttachmentOrder(){let e=new Set(this.getEffectiveAttachedTexts().map(e=>e.clientId)),t=new Set(this._attachments.map(e=>e.clientId));return this._attachmentOrder.filter(n=>t.has(n)||e.has(n))}_getEffectiveRating(){return this._showRating?this._rating:0}getData(){let e=this.getNormalizedBodyJson(),t=this.getEffectiveAttachedTexts(),n=this.getEffectiveAttachmentOrder(),r=e?JSON.stringify(e):``,i={rating:this._getEffectiveRating(),attachedTexts:t,attachments:this._attachments,attachmentOrder:n};switch(this.format){case`link`:return{...i,title:this._title,body:r,url:this._url,quoteText:``,quoteAuthor:``};case`quote`:return{...i,title:``,body:r,url:this._url,quoteText:this._quoteText,quoteAuthor:this._quoteAuthor};default:return{...i,title:this._showTitle?this._title:``,body:r,url:``,quoteText:``,quoteAuthor:``}}}getStatus(){let e=this.getData(),t=!!e.body||!!e.title.trim()||!!e.url.trim()||!!e.quoteText.trim()||!!e.quoteAuthor.trim()||e.rating>0||e.attachments.length>0||e.attachedTexts.length>0,n=!this.getUrlValidationMessage()&&!this.getLinkTitleValidationMessage(),r;switch(this.format){case`link`:r=n;break;case`quote`:r=n&&!!e.quoteText.trim();break;default:r=n&&t}return{hasContent:t,publishable:r}}#g=null;#_(){let e=this.getStatus();(this.#g?.hasContent!==e.hasContent||this.#g?.publishable!==e.publishable)&&(this.#g=e,this.dispatchEvent(new CustomEvent(`jant:compose-status`,{bubbles:!0,detail:e})))}setTitleDefault(e){this.titleByDefault=e,this._showTitle=e}reset(){this.#h(),this._title=``,this._showTitle=this.titleByDefault,this._bodyJson=null,this._editor?.commands.clearContent(),this._lastEditorSelection=null,this._url=``,this._quoteText=``,this._quoteAuthor=``,this._rating=0,this._showRating=!1,this._attachedTexts=[];for(let e of this._attachments)URL.revokeObjectURL(e.previewUrl),e.posterUrl&&URL.revokeObjectURL(e.posterUrl);this._attachments=[],this._attachmentOrder=[],this._failedAttachmentPreviews=[],this._showAltPanel=!1,this._altPanelIndex=0,this._showUrlValidation=!1,this._showLinkTitleValidation=!1,this.closeEmojiPicker()}updateAttachmentStatus(e,t,n,r,i){this._attachments=this._attachments.map(a=>a.clientId===e?{...a,status:t,mediaId:n,error:r,remoteUrl:i??a.remoteUrl}:a)}updateAttachmentPreview(e,t){this._setAttachmentPreviewFailure(e,!1),this._attachments=this._attachments.map(n=>n.clientId===e?(URL.revokeObjectURL(n.previewUrl),n.posterUrl&&URL.revokeObjectURL(n.posterUrl),{...n,file:t,previewUrl:URL.createObjectURL(t),posterUrl:null}):n)}updateAttachmentPoster(e,t){let n=URL.createObjectURL(t);this._attachments=this._attachments.map(t=>t.clientId===e?{...t,posterUrl:n}:t)}updateAttachmentProgress(e,t){this._attachments=this._attachments.map(n=>n.clientId===e?{...n,progress:t}:n)}focusInput(e){if(this.format===`link`){this.focusUrlInput(e);return}if(this.format===`quote`){this._focusTextControl(this.querySelector(`.compose-quote-text`),e);return}if(e){this._editor?.commands.focus(e);return}this._editor?.commands.focus()}focusSelection(e){if(this.format!==`note`||!this._editor){this.focusInput();return}let t=e??this.getEditorSelection();if(!t){this.focusInput();return}let n=Bt(this._editor,t);this._lastEditorSelection=n,this._editor.chain().focus().setTextSelection(n).run()}focusUrlInput(e){this._focusTextControl(this.querySelector(`.compose-url-input`),e)}focusLinkTitleInput(e){this._focusTextControl(this.querySelector(`.compose-link-title`),e)}getUrlValidationMessage(){return this.format===`note`?null:this._url.trim()?e(this._url)?null:this.labels.urlInvalid:this.format===`link`?this.labels.linkUrlRequired:null}getLinkTitleValidationMessage(){return this.format===`link`?this._title.trim()?null:this.labels.linkTitleRequired:null}revealUrlValidation(){return this._showUrlValidation=!0,this.getUrlValidationMessage()}revealLinkTitleValidation(){return this._showLinkTitleValidation=!0,this.getLinkTitleValidationMessage()}getEditorSelection(){return this._readEditorSelection()??this._lastEditorSelection}isEmojiPickerOpen(){return this._showEmojiPicker}_readEditorSelection(){if(!this._editor)return null;let{from:e,to:t}=this._editor.state.selection;return{from:e,to:t}}_focusTextControl(e,t){if(!e||(e.focus(),!t))return;let n=t===`end`?e.value.length:0;e.setSelectionRange(n,n)}_initEditor(){let e=this.querySelector(`.compose-tiptap-body`);e&&!this._editor&&(this.dataset.slashCommandDiscovered=this.slashCommandDiscovered?`true`:`false`,this._editor=le({element:e,placeholder:this.format===`note`?this.labels.bodyPlaceholder:this.labels.thoughtsPlaceholder,content:this._bodyJson,toolbarMode:`compose`,onUpdate:e=>{this._bodyJson=e,this.promoteLeadingH1Title(),Pt(this)},onFocus:()=>{this._lastFocusedField=null,this._editor?.isEmpty&&It(this)},onBlur:()=>{this.promoteLeadingH1Title({force:!0})},onSelectionUpdate:e=>{this._lastEditorSelection=e},pasteMedia:{shouldInsertInline:e=>this._shouldPasteInlineImage(e),uploadInlineImage:e=>this._uploadAndInsertImage(e),onPasteFiles:e=>{this.addFiles(e)}},rehostImages:{shouldRehost:e=>this.#d(e),rehost:e=>this.#f(e)},imageNodeLabels:Rt(this.labels),tableControlLabels:this.labels.tableControls}),this._lastEditorSelection=this._readEditorSelection(),this.adoptPendingUploads())}_destroyEditor(){this.#h(),this._editor?.destroy(),this._editor=null}static _CONTENT_PROPS=new Set([`_title`,`_bodyJson`,`_url`,`_quoteText`,`_quoteAuthor`,`_rating`,`_showTitle`,`_showRating`,`_attachedTexts`,`_attachmentOrder`]);willUpdate(e){super.willUpdate(e),!this.hasUpdated&&!this.#e&&(this._showTitle=this.titleByDefault)}updated(e){if(super.updated(e),this._editor||this._initEditor(),e.has(`format`)&&e.get(`format`)!==void 0&&(this._showUrlValidation&&=!1,this._showLinkTitleValidation&&=!1,this._destroyEditor(),this.updateComplete.then(()=>this._initEditor())),(e.has(`_attachmentOrder`)||e.has(`_attachments`)||e.has(`_attachedTexts`))&&(e.has(`_attachments`)&&this._syncFailedAttachmentPreviews(),this._attachmentOrder.length>1?this.#x():(this.#a?.destroy(),this.#a=null),this.#v()),this.#_(),this._suppressContentChangedOnce)this._suppressContentChangedOnce=!1;else for(let n of e.keys())if(t._CONTENT_PROPS.has(n)){this.dispatchEvent(new Event(`jant:compose-content-changed`,{bubbles:!0}));break}}getEditorState(){return{json:this._editor?.getJSON()??this._bodyJson,title:this._title,showTitle:this._showTitle,selection:this.getEditorSelection()}}getConvertibleFields(){return{title:this._title,url:this._url,quoteText:this._quoteText,quoteAuthor:this._quoteAuthor,showTitle:this._showTitle,bodyJson:this._normalizeDocJson(this._editor?.getJSON()??this._bodyJson)}}applyConvertedFields(e){this._suppressContentChangedOnce=!0,this._title=e.title,this._url=e.url,this._quoteText=e.quoteText,this._quoteAuthor=e.quoteAuthor,this._showTitle=e.showTitle,this._bodyJson=e.bodyJson}takeOver(e){this._title=e._title,this._showTitle=e._showTitle,this.#e=!0,this._bodyJson=e._editor?.getJSON()??e._bodyJson,this._url=e._url,this._quoteText=e._quoteText,this._quoteAuthor=e._quoteAuthor,this._rating=e._rating,this._showRating=e._showRating,this._attachedTexts=[...e._attachedTexts],this._attachments=[...e._attachments],this._attachmentOrder=[...e._attachmentOrder],this._lastEditorSelection=e.getEditorSelection(),this._editor&&(this._editor.commands.setContent(this._bodyJson??{type:`doc`,content:[{type:`paragraph`}]}),this.adoptPendingUploads()),this.#_()}hasAttachment(e){return this._attachments.some(t=>t.clientId===e)}populate(e){if(e.title&&(this._title=e.title),e.url&&(this._url=e.url),e.quoteText&&(this._quoteText=e.quoteText),e.quoteAuthor&&(this._quoteAuthor=e.quoteAuthor),e.rating&&e.rating>0&&(this._rating=e.rating,this._showRating=!0),e.showTitle===void 0?e.title&&e.format===`note`&&(this._showTitle=!0):this._showTitle=e.showTitle,e.showRating!==void 0&&(this._showRating=e.showRating),this._failedAttachmentPreviews=[],e.bodyJson)try{let t=JSON.parse(e.bodyJson);this._bodyJson=t,this._editor&&this._editor.commands.setContent(t)}catch{}if(e.media?.length){let t=e.media.map(e=>({clientId:e.clientId??L(),file:new File([],e.originalName??`existing`,{type:e.mimeType}),previewUrl:e.previewUrl,posterUrl:e.posterUrl??null,status:`done`,progress:null,mediaId:e.id,remoteUrl:e.previewUrl,alt:e.alt??``,error:null,summary:e.summary??null,chars:e.chars??null}));this._attachments=t,this._attachmentOrder=t.map(e=>e.clientId)}if(e.textAttachments?.length){let t=e.textAttachments.map(e=>{let t=null;try{t=JSON.parse(e.bodyJson)}catch{}return{clientId:e.clientId??L(),bodyJson:t,bodyHtml:e.bodyHtml??``,summary:e.summary,mediaId:e.mediaId,originalBodyJson:t}});this._attachedTexts=t,this._attachmentOrder=[...this._attachmentOrder,...t.map(e=>e.clientId)]}if(e.attachmentOrder?.length){let t=e.attachmentOrder.map(e=>this._attachments.find(t=>t.mediaId===e||t.clientId===e)?.clientId||this._attachedTexts.find(t=>t.mediaId===e||t.clientId===e)?.clientId).filter(e=>e!==void 0),n=this._attachmentOrder.filter(e=>!t.includes(e));this._attachmentOrder=[...t,...n]}this._showUrlValidation=!1,this._showLinkTitleValidation=!1,this.#_()}setEditorState(e,t,n,r){this._bodyJson=e,this._title=t,this.format===`note`&&(this._showTitle=n||t.length>0),this._editor&&this._editor.commands.setContent(e??{type:`doc`,content:[{type:`paragraph`}]}),this._lastEditorSelection=r??this._readEditorSelection(),this.#_()}static SUMMARY_LENGTH=100;_computeSummary(e){let n=e.replace(/\s+/g,` `).trim();return n.length<=t.SUMMARY_LENGTH?n:n.slice(0,t.SUMMARY_LENGTH)+`…`}_openAttachedText(){let e={clientId:L(),bodyJson:null,bodyHtml:``,summary:``};this._attachedTexts=[...this._attachedTexts,e],this._attachmentOrder=[...this._attachmentOrder,e.clientId];let t=this._attachedTexts.length-1;this.dispatchEvent(new CustomEvent(`jant:attached-panel-open`,{bubbles:!0,detail:{index:t}}))}_moveAttachment(e,t,n=`handle`){let r=this._attachmentOrder.indexOf(e),i=r+t;if(r===-1||i<0||i>=this._attachmentOrder.length)return;let a=[...this._attachmentOrder],[o]=a.splice(r,1);o&&(a.splice(i,0,o),this._attachmentOrder=a,this.#s={clientId:e,direction:t,focusTarget:n},this.#S(e))}#v(){let e=this.#s;if(!e)return;this.#s=null;let t=this.querySelector(`[data-attachment-id="${e.clientId}"]`);if(t){if(e.focusTarget===`handle`){t.querySelector(`[data-attachment-sortable]`)?.focus({preventScroll:!0});return}(this.#y(t,e.direction)??this.#y(t,e.direction===1?-1:1))?.focus({preventScroll:!0})}}#y(e,t){let n=e.querySelector(`[data-attachment-move="${t===-1?`earlier`:`later`}"]`);return n&&!n.disabled?n:null}_handleAttachmentKeydown(e,t,n){if(t.key===`ArrowLeft`||t.key===`ArrowUp`){t.preventDefault(),this._moveAttachment(e,-1);return}if(t.key===`ArrowRight`||t.key===`ArrowDown`){t.preventDefault(),this._moveAttachment(e,1);return}n&&(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),n())}#b(){return this.#c===void 0&&(this.#c=typeof window.matchMedia==`function`?window.matchMedia(`(pointer: coarse)`):null),this.#c}_onPointerTypeChange=()=>{this.#a?.destroy(),this.#a=null,this.#x()};#x(){let e=this.querySelector(`[data-attachment-list]`);!e||this.#a||this._attachmentOrder.length<=1||this.#b()?.matches||(this.#a=ne.create(e,{...te,chosenClass:`compose-attachment-chosen`,delay:250,direction:`horizontal`,dragClass:`compose-attachment-drag`,filter:`button, a, input, textarea, select, option, [contenteditable='true']`,ghostClass:`compose-attachment-ghost`,handle:`[data-attachment-sortable]`,preventOnFilter:!1,scroll:e,onChoose:()=>{E(e,!0)},onStart:e=>{this.#o=O(e)},onUnchoose:()=>{E(e,!1)},onEnd:t=>{let n=D(e,`[data-attachment-id]`,`attachmentId`);if(w(e,t,this.#o),this.#o=null,E(e,!1),this.#a?.destroy(),this.#a=null,n.length===this._attachmentOrder.length){this._attachmentOrder=n;let{movedId:e}=T(n,t.newIndex);e&&(this._suppressAttachedTextOpenUntil=Date.now()+250,this.#S(e))}}}))}#S(e){this.updateComplete.then(()=>{this.querySelector(`[data-attachment-id="${e}"]`)?.scrollIntoView({behavior:`smooth`,block:`nearest`,inline:`nearest`})})}_maybeEditAttachedText(e){Date.now()<this._suppressAttachedTextOpenUntil||this._editAttachedText(e)}_editAttachedText(e){this.dispatchEvent(new CustomEvent(`jant:attached-panel-open`,{bubbles:!0,detail:{index:e}}))}_removeAttachedText(e){let t=this._attachedTexts[e];this._attachedTexts=this._attachedTexts.filter((t,n)=>n!==e),t&&(this._attachmentOrder=this._attachmentOrder.filter(e=>e!==t.clientId))}updateAttachedText(e,t,n){let r=this._normalizeDocJson(t),i=this._extractPlainText(r);this._attachedTexts=this._attachedTexts.map((t,a)=>a===e?{...t,bodyJson:r,bodyHtml:r?n??``:``,summary:this._computeSummary(i)}:t)}closeAttachedPanel(e){let t=this._attachedTexts[e];t&&(t.mediaId||this._hasAttachedTextContent(t.bodyJson)||(this._attachedTexts=this._attachedTexts.filter((t,n)=>n!==e),this._attachmentOrder=this._attachmentOrder.filter(e=>e!==t.clientId)))}_hasAttachedTextContent(e){let t=this._normalizeDocJson(e);return t?this._extractPlainText(t).trim().length>0:!1}_extractPlainText(e){if(!e)return``;let t=``,n=e=>{e.text&&(t+=e.text),e.content&&e.content.forEach(n)};return n(e),t}_onInput(e,t){let n=t.target;this[e]=n.value,n.tagName===`TEXTAREA`&&this._autoResize(n)}_autoResize(e){e.style.height=`auto`,e.style.height=`${e.scrollHeight}px`}#C=null;#w=null;_recordBodyPress=e=>{this.#C=e.target,this.#w=null};_recordBodyRelease=e=>{this.#w=e.target};_focusBodyFromBlankSpace=e=>{let t=this.#C,n=this.#w;if(this.#C=null,this.#w=null,t!==e.target||n!==e.target)return;let r=e.target;r&&(r.classList.contains(`compose-body`)||r.classList.contains(`compose-field-enter`)||r.classList.contains(`compose-tiptap-wrap`))&&this._editor?.commands.focus(`end`)};_setRating(e){this._rating=this._rating===e?0:e}_shouldPasteInlineImage(e){return!e.type.startsWith(`image/`)||this.format!==`note`||!this._showTitle?!1:this._title.trim().length>0}_openFilePicker(){this._fileInput||(this._fileInput=document.createElement(`input`),this._fileInput.type=`file`,this._fileInput.multiple=!0,this._fileInput.style.display=`none`,this._fileInput.addEventListener(`change`,()=>this._handleFilesSelected()),this.appendChild(this._fileInput)),this._fileInput.value=``,this._trackFilePickerSession(this._fileInput),this._fileInput.click()}_handleFilesSelected(){let e=this._fileInput?.files;e&&e.length!==0&&this.addFiles(e)}addFiles(e){let t=Array.from(e);if(t.length===0)return;let n=[],r=[];for(let e of t){let t=Ye(e,{maxFileSizeMB:this.uploadMaxFileSize});if(t){l(t,`error`);continue}let i=L(),a=URL.createObjectURL(e);n.push({clientId:i,file:e,previewUrl:a,posterUrl:null,status:`pending`,progress:null,mediaId:null,remoteUrl:null,alt:``,error:null,summary:null,chars:null}),r.push({file:e,clientId:i})}if(n.length!==0){this._attachments=[...this._attachments,...n],this._attachmentOrder=[...this._attachmentOrder,...n.map(e=>e.clientId)];for(let e of n)F(e.file.type)===`text`&&e.file.text().then(t=>{let n=this._computeSummary(t),r=t.length;this._attachments=this._attachments.map(t=>t.clientId===e.clientId?{...t,summary:n,chars:r}:t)});this.dispatchEvent(new CustomEvent(`jant:files-selected`,{bubbles:!0,detail:{files:r}}))}}removeAttachment(e){let t=this._attachments.findIndex(t=>t.clientId===e);t!==-1&&this._removeAttachment(t)}_removeAttachment(e){let t=this._attachments[e];t&&(this._setAttachmentPreviewFailure(t.clientId,!1),URL.revokeObjectURL(t.previewUrl),t.posterUrl&&URL.revokeObjectURL(t.posterUrl),this.dispatchEvent(new CustomEvent(`jant:attachment-removed`,{bubbles:!0,detail:{clientId:t.clientId,mediaId:t.mediaId}}))),t&&(this._attachmentOrder=this._attachmentOrder.filter(e=>e!==t.clientId)),this._attachments=this._attachments.filter((t,n)=>n!==e),this._showAltPanel&&this._altPanelIndex===e?(this._showAltPanel=!1,this.dispatchEvent(new CustomEvent(`jant:alt-panel-close`,{bubbles:!0}))):this._showAltPanel&&this._altPanelIndex>e&&--this._altPanelIndex}_retryAllFailed(){let e=this._attachments.filter(e=>e.status===`error`);e.length!==0&&(this._attachments=this._attachments.map(e=>e.status===`error`?{...e,status:`pending`,progress:null,error:null}:e),this.dispatchEvent(new CustomEvent(`jant:files-selected`,{bubbles:!0,detail:{files:e.map(e=>({file:e.file,clientId:e.clientId}))}})))}_openAltPanel(e){this._altPanelIndex=e,this._showAltPanel=!0,this.dispatchEvent(new CustomEvent(`jant:alt-panel-open`,{bubbles:!0,detail:{index:e}}))}updateAlt(e,t){this._attachments=this._attachments.map((n,r)=>r===e?{...n,alt:t}:n)}_onFieldFocus(e){let t=e.target;this._lastFocusedField=t}_handleTitleKeydown(e){e.isComposing||e.keyCode===229||e.key!==`Enter`||e.metaKey||e.ctrlKey||e.altKey||(e.preventDefault(),this._editor?.commands.focus(`start`))}_toggleEmojiPicker(){this._showEmojiPicker?this.closeEmojiPicker():(this._showEmojiPicker=!0,this._mountEmojiPicker(),globalThis.setTimeout(()=>{document.addEventListener(`click`,this._onDocClickBound)},0))}closeEmojiPicker(e){if(!this._showEmojiPicker){e?.restoreFocus&&this._restoreEmojiFocus();return}this._showEmojiPicker=!1,this._emojiContainer?.remove(),this._emojiPickerEl=null,document.removeEventListener(`click`,this._onDocClickBound),e?.restoreFocus&&this._restoreEmojiFocus()}_restoreEmojiFocus(){let e=this._lastFocusedField;if(e&&this.contains(e)&&!e.disabled){e.focus();return}this.focusSelection()}_onDocumentClick(e){let t=e.target;this.querySelector(`.compose-emoji-btn`)?.contains(t)||this._emojiContainer?.contains(t)||this.closeEmojiPicker()}async _mountEmojiPicker(){let e=this.closest(`dialog`);if(this._emojiContainer||(this._emojiContainer=document.createElement(`div`),this._emojiContainer.className=`compose-emoji-picker`),(e??document.body).appendChild(this._emojiContainer),!this._emojiPickerEl){let[{default:e},{Picker:t}]=await Promise.all([y(()=>import(`./chunks/emoji-mart-C4RpRKcU.js`).then(e=>e.n),__vite__mapDeps([0,1])),y(()=>import(`./chunks/emoji-mart-C4RpRKcU.js`).then(e=>e.t),__vite__mapDeps([0,1]))]);if(!this._showEmojiPicker)return;let n=new t({data:e,onEmojiSelect:e=>{this._insertEmoji(e.native),this.closeEmojiPicker()},theme:`auto`,previewPosition:`none`,skinTonePosition:`none`});this._emojiPickerEl=n}this._emojiContainer.innerHTML=``,this._emojiContainer.appendChild(this._emojiPickerEl);let t=this.querySelector(`.compose-emoji-btn`);if(t&&e){let n=t.getBoundingClientRect(),r=e.getBoundingClientRect(),i=n.left-r.left,a=n.top-r.top,o=i+n.width/2-176;o=Math.max(-r.left+8,Math.min(o,r.width-8));let s=a-435-8;r.top+s<8&&(s=a+n.height+8),this._emojiContainer.style.left=`${o}px`,this._emojiContainer.style.top=`${s}px`}}_insertEmoji(e){let t=this._lastFocusedField;if(!t){this._editor&&this._editor.chain().focus().insertContent(e).run();return}let n=t.selectionStart??t.value.length,r=t.selectionEnd??n,i=t.value.slice(0,n),a=t.value.slice(r);t.value=i+e+a,t.dispatchEvent(new Event(`input`,{bubbles:!0}));let o=n+e.length;globalThis.requestAnimationFrame(()=>{t.focus(),t.setSelectionRange(o,o)})}_getCategory(e){return F(e.file.type)}_formatSize(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}_formatChars(e){return e<1e3?`${e} chars`:e<1e6?`${parseFloat((e/1e3).toFixed(1))}k chars`:`${parseFloat((e/1e6).toFixed(1))}M chars`}_renderFileIcon(e,t){let n;return n=e===`application/pdf`?`<text x="12" y="16.5" text-anchor="middle" fill="currentColor" stroke="none" font-size="6" font-weight="700" font-family="system-ui, sans-serif">PDF</text>`:e===`text/markdown`?`<text x="12" y="16.5" text-anchor="middle" fill="currentColor" stroke="none" font-size="10" font-weight="700" font-family="system-ui, sans-serif">#</text>`:e===`text/csv`?`<line x1="8" y1="12" x2="16" y2="12"/><line x1="8" y1="15" x2="16" y2="15"/><line x1="8" y1="18" x2="16" y2="18"/><line x1="10.7" y1="12" x2="10.7" y2="18"/><line x1="13.3" y1="12" x2="13.3" y2="18"/>`:F(e)===`archive`?`<line x1="12" y1="10" x2="12" y2="11.5"/><line x1="12" y1="13" x2="12" y2="14.5"/><line x1="12" y1="16" x2="12" y2="17.5"/>`:e===`text/html; charset=utf-8`?`<line x1="16" y1="11" x2="8" y2="11"/><line x1="16" y1="14" x2="8" y2="14"/><line x1="12" y1="17" x2="8" y2="17"/>`:`<line x1="16" y1="13" x2="8" y2="13"/><line x1="16" y1="17" x2="8" y2="17"/><line x1="10" y1="9" x2="8" y2="9"/>`,i`<svg
|
|
1324
|
+
width="${t}"
|
|
1325
|
+
height="${t}"
|
|
1326
|
+
viewBox="0 0 24 24"
|
|
1327
|
+
fill="none"
|
|
1328
|
+
stroke="currentColor"
|
|
1329
|
+
stroke-width="1.5"
|
|
1330
|
+
stroke-linecap="round"
|
|
1331
|
+
stroke-linejoin="round"
|
|
1332
|
+
>
|
|
1333
|
+
${v(`<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/>`+n)}
|
|
1334
|
+
</svg>`}_hasFailedAttachmentPreview(e){return this._failedAttachmentPreviews.includes(e)}_setAttachmentPreviewFailure(e,t){t!==this._failedAttachmentPreviews.includes(e)&&(this._failedAttachmentPreviews=t?[...this._failedAttachmentPreviews,e]:this._failedAttachmentPreviews.filter(t=>t!==e))}_syncFailedAttachmentPreviews(){let e=new Set(this._attachments.map(e=>e.clientId)),t=this._failedAttachmentPreviews.filter(t=>e.has(t));t.length!==this._failedAttachmentPreviews.length&&(this._failedAttachmentPreviews=t)}_renderAttachmentPreviewFallback(e){let t=this.labels.brokenImageUnavailable??`Image unavailable`;return i`
|
|
1335
|
+
<div
|
|
1336
|
+
class="compose-attachment-preview-fallback"
|
|
1337
|
+
data-preview-failed=${e}
|
|
1338
|
+
aria-label=${t}
|
|
1339
|
+
>
|
|
1340
|
+
<svg
|
|
1341
|
+
width="28"
|
|
1342
|
+
height="28"
|
|
1343
|
+
viewBox="0 0 24 24"
|
|
1344
|
+
fill="none"
|
|
1345
|
+
stroke="currentColor"
|
|
1346
|
+
stroke-width="1.5"
|
|
1347
|
+
stroke-linecap="round"
|
|
1348
|
+
stroke-linejoin="round"
|
|
1349
|
+
>
|
|
1350
|
+
<rect x="3.5" y="5" width="17" height="14" rx="2.5" />
|
|
1351
|
+
<circle cx="9" cy="10" r="1.25" />
|
|
1352
|
+
<path d="m7 16 3.4-3.45 2.65 2.45 2.45-3.05 1.95 2.5" />
|
|
1353
|
+
</svg>
|
|
1354
|
+
<span class="compose-attachment-preview-fallback-label">
|
|
1355
|
+
${t}
|
|
1356
|
+
</span>
|
|
1357
|
+
${e===`video`?i`
|
|
1358
|
+
<div class="compose-attachment-play-icon">
|
|
1359
|
+
<svg width="24" height="24" viewBox="0 0 24 24" fill="white">
|
|
1360
|
+
<path d="M8 5v14l11-7z" />
|
|
1361
|
+
</svg>
|
|
1362
|
+
</div>
|
|
1363
|
+
`:o}
|
|
1364
|
+
</div>
|
|
1365
|
+
`}_renderNoteFields(){return i`
|
|
1366
|
+
<div class="compose-field-enter">
|
|
1367
|
+
${this._showTitle?i`<input
|
|
1368
|
+
type="text"
|
|
1369
|
+
.value=${this._title}
|
|
1370
|
+
@input=${e=>this._onInput(`_title`,e)}
|
|
1371
|
+
@focus=${e=>this._onFieldFocus(e)}
|
|
1372
|
+
@keydown=${this._handleTitleKeydown}
|
|
1373
|
+
class="compose-input compose-note-title"
|
|
1374
|
+
placeholder=${this.labels.titlePlaceholder}
|
|
1375
|
+
/>`:o}
|
|
1376
|
+
<div class="compose-tiptap-wrap">
|
|
1377
|
+
<div class="compose-tiptap-body"></div>
|
|
1378
|
+
<span class="compose-slash-discovery-hint" aria-hidden="true">
|
|
1379
|
+
${this.labels.slashHint}
|
|
1380
|
+
</span>
|
|
1381
|
+
</div>
|
|
1382
|
+
</div>
|
|
1383
|
+
`}_renderLinkFields(){let e=this._showUrlValidation?this.getUrlValidationMessage():null,t=this._showLinkTitleValidation?this.getLinkTitleValidationMessage():null;return i`
|
|
1384
|
+
<div class="compose-field-enter">
|
|
1385
|
+
<div
|
|
1386
|
+
class=${b({"compose-link-url-wrap":!0,"compose-link-url-wrap-invalid":!!e})}
|
|
1387
|
+
>
|
|
1388
|
+
<span class="text-base opacity-50 shrink-0">🔗</span>
|
|
1389
|
+
<input
|
|
1390
|
+
type="url"
|
|
1391
|
+
.value=${this._url}
|
|
1392
|
+
@input=${e=>this._onInput(`_url`,e)}
|
|
1393
|
+
@focus=${e=>this._onFieldFocus(e)}
|
|
1394
|
+
@blur=${()=>{this._url.trim()&&(this._showUrlValidation=!0)}}
|
|
1395
|
+
class="compose-input compose-url-input"
|
|
1396
|
+
placeholder=${this.labels.urlPlaceholder}
|
|
1397
|
+
aria-invalid=${e?`true`:`false`}
|
|
1398
|
+
aria-describedby=${P(e?this._urlStatusId:void 0)}
|
|
1399
|
+
/>
|
|
1400
|
+
</div>
|
|
1401
|
+
${e?i`<p
|
|
1402
|
+
id=${this._urlStatusId}
|
|
1403
|
+
class="compose-url-status compose-url-status-error"
|
|
1404
|
+
data-compose-url-status="error"
|
|
1405
|
+
>
|
|
1406
|
+
${e}
|
|
1407
|
+
</p>`:o}
|
|
1408
|
+
<input
|
|
1409
|
+
type="text"
|
|
1410
|
+
.value=${this._title}
|
|
1411
|
+
@input=${e=>this._onInput(`_title`,e)}
|
|
1412
|
+
@focus=${e=>this._onFieldFocus(e)}
|
|
1413
|
+
@keydown=${this._handleTitleKeydown}
|
|
1414
|
+
@blur=${()=>{this._title.trim()&&(this._showLinkTitleValidation=!0)}}
|
|
1415
|
+
class="compose-input compose-link-title"
|
|
1416
|
+
placeholder=${this.labels.linkTitlePlaceholder}
|
|
1417
|
+
aria-invalid=${t?`true`:`false`}
|
|
1418
|
+
/>
|
|
1419
|
+
${t?i`<p
|
|
1420
|
+
class="compose-url-status compose-url-status-error"
|
|
1421
|
+
data-compose-link-title-error="error"
|
|
1422
|
+
>
|
|
1423
|
+
${t}
|
|
1424
|
+
</p>`:o}
|
|
1425
|
+
<div class="compose-divider"></div>
|
|
1426
|
+
<div class="compose-tiptap-wrap">
|
|
1427
|
+
<div class="compose-tiptap-body compose-tiptap-link"></div>
|
|
1428
|
+
<span class="compose-slash-discovery-hint" aria-hidden="true">
|
|
1429
|
+
${this.labels.slashHint}
|
|
1430
|
+
</span>
|
|
1431
|
+
</div>
|
|
1432
|
+
</div>
|
|
1433
|
+
`}_renderQuoteFields(){let e=this._showUrlValidation?this.getUrlValidationMessage():null;return i`
|
|
1434
|
+
<div class="compose-field-enter">
|
|
1435
|
+
<div class="compose-quote-wrap">
|
|
1436
|
+
${zt(`compose-quote-mark`)}
|
|
1437
|
+
<textarea
|
|
1438
|
+
.value=${this._quoteText}
|
|
1439
|
+
@input=${e=>this._onInput(`_quoteText`,e)}
|
|
1440
|
+
@focus=${e=>this._onFieldFocus(e)}
|
|
1441
|
+
class="compose-input compose-quote-text"
|
|
1442
|
+
placeholder=${this.labels.quotePlaceholder}
|
|
1443
|
+
rows="4"
|
|
1444
|
+
></textarea>
|
|
1445
|
+
</div>
|
|
1446
|
+
<div class="compose-quote-author-row">
|
|
1447
|
+
<span class="compose-quote-dash" aria-hidden="true">—</span>
|
|
1448
|
+
<input
|
|
1449
|
+
type="text"
|
|
1450
|
+
.value=${this._quoteAuthor}
|
|
1451
|
+
@input=${e=>this._onInput(`_quoteAuthor`,e)}
|
|
1452
|
+
@focus=${e=>this._onFieldFocus(e)}
|
|
1453
|
+
class="compose-input compose-quote-author"
|
|
1454
|
+
placeholder=${this.labels.authorPlaceholder}
|
|
1455
|
+
/>
|
|
1456
|
+
</div>
|
|
1457
|
+
<div class="compose-quote-source">
|
|
1458
|
+
<input
|
|
1459
|
+
type="url"
|
|
1460
|
+
.value=${this._url}
|
|
1461
|
+
@input=${e=>this._onInput(`_url`,e)}
|
|
1462
|
+
@focus=${e=>this._onFieldFocus(e)}
|
|
1463
|
+
@blur=${()=>{this._showUrlValidation=!0}}
|
|
1464
|
+
class="compose-input compose-url-input compose-quote-source-input"
|
|
1465
|
+
placeholder=${this.labels.sourcePlaceholder}
|
|
1466
|
+
aria-invalid=${e?`true`:`false`}
|
|
1467
|
+
aria-describedby=${P(e?this._urlStatusId:void 0)}
|
|
1468
|
+
/>
|
|
1469
|
+
${e?i`<p
|
|
1470
|
+
id=${this._urlStatusId}
|
|
1471
|
+
class="compose-url-status compose-url-status-error"
|
|
1472
|
+
data-compose-url-status="error"
|
|
1473
|
+
>
|
|
1474
|
+
${e}
|
|
1475
|
+
</p>`:o}
|
|
1476
|
+
</div>
|
|
1477
|
+
<div
|
|
1478
|
+
class="compose-divider compose-divider-quote"
|
|
1479
|
+
aria-hidden="true"
|
|
1480
|
+
></div>
|
|
1481
|
+
<div class="compose-tiptap-wrap">
|
|
1482
|
+
<div class="compose-tiptap-body"></div>
|
|
1483
|
+
<span class="compose-slash-discovery-hint" aria-hidden="true">
|
|
1484
|
+
${this.labels.slashHint}
|
|
1485
|
+
</span>
|
|
1486
|
+
</div>
|
|
1487
|
+
</div>
|
|
1488
|
+
`}_renderStarRating(){return this._showRating?i`
|
|
1489
|
+
<div class="compose-star-rating">
|
|
1490
|
+
${[1,2,3,4,5].map(e=>i`
|
|
1491
|
+
<button
|
|
1492
|
+
type="button"
|
|
1493
|
+
class=${b({"compose-star":!0,"compose-star-filled":this._rating>=e})}
|
|
1494
|
+
@click=${()=>this._setRating(e)}
|
|
1495
|
+
>
|
|
1496
|
+
★
|
|
1497
|
+
</button>
|
|
1498
|
+
`)}
|
|
1499
|
+
${this._rating>0?i`<span class="compose-star-label">${this._rating}/5</span>`:o}
|
|
1500
|
+
</div>
|
|
1501
|
+
`:o}_renderAttachmentPreview(e){let t=this._getCategory(e);return t===`video`?i`
|
|
1502
|
+
<div class="compose-attachment-thumb">
|
|
1503
|
+
<video
|
|
1504
|
+
src=${e.previewUrl}
|
|
1505
|
+
class="compose-attachment-img"
|
|
1506
|
+
preload="metadata"
|
|
1507
|
+
muted
|
|
1508
|
+
></video>
|
|
1509
|
+
<div class="compose-attachment-play-icon">
|
|
1510
|
+
<svg width="24" height="24" viewBox="0 0 24 24" fill="white">
|
|
1511
|
+
<path d="M8 5v14l11-7z" />
|
|
1512
|
+
</svg>
|
|
1513
|
+
</div>
|
|
1514
|
+
</div>
|
|
1515
|
+
`:t===`audio`?i`
|
|
1516
|
+
<div class="compose-attachment-file-card">
|
|
1517
|
+
<div class="compose-attachment-file-icon">
|
|
1518
|
+
<svg
|
|
1519
|
+
width="20"
|
|
1520
|
+
height="20"
|
|
1521
|
+
viewBox="0 0 24 24"
|
|
1522
|
+
fill="none"
|
|
1523
|
+
stroke="currentColor"
|
|
1524
|
+
stroke-width="1.5"
|
|
1525
|
+
stroke-linecap="round"
|
|
1526
|
+
stroke-linejoin="round"
|
|
1527
|
+
>
|
|
1528
|
+
<path d="M9 18V5l12-2v13" />
|
|
1529
|
+
<circle cx="6" cy="18" r="3" />
|
|
1530
|
+
<circle cx="18" cy="16" r="3" />
|
|
1531
|
+
</svg>
|
|
1532
|
+
</div>
|
|
1533
|
+
<span class="compose-attachment-file-name">${e.file.name}</span>
|
|
1534
|
+
<span class="compose-attachment-file-size"
|
|
1535
|
+
>${this._formatSize(e.file.size)}</span
|
|
1536
|
+
>
|
|
1537
|
+
</div>
|
|
1538
|
+
`:t===`document`?i`
|
|
1539
|
+
<div class="compose-attachment-file-card">
|
|
1540
|
+
<div class="compose-attachment-file-icon">
|
|
1541
|
+
${this._renderFileIcon(e.file.type,20)}
|
|
1542
|
+
</div>
|
|
1543
|
+
<span class="compose-attachment-file-name">${e.file.name}</span>
|
|
1544
|
+
<span class="compose-attachment-file-size"
|
|
1545
|
+
>${this._formatSize(e.file.size)}</span
|
|
1546
|
+
>
|
|
1547
|
+
</div>
|
|
1548
|
+
`:t===`text`?i`
|
|
1549
|
+
<div class="compose-attachment-file-card">
|
|
1550
|
+
<div class="compose-attachment-file-icon">
|
|
1551
|
+
${this._renderFileIcon(e.file.type,20)}
|
|
1552
|
+
</div>
|
|
1553
|
+
<span class="compose-attachment-file-name">${e.file.name}</span>
|
|
1554
|
+
${e.summary?i`<span class="compose-attachment-text-summary"
|
|
1555
|
+
>${e.summary}</span
|
|
1556
|
+
>`:o}
|
|
1557
|
+
${typeof e.chars==`number`&&e.chars>0?i`<span class="compose-attachment-file-size"
|
|
1558
|
+
>${this._formatChars(e.chars)}</span
|
|
1559
|
+
>`:o}
|
|
1560
|
+
</div>
|
|
1561
|
+
`:t===`image`?i`
|
|
1562
|
+
<div class="compose-attachment-thumb">
|
|
1563
|
+
<img src=${e.previewUrl} alt="" class="compose-attachment-img" />
|
|
1564
|
+
</div>
|
|
1565
|
+
`:i`
|
|
1566
|
+
<div class="compose-attachment-file-card">
|
|
1567
|
+
<div class="compose-attachment-file-icon">
|
|
1568
|
+
${this._renderFileIcon(e.file.type,20)}
|
|
1569
|
+
</div>
|
|
1570
|
+
<span class="compose-attachment-file-name">${e.file.name}</span>
|
|
1571
|
+
<span class="compose-attachment-file-size"
|
|
1572
|
+
>${this._formatSize(e.file.size)}</span
|
|
1573
|
+
>
|
|
1574
|
+
</div>
|
|
1575
|
+
`}_renderAttachmentOverlay(e,t){return i`
|
|
1576
|
+
${e.status===`error`?i`
|
|
1577
|
+
<button
|
|
1578
|
+
type="button"
|
|
1579
|
+
class="compose-attachment-overlay compose-attachment-retry"
|
|
1580
|
+
@click=${e=>{e.stopPropagation(),this._retryAllFailed()}}
|
|
1581
|
+
>
|
|
1582
|
+
<span class="compose-retry-content">
|
|
1583
|
+
<svg
|
|
1584
|
+
width="20"
|
|
1585
|
+
height="20"
|
|
1586
|
+
viewBox="0 0 24 24"
|
|
1587
|
+
fill="none"
|
|
1588
|
+
stroke="currentColor"
|
|
1589
|
+
stroke-width="2"
|
|
1590
|
+
stroke-linecap="round"
|
|
1591
|
+
stroke-linejoin="round"
|
|
1592
|
+
>
|
|
1593
|
+
<path
|
|
1594
|
+
d="M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"
|
|
1595
|
+
/>
|
|
1596
|
+
<path d="M3 3v5h5" />
|
|
1597
|
+
<path
|
|
1598
|
+
d="M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16"
|
|
1599
|
+
/>
|
|
1600
|
+
<path d="M16 16h5v5" />
|
|
1601
|
+
</svg>
|
|
1602
|
+
<span class="compose-retry-label"
|
|
1603
|
+
>${this.labels.retryAll}</span
|
|
1604
|
+
>
|
|
1605
|
+
</span>
|
|
1606
|
+
${e.error?i`<span class="compose-attachment-error-msg"
|
|
1607
|
+
>${e.error}</span
|
|
1608
|
+
>`:o}
|
|
1609
|
+
</button>
|
|
1610
|
+
`:o}
|
|
1611
|
+
${this._renderAttachmentRemoveButton(e=>{e.stopPropagation(),this._removeAttachment(t)})}
|
|
1612
|
+
`}_renderAttachmentRemoveButton(e){return i`
|
|
1613
|
+
<button
|
|
1614
|
+
type="button"
|
|
1615
|
+
class="compose-attachment-remove"
|
|
1616
|
+
aria-label=${this.labels.removeAttachment}
|
|
1617
|
+
@click=${e}
|
|
1618
|
+
>
|
|
1619
|
+
<svg
|
|
1620
|
+
width="14"
|
|
1621
|
+
height="14"
|
|
1622
|
+
viewBox="0 0 14 14"
|
|
1623
|
+
fill="none"
|
|
1624
|
+
stroke="currentColor"
|
|
1625
|
+
stroke-width="1.9"
|
|
1626
|
+
stroke-linecap="round"
|
|
1627
|
+
>
|
|
1628
|
+
<path d="M3.5 3.5 10.5 10.5" />
|
|
1629
|
+
<path d="M10.5 3.5 3.5 10.5" />
|
|
1630
|
+
</svg>
|
|
1631
|
+
</button>
|
|
1632
|
+
`}_renderAttachmentMoveButton(e,t,n){let r=t===-1,a=r?this.labels.moveAttachmentEarlier:this.labels.moveAttachmentLater;return i`
|
|
1633
|
+
<button
|
|
1634
|
+
type="button"
|
|
1635
|
+
class="compose-attachment-move"
|
|
1636
|
+
data-attachment-move=${r?`earlier`:`later`}
|
|
1637
|
+
?disabled=${n}
|
|
1638
|
+
aria-label=${a}
|
|
1639
|
+
title=${a}
|
|
1640
|
+
@click=${n=>{n.stopPropagation(),this._moveAttachment(e,t,`move`)}}
|
|
1641
|
+
>
|
|
1642
|
+
<svg
|
|
1643
|
+
width="14"
|
|
1644
|
+
height="14"
|
|
1645
|
+
viewBox="0 0 14 14"
|
|
1646
|
+
fill="none"
|
|
1647
|
+
stroke="currentColor"
|
|
1648
|
+
stroke-width="1.9"
|
|
1649
|
+
stroke-linecap="round"
|
|
1650
|
+
stroke-linejoin="round"
|
|
1651
|
+
>
|
|
1652
|
+
<path
|
|
1653
|
+
d=${r?`M8.75 3.5 5.25 7l3.5 3.5`:`M5.25 3.5 8.75 7l-3.5 3.5`}
|
|
1654
|
+
/>
|
|
1655
|
+
</svg>
|
|
1656
|
+
</button>
|
|
1657
|
+
`}_renderAttachmentActions(e,t=o){let n=this._attachmentOrder.length,r=this._attachmentOrder.indexOf(e),a=n>1&&r!==-1;return!a&&t===o?o:i`
|
|
1658
|
+
<div class="compose-attachment-actions">
|
|
1659
|
+
${a?i`
|
|
1660
|
+
<div class="compose-attachment-move-group">
|
|
1661
|
+
${this._renderAttachmentMoveButton(e,-1,r===0)}
|
|
1662
|
+
${this._renderAttachmentMoveButton(e,1,r===n-1)}
|
|
1663
|
+
</div>
|
|
1664
|
+
`:o}
|
|
1665
|
+
${t}
|
|
1666
|
+
</div>
|
|
1667
|
+
`}_renderAttachedTextCard(e,t){return i`
|
|
1668
|
+
<div class="compose-attachment" data-attachment-id=${e.clientId}>
|
|
1669
|
+
<div
|
|
1670
|
+
class="compose-attachment-thumb compose-attachment-sortable"
|
|
1671
|
+
data-attachment-sortable
|
|
1672
|
+
tabindex="0"
|
|
1673
|
+
@click=${()=>this._maybeEditAttachedText(t)}
|
|
1674
|
+
@keydown=${n=>this._handleAttachmentKeydown(e.clientId,n,()=>this._maybeEditAttachedText(t))}
|
|
1675
|
+
>
|
|
1676
|
+
<div class="compose-attachment-text-card">
|
|
1677
|
+
<div class="compose-attachment-file-icon">
|
|
1678
|
+
${this._renderFileIcon(`text/html; charset=utf-8`,20)}
|
|
1679
|
+
</div>
|
|
1680
|
+
<span class="compose-attachment-text-summary">${e.summary}</span>
|
|
1681
|
+
${e.bodyJson?i`<span class="compose-attachment-file-size"
|
|
1682
|
+
>${this._formatChars(this._extractPlainText(e.bodyJson).length)}</span
|
|
1683
|
+
>`:o}
|
|
1684
|
+
</div>
|
|
1685
|
+
${this._renderAttachmentRemoveButton(e=>{e.stopPropagation(),this._removeAttachedText(t)})}
|
|
1686
|
+
</div>
|
|
1687
|
+
${this._renderAttachmentActions(e.clientId)}
|
|
1688
|
+
</div>
|
|
1689
|
+
`}_renderMediaAttachment(e,t){let n=this._getCategory(e),r=n!==`image`&&n!==`video`,a=n===`video`?`video`:`image`,s=this._hasFailedAttachmentPreview(e.clientId);return i`
|
|
1690
|
+
<div class="compose-attachment" data-attachment-id=${e.clientId}>
|
|
1691
|
+
${r?i`
|
|
1692
|
+
<div class="compose-attachment-thumb">
|
|
1693
|
+
<div
|
|
1694
|
+
class="compose-attachment-sortable"
|
|
1695
|
+
data-attachment-sortable
|
|
1696
|
+
tabindex="0"
|
|
1697
|
+
@keydown=${t=>this._handleAttachmentKeydown(e.clientId,t)}
|
|
1698
|
+
>
|
|
1699
|
+
${this._renderAttachmentPreview(e)}
|
|
1700
|
+
</div>
|
|
1701
|
+
${this._renderAttachmentOverlay(e,t)}
|
|
1702
|
+
</div>
|
|
1703
|
+
`:i`
|
|
1704
|
+
<div class="compose-attachment-thumb">
|
|
1705
|
+
<div
|
|
1706
|
+
class="compose-attachment-sortable"
|
|
1707
|
+
data-attachment-sortable
|
|
1708
|
+
tabindex="0"
|
|
1709
|
+
@keydown=${t=>this._handleAttachmentKeydown(e.clientId,t)}
|
|
1710
|
+
>
|
|
1711
|
+
${s?this._renderAttachmentPreviewFallback(a):n===`video`?i`
|
|
1712
|
+
<video
|
|
1713
|
+
src=${e.previewUrl}
|
|
1714
|
+
poster=${e.posterUrl??o}
|
|
1715
|
+
class="compose-attachment-img"
|
|
1716
|
+
preload="metadata"
|
|
1717
|
+
.playsInline=${!0}
|
|
1718
|
+
.muted=${!0}
|
|
1719
|
+
@loadeddata=${()=>this._setAttachmentPreviewFailure(e.clientId,!1)}
|
|
1720
|
+
@error=${()=>this._setAttachmentPreviewFailure(e.clientId,!0)}
|
|
1721
|
+
></video>
|
|
1722
|
+
<div class="compose-attachment-play-icon">
|
|
1723
|
+
<svg
|
|
1724
|
+
width="24"
|
|
1725
|
+
height="24"
|
|
1726
|
+
viewBox="0 0 24 24"
|
|
1727
|
+
fill="white"
|
|
1728
|
+
>
|
|
1729
|
+
<path d="M8 5v14l11-7z" />
|
|
1730
|
+
</svg>
|
|
1731
|
+
</div>
|
|
1732
|
+
`:e.status===`processing`?i`
|
|
1733
|
+
<div class="compose-attachment-processing">
|
|
1734
|
+
<svg
|
|
1735
|
+
class="animate-spin size-5"
|
|
1736
|
+
viewBox="0 0 24 24"
|
|
1737
|
+
fill="none"
|
|
1738
|
+
stroke="currentColor"
|
|
1739
|
+
stroke-width="2"
|
|
1740
|
+
>
|
|
1741
|
+
<path
|
|
1742
|
+
d="M12 2a10 10 0 1 0 10 10"
|
|
1743
|
+
stroke-linecap="round"
|
|
1744
|
+
/>
|
|
1745
|
+
</svg>
|
|
1746
|
+
</div>
|
|
1747
|
+
`:i`
|
|
1748
|
+
<img
|
|
1749
|
+
src=${e.previewUrl}
|
|
1750
|
+
alt=""
|
|
1751
|
+
class="compose-attachment-img"
|
|
1752
|
+
@load=${()=>this._setAttachmentPreviewFailure(e.clientId,!1)}
|
|
1753
|
+
@error=${()=>this._setAttachmentPreviewFailure(e.clientId,!0)}
|
|
1754
|
+
/>
|
|
1755
|
+
`}
|
|
1756
|
+
</div>
|
|
1757
|
+
${this._renderAttachmentOverlay(e,t)}
|
|
1758
|
+
</div>
|
|
1759
|
+
`}
|
|
1760
|
+
${this._renderAttachmentActions(e.clientId,n===`image`?i`
|
|
1761
|
+
<button
|
|
1762
|
+
type="button"
|
|
1763
|
+
class=${b({"compose-attachment-alt":!0,"compose-attachment-alt-set":e.alt.length>0})}
|
|
1764
|
+
@click=${()=>this._openAltPanel(t)}
|
|
1765
|
+
>
|
|
1766
|
+
${e.alt.length>0?`ALT`:`+ ALT`}
|
|
1767
|
+
</button>
|
|
1768
|
+
`:o)}
|
|
1769
|
+
</div>
|
|
1770
|
+
`}_renderAttachments(){return this._attachments.length===0&&this._attachedTexts.length===0?o:i`
|
|
1771
|
+
<div class="compose-attachments" data-attachment-list>
|
|
1772
|
+
${this._attachmentOrder.map(e=>{let t=this._attachments.findIndex(t=>t.clientId===e);if(t!==-1)return this._renderMediaAttachment(this._attachments[t],t);let n=this._attachedTexts.findIndex(t=>t.clientId===e);return n===-1?o:this._renderAttachedTextCard(this._attachedTexts[n],n)})}
|
|
1773
|
+
</div>
|
|
1774
|
+
`}_renderAttachmentDock(){return this._attachments.length===0&&this._attachedTexts.length===0?o:i`
|
|
1775
|
+
<div class="compose-attachments-dock">${this._renderAttachments()}</div>
|
|
1776
|
+
`}_renderToolsRow(){let e=this._attachedTexts.length>0;return i`
|
|
1777
|
+
<div class="compose-tools-row">
|
|
1778
|
+
<button
|
|
1779
|
+
type="button"
|
|
1780
|
+
class=${b({"compose-tool-btn":!0,"compose-tool-btn-add":this._attachments.length>0})}
|
|
1781
|
+
title=${this._attachments.length>0?``:this.labels.media}
|
|
1782
|
+
@click=${()=>this._openFilePicker()}
|
|
1783
|
+
>
|
|
1784
|
+
${J(q.media)}
|
|
1785
|
+
${this._attachments.length>0?i`<span class="compose-tool-label"
|
|
1786
|
+
>${this.labels.addMore}</span
|
|
1787
|
+
>`:o}
|
|
1788
|
+
</button>
|
|
1789
|
+
|
|
1790
|
+
<button
|
|
1791
|
+
type="button"
|
|
1792
|
+
class=${b({"compose-tool-btn":!0,"compose-tool-btn-add":e})}
|
|
1793
|
+
title=${e?``:this.labels.attachedText}
|
|
1794
|
+
@click=${()=>this._openAttachedText()}
|
|
1795
|
+
>
|
|
1796
|
+
${J(q.attachedText)}
|
|
1797
|
+
${e?i`<span class="compose-tool-label"
|
|
1798
|
+
>${this.labels.addMore}</span
|
|
1799
|
+
>`:o}
|
|
1800
|
+
</button>
|
|
1801
|
+
|
|
1802
|
+
<button
|
|
1803
|
+
type="button"
|
|
1804
|
+
class=${b({"compose-tool-btn":!0,"compose-emoji-btn":!0,"compose-tool-btn-active":this._showEmojiPicker})}
|
|
1805
|
+
title=${this.labels.emoji}
|
|
1806
|
+
aria-pressed=${this._showEmojiPicker?`true`:`false`}
|
|
1807
|
+
@click=${()=>this._toggleEmojiPicker()}
|
|
1808
|
+
>
|
|
1809
|
+
${J(q.emoji)}
|
|
1810
|
+
</button>
|
|
1811
|
+
|
|
1812
|
+
<div class="compose-tool-gap"></div>
|
|
1813
|
+
|
|
1814
|
+
<button
|
|
1815
|
+
type="button"
|
|
1816
|
+
class=${b({"compose-tool-btn":!0,"compose-tool-btn-active":this._showRating})}
|
|
1817
|
+
title=${this.labels.rate}
|
|
1818
|
+
aria-pressed=${this._showRating?`true`:`false`}
|
|
1819
|
+
@click=${()=>{let e=!this._showRating;this._showRating=e,e&&this.updateComplete.then(()=>{this.querySelector(`.compose-star-rating`)?.scrollIntoView({block:`nearest`,behavior:`smooth`})})}}
|
|
1820
|
+
>
|
|
1821
|
+
${J(q.rate)}
|
|
1822
|
+
</button>
|
|
1823
|
+
|
|
1824
|
+
${this.format===`note`?i`
|
|
1825
|
+
<button
|
|
1826
|
+
type="button"
|
|
1827
|
+
class=${b({"compose-tool-btn":!0,"compose-tool-btn-active":this._showTitle})}
|
|
1828
|
+
title=${this.labels.title}
|
|
1829
|
+
aria-pressed=${this._showTitle?`true`:`false`}
|
|
1830
|
+
@click=${()=>{let e=!this._showTitle;this._showTitle=e,this.dispatchEvent(new CustomEvent(`jant:title-toggle`,{bubbles:!0,detail:{showTitle:e}})),e&&this.updateComplete.then(()=>{this.querySelector(`.compose-note-title`)?.focus()})}}
|
|
1831
|
+
>
|
|
1832
|
+
${J(q.title)}
|
|
1833
|
+
</button>
|
|
1834
|
+
`:o}
|
|
1835
|
+
${this.format===`note`?i`
|
|
1836
|
+
<div class="compose-tool-view-group">
|
|
1837
|
+
<button
|
|
1838
|
+
type="button"
|
|
1839
|
+
class="compose-tool-btn compose-tool-btn-view"
|
|
1840
|
+
title=${this.labels.fullscreen}
|
|
1841
|
+
aria-label=${this.labels.fullscreen}
|
|
1842
|
+
@click=${()=>this.openFullscreen()}
|
|
1843
|
+
>
|
|
1844
|
+
${J(q.fullscreen)}
|
|
1845
|
+
</button>
|
|
1846
|
+
</div>
|
|
1847
|
+
`:o}
|
|
1848
|
+
</div>
|
|
1849
|
+
`}_renderFormatHeader(){let e={note:this.labels.note,link:this.labels.link,quote:this.labels.quote};return i`
|
|
1850
|
+
<div class="compose-thread-post-header">
|
|
1851
|
+
<div class="compose-segmented">
|
|
1852
|
+
<!-- No sliding indicator: the items size to their labels now, so a
|
|
1853
|
+
thirds-based pill would not line up. The active item carries its
|
|
1854
|
+
own background instead. -->
|
|
1855
|
+
${[`note`,`link`,`quote`].map(t=>i`
|
|
1856
|
+
<button
|
|
1857
|
+
type="button"
|
|
1858
|
+
class=${b({"compose-segmented-item":!0,"compose-segmented-item-active":this.format===t})}
|
|
1859
|
+
@click=${()=>{this.format!==t&&this.dispatchEvent(new CustomEvent(`jant:format-change`,{bubbles:!0,detail:{format:t}}))}}
|
|
1860
|
+
>
|
|
1861
|
+
${e[t]}
|
|
1862
|
+
</button>
|
|
1863
|
+
`)}
|
|
1864
|
+
</div>
|
|
1865
|
+
${this.positionLabel?i`<span class="compose-post-position"
|
|
1866
|
+
>${this.positionLabel}</span
|
|
1867
|
+
>`:o}
|
|
1868
|
+
${this.badgeLabel?i`<span class="compose-post-position compose-post-badge"
|
|
1869
|
+
>${this.badgeLabel}</span
|
|
1870
|
+
>`:o}
|
|
1871
|
+
${this.headerExtra??o}
|
|
1872
|
+
${this.removable?i`<button
|
|
1873
|
+
type="button"
|
|
1874
|
+
class="compose-thread-post-remove"
|
|
1875
|
+
title="Remove post"
|
|
1876
|
+
@click=${()=>{this.dispatchEvent(new CustomEvent(`jant:thread-remove`,{bubbles:!0}))}}
|
|
1877
|
+
>
|
|
1878
|
+
<svg
|
|
1879
|
+
width="14"
|
|
1880
|
+
height="14"
|
|
1881
|
+
viewBox="0 0 16 16"
|
|
1882
|
+
fill="none"
|
|
1883
|
+
stroke="currentColor"
|
|
1884
|
+
stroke-width="1.8"
|
|
1885
|
+
stroke-linecap="round"
|
|
1886
|
+
aria-hidden="true"
|
|
1887
|
+
>
|
|
1888
|
+
${v(`<path d="M4.5 4.5 11.5 11.5M11.5 4.5 4.5 11.5"/>`)}
|
|
1889
|
+
</svg>
|
|
1890
|
+
</button>`:o}
|
|
1891
|
+
</div>
|
|
1892
|
+
`}openFullscreen(){if(this.format!==`note`)return;let e=this.getEditorState();this.dispatchEvent(new CustomEvent(`jant:fullscreen-open`,{bubbles:!0,detail:{...e,labels:this.labels}}))}render(){return i`
|
|
1893
|
+
${this._renderFormatHeader()}
|
|
1894
|
+
<section
|
|
1895
|
+
class="compose-body"
|
|
1896
|
+
@mousedown=${this._recordBodyPress}
|
|
1897
|
+
@mouseup=${this._recordBodyRelease}
|
|
1898
|
+
@click=${this._focusBodyFromBlankSpace}
|
|
1899
|
+
>
|
|
1900
|
+
${this.format===`note`?this._renderNoteFields():this.format===`link`?this._renderLinkFields():this._renderQuoteFields()}
|
|
1901
|
+
</section>
|
|
1902
|
+
${this._renderAttachmentDock()} ${this._renderStarRating()}
|
|
1903
|
+
${this._renderToolsRow()}
|
|
1904
|
+
`}};customElements.define(`jant-compose-editor`,Vt);var Ht=`.tiptap-slash-menu, .tiptap-link-input, .tiptap-table-size-picker, .tiptap-table-options:not([hidden])`,Ut=class extends c{static properties={labels:{type:Object},_open:{state:!0},_title:{state:!0},_showTitle:{state:!0},_replyContext:{state:!0},_replyExpanded:{state:!0}};_editor=null;_content=null;_selection=null;_editorIndex=0;_fileInput=null;#e=new Set;createRenderRoot(){return this}constructor(){super(),this.labels={},this._open=!1,this._title=``,this._showTitle=!0,this._replyContext=null,this._replyExpanded=!1}connectedCallback(){super.connectedCallback(),document.addEventListener(`jant:fullscreen-open`,this._onOpen),document.addEventListener(`jant:slash-image`,this._onSlashImage),document.addEventListener(`keydown`,this._onDocumentKeydown,!0)}disconnectedCallback(){super.disconnectedCallback(),document.removeEventListener(`jant:fullscreen-open`,this._onOpen),document.removeEventListener(`jant:slash-image`,this._onSlashImage),document.removeEventListener(`keydown`,this._onDocumentKeydown,!0),this._fileInput?.remove(),this._destroyEditor()}_onSlashImage=()=>{this._open&&this._editor&&this._triggerImagePicker()};_triggerImagePicker(){this._fileInput||(this._fileInput=document.createElement(`input`),this._fileInput.type=`file`,this._fileInput.accept=`image/*`,this._fileInput.style.display=`none`,this._fileInput.addEventListener(`change`,()=>{let e=this._fileInput?.files?.[0];e&&this._editor&&this._uploadAndInsertImage(e),this._fileInput&&(this._fileInput.value=``)}),document.body.appendChild(this._fileInput)),this._fileInput.click()}_uploadAndInsertImage(e){let t=this._editor;if(!t)return Promise.resolve();let n=M(t,e).finally(()=>{this.#e.delete(n)});return this.#e.add(n),n}_onOpen=e=>{this._content=e.detail.json,this._selection=e.detail.selection??null,this._title=e.detail.title,e.detail.labels&&(this.labels=e.detail.labels),this._showTitle=e.detail.showTitle||e.detail.title.trim().length>0,this._replyContext=e.detail.replyContext??null,this._replyExpanded=e.detail.replyContext?.expanded??!1,this._editorIndex=e.detail.editorIndex??0,this._open=!0,this.updateComplete.then(()=>{let e=this.querySelector(`.compose-fullscreen-dialog`);e&&!e.open&&e.showModal(),this._initEditor()})};_initEditor(){let e=this.querySelector(`.compose-fullscreen .compose-tiptap-body`);if(!e||this._editor)return;this._editor=le({element:e,placeholder:this.labels.bodyPlaceholder??`Write something…`,content:this._content,toolbarMode:`compose`,onUpdate:e=>{this._content=e},pasteMedia:{shouldInsertInline:e=>e.type.startsWith(`image/`),uploadInlineImage:e=>this._uploadAndInsertImage(e)},imageNodeLabels:Rt(this.labels),tableControlLabels:this.labels.tableControls});let t=this._selection;if(t){let e=this._editor.state.doc.content.size,n=Math.max(1,Math.min(t.from,e)),r=Math.max(n,Math.min(t.to,e));this._selection={from:n,to:r},this._editor.chain().focus().setTextSelection({from:n,to:r}).run();return}this._editor.commands.focus()}_destroyEditor(){this.#e.clear(),this._editor?.destroy(),this._editor=null}_onDialogCancel=e=>{e.preventDefault(),this._close()};_onDocumentKeydown=e=>{if(this._open&&!(e.isComposing||e.keyCode===229)){if((e.metaKey||e.ctrlKey)&&e.key===`Enter`){e.preventDefault(),e.stopPropagation(),this._publish();return}e.key===`Escape`&&(this._hasActiveEscapeOverlay()||(e.preventDefault(),e.stopPropagation(),this._close()))}};_hasActiveEscapeOverlay(){let e=this.querySelector(`.compose-fullscreen-dialog[open]`);return e?Array.from(e.querySelectorAll(Ht)).some(e=>getComputedStyle(e).display!==`none`):!1}_finishClose(e){let t=this._editor?.getJSON()??this._content,n=this._editor?{from:this._editor.state.selection.from,to:this._editor.state.selection.to}:this._selection;this._destroyEditor(),this.querySelector(`.compose-fullscreen-dialog`)?.close(),this._open=!1,this._replyContext=null,document.dispatchEvent(new CustomEvent(`jant:fullscreen-close`,{bubbles:!0,detail:{json:t,title:this._title,showTitle:this._showTitle||this._title.trim().length>0,selection:n,replyExpanded:this._replyExpanded,intent:e,editorIndex:this._editorIndex}}))}_close(){this._open&&this._finishClose()}_publish(){this._open&&this._finishClose(`publish`)}_revealTitle(){this._showTitle=!0,this.updateComplete.then(()=>{this.querySelector(`.compose-fullscreen-title`)?.focus()})}_renderTitleField(e){let t=b({"compose-fullscreen-title":!0,"compose-fullscreen-title-reply":e===`reply`}),n=b({"compose-fullscreen-title-placeholder":!0,"compose-fullscreen-title-placeholder-reply":e===`reply`});return this._showTitle?i`
|
|
1905
|
+
<div class="compose-fullscreen-title-shell">
|
|
1906
|
+
<input
|
|
1907
|
+
type="text"
|
|
1908
|
+
.value=${this._title}
|
|
1909
|
+
@input=${e=>{this._title=e.target.value}}
|
|
1910
|
+
@keydown=${e=>{e.isComposing||e.keyCode===229||e.key===`Enter`&&(e.preventDefault(),this._editor?.commands.focus(`start`))}}
|
|
1911
|
+
class=${t}
|
|
1912
|
+
placeholder=${this.labels.titlePlaceholder??`Title`}
|
|
1913
|
+
/>
|
|
1914
|
+
</div>
|
|
1915
|
+
`:i`
|
|
1916
|
+
<button
|
|
1917
|
+
type="button"
|
|
1918
|
+
class=${n}
|
|
1919
|
+
@click=${()=>this._revealTitle()}
|
|
1920
|
+
>
|
|
1921
|
+
${this.labels.titlePlaceholder||this.labels.title||`Title`}
|
|
1922
|
+
</button>
|
|
1923
|
+
`}render(){if(!this._open)return o;let e=this._replyContext,t=e=>i`
|
|
1924
|
+
<div
|
|
1925
|
+
class=${b({"compose-fullscreen-editor-surface":!0,"compose-fullscreen-editor-surface-reply":e===`reply`})}
|
|
1926
|
+
>
|
|
1927
|
+
${this._renderTitleField(e)}
|
|
1928
|
+
<div class="compose-tiptap-body"></div>
|
|
1929
|
+
</div>
|
|
1930
|
+
`;return i`
|
|
1931
|
+
<dialog
|
|
1932
|
+
class="compose-fullscreen-dialog"
|
|
1933
|
+
aria-label=${this.labels.fullscreen||this.labels.note||`Fullscreen`}
|
|
1934
|
+
@cancel=${this._onDialogCancel}
|
|
1935
|
+
>
|
|
1936
|
+
<div class="compose-fullscreen">
|
|
1937
|
+
<header class="compose-fullscreen-toolbar">
|
|
1938
|
+
<div class="compose-fullscreen-toolbar-inner">
|
|
1939
|
+
<button
|
|
1940
|
+
type="button"
|
|
1941
|
+
class="compose-fullscreen-done"
|
|
1942
|
+
title=${this.labels.exitFullscreen||`Exit fullscreen`}
|
|
1943
|
+
aria-label=${this.labels.exitFullscreen||`Exit fullscreen`}
|
|
1944
|
+
@click=${()=>void this._close()}
|
|
1945
|
+
>
|
|
1946
|
+
<svg
|
|
1947
|
+
width="18"
|
|
1948
|
+
height="18"
|
|
1949
|
+
viewBox="0 0 18 18"
|
|
1950
|
+
fill="none"
|
|
1951
|
+
stroke="currentColor"
|
|
1952
|
+
stroke-width="1.48"
|
|
1953
|
+
stroke-linecap="round"
|
|
1954
|
+
stroke-linejoin="round"
|
|
1955
|
+
>
|
|
1956
|
+
<path d="M3 6.85h2.85V4" />
|
|
1957
|
+
<path d="M15 6.85h-2.85V4" />
|
|
1958
|
+
<path d="M6.85 15V12.15H4" />
|
|
1959
|
+
<path d="M11.15 15V12.15H14" />
|
|
1960
|
+
</svg>
|
|
1961
|
+
</button>
|
|
1962
|
+
</div>
|
|
1963
|
+
</header>
|
|
1964
|
+
<div class="compose-fullscreen-content">
|
|
1965
|
+
<div class="compose-fullscreen-inner">
|
|
1966
|
+
${e?i`
|
|
1967
|
+
<div
|
|
1968
|
+
class="compose-thread-layout compose-fullscreen-thread-layout"
|
|
1969
|
+
>
|
|
1970
|
+
<div class="compose-reply-row">
|
|
1971
|
+
<div class="compose-thread-dot"></div>
|
|
1972
|
+
<div
|
|
1973
|
+
class=${b({"compose-reply-context":!0,expanded:this._replyExpanded})}
|
|
1974
|
+
>
|
|
1975
|
+
<div class="compose-reply-context-body">
|
|
1976
|
+
${d(e.contentHtml)}
|
|
1977
|
+
</div>
|
|
1978
|
+
${this._replyExpanded?o:i`<div class="compose-reply-fade"></div>`}
|
|
1979
|
+
</div>
|
|
1980
|
+
</div>
|
|
1981
|
+
<div class="compose-reply-meta">
|
|
1982
|
+
${e.dateText?i`<span>${e.dateText}</span
|
|
1983
|
+
><span>·</span>`:o}
|
|
1984
|
+
<button
|
|
1985
|
+
type="button"
|
|
1986
|
+
class="compose-reply-toggle"
|
|
1987
|
+
@click=${()=>{this._replyExpanded=!this._replyExpanded}}
|
|
1988
|
+
>
|
|
1989
|
+
${this._replyExpanded?this.labels.showLess:this.labels.showMore}
|
|
1990
|
+
</button>
|
|
1991
|
+
</div>
|
|
1992
|
+
<div
|
|
1993
|
+
class="compose-editor-row compose-fullscreen-editor-row is-current"
|
|
1994
|
+
>
|
|
1995
|
+
<div class="compose-thread-dot"></div>
|
|
1996
|
+
${t(`reply`)}
|
|
1997
|
+
</div>
|
|
1998
|
+
</div>
|
|
1999
|
+
`:t(`note`)}
|
|
2000
|
+
</div>
|
|
2001
|
+
</div>
|
|
2002
|
+
</div>
|
|
2003
|
+
</dialog>
|
|
2004
|
+
`}};customElements.define(`jant-compose-fullscreen`,Ut);var Wt;function Gt(){return Wt??=y(()=>import(`./chunks/mediabunny-DRaCQ1r-.js`).then(e=>e.t),__vite__mapDeps([2,1])),Wt}function Kt(){return typeof AudioEncoder<`u`}async function qt(e,t){let{Input:n,Output:r,Mp4OutputFormat:i,BufferTarget:a,BlobSource:o,Conversion:s,ALL_FORMATS:c}=await Gt(),l=new n({source:new o(e),formats:c}),u=new a,d=new r({format:new i({fastStart:`in-memory`}),target:u});try{let n=await s.init({input:l,output:d,video:{discard:!0},audio:{codec:`aac`}});t&&(n.onProgress=t),await n.execute();let r=u.buffer;if(!r)throw Error(`Audio processing produced no output`);let i=e.name.replace(/\.[^.]+$/,``);return{file:new File([r],`${i}.m4a`,{type:`audio/mp4`})}}finally{l.dispose()}}var Jt={isSupported:Kt,processToFile:qt},Yt=new Set([`moov`,`trak`]);function Xt(e){return 12+(e===1?32:20)+8+2}function Zt(e){let t=new DataView(e),n=(e,r)=>{let i=e;for(;i+8<=r;){let e=t.getUint32(i),a=String.fromCharCode(t.getUint8(i+4),t.getUint8(i+5),t.getUint8(i+6),t.getUint8(i+7));if(e===0&&(e=r-i),e<8||i+e>r)break;if(a===`tkhd`){let n=t.getUint8(i+8),r=i+Xt(n);r+2<=i+e&&t.getUint16(r)!==0&&t.setUint16(r,0)}else Yt.has(a)&&n(i+8,i+e);i+=e}};n(0,e.byteLength)}var Qt=1920,$t=1080,en=640,tn=32,nn=79e5,rn=2073600,an=.95,on={avc:1,hevc:1/.6,vp9:1/.6,av1:1/.4,vp8:1/1.2};function sn(e,t){let n=nn*(t/rn)**an;if(!e.bitrate||!e.pixels)return Math.round(n);let r=(e.codec&&on[e.codec])??1,i=e.bitrate*r*(t/e.pixels)**an;return Math.round(Math.min(n,i))}function cn(){return typeof VideoEncoder<`u`}function ln(e,t){console.warn(`[jant] video probe: ${e} failed`,t)}async function Y(e,t){try{return await t()}catch(t){ln(e,t);return}}function un(e,t,n){let r=document.createElement(`canvas`);r.width=t,r.height=n;let i=r.getContext(`2d`);return i?(i.drawImage(e,0,0,t,n),{canvas:r,ctx:i}):null}async function dn(e){let{Input:t,BlobSource:n,ALL_FORMATS:r,CanvasSink:i}=await Gt(),a=new t({source:new n(e),formats:r});try{let e=await Y(`open video track`,()=>a.getPrimaryVideoTrack());if(!e)return{};let t=await Y(`read codec`,()=>e.getCodec()),n=await Y(`compute bitrate`,async()=>(await e.computePacketStats()).averageBitrate),r=await Y(`compute duration`,()=>a.computeDuration()),o={sourceWidth:e.displayWidth,sourceHeight:e.displayHeight,rotation:e.rotation,durationSeconds:r===void 0?void 0:u(r),videoCodec:t,videoBitrate:n},s=r===void 0?0:Math.min(r*.1,1),c=await Y(`capture frame`,()=>new i(e).getCanvas(s));if(!c)return o;let l=c.canvas,d=l.width,f=l.height,p=Math.min(en/d,1),m=un(l,Math.round(d*p),Math.round(f*p)),h=m?await Y(`encode poster`,()=>new Promise(e=>{m.canvas.toBlob(t=>e(t??void 0),`image/webp`,.8)})):void 0,g=Math.min(tn/d,tn/f,1),_=Math.max(Math.round(d*g),1),v=Math.max(Math.round(f*g),1),y=un(l,_,v),b=y?await Y(`encode blurhash`,async()=>N(y.ctx.getImageData(0,0,_,v).data,_,v,4,3)):void 0;return{...o,poster:h,blurhash:b}}finally{a.dispose()}}function fn(e,t){let{width:n,height:r}=e,i=n||t.maxLongEdge,a=r||t.maxShortEdge,o=!1;if(n&&r){let e=Math.max(n,r),s=Math.min(n,r),c=Math.min(t.maxLongEdge/e,t.maxShortEdge/s,1);o=c<1,o&&(i=Math.round(n*c),a=Math.round(r*c),i+=i%2,a+=a%2)}let s=o||e.videoCodec!==`avc`;return{needsResize:o,width:i,height:a,videoNeedsReencode:s,videoBitrate:s?sn({pixels:(n??0)*(r??0),bitrate:e.videoBitrate,codec:e.videoCodec},i*a):void 0}}async function pn(e,t){let{poster:n,blurhash:r,sourceWidth:i,sourceHeight:a,rotation:o,durationSeconds:s,videoCodec:c,videoBitrate:l}=await dn(e),{needsResize:u,width:d,height:f,videoBitrate:p}=fn({width:i,height:a,videoCodec:c,videoBitrate:l},{maxLongEdge:Qt,maxShortEdge:$t}),{Input:m,Output:h,Mp4OutputFormat:g,BufferTarget:_,BlobSource:v,Conversion:y,Quality:b,ALL_FORMATS:x}=await Gt(),S=new m({source:new v(e),formats:x}),C=new _,w=new h({format:new g({fastStart:`in-memory`}),target:C});try{let i=await y.init({input:S,output:w,video:{codec:`avc`,...u?{width:d,height:f,fit:`contain`}:{},...p===void 0?{}:{quality:new b({bitrate:p})}},audio:{codec:`aac`}});t&&(i.onProgress=t),await i.execute();let a=C.buffer;if(!a)throw Error(`Video processing produced no output`);Zt(a);let c=e.name.replace(/\.[^.]+$/,``),l=new File([a],`${c}.mp4`,{type:`video/mp4`}),m=await _n(l),h=Math.abs(m.width-d)<=2&&Math.abs(m.height-f)<=2;return o&&!h&&(gn(a),l=new File([a],`${c}.mp4`,{type:`video/mp4`}),m=await _n(l)),{file:l,width:m.width,height:m.height,durationSeconds:s,poster:n,blurhash:r}}finally{S.dispose()}}var mn=[65536,0,0,0,65536,0,0,0,1073741824];function hn(e,t,n,r){let i=t;for(;i+8<=n;){let t=e.getUint32(i),a=String.fromCharCode(e.getUint8(i+4),e.getUint8(i+5),e.getUint8(i+6),e.getUint8(i+7));if(t===0&&(t=n-i),t<8||i+t>n)break;r(i,t,a),(a===`moov`||a===`trak`||a===`mdia`||a===`edts`)&&hn(e,i+8,i+t,r),i+=t}}function gn(e){let t=new DataView(e);hn(t,0,e.byteLength,(n,r,i)=>{if(i!==`tkhd`)return;let a=n+8,o=a+(t.getUint8(a)===0?40:52);if(o+36>e.byteLength)return;let s=!0;for(let e=0;e<9;e++)if(t.getInt32(o+e*4)!==mn[e]){s=!1;break}if(!s)for(let e=0;e<9;e++)t.setInt32(o+e*4,mn[e])})}function _n(e){return new Promise((t,n)=>{let r=URL.createObjectURL(e),i=document.createElement(`video`);i.preload=`metadata`,i.onloadedmetadata=()=>{URL.revokeObjectURL(r),t({width:i.videoWidth,height:i.videoHeight})},i.onerror=()=>{URL.revokeObjectURL(r),n(Error(`Failed to probe transcoded video dimensions`))},i.src=r})}var vn={isSupported:cn,processToFile:pn};async function yn(e){let t=await e.arrayBuffer(),n=new AudioContext;try{let e=(await n.decodeAudioData(t)).getChannelData(0),r=Math.max(1,Math.floor(e.length/100)),i=Array(100);for(let t=0;t<100;t++){let n=0,a=t*r,o=Math.min(a+r,e.length);for(let t=a;t<o;t++){let r=Math.abs(e[t]);r>n&&(n=r)}i[t]=n}let a=0;for(let e of i)e>a&&(a=e);if(a>0)for(let e=0;e<100;e++)i[e]=Math.round(i[e]/a*100)/100;return JSON.stringify(i)}finally{await n.close()}}async function bn(e,t,n=`POST`){try{return await fetch(e,{method:n,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:t})}catch{return null}}async function xn(e,t){if(!e)return t?.publishFailedOffline??`Couldn't reach the server. Try again.`;let n=await S(e);return C(n,`error`)??t?.publishFailed??`Couldn't publish. Try again.`}function Sn(e){try{return A(JSON.parse(e))}catch{return!1}}function Cn(e){return e instanceof globalThis.Element?e.closest(`jant-compose-editor`):null}function wn(e){return e instanceof globalThis.Element?e.closest(`jant-compose-dialog`):null}async function Tn(e){return!e.replyRefreshKind||!e.replyRefreshId?!1:e.replyRefreshKind===`timeline-item`?f(e.replyThreadRootId??e.replyRefreshId):e.replyRefreshKind===`post-view`?_(e.replyRefreshId):h(e.replyRefreshId)}var En=new Map,Dn=new Set,X=new Map,Z=null;function Q(){if(!Z)return;let{clientIds:e,baseMsg:t}=Z;if(e.length===0)return;let r=0,i=0;for(let t of e){let e=X.get(t)??0;r+=Math.min(1,Math.max(0,e)),e>=1&&(i+=1)}let a=e.length,o=Math.floor(r/a*100),s=Math.min(i+1,a),c=a===1?`${t} ${o}%`:`${t} ${o}% ${s}/${a}`;n(`compose-deferred`,c)}var $=new Map;function On(e,t){if(!e||e.isConnected)return e;let n=document.querySelectorAll(`jant-compose-editor`);for(let e of n)if(e.hasAttachment(t))return e;return e}function kn(e){return new Promise(t=>{let n=setTimeout(()=>{a(),t(null)},3e3),r=URL.createObjectURL(e),i=document.createElement(`video`);i.muted=!0,i.playsInline=!0,i.preload=`auto`;function a(){clearTimeout(n),i.removeAttribute(`src`),i.load(),URL.revokeObjectURL(r)}i.onloadeddata=()=>{try{let e=i.videoWidth,n=i.videoHeight;if(!e||!n){a(),t(null);return}let r=Math.min(640/e,1),o=Math.round(e*r),s=Math.round(n*r),c=document.createElement(`canvas`);c.width=o,c.height=s;let l=c.getContext(`2d`);if(!l){a(),t(null);return}l.drawImage(i,0,0,o,s),c.toBlob(e=>{a(),t(e)},`image/webp`,.6)}catch{a(),t(null)}},i.onerror=()=>{a(),t(null)},i.src=r})}var An=12;async function jn(e){let t=await e.slice(0,An).arrayBuffer();return Je(new Uint8Array(t))===`image/heic`}async function Mn(e,t,n){let r=()=>On(n,t),i=e.type,a=e.name;try{let n,o,s,c,u,d,f;if(i.startsWith(`video/`)){if(!vn.isSupported())return r()?.updateAttachmentStatus(t,`error`,null,`Your browser doesn't support video processing. Use Chrome or Edge to upload videos.`),null;let i=kn(e).then(e=>(e&&r()?.updateAttachmentPoster(t,e),e)).catch(()=>null);r()?.updateAttachmentStatus(t,`processing`,null,null);let a=await vn.processToFile(e,e=>{r()?.updateAttachmentProgress(t,e)});n=a.file,e=null,o=a.width,s=a.height,c=a.durationSeconds,u=a.blurhash,f=a.poster??await i??void 0,f&&r()?.updateAttachmentPoster(t,f)}else if(i.startsWith(`audio/`)){if(!Jt.isSupported())return r()?.updateAttachmentStatus(t,`error`,null,`Your browser doesn't support audio processing. Use Chrome or Edge to upload audio.`),null;try{d=await yn(e)}catch{}r()?.updateAttachmentStatus(t,`processing`,null,null),n=(await Jt.processToFile(e,e=>{r()?.updateAttachmentProgress(t,e)})).file,e=null}else if(i.startsWith(`image/`)||/\.heic$/i.test(a)||/\.heif$/i.test(a)){let i=e;try{if(await jn(i)){let{heicTo:e}=await y(async()=>{let{heicTo:e}=await import(`./chunks/heic-to-CuP2Qlsw.js`);return{heicTo:e}},[]);r()?.updateAttachmentStatus(t,`processing`,null,null);let n=await e({blob:i,type:`image/jpeg`,quality:.92});i=new File([n],a.replace(/\.heic$/i,`.jpg`),{type:`image/jpeg`}),r()?.updateAttachmentPreview(t,i)}let c=await ae.processToFile(i);n=c.file,o=c.width,s=c.height,u=c.blurhash,e=null,i=null}catch{return r()?.removeAttachment(t),l(`Image format not supported.`,`error`),null}}else n=e;r()?.updateAttachmentStatus(t,`uploading`,null,null);let p,m;if(F(i)===`text`)try{let e=await n.text(),t=e.replace(/\s+/g,` `).trim();m=e.length,p=t.length<=100?t:t.slice(0,100)+`…`}catch{}X.set(t,0),Q();let h=await ce(n,{width:o,height:s,durationSeconds:c,blurhash:u,waveform:d,poster:f,summary:p,chars:m},e=>{r()?.updateAttachmentProgress(t,e),X.set(t,e),Q()});return X.set(t,1),Q(),r()?.updateAttachmentStatus(t,`done`,h.id,null,h.url),$.set(t,h),h.id}catch(e){X.delete(t),Q();let i=e instanceof Error?e.message:`Upload failed`;return r()?.updateAttachmentStatus(t,`error`,null,i),n||l(i,`error`),null}}document.addEventListener(`jant:attachment-removed`,e=>{let{clientId:t,mediaId:n}=e.detail;$.delete(t),n?fetch(`/api/upload/${n}`,{method:`DELETE`}).catch(()=>{}):Dn.add(t)}),document.addEventListener(`jant:files-selected`,e=>{let t=e,n=Cn(t.target);for(let{file:e,clientId:r}of t.detail.files){let t=Mn(e,r,n).then(e=>Dn.has(r)?(Dn.delete(r),e&&fetch(`/api/upload/${e}`,{method:`DELETE`}).catch(()=>{}),null):e);En.set(r,t),t.finally(()=>En.delete(r))}});function Nn(e,t){let n=e.format===`quote`,r=e.format===`link`,i=!!e.editPostId,a=e=>e||void 0,o=e=>e||null;return{format:e.format,title:n?void 0:i?o(e.title):a(e.title),body:i?o(e.body):a(e.body),url:r?i?o(e.url):a(e.url):i?null:void 0,sourceName:n?i?o(e.quoteAuthor):a(e.quoteAuthor):void 0,sourceUrl:n?i?o(e.url):a(e.url):void 0,quoteText:n?i?o(e.quoteText):a(e.quoteText):i?null:void 0,slug:e.slug||void 0,status:e.status,publishedAt:e.status===`published`?e.publishedAt:void 0,visibility:e.visibility||void 0,rating:i?e.rating>0?e.rating:null:e.rating||void 0,collectionIds:e.replyToId?void 0:e.collectionIds,attachments:t.length>0?t:void 0,replyToId:e.replyToId||void 0,quietReply:e.quietReply||void 0,language:e.language||void 0,translationOfId:i?void 0:e.translationOfId||void 0}}function Pn(e){return JSON.stringify(e.bodyJson)!==JSON.stringify(e.originalBodyJson??null)}function Fn(e,t){let n=[];for(let r of e.attachments){if(r.type===`media`){let e=r.mediaId??t.get(r.clientId)??$.get(r.clientId)?.id;if(!e)continue;n.push({type:`media`,mediaId:e,alt:r.alt});continue}if(r.mediaId&&!Pn(r)){n.push({type:`media`,mediaId:r.mediaId});continue}n.push({type:`text`,contentFormat:`markdown`,content:oe(JSON.stringify(r.bodyJson)),summary:r.summary})}return n}document.addEventListener(`jant:compose-submit-deferred`,async e=>{let n=e,i=n.detail,o=wn(n.target)??document.querySelector(`jant-compose-dialog`),c=!!o?.pageMode,u=!!document.querySelector(`[data-preview-status]`),d=o?.labels,p=d?.uploading??`Uploading...`,m=d?.publishing??`Publishing...`,g=d?.saving??`Saving...`,v=i.threadPosts?i.threadPosts.some(e=>Sn(e.body)):Sn(i.body),y=i.pendingAttachments.length>0||v,b=d?.published??`Published!`,x=d?.view??`View`,w=!!i.editPostId,ee=!!(i.threadPosts&&i.threadPosts.length>=2),te=i.status===`published`&&(!w||!!i.draftSourceId),T=!0;a(`compose-deferred`,y?p:te?m:g),i.pendingAttachments.length>0&&(Z={clientIds:i.pendingAttachments.map(e=>e.clientId),baseMsg:p},Q());let E=(e,n=`success`)=>{if(Z){for(let e of Z.clientIds)X.delete(e);Z=null}T?(T=!1,t(`compose-deferred`,e,n)):l(e,n)},D=()=>{c&&o&&(o.reset(),o.updateComplete.then(()=>{o.querySelector(`jant-compose-editor`)?.focusInput()}))},ne=()=>{c&&o&&(o.loading=!1)},O=()=>{if(w){i.editPostId&&o?.clearEditDraftFromStorage?.(i.editPostId);return}o?.clearLocalDraftFromStorage?.()},re=()=>{let e=i.threadPosts?.length?i.threadPosts:[i],t=[],n=new Set;for(let r of e)for(let e of r.attachments){if(e.type!==`media`||n.has(e.clientId))continue;n.add(e.clientId);let r=$.get(e.clientId);r&&t.push({clientId:e.clientId,mediaId:r.id,url:r.url,mimeType:r.mimeType,name:r.filename||void 0,alt:e.alt||void 0})}return t},ie=async()=>{if(o&&!c){if(i.draftSourceId){if(typeof o.openDraft!=`function`)return;await o.openDraft(i.draftSourceId);return}if(w&&i.editPostId){if(typeof o.openEdit!=`function`)return;await o.openEdit(i.editPostId,{restoreToast:!1});return}if(i.replyToId){if(typeof o.openReply!=`function`)return;await o.openReply(i.replyToId,void 0,i.replyThreadRootId,i.replyRefreshKind&&i.replyRefreshId?{kind:i.replyRefreshKind,id:i.replyRefreshId}:void 0,{restoreDraft:!0,initialFormat:i.format,restoreToast:!1,restoreMedia:re()});return}typeof o.openNew==`function`&&await o.openNew({restoreDraft:!0,restoreToast:!1,restoreMedia:re()})}},k=async e=>{ne(),await ie(),E(e,`error`)},A=async()=>{await o?.refreshCollections()},j=(e,t)=>{s(e,`success`,t)},M=()=>!c||!o||!o.consumePageLeaveRequest()?!1:(o.preparePageLeave(),globalThis.location.assign(o.closeHref||r(`/`)),!0),N=null;try{let e=i.pendingAttachments.map(e=>e.clientId),t=e.map(e=>En.get(e)??Promise.resolve(null)),n=await Promise.all(t);if(n.filter((t,n)=>t===null&&!$.has(e[n]??``)).length>0){if(i.status===`published`&&!w)N=`upload`;else{await k(`Upload failed. Post not created.`);return}}let a=new Map;for(let t=0;t<e.length;t++){let r=e[t],i=n[t];r&&i&&a.set(r,i)}if(ee&&i.threadPosts){let e=i.threadPosts,t=N?`draft`:i.status,n=(await Promise.all(e.map(async e=>{let n=e.body;if(Sn(n))try{let e=JSON.parse(n),t=await pe(e);n=t?JSON.stringify(t):``}catch{}return{...e,body:n,status:t}}))).map(e=>Nn(e,Fn(e,a))),r={posts:n};w&&i.editPostId&&(r.replaceThreadId=i.editPostId);let s=await bn(`/compose/thread`,JSON.stringify(r));if(!s?.ok){if(i.status===`published`&&!N){let e={posts:n.map(e=>({...e,status:`draft`}))};if((await bn(`/compose/thread`,JSON.stringify(e)))?.ok){N=`server`,O();let e=d?.publishFailedDraft??`Couldn't publish. Saved as draft.`;await A(),M()||D(),E(e);return}}await k(await xn(s,d));return}if(N===`upload`){O();let e=d?.uploadFailedDraft??`Some uploads failed. Saved as draft.`;await A(),D(),E(e);return}let l=await S(s),f=C(l,`status`),p=C(l,`permalink`),m=C(l,`toast`);if(f===`published`)O(),u&&i.draftSourceId?(j(b),globalThis.location.assign(p??globalThis.location.pathname)):c?(await A(),D(),E(b)):(j(b,p?{label:x,href:p}:void 0),globalThis.location.reload());else{if(O(),u&&i.draftSourceId){j(m??`Draft saved.`),globalThis.location.assign(globalThis.location.pathname);return}await A(),M()||D(),E(m??`Draft saved.`),In(o,`draft`)}return}let s=Fn(i,a);if(v)try{let e=JSON.parse(i.body),t=await pe(e);i.body=t?JSON.stringify(t):``}catch{}let l=w?`/api/posts/${i.editPostId}`:`/compose`,p=w?`PUT`:`POST`,m=Nn({...i,status:N?`draft`:i.status},s),g=await bn(l,JSON.stringify(m),p);if(!g?.ok){if(i.status===`published`&&!w&&!N){let e={...m,status:`draft`},t=await bn(l,JSON.stringify(e),p);if(t?.ok){N=`server`,O();let e=await S(t),n=d?.publishFailedDraft??`Couldn't publish. Saved as draft.`;await A(),M()||D(),E(n);let r=C(e,`toast`);r&&E(r);return}}await k(await xn(g,d));return}if(w){O();let e=await S(g),t=i.editPostId??``,n=C(e,`slug`),a=C(e,`status`)??i.status,s=n?r(a===`draft`?`/preview/${n}`:`/${n}`):null,l=a===`draft`?`Draft saved.`:i.draftSourceId?b:`Post updated.`;if(a===`draft`){if(u){j(l),globalThis.location.assign(s??globalThis.location.pathname);return}await A(),E(l),In(o,`draft`);return}if(c)s&&s!==globalThis.location.pathname?(j(l),globalThis.location.assign(s)):t&&await _(t)?E(l):(j(l),globalThis.location.assign(globalThis.location.pathname));else if(t){if(document.querySelector(`[data-post-view][data-post-view-id="${t}"]`)){if(s&&s!==globalThis.location.pathname){j(l),globalThis.location.assign(s);return}await _(t)?E(l):(j(l),globalThis.location.reload())}else{let e=document.querySelector(`article[data-post-id="${t}"]`)?.closest(`[data-timeline-item]`)?.dataset.threadRootId;(e?await f(e):await h(t))?E(l):(j(l),globalThis.location.reload())}}else j(l),globalThis.location.reload();return}if(N===`upload`){O();let e=d?.uploadFailedDraft??`Some uploads failed. Saved as draft.`;await A(),D(),E(e);return}let y=await S(g),te=C(y,`status`),T=C(y,`permalink`),ne=C(y,`toast`);if(te===`published`){if(O(),c)await A(),D(),E(b);else if(i.replyToId){if(await A(),!await Tn(i)){j(b,T?{label:x,href:T}:void 0),globalThis.location.reload();return}E(b)}else j(b,T?{label:x,href:T}:void 0),globalThis.location.reload();return}O(),await A(),M()||D(),E(ne??`Draft saved.`),In(o,`draft`)}catch{await k(await xn(null,d))}});function In(e,t){(e??document).dispatchEvent(new CustomEvent(`jant:compose-submit-complete`,{bubbles:!0,detail:{status:t}}))}document.readyState===`loading`&&document.addEventListener(`DOMContentLoaded`,()=>{}),document.querySelector(`jant-compose-fullscreen`)||document.body.appendChild(document.createElement(`jant-compose-fullscreen`));
|