@lvl99dotcom/edaha-editor 0.3.0 → 0.4.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.
Files changed (37) hide show
  1. package/README.md +8 -1
  2. package/dist/client/assets/index--k7n6Qb8.css +1 -0
  3. package/dist/client/assets/{index-BwcJ6yrI.js → index-owkKXGfS.js} +140 -126
  4. package/dist/client/index.html +2 -2
  5. package/dist/client-lib/index.js +4037 -0
  6. package/dist/client-lib/style.css +1569 -0
  7. package/dist/editor/index.d.ts +24 -1
  8. package/dist/editor/index.js +15 -1
  9. package/dist/server/store/index.d.ts +2 -1
  10. package/dist/server/store/index.js +4 -3
  11. package/dist/types/client/components/define/index.d.ts +7 -0
  12. package/dist/types/client/components/edaha-article/index.d.ts +380 -0
  13. package/dist/types/client/components/edaha-article-browser/index.d.ts +162 -0
  14. package/dist/types/client/components/edaha-article-data-field/index.d.ts +121 -0
  15. package/dist/types/client/components/edaha-article-data-group/index.d.ts +40 -0
  16. package/dist/types/client/components/edaha-editor/index.d.ts +289 -0
  17. package/dist/types/client/components/edaha-embed-dialog/index.d.ts +84 -0
  18. package/dist/types/client/components/edaha-file-browser/index.d.ts +203 -0
  19. package/dist/types/client/components/edaha-markdown/index.d.ts +70 -0
  20. package/dist/types/client/components/edaha-metadata-field/index.d.ts +100 -0
  21. package/dist/types/client/components/edaha-richtext/index.d.ts +88 -0
  22. package/dist/types/client/components/edaha-toasts/index.d.ts +47 -0
  23. package/dist/types/client/dates/index.d.ts +14 -0
  24. package/dist/types/client/editorApi/index.d.ts +129 -0
  25. package/dist/types/client/embeds/index.d.ts +74 -0
  26. package/dist/types/client/icons/index.d.ts +60 -0
  27. package/dist/types/client/index.d.ts +2 -0
  28. package/dist/types/client/markdown/index.d.ts +163 -0
  29. package/dist/types/client/metadataForm/index.d.ts +77 -0
  30. package/dist/types/client/narrow/index.d.ts +21 -0
  31. package/dist/types/client/richtext/editor/index.d.ts +34 -0
  32. package/dist/types/client/richtext/extensions/index.d.ts +90 -0
  33. package/dist/types/client/sortTable/index.d.ts +24 -0
  34. package/dist/types/client/theme/index.d.ts +48 -0
  35. package/dist/types/server/types/index.d.ts +251 -0
  36. package/package.json +15 -10
  37. package/dist/client/assets/index-D2Y17Fm-.css +0 -1
@@ -0,0 +1,4037 @@
1
+ import { LitElement as e, html as t, nothing as n, render as r, unsafeCSS as i } from "lit";
2
+ import { classMap as a } from "lit/directives/class-map.js";
3
+ import { keyed as o } from "lit/directives/keyed.js";
4
+ import { unsafeHTML as s } from "lit/directives/unsafe-html.js";
5
+ import { styleMap as c } from "lit/directives/style-map.js";
6
+ import { headingIds as l, slugify as u } from "@lvl99dotcom/edaha.md/generator/slug";
7
+ import { live as d } from "lit/directives/live.js";
8
+ import { EMBED_BLOCK as f, embedBlock as p, embedOptionsOf as ee, embedText as te, splitEmbed as ne } from "@lvl99dotcom/edaha.md/embeds/blocks";
9
+ import { Editor as re, Extension as ie, Mark as m, Node as h, isTextSelection as ae } from "@tiptap/core";
10
+ import oe from "@tiptap/extension-bubble-menu";
11
+ import { Details as se, DetailsContent as ce, DetailsSummary as le } from "@tiptap/extension-details";
12
+ import ue from "@tiptap/extension-image";
13
+ import { TableKit as de } from "@tiptap/extension-table";
14
+ import fe from "@tiptap/starter-kit";
15
+ import { NodeSelection as pe, Plugin as me, PluginKey as he, TextSelection as ge } from "@tiptap/pm/state";
16
+ import { Decoration as _e, DecorationSet as ve } from "@tiptap/pm/view";
17
+ import { repeat as ye } from "lit/directives/repeat.js";
18
+ import { resolveFields as be } from "@lvl99dotcom/edaha.md/generator/fields";
19
+ import { MetadataValidator as xe, fieldKind as Se, fieldOptions as g, hasFieldKind as Ce, typeMetadataKeys as we } from "@lvl99dotcom/edaha.md/generator/metadata";
20
+ import { BUILT_IN_GROUPS as Te } from "@lvl99dotcom/edaha.md/generator/metadataGroups";
21
+ // src/client/icons/index.ts
22
+ var Ee = {
23
+ add_column_right: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"48\" height=\"48\" viewBox=\"0 -960 960 960\"><path d=\"M140-780v600h269v-600H140ZM80-120v-720h720v150h-60v-90H469v600h271v-90h60v150H80Zm389-360Zm-60 0h60-60Zm0 0Zm331 110v-80h-80v-60h80v-80h60v80h80v60h-80v80h-60Z\"/></svg>",
24
+ add_photo_alternate: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"48\" height=\"48\" viewBox=\"0 -960 960 960\"><path d=\"M480-480ZM180-120q-24 0-42-18t-18-42v-600q0-24 18-42t42-18h365v60H180v600h600v-365h60v365q0 24-18 42t-42 18H180Zm60-162h480L576-474 449-307l-94-124-115 149Zm453-323v-87h-88v-60h88v-88h60v88h87v60h-87v87h-60Z\"/></svg>",
25
+ add_row_below: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"48\" height=\"48\" viewBox=\"0 -960 960 960\"><path d=\"M180-551h600v-269H180v269Zm-60 391v-720h720v720H690v-60h90v-271H180v271h90v60H120Zm360-331Zm0-60v60-60Zm0 0ZM450-80v-80h-80v-60h80v-80h60v80h80v60h-80v80h-60Z\"/></svg>",
26
+ close: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"48\" height=\"48\" viewBox=\"0 -960 960 960\"><path d=\"m249-207-42-42 231-231-231-231 42-42 231 231 231-231 42 42-231 231 231 231-42 42-231-231-231 231Z\"/></svg>",
27
+ content_copy: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"48\" height=\"48\" viewBox=\"0 -960 960 960\"><path d=\"M300-200q-24 0-42-18t-18-42v-560q0-24 18-42t42-18h440q24 0 42 18t18 42v560q0 24-18 42t-42 18H300Zm0-60h440v-560H300v560ZM180-80q-24 0-42-18t-18-42v-620h60v620h500v60H180Zm120-180v-560 560Z\"/></svg>",
28
+ delete: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"48\" height=\"48\" viewBox=\"0 -960 960 960\"><path d=\"M261-120q-24.75 0-42.37-17.63Q201-155.25 201-180v-570h-41v-60h188v-30h264v30h188v60h-41v570q0 24-18 42t-42 18H261Zm438-630H261v570h438v-570ZM367-266h60v-399h-60v399Zm166 0h60v-399h-60v399ZM261-750v570-570Z\"/></svg>",
29
+ find_replace: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"48\" height=\"48\" viewBox=\"0 -960 960 960\"><path d=\"M164-572q17-100 95.5-164T440-800q65 0 121.5 30t98.5 81v-111h60v228H492v-60h134q-32-48-80.5-78T440-740q-77 0-137.5 46.5T225-572h-61Zm633 452L613-304q-37 31-81 47t-92 16q-65 0-122.5-27T220-346v106h-60v-228h228v60H249q33 48 83 77.5T440-301q75 0 133.5-47T651-468h61q-5 34-19.5 64.5T656-347l184 184-43 43Z\"/></svg>",
30
+ folder_open: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"48\" height=\"48\" viewBox=\"0 -960 960 960\"><path d=\"M140-160q-23 0-41.5-18.5T80-220v-520q0-23 18.5-41.5T140-800h281l60 60h339q23 0 41.5 18.5T880-680H455l-60-60H140v520l102-400h698L833-206q-6 24-22 35t-41 11H140Zm63-60h572l84-340H287l-84 340Zm0 0 84-340-84 340Zm-63-460v-60 60Z\"/></svg>",
31
+ code_blocks: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"48\" height=\"48\" viewBox=\"0 -960 960 960\"><path d=\"m379-343 44-44-93-93 92-92-44-44-136 136 137 137Zm202 0 137-137-137-137-44 44 93 93-93 93 44 44ZM180-120q-24 0-42-18t-18-42v-600q0-24 18-42t42-18h600q24 0 42 18t18 42v600q0 24-18 42t-42 18H180Zm0-60h600v-600H180v600Zm0-600v600-600Z\"/></svg>",
32
+ delete_sweep: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"48\" height=\"48\" viewBox=\"0 -960 960 960\"><path d=\"M600-230v-60h145v60H600Zm0-368v-60h280v60H600Zm0 184v-60h235v60H600ZM125-675H80v-60h170v-45h135v45h170v60h-45v415q0 24-18 42t-42 18H185q-24 0-42-18t-18-42v-415Zm60 0v415h265v-415H185Zm0 0v415-415Z\"/></svg>",
33
+ expand_circle_down: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"48\" height=\"48\" viewBox=\"0 -960 960 960\"><path d=\"m480-351 173-173-43-42-130 130-130-130-43 42 173 173Zm0 271q-82 0-155-31.5t-127.5-86Q143-252 111.5-325T80-480q0-83 31.5-156t86-127Q252-817 325-848.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 82-31.5 155T763-197.5q-54 54.5-127 86T480-80Zm0-60q142 0 241-99.5T820-480q0-142-99-241t-241-99q-141 0-240.5 99T140-480q0 141 99.5 240.5T480-140Zm0-340Z\"/></svg>",
34
+ format_bold: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"48\" height=\"48\" viewBox=\"0 -960 960 960\"><path d=\"M275-200v-560h228q66 0 114.5 42T666-612q0 38-21 70t-56 49v6q43 14 69.5 50t26.5 81q0 68-52.5 112T510-200H275Zm86-76h144q38 0 66-25t28-63q0-37-28-62t-66-25H361v175Zm0-247h136q35 0 60.5-23t25.5-58q0-35-25.5-58.5T497-686H361v163Z\"/></svg>",
35
+ format_h1: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"48\" height=\"48\" viewBox=\"0 -960 960 960\"><path d=\"M200-280v-400h60v170h180v-170h60v400h-60v-170H260v170h-60Zm500 0v-340h-80v-60h140v400h-60Z\"/></svg>",
36
+ format_h2: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"48\" height=\"48\" viewBox=\"0 -960 960 960\"><path d=\"M120-280v-400h60v170h180v-170h60v400h-60v-170H180v170h-60Zm420 0v-170q0-24.75 17.63-42.38Q575.25-510 600-510h180v-110H540v-60h240q25 0 42.5 17.62Q840-644.75 840-620v110q0 24.75-17.62 42.37Q804.75-450 780-450H600v110h240v60H540Z\"/></svg>",
37
+ format_h3: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"48\" height=\"48\" viewBox=\"0 -960 960 960\"><path d=\"M120-280v-400h60v170h180v-170h60v400h-60v-170H180v170h-60Zm420 0v-60h240v-110H620v-60h160v-110H540v-60h240q25 0 42.5 17.62Q840-644.75 840-620v280q0 24.75-17.62 42.37Q804.75-280 780-280H540Z\"/></svg>",
38
+ format_italic: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"48\" height=\"48\" viewBox=\"0 -960 960 960\"><path d=\"M224-199v-80h134l139-409H338v-80h380v80H584L445-279h159v80H224Z\"/></svg>",
39
+ format_list_bulleted: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"48\" height=\"48\" viewBox=\"0 -960 960 960\"><path d=\"M377-198v-60h463v60H377Zm0-252v-60h463v60H377Zm0-253v-60h463v60H377ZM189-161q-28.05 0-48.02-19Q121-199 121-227.5t19.5-48q19.5-19.5 48-19.5t47.5 19.98q19 19.97 19 48.02 0 27.23-19.39 46.61Q216.23-161 189-161Zm0-252q-28.05 0-48.02-19.5Q121-452 121-480t19.98-47.5Q160.95-547 189-547q27.23 0 46.61 19.5Q255-508 255-480t-19.39 47.5Q216.23-413 189-413Zm-48.5-272.5Q121-705 121-733t19.5-47.5Q160-800 188-800t47.5 19.5Q255-761 255-733t-19.5 47.5Q216-666 188-666t-47.5-19.5Z\"/></svg>",
40
+ format_list_numbered: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"48\" height=\"48\" viewBox=\"0 -960 960 960\"><path d=\"M120-80v-60h100v-30h-60v-60h60v-30H120v-60h120q17 0 28.5 11.5T280-280v40q0 17-11.5 28.5T240-200q17 0 28.5 11.5T280-160v40q0 17-11.5 28.5T240-80H120Zm0-280v-110q0-17 11.5-28.5T160-510h60v-30H120v-60h120q17 0 28.5 11.5T280-560v70q0 17-11.5 28.5T240-450h-60v30h100v60H120Zm60-280v-180h-60v-60h120v240h-60Zm189 431v-60h471v60H369Zm0-243v-60h471v60H369Zm0-243v-60h471v60H369Z\"/></svg>",
41
+ format_quote: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"48\" height=\"48\" viewBox=\"0 -960 960 960\"><path d=\"m248-240 94-162q-5 1-11 1.5t-11 .5q-66 0-113-47t-47-113q0-66 47-113t113-47q66 0 113 47t47 113q0 21-5.5 41T458-480L320-240h-72Zm360 0 94-162q-5 1-11 1.5t-11 .5q-66 0-113-47t-47-113q0-66 47-113t113-47q66 0 113 47t47 113q0 21-5.5 41T818-480L680-240h-72ZM376.5-503.5Q400-527 400-560t-23.5-56.5Q353-640 320-640t-56.5 23.5Q240-593 240-560t23.5 56.5Q287-480 320-480t56.5-23.5Zm360 0Q760-527 760-560t-23.5-56.5Q713-640 680-640t-56.5 23.5Q600-593 600-560t23.5 56.5Q647-480 680-480t56.5-23.5ZM680-560Zm-360 0Z\"/></svg>",
42
+ format_underlined: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"48\" height=\"48\" viewBox=\"0 -960 960 960\"><path d=\"M200-140v-60h560v60H200Zm123.5-198.5Q267-397 267-497v-343h83v343q0 63 34 101t96 38q62 0 96-38t34-101v-343h83v343q0 100-56.5 158.5T480-280q-100 0-156.5-58.5Z\"/></svg>",
43
+ fullscreen: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"48\" height=\"48\" viewBox=\"0 -960 960 960\"><path d=\"M120-120v-193h60v133h133v60H120Zm527 0v-60h133v-133h60v193H647ZM120-647v-193h193v60H180v133h-60Zm660 0v-133H647v-60h193v193h-60Z\"/></svg>",
44
+ fullscreen_exit: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"48\" height=\"48\" viewBox=\"0 -960 960 960\"><path d=\"M253-120v-133H120v-60h193v193h-60Zm394 0v-193h193v60H707v133h-60ZM120-647v-60h133v-133h60v193H120Zm527 0v-193h60v133h133v60H647Z\"/></svg>",
45
+ image: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"48\" height=\"48\" viewBox=\"0 -960 960 960\"><path d=\"M180-120q-24 0-42-18t-18-42v-600q0-24 18-42t42-18h600q24 0 42 18t18 42v600q0 24-18 42t-42 18H180Zm0-60h600v-600H180v600Zm56-97h489L578-473 446-302l-93-127-117 152Zm-56 97v-600 600Z\"/></svg>",
46
+ link: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"48\" height=\"48\" viewBox=\"0 -960 960 960\"><path d=\"M450-280H280q-83 0-141.5-58.5T80-480q0-83 58.5-141.5T280-680h170v60H280q-58.33 0-99.17 40.76-40.83 40.77-40.83 99Q140-422 180.83-381q40.84 41 99.17 41h170v60ZM325-450v-60h310v60H325Zm185 170v-60h170q58.33 0 99.17-40.76 40.83-40.77 40.83-99Q820-538 779.17-579q-40.84-41-99.17-41H510v-60h170q83 0 141.5 58.5T880-480q0 83-58.5 141.5T680-280H510Z\"/></svg>",
47
+ manage_search: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"48\" height=\"48\" viewBox=\"0 -960 960 960\"><path d=\"M80-200v-60h400v60H80Zm0-210v-60h200v60H80Zm0-210v-60h200v60H80Zm758 420L678-360q-26 20-56 30t-62 10q-83 0-141.5-58.5T360-520q0-83 58.5-141.5T560-720q83 0 141.5 58.5T760-520q0 32-10 62t-30 56l160 160-42 42ZM559.76-380Q618-380 659-420.76q41-40.77 41-99Q700-578 659.24-619q-40.77-41-99-41Q502-660 461-619.24q-41 40.77-41 99Q420-462 460.76-421q40.77 41 99 41Z\"/></svg>",
48
+ menu: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"48\" height=\"48\" viewBox=\"0 -960 960 960\"><path d=\"M120-240v-60h720v60H120Zm0-210v-60h720v60H120Zm0-210v-60h720v60H120Z\"/></svg>",
49
+ playlist_remove: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"48\" height=\"48\" viewBox=\"0 -960 960 960\"><path d=\"m571-80-43-43 114-113-114-113 43-43 113 114 113-114 43 43-114 113 114 113-43 43-113-114L571-80ZM120-330v-60h300v60H120Zm0-165v-60h470v60H120Zm0-165v-60h470v60H120Z\"/></svg>",
50
+ raw_on: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"48\" height=\"48\" viewBox=\"0 -960 960 960\"><path d=\"M120-360v-240h144q23 0 35.5 12.5T312-552v63q0 20-12 30.5T271-446l37 86h-50l-32-81h-58v81h-48Zm226 0 66-240h84l70 240h-54l-18-61h-82l-15 61h-51Zm290 0-61-240h49l37 142 34-142h45l37 142 33-142h50l-58 240h-50l-33-131-37 131h-46ZM426-469h53l-18-67h-17l-18 67Zm-258-20h96v-63h-96v63Z\"/></svg>",
51
+ read_more: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"48\" height=\"48\" viewBox=\"0 -960 960 960\"><path d=\"m288-276-42-42 131-132H80v-60h297L246-642l42-42 204 204-204 204Zm252-34v-60h340v60H540Zm0-280v-60h340v60H540Zm120 140v-60h220v60H660Z\"/></svg>",
52
+ smart_display: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"48\" height=\"48\" viewBox=\"0 -960 960 960\"><path d=\"m392-313 260-169-260-169v338ZM140-160q-24 0-42-18t-18-42v-520q0-24 18-42t42-18h680q24 0 42 18t18 42v520q0 24-18 42t-42 18H140Zm0-60h680v-520H140v520Zm0 0v-520 520Z\"/></svg>",
53
+ strikethrough_s: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"48\" height=\"48\" viewBox=\"0 -960 960 960\"><path d=\"M504-160q-78 0-142-41.5T269-313l69-29q20 48 65 77t101 29q52 0 83-27t31-73q0-23-9.5-48.5T582-430h84q14 23 21 46t7 48q0 78-53 127t-137 49ZM80-490v-60h800v60H80Zm394-316q66 0 117 31t75 86l-69 31q-14-34-46.5-53T474-730q-49 0-79 24t-30 66q0 8 1 15t3 15h-74q-2-8-3-16t-1-16q0-73 51-118.5T474-806Z\"/></svg>",
54
+ table: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"48\" height=\"48\" viewBox=\"0 -960 960 960\"><path d=\"M180-120q-24 0-42-18t-18-42v-600q0-24 18-42t42-18h600q24 0 42 18t18 42v600q0 24-18 42t-42 18H180Zm270-250H180v190h270v-190Zm60 0v190h270v-190H510Zm-60-60v-190H180v190h270Zm60 0h270v-190H510v190ZM180-680h600v-100H180v100Z\"/></svg>",
55
+ text_decrease: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"48\" height=\"48\" viewBox=\"0 -960 960 960\"><path d=\"m40-200 220-560h80l220 560h-75l-57-150H172l-57 150H40Zm156-214h208L302-685h-4L196-414Zm414-36v-60h310v60H610Z\"/></svg>",
56
+ text_increase: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"48\" height=\"48\" viewBox=\"0 -960 960 960\"><path d=\"m40-200 220-560h80l220 560h-75l-57-150H172l-57 150H40Zm156-214h208L302-685h-4L196-414Zm534 94v-130H600v-60h130v-130h60v130h130v60H790v130h-60Z\"/></svg>"
57
+ }, De = {
58
+ Bold: "format_bold",
59
+ Italic: "format_italic",
60
+ Underline: "format_underlined",
61
+ Strikethrough: "strikethrough_s",
62
+ Small: "text_decrease",
63
+ Big: "text_increase",
64
+ Link: "link",
65
+ Heading: "format_h2",
66
+ Subheading: "format_h3",
67
+ "Heading 1": "format_h1",
68
+ "Heading 2": "format_h2",
69
+ "Heading 3": "format_h3",
70
+ "Bullet list": "format_list_bulleted",
71
+ "Numbered list": "format_list_numbered",
72
+ Quote: "format_quote",
73
+ Code: "code_blocks",
74
+ Details: "expand_circle_down",
75
+ "Image URL": "image",
76
+ Table: "table",
77
+ "Add row": "add_row_below",
78
+ "Add column": "add_column_right",
79
+ "Remove row": "playlist_remove",
80
+ "Remove column": "playlist_remove",
81
+ "Remove table": "delete_sweep",
82
+ Embed: "smart_display",
83
+ Raw: "raw_on",
84
+ "Read more": "read_more",
85
+ "Upload image": "add_photo_alternate",
86
+ "Choose file": "folder_open"
87
+ }, _ = (e) => t`<span class="icon icon-${e}" aria-hidden="true"
88
+ >${s(Ee[e])}</span
89
+ >`, v = (e) => {
90
+ let n = De[e];
91
+ return n ? t`${_(n)}<span class="visually-hidden">${e}</span>` : e;
92
+ }, Oe = (e, t) => e.find((e) => e.key === t)?.name ?? (t ? `Unknown embed "${t}"` : "Embed without a kind"), ke = (e) => e?.icon ? t`<span class="icon embed-icon" aria-hidden="true"
93
+ >${s(e.icon)}</span
94
+ >` : "", Ae = (e, { pressed: n, disabled: r, onClick: i }) => t`<button
95
+ type="button"
96
+ class="toolbar-button toolbar-embed"
97
+ data-embed=${e.key}
98
+ title=${e.name}
99
+ aria-pressed=${String(n)}
100
+ ?disabled=${r}
101
+ @click=${i}
102
+ >
103
+ ${e.icon ? ke(e) : _("smart_display")}<span
104
+ class="visually-hidden"
105
+ >${e.name}</span
106
+ >
107
+ </button>`, je = (e, t = window.location) => {
108
+ if (!e) return e;
109
+ let n = new URL(e, t.href);
110
+ return n.hostname === "127.0.0.1" ? (n.hostname = "localhost", n.href) : e;
111
+ }, y = class extends Error {
112
+ problems;
113
+ constructor(e, t) {
114
+ super(e), this.problems = t;
115
+ }
116
+ }, Me = (e) => {
117
+ let t = new URLSearchParams(Object.entries(e).filter(([, e]) => e !== void 0 && e !== "").map(([e, t]) => [e, String(t)]));
118
+ return t.size ? `?${t}` : "";
119
+ }, b = ({ type: e, slug: t, name: n }) => `/api/files/${e}/${t}/${encodeURIComponent(n)}`, Ne = class {
120
+ fetch;
121
+ baseUrl;
122
+ constructor(e = {}) {
123
+ let t = typeof e == "function" ? { fetch: e } : e, n = (...e) => fetch(...e), { baseUrl: r = "", fetch: i = n } = t;
124
+ this.baseUrl = r.replace(/\/+$/, ""), this.fetch = i;
125
+ }
126
+ url(e) {
127
+ return /^\/(?!\/)/.test(e) ? `${this.baseUrl}${e}` : e;
128
+ }
129
+ previewUrl(e) {
130
+ return je(this.url(e));
131
+ }
132
+ async request(e, t) {
133
+ let n = await this.fetch(this.url(e), t);
134
+ if (n.status === 204) return;
135
+ let r = await n.json().catch(() => ({}));
136
+ if (!n.ok) throw new y(r.error ?? `Request failed with ${n.status}`, r.problems);
137
+ return r;
138
+ }
139
+ send(e, t, n) {
140
+ return this.request(t, {
141
+ method: e,
142
+ headers: { "Content-Type": "application/json" },
143
+ body: JSON.stringify(n)
144
+ });
145
+ }
146
+ query(e = {}) {
147
+ return this.request(`/api/articles${Me(e)}`);
148
+ }
149
+ queryFiles(e = {}) {
150
+ return this.request(`/api/files${Me(e)}`);
151
+ }
152
+ fileFilters() {
153
+ return this.request("/api/files/filters");
154
+ }
155
+ fileReferences(e) {
156
+ return this.request(`${b(e)}/references`);
157
+ }
158
+ replaceFile(e, t) {
159
+ let n = new FormData();
160
+ return n.append("file", t), this.request(b(e), {
161
+ method: "PUT",
162
+ body: n
163
+ });
164
+ }
165
+ deleteFile(e) {
166
+ return this.request(b(e), { method: "DELETE" });
167
+ }
168
+ recent() {
169
+ return this.request("/api/articles/recent");
170
+ }
171
+ filters() {
172
+ return this.request("/api/articles/filters");
173
+ }
174
+ metadata() {
175
+ return this.request("/api/metadata");
176
+ }
177
+ site() {
178
+ return this.request("/api/site");
179
+ }
180
+ types() {
181
+ return this.request("/api/types");
182
+ }
183
+ templates(e) {
184
+ return this.request(`/api/templates/${e}`);
185
+ }
186
+ read({ type: e, slug: t }) {
187
+ return this.request(`/api/articles/${e}/${t}`);
188
+ }
189
+ create(e) {
190
+ return this.send("POST", "/api/articles", e);
191
+ }
192
+ save(e, t) {
193
+ return this.send("PUT", `/api/articles/${e.type}/${e.slug}`, t);
194
+ }
195
+ remove({ type: e, slug: t }) {
196
+ return this.request(`/api/articles/${e}/${t}`, { method: "DELETE" });
197
+ }
198
+ embeds() {
199
+ return this.request("/api/embeds");
200
+ }
201
+ async validateEmbed(e, t, n = {}) {
202
+ return (await this.send("POST", "/api/embed-validations", {
203
+ key: e,
204
+ content: t,
205
+ options: n
206
+ })).errors;
207
+ }
208
+ embedFrame(e, t, n = {}) {
209
+ return this.send("POST", "/api/embed-frames", {
210
+ key: e,
211
+ content: t,
212
+ options: n
213
+ });
214
+ }
215
+ async toMarkdown(e, t) {
216
+ return (await this.send("POST", "/api/convert/markdown", {
217
+ html: e,
218
+ location: t
219
+ })).markdown;
220
+ }
221
+ async toHtml(e, t) {
222
+ return (await this.send("POST", "/api/convert/html", {
223
+ markdown: e,
224
+ location: t
225
+ })).html;
226
+ }
227
+ async preview(e, t) {
228
+ return (await this.send("POST", "/api/preview", {
229
+ data: e,
230
+ location: t
231
+ })).url;
232
+ }
233
+ upload({ type: e, slug: t }, n) {
234
+ let r = new FormData();
235
+ return r.append("file", n), this.request(`/api/articles/${e}/${t}/files`, {
236
+ method: "POST",
237
+ body: r
238
+ });
239
+ }
240
+ }, x = (e, t) => {
241
+ customElements.get(e) || customElements.define(e, t);
242
+ }, S = (e) => String(e).padStart(2, "0"), Pe = (e) => {
243
+ let t = new Date(e);
244
+ return `${t.getFullYear()}-${S(t.getMonth() + 1)}-${S(t.getDate())}T${S(t.getHours())}:${S(t.getMinutes())}`;
245
+ }, Fe = (e) => {
246
+ let t = new Date(e);
247
+ return e && !Number.isNaN(t.getTime()) ? t.toISOString() : "";
248
+ }, Ie = "<!-- readmore -->", C = /^\[([^\]]*)\]\(([^)\s]*)\)$/, Le = RegExp(`^${f.source}$`), Re = /^([-*+]|\d+[.)]) /, ze = /^#{1,6} /, Be = /^:?-+:?$/, Ve = (e, t) => {
249
+ let n = 0, r = Math.min(e.length, t.length);
250
+ for (; n < r && e[n] === t[n];) n++;
251
+ let i = 0;
252
+ for (; i < r - n && e[e.length - 1 - i] === t[t.length - 1 - i];) i++;
253
+ return {
254
+ start: n,
255
+ end: e.length - i,
256
+ text: t.slice(n, t.length - i)
257
+ };
258
+ }, w = (e, t, n, r, i = 0, a = r.length) => ({
259
+ value: e.slice(0, t) + r + e.slice(n),
260
+ start: t + i,
261
+ end: t + a
262
+ }), He = ({ value: e, start: t, end: n }) => {
263
+ let r = e.lastIndexOf("\n", t - 1) + 1, i = n > t && e[n - 1] === "\n", a = e.indexOf("\n", i ? n - 1 : n);
264
+ return [r, a === -1 ? e.length : a];
265
+ }, T = (e, t, n, r = "text") => {
266
+ let { value: i, start: a, end: o } = e, s = i.slice(a, o);
267
+ if (s.length >= t.length + n.length && s.startsWith(t) && s.endsWith(n)) return w(i, a, o, s.slice(t.length, s.length - n.length));
268
+ if (i.slice(a - t.length, a) === t && i.slice(o, o + n.length) === n) return w(i, a - t.length, o + n.length, s);
269
+ let c = s || r;
270
+ return w(i, a, o, t + c + n, t.length, t.length + c.length);
271
+ }, E = (e, t, n, r) => {
272
+ let [i, a] = He(e), o = e.value.slice(i, a).split("\n"), s = o.filter((e) => e.trim()), c = s.length > 0 && s.every((e) => t.test(e)), l = 0, u = o.map((e) => !e.trim() && s.length ? e : c ? e.replace(t, "") : n(l++) + (r ? e.replace(r, "") : e)).join("\n");
273
+ return e.start === e.end && o.length === 1 ? w(e.value, i, a, u, u.length) : w(e.value, i, a, u);
274
+ }, D = (e, t, n) => {
275
+ let [r, i] = He(e), a = e.value.slice(r, i);
276
+ return a.length >= t.length + n.length + 2 && a.startsWith(`${t}\n`) && a.endsWith(`\n${n}`) ? w(e.value, r, i, a.slice(t.length + 1, a.length - n.length - 1)) : w(e.value, r, i, `${t}\n${a}\n${n}`, t.length + 1, t.length + 1 + a.length);
277
+ }, O = ({ value: e, start: t, end: n }, r, i = 0, a = r.length) => {
278
+ let o = e.slice(0, t), s = e.slice(n), c = !o || o.endsWith("\n\n") ? "" : o.endsWith("\n") ? "\n" : "\n\n", l = !s || s.startsWith("\n\n") ? "" : s.startsWith("\n") ? "\n" : "\n\n";
279
+ return w(e, t, n, c + r + l, c.length + i, c.length + a);
280
+ }, k = ({ value: e, start: t, end: n }, r) => w(e, t, n, r, r.length), Ue = ({ value: e, start: t, end: n }) => C.exec(e.slice(t, n))?.[2], We = (e, t) => {
281
+ let { value: n, start: r, end: i } = e, a = n.slice(r, i), o = C.exec(a);
282
+ if (!t) return o ? w(n, r, i, o[1]) : void 0;
283
+ let s = o ? o[1] : a || t;
284
+ return w(n, r, i, `[${s}](${t})`, 1, 1 + s.length);
285
+ }, Ge = (e, t, n, r) => r ? k(e, `![](${t})`) : e.start === e.end ? k(e, `[${n}](${t})`) : We(e, t), A = ({ value: e, start: t, end: n }) => {
286
+ let r = Le.exec(e.slice(t, n));
287
+ if (!r) return;
288
+ let { content: i, options: a } = ne(r[2]);
289
+ return {
290
+ key: r[1] ?? "",
291
+ content: i,
292
+ options: a
293
+ };
294
+ }, Ke = (e, t) => {
295
+ let n = p(t.key, t.content, t.options);
296
+ return A(e) ? w(e.value, e.start, e.end, n) : O(e, n);
297
+ }, qe = (e, t) => O({
298
+ ...e,
299
+ start: e.end
300
+ }, p(t.key, t.content, t.options)), Je = (e) => e.value.slice(e.start, e.end).trim() === "<!-- readmore -->" ? w(e.value, e.start, e.end, "") : O(e, Ie, 17, 17), Ye = (e) => e.trim().replace(/^\|/, "").replace(/(?<!\\)\|$/, "").split(/(?<!\\)\|/).map((e) => e.trim()), j = (e) => e.map((e) => `| ${e.join(" | ")} |`).join("\n"), M = ({ value: e, start: t }) => {
301
+ let n = e.split("\n"), r = e.slice(0, t).split("\n").length - 1, i = e.lastIndexOf("\n", t - 1) + 1, a = (e) => n[e]?.trim().startsWith("|");
302
+ if (!a(r)) return;
303
+ let o = r;
304
+ for (; o > 0 && a(o - 1);) o--;
305
+ let s = r;
306
+ for (; a(s + 1);) s++;
307
+ let c = n.slice(o, s + 1).map(Ye);
308
+ if (c.length < 2 || !c[1].every((e) => Be.test(e))) return;
309
+ let l = n.slice(0, o).join("\n").length + +!!o, u = l + n.slice(o, s + 1).join("\n").length, d = e.slice(i, t).trim().split(/(?<!\\)\|/).length - 1, f = c[0].length;
310
+ return {
311
+ from: l,
312
+ to: u,
313
+ rows: c,
314
+ row: r - o,
315
+ column: Math.min(Math.max(d - 1, 0), f - 1)
316
+ };
317
+ }, N = (e, { from: t, to: n }, r, i, a) => {
318
+ let o = j(r), s = j(r.slice(0, i)).length + +!!i, c = r[i], l = 2 + c.slice(0, a).reduce((e, t) => e + t.length + 3, 0) + c[a].length;
319
+ return w(e, t, n, o, s + l, s + l);
320
+ }, Xe = 3, Ze = (e) => {
321
+ let t = (e) => Array(Xe).fill(e);
322
+ return O(e, j([
323
+ t("Header"),
324
+ t("---"),
325
+ ...Array.from({ length: 2 }, () => t(""))
326
+ ]), 2, 8);
327
+ }, Qe = (e) => {
328
+ let t = M(e);
329
+ if (!t) return;
330
+ let n = Math.max(t.row + 1, 2), r = [...t.rows];
331
+ return r.splice(n, 0, Array(r[0].length).fill("")), N(e.value, t, r, n, 0);
332
+ }, $e = (e) => {
333
+ let t = M(e);
334
+ if (!t) return;
335
+ let n = t.column + 1, r = t.rows.map((e, t) => {
336
+ let r = [...e];
337
+ return r.splice(n, 0, t === 1 ? "---" : ""), r;
338
+ });
339
+ return N(e.value, t, r, t.row, n);
340
+ }, et = (e) => {
341
+ let t = M(e);
342
+ if (!t || t.row < 2) return;
343
+ let n = t.rows.filter((e, n) => n !== t.row);
344
+ return N(e.value, t, n, Math.min(t.row, n.length - 1), t.column);
345
+ }, tt = (e) => {
346
+ let t = M(e);
347
+ if (!t) return;
348
+ if (t.rows[0].length <= 1) return nt(e);
349
+ let n = t.rows.map((e) => e.filter((e, n) => n !== t.column));
350
+ return N(e.value, t, n, t.row, Math.min(t.column, n[0].length - 1));
351
+ }, nt = (e) => {
352
+ let t = M(e);
353
+ return t ? w(e.value, t.from, t.to, "") : void 0;
354
+ }, rt = (e, t) => {
355
+ let n = `${"#".repeat(t)} `;
356
+ return E(e, RegExp(`^${n}`), () => n, ze);
357
+ }, it = (e) => E(e, /^[-*+] /, () => "- ", Re), at = (e) => E(e, /^\d+[.)] /, (e) => `${e + 1}. `, Re), ot = (e) => E(e, /^> ?/, () => "> "), P = (e) => M(e) !== void 0;
358
+ x("edaha-markdown", class extends e {
359
+ static properties = {
360
+ value: { attribute: !1 },
361
+ textareaId: { attribute: !1 },
362
+ uploadImage: { attribute: !1 },
363
+ chooseFile: { attribute: !1 },
364
+ embedTools: { attribute: !1 }
365
+ };
366
+ prompt = (e, t) => window.prompt(e, t);
367
+ constructor() {
368
+ super(), this.value = "", this.textareaId = "";
369
+ }
370
+ createRenderRoot() {
371
+ return this;
372
+ }
373
+ actions = [
374
+ {
375
+ label: "Bold",
376
+ run: (e) => T(e, "**", "**")
377
+ },
378
+ {
379
+ label: "Italic",
380
+ run: (e) => T(e, "_", "_")
381
+ },
382
+ {
383
+ label: "Underline",
384
+ run: (e) => T(e, "<u>", "</u>")
385
+ },
386
+ {
387
+ label: "Strikethrough",
388
+ run: (e) => T(e, "~~", "~~")
389
+ },
390
+ {
391
+ label: "Small",
392
+ run: (e) => T(e, "<small>", "</small>")
393
+ },
394
+ {
395
+ label: "Big",
396
+ run: (e) => T(e, "<big>", "</big>")
397
+ },
398
+ {
399
+ label: "Link",
400
+ run: (e) => {
401
+ let t = this.prompt("Link URL (empty to remove)", Ue(e));
402
+ return t === null ? void 0 : We(e, t.trim());
403
+ }
404
+ },
405
+ {
406
+ label: "Heading",
407
+ run: (e) => rt(e, 2)
408
+ },
409
+ {
410
+ label: "Subheading",
411
+ run: (e) => rt(e, 3)
412
+ },
413
+ {
414
+ label: "Bullet list",
415
+ run: it
416
+ },
417
+ {
418
+ label: "Numbered list",
419
+ run: at
420
+ },
421
+ {
422
+ label: "Quote",
423
+ run: ot
424
+ },
425
+ {
426
+ label: "Code",
427
+ run: (e) => D(e, "```", "```")
428
+ },
429
+ {
430
+ label: "Details",
431
+ run: (e) => D(e, "<details>\n<summary>Summary</summary>\n", "\n</details>")
432
+ },
433
+ {
434
+ label: "Image URL",
435
+ run: (e) => {
436
+ let t = this.prompt("Image URL")?.trim();
437
+ return t ? k(e, `![](${t})`) : void 0;
438
+ }
439
+ },
440
+ {
441
+ label: "Table",
442
+ run: Ze
443
+ },
444
+ {
445
+ label: "Add row",
446
+ run: Qe,
447
+ enabled: P
448
+ },
449
+ {
450
+ label: "Add column",
451
+ run: $e,
452
+ enabled: P
453
+ },
454
+ {
455
+ label: "Remove row",
456
+ run: et,
457
+ enabled: P
458
+ },
459
+ {
460
+ label: "Remove column",
461
+ run: tt,
462
+ enabled: P
463
+ },
464
+ {
465
+ label: "Remove table",
466
+ run: nt,
467
+ enabled: P
468
+ },
469
+ {
470
+ label: "Raw",
471
+ run: (e) => D(e, "<!-- raw -->", "<!-- /raw -->")
472
+ },
473
+ {
474
+ label: "Read more",
475
+ run: Je
476
+ }
477
+ ];
478
+ get textarea() {
479
+ return this.querySelector("textarea");
480
+ }
481
+ get selection() {
482
+ let e = this.textarea;
483
+ return e ? {
484
+ value: e.value,
485
+ start: e.selectionStart,
486
+ end: e.selectionEnd
487
+ } : {
488
+ value: this.value,
489
+ start: 0,
490
+ end: 0
491
+ };
492
+ }
493
+ sync() {
494
+ let e = this.textarea.value;
495
+ e !== this.value && (this.value = e, this.dispatchEvent(new Event("markdown-change", { bubbles: !0 })));
496
+ }
497
+ apply(e) {
498
+ let t = this.textarea;
499
+ if (e && t) {
500
+ if (t.focus(), e.value !== t.value) {
501
+ let { start: n, end: r, text: i } = Ve(t.value, e.value);
502
+ t.setSelectionRange(n, r), typeof document.execCommand == "function" && document.execCommand(i ? "insertText" : "delete", !1, i), t.value !== e.value && (t.value = e.value);
503
+ }
504
+ t.setSelectionRange(e.start, e.end), this.sync(), this.requestUpdate();
505
+ }
506
+ }
507
+ async onImageFile(e) {
508
+ let t = e.target, n = t.files?.[0];
509
+ if (t.value = "", !n || !this.uploadImage) return;
510
+ let r = this.selection;
511
+ try {
512
+ let e = await this.uploadImage(n);
513
+ this.apply(k(r, `![](${e})`));
514
+ } catch {}
515
+ }
516
+ async editEmbed(e, t) {
517
+ let n = A(e), r = n?.key !== t, i = await this.embedTools?.edit(r ? {
518
+ key: t,
519
+ content: "",
520
+ options: {}
521
+ } : n, r);
522
+ i ? this.apply((r ? qe : Ke)(e, i)) : this.textarea?.focus();
523
+ }
524
+ async onChooseFile() {
525
+ let e = this.selection, t = await this.chooseFile?.();
526
+ t && this.apply(Ge(e, t.url, t.name, t.kind === "image"));
527
+ }
528
+ render() {
529
+ let e = this.selection, n = () => this.requestUpdate();
530
+ return t`
531
+ <div
532
+ class="editor-toolbar markdown-toolbar"
533
+ role="toolbar"
534
+ aria-label="Formatting"
535
+ >
536
+ ${this.actions.map((n) => t`<button
537
+ type="button"
538
+ class="toolbar-button"
539
+ data-action=${n.label}
540
+ title=${n.label}
541
+ ?disabled=${n.enabled ? !n.enabled(e) : !1}
542
+ @click=${() => this.apply(n.run(this.selection))}
543
+ >
544
+ ${v(n.label)}
545
+ </button>`)}
546
+ ${this.embedTools?.embeds.map((t) => Ae(t, {
547
+ pressed: A(e)?.key === t.key,
548
+ disabled: !1,
549
+ onClick: () => void this.editEmbed(this.selection, t.key)
550
+ }))}
551
+ <label
552
+ class="toolbar-button toolbar-upload"
553
+ title="Upload image"
554
+ ?data-disabled=${!this.uploadImage}
555
+ >
556
+ ${v("Upload image")}
557
+ <input
558
+ type="file"
559
+ class="visually-hidden"
560
+ accept="image/png, image/jpeg, image/gif, image/webp"
561
+ ?disabled=${!this.uploadImage}
562
+ @change=${(e) => void this.onImageFile(e)}
563
+ />
564
+ </label>
565
+ <button
566
+ type="button"
567
+ class="toolbar-button"
568
+ data-action="Choose file"
569
+ title="Choose file"
570
+ ?disabled=${!this.chooseFile}
571
+ @click=${() => void this.onChooseFile()}
572
+ >
573
+ ${v("Choose file")}
574
+ </button>
575
+ </div>
576
+ <textarea
577
+ id=${this.textareaId}
578
+ .value=${d(this.value)}
579
+ @input=${() => this.sync()}
580
+ @keyup=${n}
581
+ @click=${n}
582
+ @select=${n}
583
+ ></textarea>
584
+ `;
585
+ }
586
+ });
587
+ // src/client/richtext/extensions/index.ts
588
+ var st = "embed-edit", ct = "embed-refresh", F = (e, t, { editor: n, getPos: r }, i = []) => {
589
+ let a = document.createElement("div");
590
+ a.className = e, a.contentEditable = "false";
591
+ let o = document.createElement("div");
592
+ o.className = "block-header";
593
+ let s = document.createElement("span");
594
+ s.textContent = t, o.append(s), a.append(o);
595
+ let c = {
596
+ text: "Remove",
597
+ onClick: (e) => {
598
+ let t = n.state.doc.nodeAt(e);
599
+ n.chain().focus().deleteRange({
600
+ from: e,
601
+ to: e + t.nodeSize
602
+ }).run();
603
+ }
604
+ };
605
+ for (let { text: e, onClick: t } of [...i, c]) {
606
+ let n = document.createElement("button");
607
+ n.type = "button", n.textContent = e, n.addEventListener("click", () => {
608
+ let e = r();
609
+ typeof e == "number" && t(e, a);
610
+ }), o.append(n);
611
+ }
612
+ return {
613
+ view: {
614
+ dom: a,
615
+ stopEvent: (e) => e.target.closest("button") !== null,
616
+ ignoreMutation: () => !0
617
+ },
618
+ dom: a,
619
+ title: s
620
+ };
621
+ }, lt = h.create({
622
+ name: "readmore",
623
+ group: "block",
624
+ atom: !0,
625
+ priority: 1e3,
626
+ parseHTML: () => [{ tag: "hr.readmore" }],
627
+ renderHTML: () => ["hr", {
628
+ class: "readmore",
629
+ title: "Read more"
630
+ }],
631
+ addNodeView: () => (e) => F("readmore-block", "Read more", e).view,
632
+ addCommands() {
633
+ return { setReadmore: () => ({ chain: e, state: t }) => {
634
+ let n = [];
635
+ return t.doc.descendants((e, t) => {
636
+ e.type.name === this.name && n.push(t);
637
+ }), e().command(({ tr: e }) => {
638
+ for (let t of n.reverse()) e.delete(t, t + 1);
639
+ return !0;
640
+ }).insertContent({ type: this.name }).command(({ tr: e }) => {
641
+ let n = 0;
642
+ return e.doc.descendants((e, t) => {
643
+ e.type.name === this.name && (n = t + 1);
644
+ }), e.doc.nodeAt(n)?.isTextblock || e.insert(n, t.schema.nodes.paragraph.create()), e.setSelection(ge.create(e.doc, n + 1)), !0;
645
+ }).run();
646
+ } };
647
+ }
648
+ }), ut = h.create({
649
+ name: "raw",
650
+ group: "block",
651
+ content: "text*",
652
+ marks: "",
653
+ code: !0,
654
+ defining: !0,
655
+ priority: 1e3,
656
+ parseHTML: () => [{
657
+ tag: "pre.raw",
658
+ preserveWhitespace: "full"
659
+ }],
660
+ renderHTML: () => [
661
+ "pre",
662
+ { class: "raw" },
663
+ 0
664
+ ],
665
+ addCommands() {
666
+ return { toggleRaw: () => ({ commands: e }) => e.toggleNode(this.name, "paragraph") };
667
+ }
668
+ }), dt = m.create({
669
+ name: "rawInline",
670
+ code: !0,
671
+ excludes: "_",
672
+ parseHTML: () => [{ tag: "span.raw" }],
673
+ renderHTML: () => [
674
+ "span",
675
+ { class: "raw" },
676
+ 0
677
+ ]
678
+ }), ft = m.create({
679
+ name: "small",
680
+ parseHTML: () => [{ tag: "small" }],
681
+ renderHTML: () => ["small", 0]
682
+ }), pt = m.create({
683
+ name: "big",
684
+ parseHTML: () => [{ tag: "big" }],
685
+ renderHTML: () => ["big", 0]
686
+ }), I = /* @__PURE__ */ new Map();
687
+ addEventListener("message", (e) => {
688
+ let t = e.source && I.get(e.source), n = e.data?.edahaEmbedHeight;
689
+ t && typeof n == "number" && (t.style.height = `${Math.min(Math.max(n, 40), 2e3)}px`);
690
+ });
691
+ var L = (e) => {
692
+ for (let [t, n] of I) e.contains(n) && I.delete(t);
693
+ }, mt = () => document.documentElement.dataset.theme === "dark" || document.documentElement.dataset.theme !== "light" && globalThis.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light", ht = h.create({
694
+ name: "embed",
695
+ group: "block",
696
+ atom: !0,
697
+ addOptions: () => ({ tools: () => void 0 }),
698
+ addAttributes: () => ({
699
+ key: { default: "" },
700
+ content: { default: "" },
701
+ options: { default: {} }
702
+ }),
703
+ parseHTML: () => [{
704
+ tag: "div.embed",
705
+ getAttrs: (e) => ({
706
+ key: e.getAttribute("data-embed") ?? "",
707
+ content: e.getAttribute("data-content") ?? "",
708
+ options: ee(e.getAttribute("data-options"))
709
+ })
710
+ }],
711
+ renderHTML: ({ node: e }) => ["div", {
712
+ class: "embed",
713
+ "data-embed": e.attrs.key,
714
+ "data-content": e.attrs.content,
715
+ "data-options": Object.keys(e.attrs.options).length ? JSON.stringify(e.attrs.options) : null
716
+ }],
717
+ addNodeView() {
718
+ return (e) => {
719
+ let { editor: t } = e, n = F("embed-block", "", e, [{
720
+ text: "Edit",
721
+ onClick: (e, n) => {
722
+ t.commands.setNodeSelection(e), n.dispatchEvent(new Event(st, { bubbles: !0 }));
723
+ }
724
+ }]), r = n.dom.querySelector("button"), i = document.createElement("span");
725
+ i.className = "icon embed-icon", i.setAttribute("aria-hidden", "true"), n.title.before(i);
726
+ let a = document.createElement("div");
727
+ a.className = "embed-preview", n.dom.append(a);
728
+ let o = "", s = e.node.attrs, c = async (e) => {
729
+ let t = `${e.key}\0${JSON.stringify(e.options)}\0${e.content}`;
730
+ if (t === o) return;
731
+ o = t;
732
+ let s = this.options.tools(), c = s?.embeds.find((t) => t.key === e.key);
733
+ n.title.textContent = Oe(s?.embeds ?? [], e.key), i.innerHTML = c?.icon ?? "", r.hidden = !c, L(a), a.replaceChildren();
734
+ let l = document.createElement("pre");
735
+ if (l.className = "embed-content", l.textContent = te(e.content, e.options), !s) a.append(l);
736
+ else {
737
+ a.textContent = "Loading…";
738
+ try {
739
+ let r = await s.loadFrame(e);
740
+ if (o !== t) return;
741
+ a.replaceChildren();
742
+ for (let e of r.warnings) {
743
+ let t = document.createElement("p");
744
+ t.className = "embed-warning", t.textContent = e, a.append(t);
745
+ }
746
+ if (r.errors.length) {
747
+ let e = document.createElement("div");
748
+ e.className = "embed-errors";
749
+ let t = document.createElement("p");
750
+ t.textContent = "This embed isn't valid, so the website leaves it out:";
751
+ let n = document.createElement("ul");
752
+ for (let e of r.errors) {
753
+ let t = document.createElement("li");
754
+ t.textContent = e, n.append(t);
755
+ }
756
+ e.append(t, n), a.append(e);
757
+ }
758
+ if (r.errors.length || r.warnings.length) {
759
+ a.append(l);
760
+ return;
761
+ }
762
+ let i = document.createElement("iframe");
763
+ i.className = "embed-frame", i.title = `${n.title.textContent}: preview`, i.setAttribute("sandbox", "allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox"), i.src = je(`${r.url}?theme=${mt()}`), a.append(i), i.contentWindow && I.set(i.contentWindow, i);
764
+ } catch (e) {
765
+ o === t && (a.textContent = `No preview: ${e.message}`);
766
+ }
767
+ }
768
+ };
769
+ return c(s), n.dom.addEventListener(ct, () => {
770
+ o = "", c(s);
771
+ }), {
772
+ ...n.view,
773
+ update: (e) => e.type === this.type && (s = e.attrs, c(s), !0),
774
+ destroy: () => L(a)
775
+ };
776
+ };
777
+ },
778
+ addCommands() {
779
+ return {
780
+ setEmbed: (e) => ({ commands: t, editor: n }) => n.isActive(this.name) ? t.updateAttributes(this.name, e) : t.insertContent({
781
+ type: this.name,
782
+ attrs: e
783
+ }),
784
+ insertEmbed: (e) => ({ commands: t, state: n }) => n.selection instanceof pe ? t.insertContentAt(n.selection.to, {
785
+ type: this.name,
786
+ attrs: e
787
+ }) : t.insertContent({
788
+ type: this.name,
789
+ attrs: e
790
+ })
791
+ };
792
+ }
793
+ }), gt = ie.create({
794
+ name: "headingIds",
795
+ addProseMirrorPlugins: () => [new me({
796
+ key: new he("headingIds"),
797
+ props: { decorations: (e) => {
798
+ let t = [];
799
+ e.doc.descendants((e, n) => {
800
+ e.type.name === "heading" && t.push({
801
+ pos: n,
802
+ node: e
803
+ });
804
+ });
805
+ let n = l(t.map(({ node: e }) => e.textContent));
806
+ return ve.create(e.doc, t.flatMap(({ pos: e, node: t }, r) => {
807
+ let i = n[r];
808
+ if (!i) return [];
809
+ let a = document.createElement("span");
810
+ return a.className = "heading-id", a.contentEditable = "false", a.textContent = `#${i}`, [_e.widget(e + t.nodeSize - 1, a, {
811
+ side: 1,
812
+ key: i,
813
+ ignoreSelection: !0
814
+ })];
815
+ }));
816
+ } }
817
+ })]
818
+ }), _t = ie.create({
819
+ name: "selectDetails",
820
+ addProseMirrorPlugins: () => [new me({
821
+ key: new he("selectDetails"),
822
+ props: { handleClickOn: (e, t, n, r, i, a) => !a || n.type.name !== "details" ? !1 : (e.dispatch(e.state.tr.setSelection(pe.create(e.state.doc, r))), !0) }
823
+ })]
824
+ }), vt = ue.extend({
825
+ addOptions() {
826
+ return {
827
+ ...this.parent?.(),
828
+ address: (e) => e
829
+ };
830
+ },
831
+ addNodeView() {
832
+ return ({ node: e }) => {
833
+ let t = document.createElement("img"), n = ({ attrs: e }) => {
834
+ t.src = this.options.address(String(e.src));
835
+ for (let n of ["alt", "title"]) e[n] ? t.setAttribute(n, String(e[n])) : t.removeAttribute(n);
836
+ };
837
+ return n(e), {
838
+ dom: t,
839
+ update: (t) => t.type === e.type && (n(t), !0)
840
+ };
841
+ };
842
+ }
843
+ }), yt = (e, t) => {
844
+ let { selection: n, doc: r } = e.state;
845
+ return (e.view.hasFocus() || t.contains(document.activeElement)) && e.isEditable && ae(n) && r.textBetween(n.from, n.to).length > 0 && !e.isActive("codeBlock") && !e.isActive("raw") && !e.isActive("rawInline");
846
+ }, bt = (e, t, n, r = () => void 0, i, a = (e) => e) => new re({
847
+ element: e,
848
+ content: t,
849
+ extensions: [
850
+ fe.configure({
851
+ link: {
852
+ openOnClick: !1,
853
+ autolink: !0
854
+ },
855
+ heading: { levels: [
856
+ 1,
857
+ 2,
858
+ 3,
859
+ 4
860
+ ] }
861
+ }),
862
+ vt.configure({ address: a }),
863
+ de.configure({ table: { resizable: !1 } }),
864
+ se,
865
+ le,
866
+ ce,
867
+ _t,
868
+ ft,
869
+ pt,
870
+ gt,
871
+ lt,
872
+ ut,
873
+ dt,
874
+ ht.configure({ tools: r }),
875
+ ...i ? [oe.configure({
876
+ element: i,
877
+ shouldShow: ({ editor: e }) => yt(e, i)
878
+ })] : []
879
+ ],
880
+ onUpdate: ({ editor: e }) => n(e.getHTML())
881
+ }), R = (e) => ({
882
+ label: `Heading ${e}`,
883
+ run: (t) => t.chain().focus().toggleHeading({ level: e }).run(),
884
+ active: (t) => t.isActive("heading", { level: e })
885
+ }), xt = (e, n) => t`<button
886
+ type="button"
887
+ class="toolbar-button"
888
+ data-action=${e.label}
889
+ title=${e.label}
890
+ ?disabled=${!n || (e.enabled ? !e.enabled(n) : !1)}
891
+ aria-pressed=${n && e.active ? String(e.active(n)) : "false"}
892
+ @click=${() => n && e.run(n)}
893
+ >
894
+ ${v(e.label)}
895
+ </button>`, z = (e) => e.isActive("table");
896
+ x("edaha-richtext", class extends e {
897
+ static properties = {
898
+ value: { attribute: !1 },
899
+ uploadImage: { attribute: !1 },
900
+ chooseFile: { attribute: !1 },
901
+ embedTools: { attribute: !1 },
902
+ fileAddress: { attribute: !1 }
903
+ };
904
+ editor;
905
+ formatMenu;
906
+ prompt = (e, t) => window.prompt(e, t);
907
+ constructor() {
908
+ super(), this.value = "", this.formatMenu = document.createElement("div"), this.formatMenu.className = "editor-toolbar format-menu", this.formatMenu.setAttribute("role", "toolbar"), this.formatMenu.setAttribute("aria-label", "Text format"), this.formatMenu.addEventListener("mousedown", (e) => e.preventDefault()), this.formatMenu.addEventListener("keydown", (e) => {
909
+ e.key === "Escape" && this.editor?.commands.focus();
910
+ });
911
+ }
912
+ createRenderRoot() {
913
+ return this;
914
+ }
915
+ formatActions = [
916
+ {
917
+ label: "Bold",
918
+ run: (e) => e.chain().focus().toggleBold().run(),
919
+ active: (e) => e.isActive("bold")
920
+ },
921
+ {
922
+ label: "Italic",
923
+ run: (e) => e.chain().focus().toggleItalic().run(),
924
+ active: (e) => e.isActive("italic")
925
+ },
926
+ {
927
+ label: "Underline",
928
+ run: (e) => e.chain().focus().toggleUnderline().run(),
929
+ active: (e) => e.isActive("underline")
930
+ },
931
+ {
932
+ label: "Strikethrough",
933
+ run: (e) => e.chain().focus().toggleStrike().run(),
934
+ active: (e) => e.isActive("strike")
935
+ },
936
+ {
937
+ label: "Link",
938
+ run: (e) => this.editLink(e),
939
+ active: (e) => e.isActive("link")
940
+ },
941
+ R(1),
942
+ R(2),
943
+ R(3)
944
+ ];
945
+ actions = [
946
+ {
947
+ label: "Bold",
948
+ run: (e) => e.chain().focus().toggleBold().run(),
949
+ active: (e) => e.isActive("bold")
950
+ },
951
+ {
952
+ label: "Italic",
953
+ run: (e) => e.chain().focus().toggleItalic().run(),
954
+ active: (e) => e.isActive("italic")
955
+ },
956
+ {
957
+ label: "Underline",
958
+ run: (e) => e.chain().focus().toggleUnderline().run(),
959
+ active: (e) => e.isActive("underline")
960
+ },
961
+ {
962
+ label: "Strikethrough",
963
+ run: (e) => e.chain().focus().toggleStrike().run(),
964
+ active: (e) => e.isActive("strike")
965
+ },
966
+ {
967
+ label: "Small",
968
+ run: (e) => e.chain().focus().toggleMark("small").run(),
969
+ active: (e) => e.isActive("small")
970
+ },
971
+ {
972
+ label: "Big",
973
+ run: (e) => e.chain().focus().toggleMark("big").run(),
974
+ active: (e) => e.isActive("big")
975
+ },
976
+ {
977
+ label: "Link",
978
+ run: (e) => this.editLink(e),
979
+ active: (e) => e.isActive("link")
980
+ },
981
+ {
982
+ label: "Heading",
983
+ run: (e) => e.chain().focus().toggleHeading({ level: 2 }).run(),
984
+ active: (e) => e.isActive("heading", { level: 2 })
985
+ },
986
+ {
987
+ label: "Subheading",
988
+ run: (e) => e.chain().focus().toggleHeading({ level: 3 }).run(),
989
+ active: (e) => e.isActive("heading", { level: 3 })
990
+ },
991
+ {
992
+ label: "Bullet list",
993
+ run: (e) => e.chain().focus().toggleBulletList().run(),
994
+ active: (e) => e.isActive("bulletList")
995
+ },
996
+ {
997
+ label: "Numbered list",
998
+ run: (e) => e.chain().focus().toggleOrderedList().run(),
999
+ active: (e) => e.isActive("orderedList")
1000
+ },
1001
+ {
1002
+ label: "Quote",
1003
+ run: (e) => e.chain().focus().toggleBlockquote().run(),
1004
+ active: (e) => e.isActive("blockquote")
1005
+ },
1006
+ {
1007
+ label: "Code",
1008
+ run: (e) => e.chain().focus().toggleCodeBlock().run(),
1009
+ active: (e) => e.isActive("codeBlock")
1010
+ },
1011
+ {
1012
+ label: "Details",
1013
+ run: (e) => e.isActive("details") ? e.chain().focus().unsetDetails().run() : e.chain().focus().setDetails().run(),
1014
+ active: (e) => e.isActive("details")
1015
+ },
1016
+ {
1017
+ label: "Image URL",
1018
+ run: (e) => this.insertImageUrl(e)
1019
+ },
1020
+ {
1021
+ label: "Table",
1022
+ run: (e) => e.chain().focus().insertTable({
1023
+ rows: 3,
1024
+ cols: 3,
1025
+ withHeaderRow: !0
1026
+ }).run(),
1027
+ active: z
1028
+ },
1029
+ {
1030
+ label: "Add row",
1031
+ run: (e) => e.chain().focus().addRowAfter().run(),
1032
+ enabled: z
1033
+ },
1034
+ {
1035
+ label: "Add column",
1036
+ run: (e) => e.chain().focus().addColumnAfter().run(),
1037
+ enabled: z
1038
+ },
1039
+ {
1040
+ label: "Remove row",
1041
+ run: (e) => e.chain().focus().deleteRow().run(),
1042
+ enabled: z
1043
+ },
1044
+ {
1045
+ label: "Remove column",
1046
+ run: (e) => e.chain().focus().deleteColumn().run(),
1047
+ enabled: z
1048
+ },
1049
+ {
1050
+ label: "Remove table",
1051
+ run: (e) => e.chain().focus().deleteTable().run(),
1052
+ enabled: z
1053
+ },
1054
+ {
1055
+ label: "Raw",
1056
+ run: (e) => e.chain().focus().toggleRaw().run(),
1057
+ active: (e) => e.isActive("raw")
1058
+ },
1059
+ {
1060
+ label: "Read more",
1061
+ run: (e) => e.isActive("readmore") ? e.chain().focus().deleteSelection().run() : e.chain().focus().setReadmore().run(),
1062
+ active: (e) => e.isActive("readmore")
1063
+ }
1064
+ ];
1065
+ editLink(e) {
1066
+ let t = this.prompt("Link URL (empty to remove)", e.getAttributes("link").href);
1067
+ t !== null && (t.trim() === "" ? e.chain().focus().unsetLink().run() : e.chain().focus().extendMarkRange("link").setLink({ href: t.trim() }).run());
1068
+ }
1069
+ insertImageUrl(e) {
1070
+ let t = this.prompt("Image URL")?.trim();
1071
+ t && e.chain().focus().setImage({ src: t }).run();
1072
+ }
1073
+ async editEmbed(e, t) {
1074
+ let n = e.isActive("embed") ? e.getAttributes("embed") : void 0, r = t !== void 0 && n?.key !== t, i = r ? {
1075
+ key: t,
1076
+ content: "",
1077
+ options: {}
1078
+ } : n;
1079
+ if (!this.embedTools || !i) return;
1080
+ let a = await this.embedTools.edit(i, r);
1081
+ a ? r ? e.chain().focus().insertEmbed(a).run() : e.chain().focus().setEmbed(a).run() : e.commands.focus();
1082
+ }
1083
+ async onImageFile(e) {
1084
+ let t = e.target, n = t.files?.[0];
1085
+ if (t.value = "", n && this.uploadImage && this.editor) try {
1086
+ let e = await this.uploadImage(n);
1087
+ this.editor.chain().focus().setImage({
1088
+ src: e,
1089
+ alt: ""
1090
+ }).run();
1091
+ } catch {}
1092
+ }
1093
+ insertFile({ url: e, name: t, kind: n }) {
1094
+ let r = this.editor?.chain().focus();
1095
+ r && (n === "image" ? r.setImage({
1096
+ src: e,
1097
+ alt: ""
1098
+ }).run() : this.editor?.state.selection.empty ? r.insertContent({
1099
+ type: "text",
1100
+ text: t,
1101
+ marks: [{
1102
+ type: "link",
1103
+ attrs: { href: e }
1104
+ }]
1105
+ }).run() : r.setLink({ href: e }).run());
1106
+ }
1107
+ async onChooseFile() {
1108
+ let e = await this.chooseFile?.();
1109
+ e && this.insertFile(e);
1110
+ }
1111
+ firstUpdated() {
1112
+ let e = this.querySelector(".richtext-content");
1113
+ this.editor = bt(e, this.value, (e) => {
1114
+ this.value = e, this.dispatchEvent(new Event("richtext-change", { bubbles: !0 })), this.requestUpdate();
1115
+ }, () => this.embedTools, this.formatMenu, (e) => this.fileAddress?.(e) ?? e), e.addEventListener(st, () => {
1116
+ this.editor && this.editEmbed(this.editor);
1117
+ }), this.editor.on("selectionUpdate", () => this.requestUpdate()), this.requestUpdate();
1118
+ }
1119
+ updated(e) {
1120
+ if (r(this.formatActions.map((e) => xt(e, this.editor)), this.formatMenu), e.has("value") && this.editor && this.editor.getHTML() !== this.value && this.editor.commands.setContent(this.value, { emitUpdate: !1 }), e.has("embedTools")) for (let e of this.querySelectorAll(".embed-block")) e.dispatchEvent(new Event(ct));
1121
+ }
1122
+ disconnectedCallback() {
1123
+ super.disconnectedCallback(), this.editor?.destroy(), this.editor = void 0;
1124
+ }
1125
+ render() {
1126
+ let e = this.editor;
1127
+ return t`
1128
+ <div
1129
+ class="editor-toolbar richtext-toolbar"
1130
+ role="toolbar"
1131
+ aria-label="Formatting"
1132
+ >
1133
+ ${this.actions.map((t) => xt(t, e))}
1134
+ ${this.embedTools?.embeds.map((t) => Ae(t, {
1135
+ pressed: !!e?.isActive("embed", { key: t.key }),
1136
+ disabled: !e,
1137
+ onClick: () => e && void this.editEmbed(e, t.key)
1138
+ }))}
1139
+ <label
1140
+ class="toolbar-button toolbar-upload"
1141
+ title="Upload image"
1142
+ ?data-disabled=${!e || !this.uploadImage}
1143
+ >
1144
+ ${v("Upload image")}
1145
+ <input
1146
+ type="file"
1147
+ class="visually-hidden"
1148
+ accept="image/png, image/jpeg, image/gif, image/webp"
1149
+ ?disabled=${!e || !this.uploadImage}
1150
+ @change=${(e) => void this.onImageFile(e)}
1151
+ />
1152
+ </label>
1153
+ <button
1154
+ type="button"
1155
+ class="toolbar-button"
1156
+ data-action="Choose file"
1157
+ title="Choose file"
1158
+ ?disabled=${!e || !this.chooseFile}
1159
+ @click=${() => void this.onChooseFile()}
1160
+ >
1161
+ ${v("Choose file")}
1162
+ </button>
1163
+ </div>
1164
+ <div class="richtext-content"></div>
1165
+ `;
1166
+ }
1167
+ });
1168
+ // src/client/sortTable/index.ts
1169
+ var B = (e, t) => e.sort === t ? e.order === "asc" ? {
1170
+ sort: t,
1171
+ order: "desc"
1172
+ } : {} : {
1173
+ sort: t,
1174
+ order: "asc"
1175
+ }, St = (e, n, r, i) => {
1176
+ let a = r.sort === e ? r.order : void 0, o = B(r, e), s = o.sort ? `Sort by ${n.toLowerCase()}, ${o.order === "asc" ? "ascending" : "descending"}` : "Go back to the default order";
1177
+ return t`<th
1178
+ scope="col"
1179
+ aria-sort=${a ? a === "asc" ? "ascending" : "descending" : "none"}
1180
+ >
1181
+ <button
1182
+ type="button"
1183
+ class="sort-heading"
1184
+ title=${s}
1185
+ @click=${() => i(e)}
1186
+ >
1187
+ ${n}<span class="sort-heading-arrow" aria-hidden="true"
1188
+ >${a === "asc" ? "▲" : a === "desc" ? "▼" : ""}</span
1189
+ >
1190
+ </button>
1191
+ </th>`;
1192
+ }, Ct = [
1193
+ {
1194
+ value: "image",
1195
+ label: "Image"
1196
+ },
1197
+ {
1198
+ value: "document",
1199
+ label: "Document"
1200
+ },
1201
+ {
1202
+ value: "archive",
1203
+ label: "Archive"
1204
+ },
1205
+ {
1206
+ value: "video",
1207
+ label: "Video"
1208
+ },
1209
+ {
1210
+ value: "audio",
1211
+ label: "Audio"
1212
+ },
1213
+ {
1214
+ value: "other",
1215
+ label: "Other"
1216
+ }
1217
+ ], wt = [
1218
+ {
1219
+ sort: "name",
1220
+ label: "Name"
1221
+ },
1222
+ {
1223
+ sort: "kind",
1224
+ label: "Type"
1225
+ },
1226
+ {
1227
+ sort: "size",
1228
+ label: "Size"
1229
+ },
1230
+ {
1231
+ sort: "location",
1232
+ label: "Location"
1233
+ }
1234
+ ], Tt = "files-changed", Et = (e = "") => e && e.split(",").every((e) => e.trim().startsWith("image/")) ? "image" : void 0, Dt = [
1235
+ "B",
1236
+ "KB",
1237
+ "MB",
1238
+ "GB"
1239
+ ], Ot = (e) => {
1240
+ let t = Math.min(Math.max(Math.floor(Math.log(e) / Math.log(1024)), 0), Dt.length - 1), n = e / 1024 ** t;
1241
+ return `${t && n < 10 ? Math.round(n * 10) / 10 : Math.round(n)} ${Dt[t]}`;
1242
+ }, V = (e) => `${e} ${e === 1 ? "article" : "articles"}`;
1243
+ x("edaha-file-browser", class extends e {
1244
+ static properties = {
1245
+ api: { attribute: !1 },
1246
+ types: { attribute: !1 },
1247
+ search: { state: !0 },
1248
+ kind: { state: !0 },
1249
+ type: { state: !0 },
1250
+ sort: { state: !0 },
1251
+ order: { state: !0 },
1252
+ page: { state: !0 },
1253
+ result: { state: !0 },
1254
+ filters: { state: !0 },
1255
+ loading: { state: !0 },
1256
+ message: { state: !0 },
1257
+ error: { state: !0 },
1258
+ picking: { state: !0 }
1259
+ };
1260
+ searchDelay = 250;
1261
+ confirm = (e) => window.confirm(e);
1262
+ copy = async (e) => {
1263
+ try {
1264
+ await navigator.clipboard.writeText(e);
1265
+ return;
1266
+ } catch {}
1267
+ let t = document.createElement("textarea");
1268
+ t.value = e, t.className = "visually-hidden", t.setAttribute("aria-hidden", "true"), (this.dialog ?? this).append(t), t.select();
1269
+ let n = document.execCommand("copy");
1270
+ if (t.remove(), !n) throw Error("Can't copy");
1271
+ };
1272
+ searchTimer;
1273
+ searches = 0;
1274
+ replacing;
1275
+ constructor() {
1276
+ super(), this.types = {}, this.search = "", this.kind = "", this.type = "", this.page = 1, this.filters = {
1277
+ kinds: [],
1278
+ types: []
1279
+ }, this.loading = !1, this.message = "", this.error = "";
1280
+ }
1281
+ createRenderRoot() {
1282
+ return this;
1283
+ }
1284
+ get dialog() {
1285
+ return this.querySelector("dialog");
1286
+ }
1287
+ get open() {
1288
+ return this.dialog?.open ?? !1;
1289
+ }
1290
+ async show() {
1291
+ this.finishPicking(), await this.openWith("");
1292
+ }
1293
+ async openWith(e) {
1294
+ this.search = "", this.kind = e, this.type = "", this.page = 1, this.message = "", await this.updateComplete, this.open || this.dialog?.showModal(), this.querySelector("#file-browser-search")?.focus(), await Promise.all([this.loadFilters(), this.load()]);
1295
+ }
1296
+ async pick(e = "") {
1297
+ this.finishPicking();
1298
+ let t = new Promise((e) => this.picking = e);
1299
+ return await this.openWith(e), t;
1300
+ }
1301
+ finishPicking(e) {
1302
+ let t = this.picking;
1303
+ this.picking = void 0, t?.(e);
1304
+ }
1305
+ chooseFile(e) {
1306
+ this.finishPicking(e), this.close();
1307
+ }
1308
+ close() {
1309
+ clearTimeout(this.searchTimer), this.open && this.dialog?.close();
1310
+ }
1311
+ async loadFilters() {
1312
+ try {
1313
+ this.filters = await this.api.fileFilters();
1314
+ } catch {}
1315
+ }
1316
+ async load() {
1317
+ clearTimeout(this.searchTimer);
1318
+ let e = ++this.searches;
1319
+ this.loading = !0;
1320
+ try {
1321
+ let t = await this.api.queryFiles({
1322
+ search: this.search,
1323
+ kind: this.kind || void 0,
1324
+ type: this.type,
1325
+ sort: this.sort,
1326
+ order: this.order,
1327
+ page: this.page
1328
+ });
1329
+ if (e !== this.searches) return;
1330
+ this.result = t, this.error = "";
1331
+ } catch (t) {
1332
+ if (e !== this.searches) return;
1333
+ this.error = t.message;
1334
+ }
1335
+ this.loading = !1;
1336
+ }
1337
+ choose(e, t) {
1338
+ this[e] = t, this.page = 1, this.message = "", this.load();
1339
+ }
1340
+ onSearch(e) {
1341
+ this.search = e, this.page = 1, this.message = "", clearTimeout(this.searchTimer), this.searchTimer = setTimeout(() => void this.load(), this.searchDelay);
1342
+ }
1343
+ sortBy(e) {
1344
+ ({sort: this.sort, order: this.order} = B({
1345
+ sort: this.sort,
1346
+ order: this.order
1347
+ }, e)), this.page = 1, this.message = "", this.load();
1348
+ }
1349
+ async goTo(e) {
1350
+ this.page = e, this.message = "", await this.load(), this.querySelector(".file-browser-results")?.scrollTo?.(0, 0);
1351
+ }
1352
+ report(e, t = "") {
1353
+ this.message = e, this.error = t;
1354
+ }
1355
+ async copyUrl(e) {
1356
+ try {
1357
+ await this.copy(e.url), this.report(`Copied ${e.url}`);
1358
+ } catch {
1359
+ this.report("", `Couldn't copy ${e.url}`);
1360
+ }
1361
+ }
1362
+ chooseReplacement(e) {
1363
+ this.replacing = e, this.querySelector("#file-browser-replacement")?.click();
1364
+ }
1365
+ async changed(e, t) {
1366
+ this.dispatchEvent(new CustomEvent(Tt, {
1367
+ detail: {
1368
+ file: e,
1369
+ ...t
1370
+ },
1371
+ bubbles: !0
1372
+ })), await Promise.all([this.loadFilters(), this.load()]);
1373
+ }
1374
+ async replace(e, t) {
1375
+ try {
1376
+ let n = await this.api.fileReferences(e);
1377
+ if (!this.confirm(`Replace ${e.name} in ${e.type}/${e.slug} with ${t.name}?${n.length ? ` ${V(n.length)} will refer to the new file if its name differs.` : ""}`)) return;
1378
+ let r = await this.api.replaceFile(e, t);
1379
+ this.report(r.name === e.name ? `Replaced ${e.name}` : `Replaced ${e.name} with ${r.name}${r.articles.length ? `, updating ${V(r.articles.length)}` : ""}`), await this.changed(e, r);
1380
+ } catch (e) {
1381
+ this.report("", e.message);
1382
+ }
1383
+ }
1384
+ async delete(e) {
1385
+ try {
1386
+ let t = await this.api.fileReferences(e);
1387
+ if (!this.confirm(`Delete ${e.name} from ${e.type}/${e.slug}?${t.length ? ` It will also be removed from ${V(t.length)}.` : ""}`)) return;
1388
+ let n = await this.api.deleteFile(e);
1389
+ this.report(`Deleted ${e.name}${n.articles.length ? `, updating ${V(n.articles.length)}` : ""}`), await this.changed(e, n);
1390
+ } catch (e) {
1391
+ this.report("", e.message);
1392
+ }
1393
+ }
1394
+ renderSelect(e, n, r, i) {
1395
+ let a = `file-browser-${e}`;
1396
+ return t`<div class="article-browser-field">
1397
+ <label for=${a}>${n}</label>
1398
+ <select
1399
+ id=${a}
1400
+ @change=${(t) => this.choose(e, t.target.value)}
1401
+ >
1402
+ <option value="" ?selected=${!this[e]}>${r}</option>
1403
+ ${i.map((n) => t`<option
1404
+ value=${n.value}
1405
+ ?selected=${this[e] === n.value}
1406
+ >
1407
+ ${n.label}
1408
+ </option>`)}
1409
+ </select>
1410
+ </div>`;
1411
+ }
1412
+ renderOperation(e, n, r) {
1413
+ return t`<button
1414
+ type="button"
1415
+ class="btn-icon"
1416
+ title=${e}
1417
+ @click=${r}
1418
+ >
1419
+ ${_(n)}<span class="visually-hidden">${e}</span>
1420
+ </button>`;
1421
+ }
1422
+ renderResults() {
1423
+ let e = this.result;
1424
+ if (!e) return n;
1425
+ if (!e.files.length) return t`<p class="article-browser-empty">No files found.</p>`;
1426
+ let r = Object.fromEntries(Ct.map(({ value: e, label: t }) => [e, t]));
1427
+ return t`<table class="article-browser-table file-browser-table">
1428
+ <thead>
1429
+ <tr>
1430
+ ${wt.map(({ sort: e, label: t }) => St(e, t, {
1431
+ sort: this.sort,
1432
+ order: this.order
1433
+ }, (e) => this.sortBy(e)))}
1434
+ <th scope="col">Operations</th>
1435
+ </tr>
1436
+ </thead>
1437
+ <tbody>
1438
+ ${e.files.map((e) => {
1439
+ let i = `${e.type}/${e.slug}`;
1440
+ return t`<tr>
1441
+ <td>
1442
+ <a
1443
+ href=${this.api.url(`/files/${i}/${encodeURIComponent(e.name)}`)}
1444
+ target="_blank"
1445
+ >${e.name}</a
1446
+ >
1447
+ </td>
1448
+ <td>${r[e.kind]}</td>
1449
+ <td>${Ot(e.size)}</td>
1450
+ <td>
1451
+ <a href=${this.api.url(`/#${i}`)} target="_blank"
1452
+ >${i}</a
1453
+ >
1454
+ </td>
1455
+ <td class="file-browser-operations">
1456
+ ${this.picking ? t`<button
1457
+ type="button"
1458
+ class="btn"
1459
+ @click=${() => this.chooseFile(e)}
1460
+ >
1461
+ Choose<span class="visually-hidden"> ${e.name}</span>
1462
+ </button>` : n}
1463
+ ${this.renderOperation(`Copy URL of ${e.name}`, "content_copy", () => void this.copyUrl(e))}
1464
+ ${this.renderOperation(`Replace ${e.name}…`, "find_replace", () => this.chooseReplacement(e))}
1465
+ ${this.renderOperation(`Delete ${e.name}…`, "delete", () => void this.delete(e))}
1466
+ </td>
1467
+ </tr>`;
1468
+ })}
1469
+ </tbody>
1470
+ </table>`;
1471
+ }
1472
+ renderPages() {
1473
+ let e = this.result;
1474
+ return !e || e.pages < 2 ? n : t`<nav class="article-browser-pages" aria-label="Pages">
1475
+ <button
1476
+ type="button"
1477
+ class="btn"
1478
+ ?disabled=${e.page <= 1}
1479
+ @click=${() => void this.goTo(e.page - 1)}
1480
+ >
1481
+ Previous
1482
+ </button>
1483
+ <span>Page ${e.page} of ${e.pages}</span>
1484
+ <button
1485
+ type="button"
1486
+ class="btn"
1487
+ ?disabled=${e.page >= e.pages}
1488
+ @click=${() => void this.goTo(e.page + 1)}
1489
+ >
1490
+ Next
1491
+ </button>
1492
+ </nav>`;
1493
+ }
1494
+ statusText() {
1495
+ if (this.error) return this.error;
1496
+ if (this.message) return this.message;
1497
+ if (this.loading || !this.result) return "Loading…";
1498
+ let { total: e } = this.result;
1499
+ return `${e} ${e === 1 ? "file" : "files"} found`;
1500
+ }
1501
+ render() {
1502
+ let e = Ct.filter(({ value: e }) => this.filters.kinds.includes(e)), n = this.filters.types.map((e) => ({
1503
+ value: e,
1504
+ label: this.types[e]?.labelPlural ?? e
1505
+ }));
1506
+ return t`<dialog
1507
+ class="article-browser file-browser"
1508
+ aria-labelledby="file-browser-title"
1509
+ @close=${() => {
1510
+ clearTimeout(this.searchTimer), this.finishPicking();
1511
+ }}
1512
+ >
1513
+ <div class="article-browser-header">
1514
+ <h2 id="file-browser-title">
1515
+ ${this.picking ? "Choose a file" : "Files"}
1516
+ </h2>
1517
+ <button
1518
+ type="button"
1519
+ class="btn-icon"
1520
+ title="Close"
1521
+ @click=${() => this.close()}
1522
+ >
1523
+ ${_("close")}<span class="visually-hidden">Close</span>
1524
+ </button>
1525
+ </div>
1526
+ <div class="article-browser-controls" role="search">
1527
+ <div class="article-browser-field article-browser-search">
1528
+ <label for="file-browser-search">Search names</label>
1529
+ <input
1530
+ type="search"
1531
+ id="file-browser-search"
1532
+ .value=${this.search}
1533
+ @input=${(e) => this.onSearch(e.target.value)}
1534
+ />
1535
+ </div>
1536
+ ${this.renderSelect("kind", "Type", "All types", e)}
1537
+ ${this.renderSelect("type", "Article type", "All article types", n)}
1538
+ </div>
1539
+ <p
1540
+ class="article-browser-status ${this.error ? "error" : ""}"
1541
+ role="status"
1542
+ >
1543
+ ${this.statusText()}
1544
+ </p>
1545
+ <div class="article-browser-results file-browser-results">
1546
+ ${this.renderResults()} ${this.renderPages()}
1547
+ </div>
1548
+ <!-- Chooses the replacement for the file being replaced -->
1549
+ <input
1550
+ type="file"
1551
+ id="file-browser-replacement"
1552
+ class="visually-hidden"
1553
+ tabindex="-1"
1554
+ aria-hidden="true"
1555
+ @change=${(e) => {
1556
+ let t = e.target, n = t.files?.[0], r = this.replacing;
1557
+ t.value = "", this.replacing = void 0, r && n && this.replace(r, n);
1558
+ }}
1559
+ />
1560
+ </dialog>`;
1561
+ }
1562
+ });
1563
+ // src/client/components/edaha-article-data-field/index.ts
1564
+ var kt = /\.(png|jpe?g|gif|webp|svg)$/i;
1565
+ x("edaha-article-data-field", class extends e {
1566
+ static properties = {
1567
+ name: {},
1568
+ type: {},
1569
+ label: {},
1570
+ placeholder: {},
1571
+ accept: {},
1572
+ rows: { type: Number },
1573
+ value: { attribute: !1 },
1574
+ options: { attribute: !1 },
1575
+ previewUrl: { attribute: !1 },
1576
+ uploadImage: { attribute: !1 },
1577
+ chooseFile: { attribute: !1 },
1578
+ embedTools: { attribute: !1 },
1579
+ fileAddress: { attribute: !1 },
1580
+ preview: { type: Boolean },
1581
+ allowchange: { type: Boolean },
1582
+ allowclear: { type: Boolean },
1583
+ disabled: { type: Boolean },
1584
+ changed: { type: Boolean }
1585
+ };
1586
+ constructor() {
1587
+ super(), this.name = "", this.type = "text", this.label = "", this.placeholder = "", this.accept = "", this.rows = 3, this.value = "", this.options = [], this.preview = !1, this.allowchange = !1, this.allowclear = !1, this.disabled = !1, this.changed = !1;
1588
+ }
1589
+ createRenderRoot() {
1590
+ return this;
1591
+ }
1592
+ change(e) {
1593
+ this.value = e, this.dispatchEvent(new CustomEvent("field-change", {
1594
+ detail: {
1595
+ name: this.name,
1596
+ value: e
1597
+ },
1598
+ bubbles: !0
1599
+ }));
1600
+ }
1601
+ get inputId() {
1602
+ return `field-${this.name.replace(/[^a-z0-9-]/gi, "-")}`;
1603
+ }
1604
+ renderInput() {
1605
+ let e = (e) => this.change(e.target.value);
1606
+ switch (this.type) {
1607
+ case "textarea": return t`<textarea
1608
+ id=${this.inputId}
1609
+ rows=${this.rows}
1610
+ placeholder=${this.placeholder}
1611
+ ?disabled=${this.disabled}
1612
+ .value=${this.value}
1613
+ @input=${e}
1614
+ ></textarea>`;
1615
+ case "select": return t`<select
1616
+ id=${this.inputId}
1617
+ ?disabled=${this.disabled}
1618
+ @change=${e}
1619
+ >
1620
+ ${this.options.map((e) => t`<option
1621
+ value=${e.value}
1622
+ ?selected=${e.value === this.value}
1623
+ >
1624
+ ${e.label}
1625
+ </option>`)}
1626
+ </select>`;
1627
+ case "richtext": return t`<edaha-richtext
1628
+ id=${this.inputId}
1629
+ .value=${this.value}
1630
+ .uploadImage=${this.uploadImage}
1631
+ .chooseFile=${this.chooseFile}
1632
+ .embedTools=${this.embedTools}
1633
+ .fileAddress=${this.fileAddress}
1634
+ @richtext-change=${(e) => {
1635
+ e.stopPropagation(), this.change(e.currentTarget.value);
1636
+ }}
1637
+ ></edaha-richtext>`;
1638
+ case "markdown": return t`<edaha-markdown
1639
+ .textareaId=${this.inputId}
1640
+ .value=${this.value}
1641
+ .uploadImage=${this.uploadImage}
1642
+ .chooseFile=${this.chooseFile}
1643
+ .embedTools=${this.embedTools}
1644
+ @markdown-change=${(e) => {
1645
+ e.stopPropagation(), this.change(e.currentTarget.value);
1646
+ }}
1647
+ ></edaha-markdown>`;
1648
+ case "file": return this.renderFile();
1649
+ default: return t`<input
1650
+ id=${this.inputId}
1651
+ type=${this.type}
1652
+ placeholder=${this.placeholder}
1653
+ ?disabled=${this.disabled}
1654
+ .value=${this.value}
1655
+ @input=${e}
1656
+ />`;
1657
+ }
1658
+ }
1659
+ async chooseExisting() {
1660
+ let e = await this.chooseFile?.(Et(this.accept));
1661
+ e && this.change(e.url);
1662
+ }
1663
+ renderFile() {
1664
+ let e = !this.value || this.allowchange;
1665
+ return t`
1666
+ ${this.value ? t`<p class="file-current">
1667
+ ${this.preview && this.previewUrl && kt.test(this.value) ? t`<img src=${this.previewUrl} alt="" width="120" />` : n}
1668
+ <span>${this.value}</span>
1669
+ </p>` : n}
1670
+ ${e ? t`<input
1671
+ id=${this.inputId}
1672
+ type="file"
1673
+ accept=${this.accept}
1674
+ ?disabled=${this.disabled}
1675
+ @change=${(e) => {
1676
+ let t = e.target, n = t.files?.[0];
1677
+ t.value = "", n && this.dispatchEvent(new CustomEvent("field-file", {
1678
+ detail: n,
1679
+ bubbles: !0
1680
+ }));
1681
+ }}
1682
+ />${this.chooseFile ? t`<button
1683
+ type="button"
1684
+ class="btn btn-choose-file"
1685
+ @click=${() => void this.chooseExisting()}
1686
+ >
1687
+ Choose existing file…<span class="visually-hidden">
1688
+ for ${this.label}</span
1689
+ >
1690
+ </button>` : n}` : n}
1691
+ `;
1692
+ }
1693
+ render() {
1694
+ return t`
1695
+ ${this.label ? t`<label for=${this.inputId}
1696
+ >${this.label}${this.changed ? t`<span
1697
+ class="changed"
1698
+ title="Changed since it was saved"
1699
+ >
1700
+ *</span
1701
+ >` : n}</label
1702
+ >` : n}
1703
+ ${this.renderInput()}
1704
+ ${this.allowclear && this.value ? t`<button
1705
+ type="button"
1706
+ class="btn clear"
1707
+ ?disabled=${this.disabled}
1708
+ @click=${() => this.change("")}
1709
+ >
1710
+ Clear
1711
+ </button>` : n}
1712
+ `;
1713
+ }
1714
+ });
1715
+ // src/client/components/edaha-article-data-group/style.css?inline
1716
+ var At = ":host{display:block}";
1717
+ x("edaha-article-data-group", class extends e {
1718
+ static properties = {
1719
+ name: {},
1720
+ label: {},
1721
+ multiple: { type: Boolean },
1722
+ allowclear: { type: Boolean },
1723
+ disabled: { type: Boolean },
1724
+ changed: { type: Boolean }
1725
+ };
1726
+ static styles = i(At);
1727
+ constructor() {
1728
+ super(), this.name = "", this.label = "", this.multiple = !1, this.allowclear = !1, this.disabled = !1, this.changed = !1;
1729
+ }
1730
+ fire(e) {
1731
+ this.dispatchEvent(new CustomEvent(e, {
1732
+ detail: this.name,
1733
+ bubbles: !0
1734
+ }));
1735
+ }
1736
+ render() {
1737
+ return t`<fieldset ?disabled=${this.disabled}>
1738
+ ${this.label ? t`<legend>
1739
+ ${this.label}${this.changed ? t`<span
1740
+ class="changed"
1741
+ title="Changed since it was saved"
1742
+ >
1743
+ *</span
1744
+ >` : n}
1745
+ </legend>` : n}
1746
+ <slot></slot>
1747
+ ${this.multiple ? t`<button
1748
+ type="button"
1749
+ class="add"
1750
+ @click=${() => this.fire("group-add")}
1751
+ >
1752
+ Add
1753
+ </button>` : n}
1754
+ ${this.allowclear ? t`<button
1755
+ type="button"
1756
+ class="clear"
1757
+ @click=${() => this.fire("group-clear")}
1758
+ >
1759
+ Clear
1760
+ </button>` : n}
1761
+ </fieldset>`;
1762
+ }
1763
+ });
1764
+ // src/client/components/edaha-toasts/index.ts
1765
+ var H = "edaha-toast", U = (e, t) => {
1766
+ e.dispatchEvent(new CustomEvent(H, {
1767
+ detail: t,
1768
+ bubbles: !0
1769
+ }));
1770
+ };
1771
+ x("edaha-toasts", class extends e {
1772
+ static properties = { toasts: { state: !0 } };
1773
+ duration = 4e3;
1774
+ nextId = 0;
1775
+ constructor() {
1776
+ super(), this.toasts = [];
1777
+ }
1778
+ createRenderRoot() {
1779
+ return this;
1780
+ }
1781
+ show(e) {
1782
+ let t = ++this.nextId;
1783
+ this.toasts = [...this.toasts, {
1784
+ ...e,
1785
+ id: t
1786
+ }], e.kind === "success" && setTimeout(() => this.dismiss(t), this.duration);
1787
+ }
1788
+ dismiss(e) {
1789
+ this.toasts = this.toasts.filter((t) => t.id !== e);
1790
+ }
1791
+ render() {
1792
+ return t`<div class="toasts">
1793
+ ${ye(this.toasts, (e) => e.id, (e) => t`<div
1794
+ class="toast ${e.kind}"
1795
+ role=${e.kind === "error" ? "alert" : "status"}
1796
+ >
1797
+ <span>${e.message}</span>
1798
+ <button type="button" @click=${() => this.dismiss(e.id)}>
1799
+ Dismiss
1800
+ </button>
1801
+ </div>`)}
1802
+ </div>`;
1803
+ }
1804
+ });
1805
+ // src/client/metadataForm/index.ts
1806
+ var jt = (e, t) => t.$edahaField?.title ?? t.title ?? e, Mt = (e) => e.$edahaField?.description ?? e.description, Nt = (e) => Ce(e.$edahaField) ? Se(e.$edahaField) : e.type === "object" ? "object" : "list", Pt = (e) => {
1807
+ let t = e.$edahaField ? g(e.$edahaField) : {};
1808
+ return Array.isArray(t.options) ? t.options : (e.enum ?? e.items?.enum ?? []).map((e) => ({ value: e }));
1809
+ }, Ft = {
1810
+ minLength: "minlength",
1811
+ maxLength: "maxlength"
1812
+ }, It = {
1813
+ minLength: "minlength",
1814
+ maxLength: "maxlength",
1815
+ pattern: "pattern",
1816
+ minimum: "min",
1817
+ maximum: "max",
1818
+ multipleOf: "step"
1819
+ }, Lt = [
1820
+ "options",
1821
+ "list",
1822
+ "multiple"
1823
+ ], W = (e) => {
1824
+ let t = {};
1825
+ for (let [n, r] of Object.entries(It)) e[n] !== void 0 && (t[r] = String(e[n]));
1826
+ let n = e.$edahaField ? g(e.$edahaField) : {};
1827
+ for (let [e, r] of Object.entries(n)) !Lt.includes(e) && r != null && (t[Ft[e] ?? e.toLowerCase()] = String(r));
1828
+ return t;
1829
+ }, G = (e, t, n) => {
1830
+ let [r, ...i] = t;
1831
+ if (r === void 0) return n;
1832
+ if (Array.isArray(e)) {
1833
+ let t = [...e];
1834
+ return t[Number(r)] = G(t[Number(r)], i, n), t;
1835
+ }
1836
+ let a = { ...e && typeof e == "object" ? e : {} }, o = G(a[r], i, n);
1837
+ return Object.fromEntries(Object.entries({
1838
+ ...a,
1839
+ [r]: o
1840
+ }).filter(([, e]) => e !== void 0));
1841
+ }, Rt = (e, t) => {
1842
+ if (typeof t == "boolean") return t;
1843
+ if (t !== "") return e === "number" || e === "range" ? Number(t) : t;
1844
+ }, zt = (e) => {
1845
+ let { value: t } = e.$edahaField ? g(e.$edahaField) : {};
1846
+ return t === void 0 ? {
1847
+ checked: !0,
1848
+ unchecked: !1
1849
+ } : {
1850
+ checked: t,
1851
+ unchecked: void 0
1852
+ };
1853
+ }, Bt = /^#?([0-9a-f]{6})$/i, Vt = (e) => {
1854
+ let t = Bt.exec(String(e ?? ""));
1855
+ return t ? `#${t[1].toLowerCase()}` : "";
1856
+ }, Ht = (e, t) => typeof t == "string" && /^[0-9a-f]{6}$/i.test(t) ? e.replace(/^#/, "") : e, K = (e, t) => e.filter((e) => e.path === t), q = (e) => t`<span class="visually-hidden">${e}</span>`, Ut = (e) => `meta-${e.replace(/[^\w-]/g, "-")}`;
1857
+ x("edaha-metadata-field", class extends e {
1858
+ static properties = {
1859
+ path: {},
1860
+ label: {},
1861
+ schema: { attribute: !1 },
1862
+ value: { attribute: !1 },
1863
+ problems: { attribute: !1 },
1864
+ hiddenFields: { attribute: !1 },
1865
+ required: { type: Boolean },
1866
+ uploadFile: { attribute: !1 },
1867
+ chooseFile: { attribute: !1 },
1868
+ fileUrl: { attribute: !1 }
1869
+ };
1870
+ constructor() {
1871
+ super(), this.path = "", this.schema = {}, this.problems = [], this.hiddenFields = /* @__PURE__ */ new Set(), this.required = !1;
1872
+ }
1873
+ createRenderRoot() {
1874
+ return this;
1875
+ }
1876
+ change(e, t) {
1877
+ this.dispatchEvent(new CustomEvent("metadata-change", {
1878
+ detail: {
1879
+ path: e,
1880
+ value: t
1881
+ },
1882
+ bubbles: !0
1883
+ }));
1884
+ }
1885
+ get key() {
1886
+ return this.path.split("/").at(-1);
1887
+ }
1888
+ get fieldTitle() {
1889
+ return this.label ?? jt(this.key, this.schema);
1890
+ }
1891
+ renderNotes(e) {
1892
+ let r = Mt(this.schema), i = this.schema.$edahaField?.info, a = K(this.problems, this.path);
1893
+ return t`${r ? t`<p class="metadata-description" id="${e}-description">
1894
+ ${r}
1895
+ </p>` : n}${i ? t`<p class="metadata-info" id="${e}-info">${i}</p>` : n}${a.length ? t`<ul class="metadata-problems" id="${e}-problems">
1896
+ ${a.map((e) => t`<li class=${e.level}>
1897
+ ${this.fieldTitle} ${e.message}
1898
+ </li>`)}
1899
+ </ul>` : n}`;
1900
+ }
1901
+ describedBy(e) {
1902
+ return [
1903
+ Mt(this.schema) && `${e}-description`,
1904
+ this.schema.$edahaField?.info && `${e}-info`,
1905
+ K(this.problems, this.path).length && `${e}-problems`
1906
+ ].filter(Boolean).join(" ");
1907
+ }
1908
+ renderChild(e, n, r, i = {}) {
1909
+ return t`<edaha-metadata-field
1910
+ path=${e}
1911
+ .label=${i.label}
1912
+ .schema=${n}
1913
+ .value=${r}
1914
+ .problems=${this.problems}
1915
+ .hiddenFields=${this.hiddenFields}
1916
+ ?required=${i.required ?? !1}
1917
+ .uploadFile=${this.uploadFile}
1918
+ .chooseFile=${this.chooseFile}
1919
+ .fileUrl=${this.fileUrl}
1920
+ ></edaha-metadata-field>`;
1921
+ }
1922
+ renderObject(e) {
1923
+ let r = this.value ?? {};
1924
+ return t`<fieldset
1925
+ class="metadata-group"
1926
+ aria-describedby=${this.describedBy(e) || n}
1927
+ >
1928
+ <legend>${this.fieldTitle}</legend>
1929
+ ${this.renderNotes(e)}
1930
+ ${Object.entries(this.schema.properties).filter(([e]) => !this.hiddenFields.has(`${this.path}/${e}`.replaceAll("/", "."))).map(([e, t]) => this.renderChild(`${this.path}/${e}`, t, r[e], { required: this.schema.required?.includes(e) ?? !1 }))}
1931
+ </fieldset>`;
1932
+ }
1933
+ renderList(e) {
1934
+ let r = Array.isArray(this.value) ? this.value : [], i = this.schema.maxItems, a = i !== void 0 && r.length >= i;
1935
+ return t`<fieldset
1936
+ class="metadata-group metadata-list"
1937
+ aria-describedby=${this.describedBy(e) || n}
1938
+ >
1939
+ <legend>${this.fieldTitle}</legend>
1940
+ ${this.renderNotes(e)}
1941
+ ${r.map((e, n) => t`<div class="metadata-item">
1942
+ ${this.renderChild(`${this.path}/${n}`, this.schema.items, e, { label: `${this.fieldTitle} ${n + 1}` })}
1943
+ <button
1944
+ type="button"
1945
+ class="btn btn-xs"
1946
+ @click=${() => this.change(this.path, r.filter((e, t) => t !== n))}
1947
+ >
1948
+ Delete${q(` ${this.fieldTitle} ${n + 1}`)}
1949
+ </button>
1950
+ </div>`)}
1951
+ <button
1952
+ type="button"
1953
+ class="btn btn-xs"
1954
+ ?disabled=${a}
1955
+ @click=${() => this.change(this.path, [...r, void 0])}
1956
+ >
1957
+ Add${q(` to ${this.fieldTitle}`)}
1958
+ </button>
1959
+ </fieldset>`;
1960
+ }
1961
+ renderSelect(e, r) {
1962
+ let i = g(this.schema.$edahaField), a = Pt(this.schema), o = i.multiple === !0, s = o ? (this.value ?? []).map(String) : [String(this.value ?? "")];
1963
+ return t`<select
1964
+ id=${e}
1965
+ ?multiple=${o}
1966
+ size=${i.list === !0 ? a.length + +!o : n}
1967
+ ?required=${this.required}
1968
+ aria-invalid=${K(this.problems, this.path).length ? "true" : "false"}
1969
+ aria-describedby=${this.describedBy(e) || n}
1970
+ @change=${(e) => {
1971
+ let t = [...e.target.selectedOptions].map((e) => a[Number(e.dataset.index)]?.value ?? void 0);
1972
+ this.change(this.path, o ? t : t[0] ?? Rt(r, ""));
1973
+ }}
1974
+ >
1975
+ ${o ? n : t`<option value="">—</option>`}
1976
+ ${a.map((e, n) => t`<option
1977
+ data-index=${n}
1978
+ value=${String(e.value)}
1979
+ ?selected=${s.includes(String(e.value))}
1980
+ >
1981
+ ${e.title ?? String(e.value)}
1982
+ </option>`)}
1983
+ </select>`;
1984
+ }
1985
+ renderRadio(e) {
1986
+ return t`<fieldset
1987
+ class="metadata-radio"
1988
+ aria-describedby=${this.describedBy(e) || n}
1989
+ >
1990
+ <legend>${this.fieldTitle}</legend>
1991
+ ${this.renderNotes(e)}
1992
+ ${Pt(this.schema).map((r, i) => t`<label class="metadata-choice">
1993
+ <input
1994
+ type="radio"
1995
+ name=${e}
1996
+ .checked=${d(this.value === r.value)}
1997
+ ?required=${this.required}
1998
+ aria-describedby=${r.description ? `${e}-${i}` : n}
1999
+ @change=${() => this.change(this.path, r.value)}
2000
+ />
2001
+ ${r.title ?? String(r.value)}
2002
+ ${r.description ? t`<small id="${e}-${i}">${r.description}</small>` : n}
2003
+ </label>`)}
2004
+ </fieldset>`;
2005
+ }
2006
+ async chooseExisting() {
2007
+ let e = await this.chooseFile?.(Et(W(this.schema).accept));
2008
+ e && this.change(this.path, e.url);
2009
+ }
2010
+ renderFile(e) {
2011
+ let r = typeof this.value == "string" ? this.value : "", i = r ? this.fileUrl?.(r) : void 0;
2012
+ return t`${r ? t`<p class="metadata-file">
2013
+ ${i ? t`<a href=${i} target="_blank">${r}</a>` : r}
2014
+ <button
2015
+ type="button"
2016
+ class="btn btn-xs"
2017
+ @click=${() => this.change(this.path, void 0)}
2018
+ >
2019
+ Clear${q(` ${this.fieldTitle}`)}
2020
+ </button>
2021
+ </p>` : n}<input
2022
+ type="file"
2023
+ id=${e}
2024
+ ?disabled=${!this.uploadFile}
2025
+ ?required=${this.required && !r}
2026
+ aria-invalid=${K(this.problems, this.path).length ? "true" : "false"}
2027
+ aria-describedby=${this.describedBy(e) || n}
2028
+ accept=${W(this.schema).accept ?? n}
2029
+ @change=${async (e) => {
2030
+ let t = e.target, n = t.files?.[0];
2031
+ if (t.value = "", n && this.uploadFile) try {
2032
+ this.change(this.path, await this.uploadFile(n));
2033
+ } catch {}
2034
+ }}
2035
+ />${this.chooseFile ? t`<button
2036
+ type="button"
2037
+ class="btn btn-choose-file"
2038
+ @click=${() => void this.chooseExisting()}
2039
+ >
2040
+ Choose existing file…${q(` for ${this.fieldTitle}`)}
2041
+ </button>` : n}`;
2042
+ }
2043
+ renderInput(e, r) {
2044
+ let i = K(this.problems, this.path).length ? "true" : "false", a = this.describedBy(e) || n;
2045
+ if (r === "select") return this.renderSelect(e, r);
2046
+ if (r === "file") return this.renderFile(e);
2047
+ if (r === "checkbox") {
2048
+ let { checked: n, unchecked: r } = zt(this.schema);
2049
+ return t`<input
2050
+ type="checkbox"
2051
+ id=${e}
2052
+ .checked=${d(this.value === n)}
2053
+ aria-invalid=${i}
2054
+ aria-describedby=${a}
2055
+ @change=${(e) => this.change(this.path, e.target.checked ? n : r)}
2056
+ />`;
2057
+ }
2058
+ if (r === "color") return t`<input
2059
+ type="color"
2060
+ id=${e}
2061
+ aria-invalid=${i}
2062
+ aria-describedby=${a}
2063
+ .value=${d(Vt(this.value))}
2064
+ @input=${(e) => this.change(this.path, Ht(e.target.value, this.value))}
2065
+ />`;
2066
+ let o = W(this.schema), s = (e) => this.change(this.path, Rt(r, e.target.value));
2067
+ return r === "textarea" ? t`<textarea
2068
+ id=${e}
2069
+ rows=${o.rows ?? 3}
2070
+ minlength=${o.minlength ?? n}
2071
+ maxlength=${o.maxlength ?? n}
2072
+ placeholder=${o.placeholder ?? n}
2073
+ ?required=${this.required}
2074
+ aria-invalid=${i}
2075
+ aria-describedby=${a}
2076
+ .value=${d(String(this.value ?? ""))}
2077
+ @input=${s}
2078
+ ></textarea>` : t`<input
2079
+ type=${r}
2080
+ id=${e}
2081
+ min=${o.min ?? n}
2082
+ max=${o.max ?? n}
2083
+ step=${o.step ?? n}
2084
+ minlength=${o.minlength ?? n}
2085
+ maxlength=${o.maxlength ?? n}
2086
+ pattern=${o.pattern ?? n}
2087
+ placeholder=${o.placeholder ?? n}
2088
+ ?required=${this.required}
2089
+ aria-invalid=${i}
2090
+ aria-describedby=${a}
2091
+ .value=${d(String(this.value ?? ""))}
2092
+ @input=${s}
2093
+ />`;
2094
+ }
2095
+ render() {
2096
+ let e = Ut(this.path), r = Nt(this.schema), i = () => this.dispatchEvent(new CustomEvent("metadata-blur", {
2097
+ detail: this.path,
2098
+ bubbles: !0
2099
+ })), a = (e) => {
2100
+ this.contains(e.relatedTarget) || i();
2101
+ };
2102
+ if (r === "object") return t`<div @focusout=${a}>${this.renderObject(e)}</div>`;
2103
+ if (r === "list") return t`<div @focusout=${a}>${this.renderList(e)}</div>`;
2104
+ if (r === "radio") return t`<div @focusout=${a}>${this.renderRadio(e)}</div>`;
2105
+ let o = t`<label for=${e}
2106
+ >${this.fieldTitle}${this.required ? t`<span class="required" aria-hidden="true"> *</span>` : n}</label
2107
+ >`;
2108
+ return r === "checkbox" ? t`<div
2109
+ class="metadata-field metadata-checkbox"
2110
+ @focusout=${a}
2111
+ >
2112
+ <div class="metadata-check">${this.renderInput(e, r)} ${o}</div>
2113
+ ${this.renderNotes(e)}
2114
+ </div>` : t`<div class="metadata-field" @focusout=${a}>
2115
+ ${o} ${this.renderNotes(e)} ${this.renderInput(e, r)}
2116
+ </div>`;
2117
+ }
2118
+ });
2119
+ var Wt = "embed-options";
2120
+ x("edaha-embed-dialog", class extends e {
2121
+ static properties = {
2122
+ embed: { state: !0 },
2123
+ content: { state: !0 },
2124
+ options: { state: !0 },
2125
+ changing: { state: !0 },
2126
+ errors: { state: !0 },
2127
+ checking: { state: !0 }
2128
+ };
2129
+ editing;
2130
+ validator;
2131
+ constructor() {
2132
+ super(), this.content = "", this.options = {}, this.changing = !1, this.errors = [], this.checking = !1;
2133
+ }
2134
+ createRenderRoot() {
2135
+ return this;
2136
+ }
2137
+ get dialog() {
2138
+ return this.querySelector("dialog");
2139
+ }
2140
+ get textarea() {
2141
+ return this.querySelector("#embed-dialog-content");
2142
+ }
2143
+ async edit(e, { content: t, options: n }, r, i) {
2144
+ this.finish(void 0), this.embed = e, this.content = t, this.options = n, this.changing = !r, this.validator = i, this.errors = [];
2145
+ let a = new Promise((e) => this.editing = e);
2146
+ return await this.updateComplete, this.dialog?.showModal(), this.textarea?.focus(), a;
2147
+ }
2148
+ finish(e) {
2149
+ let t = this.editing;
2150
+ this.editing = void 0, t?.(e);
2151
+ }
2152
+ resolvedOptions() {
2153
+ return be(this.embed?.options ?? {}, this.options);
2154
+ }
2155
+ close() {
2156
+ this.dialog?.close();
2157
+ }
2158
+ async save(e) {
2159
+ e.preventDefault();
2160
+ let t = this.content.trim();
2161
+ if (!this.embed || !t && !this.embed.contentOptional || this.checking) return;
2162
+ let n = {
2163
+ key: this.embed.key,
2164
+ content: t,
2165
+ options: this.resolvedOptions().values
2166
+ };
2167
+ if (this.validator) {
2168
+ let e = this.options;
2169
+ this.checking = !0;
2170
+ try {
2171
+ this.errors = await this.validator(n);
2172
+ } catch (e) {
2173
+ this.errors = [`The content couldn't be checked: ${e.message}`];
2174
+ }
2175
+ this.checking = !1;
2176
+ let r = t !== this.content.trim() || e !== this.options;
2177
+ if (r && (this.errors = []), r || this.errors.length) {
2178
+ this.textarea?.focus();
2179
+ return;
2180
+ }
2181
+ }
2182
+ this.finish(n), this.close();
2183
+ }
2184
+ onOptionChange(e) {
2185
+ e.stopPropagation();
2186
+ let t = e.detail.path.split("/").slice(1);
2187
+ this.options = G(this.options, t, e.detail.value), this.errors = [];
2188
+ }
2189
+ renderOptionFields() {
2190
+ let e = this.embed?.options ?? {};
2191
+ if (!Object.keys(e).length) return n;
2192
+ let { values: r, hidden: i } = this.resolvedOptions();
2193
+ return t`<edaha-metadata-field
2194
+ class="embed-dialog-options"
2195
+ path=${Wt}
2196
+ .schema=${{
2197
+ title: "Options",
2198
+ type: "object",
2199
+ properties: e
2200
+ }}
2201
+ .value=${r}
2202
+ .hiddenFields=${new Set([...i].map((e) => `${Wt}.${e}`))}
2203
+ @metadata-change=${this.onOptionChange}
2204
+ @metadata-blur=${(e) => e.stopPropagation()}
2205
+ ></edaha-metadata-field>`;
2206
+ }
2207
+ render() {
2208
+ let { embed: e } = this;
2209
+ return t`<dialog
2210
+ class="article-browser embed-dialog"
2211
+ aria-labelledby="embed-dialog-title"
2212
+ @close=${() => this.finish(void 0)}
2213
+ >
2214
+ <form @submit=${this.save}>
2215
+ <div class="article-browser-header">
2216
+ <h2 id="embed-dialog-title">
2217
+ ${this.changing ? "Change" : "Add"} ${e?.name ?? "embed"}
2218
+ </h2>
2219
+ <button
2220
+ type="button"
2221
+ class="btn-icon"
2222
+ title="Close"
2223
+ @click=${() => this.close()}
2224
+ >
2225
+ ${_("close")}<span class="visually-hidden">Close</span>
2226
+ </button>
2227
+ </div>
2228
+ <div class="embed-dialog-body">
2229
+ <p class="embed-dialog-about">
2230
+ ${ke(e)} <span>${e?.description ?? ""}</span>
2231
+ </p>
2232
+ <label for="embed-dialog-content">Content</label>
2233
+ <p id="embed-dialog-content-hint" class="embed-dialog-hint">
2234
+ ${e?.info ?? "Provide the embed's content, e.g. a URL or code"}
2235
+ </p>
2236
+ <textarea
2237
+ id="embed-dialog-content"
2238
+ rows="8"
2239
+ ?required=${!e?.contentOptional}
2240
+ spellcheck="false"
2241
+ aria-describedby=${this.errors.length ? "embed-dialog-errors embed-dialog-content-hint" : "embed-dialog-content-hint"}
2242
+ aria-invalid=${this.errors.length ? "true" : "false"}
2243
+ .value=${this.content}
2244
+ @input=${(e) => {
2245
+ this.content = e.target.value, this.errors = [];
2246
+ }}
2247
+ ></textarea>
2248
+ <div
2249
+ id="embed-dialog-errors"
2250
+ class="embed-dialog-errors"
2251
+ role="alert"
2252
+ >
2253
+ ${this.errors.length ? t`<ul>
2254
+ ${this.errors.map((e) => t`<li>${e}</li>`)}
2255
+ </ul>` : ""}
2256
+ </div>
2257
+ ${this.renderOptionFields()}
2258
+ </div>
2259
+ <div class="embed-dialog-actions">
2260
+ <button
2261
+ type="submit"
2262
+ class="btn"
2263
+ aria-disabled=${this.checking ? "true" : "false"}
2264
+ >
2265
+ ${this.checking ? "Checking…" : this.changing ? "Save" : "Add"}
2266
+ </button>
2267
+ <button type="button" class="btn" @click=${() => this.close()}>
2268
+ Cancel
2269
+ </button>
2270
+ </div>
2271
+ </form>
2272
+ </dialog>`;
2273
+ }
2274
+ });
2275
+ // src/client/components/edaha-article/index.ts
2276
+ var Gt = [
2277
+ {
2278
+ value: "published",
2279
+ label: "Published"
2280
+ },
2281
+ {
2282
+ value: "draft",
2283
+ label: "Draft"
2284
+ },
2285
+ {
2286
+ value: "unlisted",
2287
+ label: "Unlisted"
2288
+ }
2289
+ ], Kt = [
2290
+ {
2291
+ mode: "wysiwyg",
2292
+ label: "WYSIWYG"
2293
+ },
2294
+ {
2295
+ mode: "markdown",
2296
+ label: "Markdown"
2297
+ },
2298
+ {
2299
+ mode: "preview",
2300
+ label: "Preview"
2301
+ }
2302
+ ], qt = [
2303
+ {
2304
+ value: "full",
2305
+ label: "Full",
2306
+ width: "100%"
2307
+ },
2308
+ {
2309
+ value: "900",
2310
+ label: "900px",
2311
+ width: "900px"
2312
+ },
2313
+ {
2314
+ value: "600",
2315
+ label: "600px",
2316
+ width: "600px"
2317
+ },
2318
+ {
2319
+ value: "320",
2320
+ label: "320px",
2321
+ width: "320px"
2322
+ }
2323
+ ], Jt = (e) => `body-tab-${e}`, Yt = (e, t, n) => {
2324
+ switch (e) {
2325
+ case "ArrowRight": return (t + 1) % n;
2326
+ case "ArrowLeft": return (t - 1 + n) % n;
2327
+ case "Home": return 0;
2328
+ case "End": return n - 1;
2329
+ default: return;
2330
+ }
2331
+ }, Xt = (e = /* @__PURE__ */ new Date()) => ({
2332
+ type: "article",
2333
+ slug: "",
2334
+ status: "draft",
2335
+ date: e.toISOString(),
2336
+ title: "",
2337
+ author: void 0,
2338
+ excerpt: void 0,
2339
+ thumbnail: void 0,
2340
+ tags: [],
2341
+ attachments: [],
2342
+ bodyHtml: ""
2343
+ }), Zt = (e, t, n) => {
2344
+ let r = /^author\[(name|email|url)\]$/.exec(t);
2345
+ if (r) {
2346
+ let t = {
2347
+ name: "",
2348
+ ...e.author || {},
2349
+ [r[1]]: n || void 0
2350
+ };
2351
+ return {
2352
+ ...e,
2353
+ author: t.name || t.email || t.url ? {
2354
+ ...t,
2355
+ name: t.name ?? ""
2356
+ } : void 0
2357
+ };
2358
+ }
2359
+ let i = /^tags\[(\d+)\]$/.exec(t);
2360
+ if (i) {
2361
+ let t = [...e.tags];
2362
+ return t[Number(i[1])] = n, {
2363
+ ...e,
2364
+ tags: t
2365
+ };
2366
+ }
2367
+ let a = /^attachments\[(\d+)\]\[(url|name|thumbnail)\]$/.exec(t);
2368
+ if (a) {
2369
+ let t = [...e.attachments], r = Number(a[1]), i = a[2], o = t[r] ?? { url: "" };
2370
+ return t[r] = i === "url" ? {
2371
+ ...o,
2372
+ url: n
2373
+ } : {
2374
+ ...o,
2375
+ [i]: n || void 0
2376
+ }, {
2377
+ ...e,
2378
+ attachments: t
2379
+ };
2380
+ }
2381
+ switch (t) {
2382
+ case "date": return {
2383
+ ...e,
2384
+ date: Fe(n) || e.date
2385
+ };
2386
+ case "body": return {
2387
+ ...e,
2388
+ bodyHtml: n
2389
+ };
2390
+ case "excerpt":
2391
+ case "thumbnail": return {
2392
+ ...e,
2393
+ [t]: n || void 0
2394
+ };
2395
+ case "template": return {
2396
+ ...e,
2397
+ template: n === "single" ? void 0 : n
2398
+ };
2399
+ case "title":
2400
+ case "slug":
2401
+ case "type":
2402
+ case "status": return {
2403
+ ...e,
2404
+ [t]: n
2405
+ };
2406
+ default: return e;
2407
+ }
2408
+ }, Qt = (e) => ({
2409
+ ...e,
2410
+ slug: e.slug.trim() || u(e.title),
2411
+ title: e.title.trim(),
2412
+ tags: e.tags.map((e) => e.trim()).filter(Boolean),
2413
+ attachments: e.attachments.filter((e) => e.url.trim())
2414
+ }), $t = [
2415
+ "title",
2416
+ "type",
2417
+ "template",
2418
+ "status",
2419
+ "slug",
2420
+ "date",
2421
+ "author",
2422
+ "excerpt",
2423
+ "thumbnail",
2424
+ "tags",
2425
+ "attachments",
2426
+ "meta"
2427
+ ], J = (e) => Array.isArray(e) ? e.map(J) : e && typeof e == "object" ? Object.fromEntries(Object.entries(e).filter(([, e]) => e !== void 0).sort(([e], [t]) => e.localeCompare(t)).map(([e, t]) => [e, J(t)])) : e, Y = (e, t) => new Set($t.filter((n) => JSON.stringify(J(e[n])) !== JSON.stringify(J(t[n])))), en = [
2428
+ "type",
2429
+ "status",
2430
+ "slug",
2431
+ "date",
2432
+ "author",
2433
+ "tags",
2434
+ "excerpt",
2435
+ "template",
2436
+ "thumbnail",
2437
+ "attachments",
2438
+ "uploaded"
2439
+ ], X = (e) => en.includes(e), tn = (e) => t`<span class="visually-hidden">${e}</span>`, nn = (e) => new Set(e.filter((e) => e.openedByDefault).map((e) => e.key)), rn = "Some values aren't valid. Fix the fields marked ⚠️ in the settings.";
2440
+ x("edaha-article", class extends e {
2441
+ static properties = {
2442
+ api: { attribute: !1 },
2443
+ article: { attribute: !1 },
2444
+ typeOptions: { attribute: !1 },
2445
+ data: { state: !0 },
2446
+ files: { state: !0 },
2447
+ location: { state: !0 },
2448
+ busy: { state: !0 },
2449
+ message: { state: !0 },
2450
+ error: { state: !0 },
2451
+ templates: { state: !0 },
2452
+ mode: { state: !0 },
2453
+ bodyMarkdown: { state: !0 },
2454
+ previewUrl: { state: !0 },
2455
+ previewWidth: { state: !0 },
2456
+ metadataOpen: { state: !0 },
2457
+ savedData: { state: !0 },
2458
+ bodyChanged: { state: !0 },
2459
+ metadata: { attribute: !1 },
2460
+ site: { attribute: !1 },
2461
+ metaProblems: { state: !0 },
2462
+ openGroups: { state: !0 },
2463
+ compact: { attribute: !1 },
2464
+ focusMode: { attribute: !1 },
2465
+ pickFile: { attribute: !1 },
2466
+ embedTools: { state: !0 }
2467
+ };
2468
+ groupsOpened = !1;
2469
+ savedProblems = [];
2470
+ validatorFor;
2471
+ bodyCheckDelay = 300;
2472
+ savedBodyMarkdown = "";
2473
+ bodyChecks = 0;
2474
+ savedBodies = 0;
2475
+ bodyTimer;
2476
+ templatesType = "";
2477
+ confirm = (e) => window.confirm(e);
2478
+ constructor() {
2479
+ super(), this.typeOptions = [], this.data = Xt(), this.files = [], this.busy = !1, this.message = "", this.error = "", this.templates = [], this.mode = "wysiwyg", this.bodyMarkdown = "", this.previewUrl = "", this.previewWidth = "full", this.metadataOpen = !1, this.savedData = structuredClone(this.data), this.bodyChanged = !1, this.metaProblems = [], this.openGroups = nn(Te), this.compact = !1, this.focusMode = !1;
2480
+ }
2481
+ createRenderRoot() {
2482
+ return this;
2483
+ }
2484
+ toggleFocusMode() {
2485
+ this.dispatchEvent(new CustomEvent("focus-mode-change", {
2486
+ detail: !this.focusMode,
2487
+ bubbles: !0,
2488
+ composed: !0
2489
+ }));
2490
+ }
2491
+ connectedCallback() {
2492
+ super.connectedCallback(), this.loadEmbeds();
2493
+ }
2494
+ async firstUpdated() {
2495
+ if (this.article) return;
2496
+ let e = this.querySelector("edaha-article-data-field[name=\"title\"]");
2497
+ await e?.updateComplete, e?.querySelector("input")?.focus();
2498
+ }
2499
+ willUpdate(e) {
2500
+ if (e.get("compact") && !this.compact && (this.metadataOpen = !1), e.has("metadata") && this.metadata && !this.groupsOpened && (this.groupsOpened = !0, this.openGroups = nn(this.metadata.groups)), e.has("metaProblems")) {
2501
+ let e = this.groupsWithErrors();
2502
+ [...e].some((e) => !this.openGroups.has(e)) && (this.openGroups = /* @__PURE__ */ new Set([...this.openGroups, ...e]));
2503
+ }
2504
+ if (e.has("article")) {
2505
+ let { files: e, problems: t = [], ...n } = this.article ?? {
2506
+ ...Xt(),
2507
+ files: []
2508
+ };
2509
+ this.savedProblems = t.filter(({ level: e }) => e === "error"), this.metaProblems = this.savedProblems, this.data = n, this.files = e, this.location = this.article ? {
2510
+ type: this.article.type,
2511
+ slug: this.article.slug
2512
+ } : void 0, this.message = "", this.error = "", this.mode = "wysiwyg", this.savedData = structuredClone(n), this.bodyChanged = !1, this.rememberBody(n.bodyHtml, this.article ? void 0 : "");
2513
+ }
2514
+ if (this.api && this.data.type !== this.templatesType) {
2515
+ let e = this.data.type;
2516
+ this.templatesType = e, this.api.templates(e).then((t) => {
2517
+ this.data.type === e && (this.templates = t);
2518
+ }, () => {
2519
+ this.data.type === e && (this.templates = []);
2520
+ });
2521
+ }
2522
+ }
2523
+ fileUrl(e) {
2524
+ return !e || !this.location || /^([a-z][a-z0-9+.-]*:|\/)/i.test(e) ? e : `/files/${this.location.type}/${this.location.slug}/${e}`;
2525
+ }
2526
+ fileAddress = (e) => {
2527
+ let t = this.fileUrl(e);
2528
+ return t && this.api.url(t);
2529
+ };
2530
+ bodyFileAddress = (e) => this.api.url(e);
2531
+ async run(e) {
2532
+ this.busy = !0, this.error = "", this.message = "";
2533
+ try {
2534
+ return await e();
2535
+ } catch (e) {
2536
+ this.error = e.message, e instanceof y && e.problems && (this.metaProblems = e.problems), U(this, {
2537
+ kind: "error",
2538
+ message: this.error
2539
+ });
2540
+ return;
2541
+ } finally {
2542
+ this.busy = !1;
2543
+ }
2544
+ }
2545
+ async upload(e) {
2546
+ let t = this.location;
2547
+ if (!t) return;
2548
+ let n = await this.run(() => this.api.upload(t, e));
2549
+ return n && !this.files.includes(n.name) && (this.files = [...this.files, n.name].sort()), n?.name;
2550
+ }
2551
+ uploadImage = async (e) => {
2552
+ let t = await this.upload(e);
2553
+ if (!t) throw Error("Upload failed");
2554
+ return this.fileUrl(t);
2555
+ };
2556
+ uploadMarkdownImage = async (e) => {
2557
+ let t = await this.upload(e);
2558
+ if (!t) throw Error("Upload failed");
2559
+ return t;
2560
+ };
2561
+ chooseFile = async (e) => {
2562
+ let t = await this.pickFile?.(e);
2563
+ if (t) return {
2564
+ url: t.type === this.location?.type && t.slug === this.location.slug ? t.name : t.url,
2565
+ name: t.name,
2566
+ kind: t.kind
2567
+ };
2568
+ };
2569
+ chooseBodyFile = async (e) => {
2570
+ let t = await this.chooseFile(e);
2571
+ return t && {
2572
+ ...t,
2573
+ url: this.fileUrl(t.url)
2574
+ };
2575
+ };
2576
+ choosers() {
2577
+ return this.pickFile ? {
2578
+ file: this.chooseFile,
2579
+ body: this.chooseBodyFile
2580
+ } : {
2581
+ file: void 0,
2582
+ body: void 0
2583
+ };
2584
+ }
2585
+ async loadEmbeds() {
2586
+ try {
2587
+ let e = await this.api.embeds();
2588
+ this.embedTools = {
2589
+ embeds: e,
2590
+ edit: async (t, n) => {
2591
+ let r = e.find((e) => e.key === t.key), i = this.querySelector("edaha-embed-dialog");
2592
+ return r ? i.edit(r, t, n, (e) => this.api.validateEmbed(e.key, e.content, e.options)) : void 0;
2593
+ },
2594
+ loadFrame: async ({ key: e, content: t, options: n }) => {
2595
+ let r = await this.api.embedFrame(e, t, n);
2596
+ return {
2597
+ ...r,
2598
+ url: r.url && this.api.previewUrl(r.url)
2599
+ };
2600
+ }
2601
+ };
2602
+ } catch {
2603
+ this.embedTools = void 0;
2604
+ }
2605
+ }
2606
+ onFieldChange(e) {
2607
+ let { name: t, value: n } = e.detail;
2608
+ t === "bodyMarkdown" ? this.bodyMarkdown = n : this.data = Zt(this.data, t, n), (t === "body" || t === "bodyMarkdown") && this.scheduleBodyCheck();
2609
+ }
2610
+ async currentBodyMarkdown() {
2611
+ return this.mode === "markdown" ? this.bodyMarkdown : this.api.toMarkdown(this.data.bodyHtml, this.location);
2612
+ }
2613
+ scheduleBodyCheck() {
2614
+ clearTimeout(this.bodyTimer), this.bodyTimer = setTimeout(() => void this.checkBody(), this.bodyCheckDelay);
2615
+ }
2616
+ async checkBody() {
2617
+ clearTimeout(this.bodyTimer);
2618
+ let e = ++this.bodyChecks, t = await this.currentBodyMarkdown().catch(() => void 0);
2619
+ e === this.bodyChecks && t !== void 0 && this.savedBodyMarkdown !== void 0 && (this.bodyChanged = t !== this.savedBodyMarkdown);
2620
+ }
2621
+ async rememberBody(e, t) {
2622
+ let n = ++this.savedBodies, r = t;
2623
+ try {
2624
+ r ??= await this.api.toMarkdown(e, this.location);
2625
+ } catch {}
2626
+ n === this.savedBodies && (this.savedBodyMarkdown = r, await this.checkBody());
2627
+ }
2628
+ get dirty() {
2629
+ return this.bodyChanged || Y(this.data, this.savedData).size > 0;
2630
+ }
2631
+ async hasChanges() {
2632
+ return await this.checkBody(), this.dirty;
2633
+ }
2634
+ async onFieldFile(e) {
2635
+ let t = e.target.name, n = await this.upload(e.detail);
2636
+ n && (this.data = Zt(this.data, t, n));
2637
+ }
2638
+ async syncBody() {
2639
+ if (this.mode !== "markdown") return !0;
2640
+ let e = await this.run(() => this.api.toHtml(this.bodyMarkdown, this.location));
2641
+ return e !== void 0 && (this.data = {
2642
+ ...this.data,
2643
+ bodyHtml: e
2644
+ }, !0);
2645
+ }
2646
+ async setMode(e) {
2647
+ if (e !== this.mode && await this.syncBody()) {
2648
+ if (e === "markdown") {
2649
+ let e = await this.run(() => this.api.toMarkdown(this.data.bodyHtml, this.location));
2650
+ if (e === void 0) return;
2651
+ this.bodyMarkdown = e;
2652
+ } else if (e === "preview") {
2653
+ let e = await this.run(() => this.api.preview(Qt(this.data), this.location));
2654
+ if (e === void 0) return;
2655
+ this.previewUrl = e;
2656
+ }
2657
+ this.mode = e;
2658
+ }
2659
+ }
2660
+ async save() {
2661
+ let { values: e } = this.resolvedMeta(), t = this.metadataKeys().flatMap((t) => this.checkMetadata(t, e));
2662
+ if (t.length) return this.metaProblems = t, U(this, {
2663
+ kind: "error",
2664
+ message: rn
2665
+ }), !1;
2666
+ if (!await this.syncBody()) return !1;
2667
+ let n = this.metadataKeys(), r = Qt({
2668
+ ...this.data,
2669
+ meta: {
2670
+ ...Object.fromEntries(Object.entries(this.data.meta ?? {}).filter(([e]) => !n.includes(e))),
2671
+ ...e
2672
+ }
2673
+ }), i = this.location, a = await this.run(() => i ? this.api.save(i, r) : this.api.create(r));
2674
+ return a ? (this.data = r, this.savedData = structuredClone(r), this.savedProblems = [], this.metaProblems = [], this.location = a, this.message = "Saved", U(this, {
2675
+ kind: "success",
2676
+ message: this.message
2677
+ }), this.bodyChanged = !1, this.rememberBody(r.bodyHtml, this.mode === "markdown" ? this.bodyMarkdown : void 0), this.dispatchEvent(new CustomEvent("article-saved", {
2678
+ detail: a,
2679
+ bubbles: !0
2680
+ })), !0) : !1;
2681
+ }
2682
+ reset() {
2683
+ this.confirm("Reset this article to how it was last saved? Your changes will be lost.") && (clearTimeout(this.bodyTimer), this.bodyChecks++, this.data = structuredClone(this.savedData), this.metaProblems = this.savedProblems, this.mode = "wysiwyg", this.bodyChanged = !1, this.error = "", this.message = "Reset to the last saved version", U(this, {
2684
+ kind: "success",
2685
+ message: this.message
2686
+ }));
2687
+ }
2688
+ async deleteArticle() {
2689
+ let e = this.location;
2690
+ e && this.confirm(`Delete "${this.data.title}" and all its files?`) && await this.run(async () => (await this.api.remove(e), !0)) && (U(this, {
2691
+ kind: "success",
2692
+ message: `Deleted "${this.data.title}"`
2693
+ }), this.dispatchEvent(new CustomEvent("article-deleted", { bubbles: !0 })));
2694
+ }
2695
+ validator() {
2696
+ let { definitions: e } = this.metadata;
2697
+ return this.validatorFor?.definitions !== e && (this.validatorFor = {
2698
+ definitions: e,
2699
+ validator: new xe(e)
2700
+ }), this.validatorFor.validator;
2701
+ }
2702
+ metadataKeys() {
2703
+ return we(this.metadata?.definitions ?? {}, this.metadata?.types[this.data.type]);
2704
+ }
2705
+ resolvedMeta() {
2706
+ let e = this.metadata?.definitions ?? {}, t = Object.fromEntries(this.metadataKeys().map((t) => [t, e[t]]));
2707
+ return be(t, Object.fromEntries(Object.entries(this.data.meta ?? {}).filter(([e]) => e in t)));
2708
+ }
2709
+ checkMetadata(e, t = this.resolvedMeta().values) {
2710
+ let n = t[e];
2711
+ return n === void 0 ? [] : this.validator().validate(e, n);
2712
+ }
2713
+ onMetadataChange(e) {
2714
+ let { path: t, value: n } = e.detail;
2715
+ this.data = {
2716
+ ...this.data,
2717
+ meta: G(this.data.meta, t.split("/"), n)
2718
+ };
2719
+ }
2720
+ onMetadataBlur(e) {
2721
+ let t = e.detail.split("/")[0], n = (e) => e.path.split("/")[0] === t, r = this.metaProblems.some(n), i = this.checkMetadata(t);
2722
+ this.metaProblems = [...this.metaProblems.filter((e) => !n(e)), ...i], i.length && !r && U(this, {
2723
+ kind: "error",
2724
+ message: rn
2725
+ });
2726
+ }
2727
+ removeSetting(e) {
2728
+ this.data = {
2729
+ ...this.data,
2730
+ meta: G(this.data.meta, [e], void 0)
2731
+ };
2732
+ }
2733
+ metadataWarnings() {
2734
+ let e = this.metadataKeys(), t = this.metadata?.definitions ?? {};
2735
+ return Object.keys(this.data.meta ?? {}).filter((t) => !e.includes(t)).map((e) => ({
2736
+ path: e,
2737
+ message: e in t ? "isn't used by this article's type" : "isn't a known setting",
2738
+ level: "warning"
2739
+ }));
2740
+ }
2741
+ isChanged(e) {
2742
+ return Y(this.data, this.savedData).has(e);
2743
+ }
2744
+ defaultAuthor() {
2745
+ if (!this.site) return;
2746
+ let e = this.site.types[this.data.type];
2747
+ return e === void 0 ? this.site.author : e || void 0;
2748
+ }
2749
+ renderAuthor() {
2750
+ let e = this.data.author === !1, n = e ? void 0 : this.data.author, r = this.defaultAuthor(), i = n || e ? void 0 : r, a = e ? "" : this.site ? r ? `Defaults to ${r.name}` : "No author unless you name one" : "Defaults to the site name";
2751
+ return t`<edaha-article-data-group
2752
+ name="author"
2753
+ label="Author"
2754
+ ?changed=${this.isChanged("author")}
2755
+ allowclear
2756
+ @group-clear=${() => this.data = {
2757
+ ...this.data,
2758
+ author: void 0
2759
+ }}
2760
+ >
2761
+ <label class="no-author">
2762
+ <input
2763
+ type="checkbox"
2764
+ .checked=${e}
2765
+ @change=${(e) => this.data = {
2766
+ ...this.data,
2767
+ author: !e.target.checked && void 0
2768
+ }}
2769
+ />
2770
+ No author
2771
+ </label>
2772
+ <edaha-article-data-field
2773
+ name="author[name]"
2774
+ label="Name"
2775
+ placeholder=${a}
2776
+ ?disabled=${e}
2777
+ .value=${n?.name ?? ""}
2778
+ ></edaha-article-data-field>
2779
+ <edaha-article-data-field
2780
+ name="author[email]"
2781
+ type="email"
2782
+ label="Email address"
2783
+ placeholder=${i?.email ?? ""}
2784
+ ?disabled=${e}
2785
+ .value=${n?.email ?? ""}
2786
+ ></edaha-article-data-field>
2787
+ <edaha-article-data-field
2788
+ name="author[url]"
2789
+ type="url"
2790
+ label="Homepage"
2791
+ placeholder=${i?.url ?? "https://example.com"}
2792
+ ?disabled=${e}
2793
+ .value=${n?.url ?? ""}
2794
+ ></edaha-article-data-field>
2795
+ </edaha-article-data-group>`;
2796
+ }
2797
+ renderTags() {
2798
+ return t`<edaha-article-data-group
2799
+ name="tags"
2800
+ label="Tags"
2801
+ ?changed=${this.isChanged("tags")}
2802
+ multiple
2803
+ @group-add=${() => this.data = {
2804
+ ...this.data,
2805
+ tags: [...this.data.tags, ""]
2806
+ }}
2807
+ >
2808
+ ${this.data.tags.map((e, n) => t`<div class="tag">
2809
+ <edaha-article-data-field
2810
+ name="tags[${n}]"
2811
+ .value=${e}
2812
+ ></edaha-article-data-field>
2813
+ <button
2814
+ type="button"
2815
+ class="remove"
2816
+ @click=${() => this.data = {
2817
+ ...this.data,
2818
+ tags: this.data.tags.filter((e, t) => t !== n)
2819
+ }}
2820
+ >
2821
+ Remove tag
2822
+ </button>
2823
+ </div>`)}
2824
+ </edaha-article-data-group>`;
2825
+ }
2826
+ renderAttachments() {
2827
+ let e = !this.location;
2828
+ return t`<edaha-article-data-group
2829
+ name="attachments"
2830
+ label="Attachments"
2831
+ ?changed=${this.isChanged("attachments")}
2832
+ multiple
2833
+ @group-add=${() => this.data = {
2834
+ ...this.data,
2835
+ attachments: [...this.data.attachments, { url: "" }]
2836
+ }}
2837
+ >
2838
+ ${this.data.attachments.map((n, r) => t`<edaha-article-data-group name="attachments[${r}]">
2839
+ <edaha-article-data-field
2840
+ name="attachments[${r}][url]"
2841
+ type="file"
2842
+ label="Upload file"
2843
+ accept="image/png, image/jpeg, image/gif, application/zip, application/pdf"
2844
+ .value=${n.url}
2845
+ preview
2846
+ .previewUrl=${this.fileAddress(n.url)}
2847
+ .chooseFile=${this.choosers().file}
2848
+ allowchange
2849
+ ?disabled=${e}
2850
+ ></edaha-article-data-field>
2851
+ <edaha-article-data-field
2852
+ name="attachments[${r}][url]"
2853
+ type="text"
2854
+ label="File name or link"
2855
+ placeholder="https://example.com/file.pdf"
2856
+ .value=${n.url}
2857
+ ></edaha-article-data-field>
2858
+ <edaha-article-data-field
2859
+ name="attachments[${r}][name]"
2860
+ label="Name"
2861
+ placeholder="Defaults to the file name"
2862
+ .value=${n.name ?? ""}
2863
+ allowclear
2864
+ ></edaha-article-data-field>
2865
+ <button
2866
+ type="button"
2867
+ class="remove"
2868
+ @click=${() => this.data = {
2869
+ ...this.data,
2870
+ attachments: this.data.attachments.filter((e, t) => t !== r)
2871
+ }}
2872
+ >
2873
+ Remove attachment
2874
+ </button>
2875
+ </edaha-article-data-group>`)}
2876
+ </edaha-article-data-group>`;
2877
+ }
2878
+ renderBody() {
2879
+ let e;
2880
+ return e = this.mode === "markdown" ? t`<edaha-article-data-field
2881
+ name="bodyMarkdown"
2882
+ type="markdown"
2883
+ label="Body"
2884
+ ?changed=${this.bodyChanged}
2885
+ .value=${this.bodyMarkdown}
2886
+ .uploadImage=${this.location ? this.uploadMarkdownImage : void 0}
2887
+ .chooseFile=${this.choosers().file}
2888
+ .embedTools=${this.embedTools}
2889
+ ></edaha-article-data-field>` : this.mode === "preview" ? t`<div class="preview-controls">
2890
+ <label for="preview-width">Width</label>
2891
+ <select
2892
+ id="preview-width"
2893
+ @change=${(e) => this.previewWidth = e.target.value}
2894
+ >
2895
+ ${qt.map(({ value: e, label: n }) => t`<option
2896
+ value=${e}
2897
+ ?selected=${this.previewWidth === e}
2898
+ >
2899
+ ${n}
2900
+ </option>`)}
2901
+ </select>
2902
+ </div>
2903
+ <div class="preview-frame">
2904
+ <iframe
2905
+ class="preview"
2906
+ title="Preview"
2907
+ src=${this.api.previewUrl(this.previewUrl)}
2908
+ style=${c({ width: qt.find(({ value: e }) => e === this.previewWidth)?.width })}
2909
+ ></iframe>
2910
+ </div>` : t`<edaha-article-data-field
2911
+ name="body"
2912
+ type="richtext"
2913
+ label="Body"
2914
+ ?changed=${this.bodyChanged}
2915
+ .value=${this.data.bodyHtml}
2916
+ .uploadImage=${this.location ? this.uploadImage : void 0}
2917
+ .chooseFile=${this.choosers().body}
2918
+ .embedTools=${this.embedTools}
2919
+ .fileAddress=${this.bodyFileAddress}
2920
+ ></edaha-article-data-field>`, t`<div
2921
+ class="body-tabs"
2922
+ role="tablist"
2923
+ aria-label="Body"
2924
+ @keydown=${this.onTabKey}
2925
+ >
2926
+ ${Kt.map(({ mode: e, label: n }) => t`<button
2927
+ type="button"
2928
+ role="tab"
2929
+ id=${Jt(e)}
2930
+ data-mode=${e}
2931
+ aria-selected=${this.mode === e ? "true" : "false"}
2932
+ aria-controls="body-panel"
2933
+ tabindex=${this.mode === e ? 0 : -1}
2934
+ ?disabled=${this.busy}
2935
+ @click=${() => void this.setMode(e)}
2936
+ >
2937
+ ${n}
2938
+ </button>`)}
2939
+ </div>
2940
+ <div
2941
+ class="body-panel body-panel-${this.mode}"
2942
+ id="body-panel"
2943
+ role="tabpanel"
2944
+ aria-labelledby=${Jt(this.mode)}
2945
+ >
2946
+ ${e}
2947
+ </div>`;
2948
+ }
2949
+ onTabKey(e) {
2950
+ let t = [...e.currentTarget.querySelectorAll("[role=\"tab\"]")], n = t.indexOf(e.target), r = Yt(e.key, n, t.length);
2951
+ r !== void 0 && (e.preventDefault(), t[r]?.focus());
2952
+ }
2953
+ groups() {
2954
+ return this.metadata?.groups ?? Te;
2955
+ }
2956
+ groupsWithErrors() {
2957
+ let e = new Set(this.metaProblems.filter(({ level: e }) => e === "error").map(({ path: e }) => e.split("/")[0]));
2958
+ return new Set(this.groups().filter((t) => t.fields.some((t) => e.has(t))).map((e) => e.key));
2959
+ }
2960
+ settingChanged(e, t) {
2961
+ return t.has(e) ? !0 : !X(e) && JSON.stringify(J(this.data.meta?.[e])) !== JSON.stringify(J(this.savedData.meta?.[e]));
2962
+ }
2963
+ renderSetting(e, n, r) {
2964
+ let { data: i } = this;
2965
+ switch (e) {
2966
+ case "type": return t`<edaha-article-data-field
2967
+ name="type"
2968
+ ?changed=${n.has("type")}
2969
+ type="select"
2970
+ label="Type"
2971
+ .options=${r}
2972
+ .value=${i.type}
2973
+ ></edaha-article-data-field>`;
2974
+ case "status": return t`<edaha-article-data-field
2975
+ name="status"
2976
+ ?changed=${n.has("status")}
2977
+ type="select"
2978
+ label="Status"
2979
+ .options=${Gt}
2980
+ .value=${i.status}
2981
+ ></edaha-article-data-field>`;
2982
+ case "slug": return t`<edaha-article-data-field
2983
+ name="slug"
2984
+ ?changed=${n.has("slug")}
2985
+ label="Slug"
2986
+ placeholder=${u(i.title) || "title-converted-to-slug"}
2987
+ .value=${i.slug}
2988
+ ></edaha-article-data-field>`;
2989
+ case "date": return t`<edaha-article-data-field
2990
+ name="date"
2991
+ ?changed=${n.has("date")}
2992
+ type="datetime-local"
2993
+ label="Publication date"
2994
+ .value=${Pe(i.date)}
2995
+ ></edaha-article-data-field>`;
2996
+ case "author": return this.renderAuthor();
2997
+ case "tags": return this.renderTags();
2998
+ case "excerpt": return t`<edaha-article-data-field
2999
+ name="excerpt"
3000
+ ?changed=${n.has("excerpt")}
3001
+ type="textarea"
3002
+ label="Excerpt"
3003
+ placeholder="Defaults to the text before the read more break"
3004
+ .value=${i.excerpt ?? ""}
3005
+ allowclear
3006
+ ></edaha-article-data-field>`;
3007
+ case "template": return t`<edaha-article-data-field
3008
+ name="template"
3009
+ ?changed=${n.has("template")}
3010
+ type="select"
3011
+ label="Template"
3012
+ .options=${[.../* @__PURE__ */ new Set([
3013
+ "single",
3014
+ ...this.templates,
3015
+ i.template ?? "single"
3016
+ ])].map((e) => ({
3017
+ value: e,
3018
+ label: e
3019
+ }))}
3020
+ .value=${i.template ?? "single"}
3021
+ ></edaha-article-data-field>`;
3022
+ case "thumbnail": return t`<edaha-article-data-field
3023
+ name="thumbnail"
3024
+ ?changed=${n.has("thumbnail")}
3025
+ type="file"
3026
+ label="Thumbnail"
3027
+ accept="image/png, image/jpeg"
3028
+ .value=${i.thumbnail ?? ""}
3029
+ preview
3030
+ .previewUrl=${this.fileAddress(i.thumbnail)}
3031
+ .chooseFile=${this.choosers().file}
3032
+ allowchange
3033
+ allowclear
3034
+ ?disabled=${!this.location}
3035
+ ></edaha-article-data-field>`;
3036
+ case "attachments": return this.renderAttachments();
3037
+ case "uploaded": return this.renderUploaded();
3038
+ }
3039
+ }
3040
+ renderUploaded() {
3041
+ return this.location ? this.files.length ? t`<div class="files">
3042
+ <h3 class="files-title">
3043
+ Files in this article's folder (${this.files.length})
3044
+ </h3>
3045
+ <ul>
3046
+ ${this.files.map((e) => t`<li><a href=${this.fileAddress(e)} target="_blank">${e}</a></li>`)}
3047
+ </ul>
3048
+ </div>` : n : t`<p class="hint">Save the article before uploading files.</p>`;
3049
+ }
3050
+ renderCustomField(e, { values: r, hidden: i }) {
3051
+ return i.has(e) ? n : t`<edaha-metadata-field
3052
+ path=${e}
3053
+ .schema=${this.metadata.definitions[e]}
3054
+ .value=${r[e]}
3055
+ .problems=${this.metaProblems}
3056
+ .hiddenFields=${i}
3057
+ .uploadFile=${this.location ? this.uploadMarkdownImage : void 0}
3058
+ .chooseFile=${this.choosers().file}
3059
+ .fileUrl=${(e) => this.fileAddress(e)}
3060
+ ></edaha-metadata-field>`;
3061
+ }
3062
+ renderGroups(e, r) {
3063
+ let i = this.metadataKeys(), o = this.resolvedMeta(), s = this.metadataWarnings(), c = this.groupsWithErrors();
3064
+ return this.groups().map((l) => {
3065
+ let u = l.fields.filter((e) => X(e) || i.includes(e)).map((t) => X(t) ? this.renderSetting(t, e, r) : this.renderCustomField(t, o)).filter((e) => e !== n), d = l.key === "custom" ? s : [];
3066
+ if (!u.length && !d.length) return n;
3067
+ let f = l.fields.some((t) => this.settingChanged(t, e)), p = c.has(l.key);
3068
+ return t`<details
3069
+ class="settings-group ${a({ "has-errors": p })}"
3070
+ data-group=${l.key}
3071
+ ?open=${this.openGroups.has(l.key)}
3072
+ @toggle=${(e) => {
3073
+ let t = e.target.open, n = new Set(this.openGroups);
3074
+ t ? n.add(l.key) : n.delete(l.key), this.openGroups = n;
3075
+ }}
3076
+ >
3077
+ <summary>
3078
+ ${l.title}${f ? t`<span class="changed" title="Changed since it was saved"
3079
+ >*</span
3080
+ >` : n}${p || d.length ? t`<span class="settings-group-errors">
3081
+ ⚠️<span class="visually-hidden">
3082
+ ${p ? "has errors" : "has warnings"}</span
3083
+ ></span
3084
+ >` : n}
3085
+ </summary>
3086
+ ${l.description ? t`<p class="settings-group-description">
3087
+ ${l.description}
3088
+ </p>` : n}
3089
+ ${u}
3090
+ ${d.length ? t`<ul class="metadata-warnings">
3091
+ ${d.map(({ path: e, message: n }) => t`<li>
3092
+ <span
3093
+ >"${e}" ${n}; it is kept unless you remove
3094
+ it.</span
3095
+ >
3096
+ <button
3097
+ type="button"
3098
+ class="btn btn-xs"
3099
+ @click=${() => this.removeSetting(e)}
3100
+ >
3101
+ Remove${tn(` "${e}"`)}
3102
+ </button>
3103
+ </li>`)}
3104
+ </ul>` : n}
3105
+ </details>`;
3106
+ });
3107
+ }
3108
+ render() {
3109
+ let { data: e } = this, r = Y(e, this.savedData), i = this.typeOptions.some((t) => t.value === e.type) ? this.typeOptions : [...this.typeOptions, {
3110
+ value: e.type,
3111
+ label: e.type
3112
+ }];
3113
+ return t`<form
3114
+ @field-change=${this.onFieldChange}
3115
+ @metadata-change=${this.onMetadataChange}
3116
+ @metadata-blur=${this.onMetadataBlur}
3117
+ @field-file=${(e) => void this.onFieldFile(e)}
3118
+ @submit=${(e) => {
3119
+ e.preventDefault(), this.save();
3120
+ }}
3121
+ >
3122
+ <!-- Out of reach while the settings are open over it -->
3123
+ <main class="edaha-article-main" ?inert=${this.metadataOpen}>
3124
+ <div class="edaha-article-title">
3125
+ <edaha-article-data-field
3126
+ name="title"
3127
+ label="Title"
3128
+ ?changed=${r.has("title")}
3129
+ placeholder="New article title"
3130
+ .value=${e.title}
3131
+ ></edaha-article-data-field>
3132
+ <!-- Only on wide screens: narrow screens always have the compact layout focus mode gives -->
3133
+ <button
3134
+ type="button"
3135
+ class="btn-icon btn-focus-mode"
3136
+ title="Focus mode"
3137
+ aria-pressed=${this.focusMode ? "true" : "false"}
3138
+ @click=${() => this.toggleFocusMode()}
3139
+ >
3140
+ ${_(this.focusMode ? "fullscreen_exit" : "fullscreen")}<span
3141
+ class="visually-hidden"
3142
+ >Focus mode</span
3143
+ >
3144
+ </button>
3145
+ </div>
3146
+ ${this.location ? n : t`<p class="unsaved-notice">
3147
+ ⚠️ Uploading images and attachments will require a title and
3148
+ slug to be defined first
3149
+ </p>`}
3150
+ ${this.renderBody()}
3151
+ </main>
3152
+ <aside
3153
+ class="edaha-article-metadata ${a({ open: this.metadataOpen })}"
3154
+ aria-label="Article settings"
3155
+ @keydown=${(e) => {
3156
+ e.key === "Escape" && (this.metadataOpen = !1);
3157
+ }}
3158
+ >
3159
+ <!-- In the compact layout, a bar at the bottom of the screen that opens the settings full screen -->
3160
+ <div class="edaha-article-controls">
3161
+ <!-- Marked while there are unsaved changes, to show the article should be saved -->
3162
+ <button
3163
+ type="submit"
3164
+ class="btn btn-save ${a({ "btn-save-dirty": this.dirty })}"
3165
+ ?disabled=${this.busy}
3166
+ >
3167
+ Save
3168
+ </button>
3169
+ <button
3170
+ type="button"
3171
+ class="btn btn-reset"
3172
+ ?disabled=${this.busy || !this.dirty}
3173
+ @click=${() => this.reset()}
3174
+ >
3175
+ Reset…
3176
+ </button>
3177
+ ${this.location ? t`<button
3178
+ type="button"
3179
+ class="btn btn-delete"
3180
+ ?disabled=${this.busy}
3181
+ @click=${() => void this.deleteArticle()}
3182
+ >
3183
+ Delete…
3184
+ </button>` : n}
3185
+ <button
3186
+ type="button"
3187
+ class="btn btn-metadata-toggle"
3188
+ title=${this.metadataOpen ? "Hide article settings" : "Show article settings"}
3189
+ aria-expanded=${this.metadataOpen ? "true" : "false"}
3190
+ aria-controls="article-metadata-fields"
3191
+ @click=${() => this.metadataOpen = !this.metadataOpen}
3192
+ >
3193
+ <span aria-hidden="true">${this.metadataOpen ? "︾" : "︽"}</span>
3194
+ <span class="visually-hidden">Article settings</span>
3195
+ </button>
3196
+ </div>
3197
+ <div
3198
+ class="edaha-article-metadata-fields"
3199
+ id="article-metadata-fields"
3200
+ >
3201
+ ${this.renderGroups(r, i)}
3202
+ </div>
3203
+ </aside>
3204
+ </form>
3205
+ <!-- Outside the form, as it has its own -->
3206
+ <edaha-embed-dialog></edaha-embed-dialog>`;
3207
+ }
3208
+ });
3209
+ // src/client/components/edaha-article-browser/index.ts
3210
+ var an = [
3211
+ {
3212
+ value: "errors",
3213
+ label: "With errors"
3214
+ },
3215
+ {
3216
+ value: "warnings",
3217
+ label: "With warnings"
3218
+ },
3219
+ {
3220
+ value: "any",
3221
+ label: "With errors or warnings"
3222
+ }
3223
+ ], Z = (e = []) => {
3224
+ let t = (t) => {
3225
+ let n = e.filter((e) => e.level === t).length;
3226
+ return n ? `${n} ${t}${n === 1 ? "" : "s"}` : "";
3227
+ };
3228
+ return [t("error"), t("warning")].filter(Boolean).join(", ");
3229
+ }, on = [
3230
+ {
3231
+ value: "published",
3232
+ label: "Published"
3233
+ },
3234
+ {
3235
+ value: "draft",
3236
+ label: "Draft"
3237
+ },
3238
+ {
3239
+ value: "unlisted",
3240
+ label: "Unlisted"
3241
+ }
3242
+ ], sn = [
3243
+ {
3244
+ sort: "title",
3245
+ label: "Title"
3246
+ },
3247
+ {
3248
+ sort: "type",
3249
+ label: "Type"
3250
+ },
3251
+ {
3252
+ sort: "status",
3253
+ label: "Status"
3254
+ },
3255
+ {
3256
+ sort: "date",
3257
+ label: "Published"
3258
+ },
3259
+ {
3260
+ sort: "updated",
3261
+ label: "Changed"
3262
+ }
3263
+ ], cn = "article-choose", Q = (e, t) => e[t]?.labelSingle ?? t;
3264
+ x("edaha-article-browser", class extends e {
3265
+ static properties = {
3266
+ api: { attribute: !1 },
3267
+ types: { attribute: !1 },
3268
+ search: { state: !0 },
3269
+ type: { state: !0 },
3270
+ author: { state: !0 },
3271
+ tag: { state: !0 },
3272
+ status: { state: !0 },
3273
+ problems: { state: !0 },
3274
+ sort: { state: !0 },
3275
+ order: { state: !0 },
3276
+ page: { state: !0 },
3277
+ result: { state: !0 },
3278
+ filters: { state: !0 },
3279
+ loading: { state: !0 },
3280
+ error: { state: !0 }
3281
+ };
3282
+ searchDelay = 250;
3283
+ searchTimer;
3284
+ searches = 0;
3285
+ constructor() {
3286
+ super(), this.types = {}, this.search = "", this.type = "", this.author = "", this.tag = "", this.status = "", this.problems = "", this.page = 1, this.filters = {
3287
+ types: [],
3288
+ authors: [],
3289
+ tags: []
3290
+ }, this.loading = !1, this.error = "";
3291
+ }
3292
+ createRenderRoot() {
3293
+ return this;
3294
+ }
3295
+ get dialog() {
3296
+ return this.querySelector("dialog");
3297
+ }
3298
+ get open() {
3299
+ return this.dialog?.open ?? !1;
3300
+ }
3301
+ async show(e = {}) {
3302
+ this.search = e.search ?? "", this.type = e.type ?? "", this.author = "", this.tag = "", this.status = "", this.problems = e.problems ?? "", this.page = 1, await this.updateComplete, this.open || this.dialog?.showModal(), this.querySelector("#article-browser-search")?.focus(), await Promise.all([this.loadFilters(), this.load()]);
3303
+ }
3304
+ close() {
3305
+ clearTimeout(this.searchTimer), this.open && this.dialog?.close();
3306
+ }
3307
+ async loadFilters() {
3308
+ try {
3309
+ this.filters = await this.api.filters();
3310
+ } catch {}
3311
+ }
3312
+ async load() {
3313
+ clearTimeout(this.searchTimer);
3314
+ let e = ++this.searches;
3315
+ this.loading = !0;
3316
+ try {
3317
+ let t = await this.api.query({
3318
+ search: this.search,
3319
+ type: this.type,
3320
+ author: this.author,
3321
+ tag: this.tag,
3322
+ status: this.status || void 0,
3323
+ problems: this.problems || void 0,
3324
+ sort: this.sort,
3325
+ order: this.order,
3326
+ page: this.page
3327
+ });
3328
+ if (e !== this.searches) return;
3329
+ this.result = t, this.error = "";
3330
+ } catch (t) {
3331
+ if (e !== this.searches) return;
3332
+ this.error = t.message;
3333
+ }
3334
+ this.loading = !1;
3335
+ }
3336
+ choose(e, t) {
3337
+ this[e] = t, this.page = 1, this.load();
3338
+ }
3339
+ onSearch(e) {
3340
+ this.search = e, this.page = 1, clearTimeout(this.searchTimer), this.searchTimer = setTimeout(() => void this.load(), this.searchDelay);
3341
+ }
3342
+ sortBy(e) {
3343
+ ({sort: this.sort, order: this.order} = B({
3344
+ sort: this.sort,
3345
+ order: this.order
3346
+ }, e)), this.page = 1, this.load();
3347
+ }
3348
+ async goTo(e) {
3349
+ this.page = e, await this.load(), this.querySelector(".article-browser-results")?.scrollTo?.(0, 0);
3350
+ }
3351
+ chooseArticle(e) {
3352
+ this.close(), this.dispatchEvent(new CustomEvent(cn, {
3353
+ detail: {
3354
+ type: e.type,
3355
+ slug: e.slug
3356
+ },
3357
+ bubbles: !0
3358
+ }));
3359
+ }
3360
+ renderSelect(e, n, r, i) {
3361
+ let a = `article-browser-${e}`;
3362
+ return t`<div class="article-browser-field">
3363
+ <label for=${a}>${n}</label>
3364
+ <select
3365
+ id=${a}
3366
+ @change=${(t) => this.choose(e, t.target.value)}
3367
+ >
3368
+ <option value="" ?selected=${!this[e]}>${r}</option>
3369
+ ${i.map((n) => t`<option
3370
+ value=${n.value}
3371
+ ?selected=${this[e] === n.value}
3372
+ >
3373
+ ${n.label}
3374
+ </option>`)}
3375
+ </select>
3376
+ </div>`;
3377
+ }
3378
+ renderResults() {
3379
+ let e = this.result;
3380
+ if (!e) return n;
3381
+ if (!e.articles.length) return t`<p class="article-browser-empty">No articles found.</p>`;
3382
+ let r = Object.fromEntries(on.map(({ value: e, label: t }) => [e, t]));
3383
+ return t`<table class="article-browser-table">
3384
+ <thead>
3385
+ <tr>
3386
+ ${sn.map(({ sort: e, label: t }) => St(e, t, {
3387
+ sort: this.sort,
3388
+ order: this.order
3389
+ }, (e) => this.sortBy(e)))}
3390
+ </tr>
3391
+ </thead>
3392
+ <tbody>
3393
+ ${e.articles.map((e) => t`<tr>
3394
+ <td>
3395
+ <a
3396
+ href="#${e.type}/${e.slug}"
3397
+ @click=${(t) => {
3398
+ t.preventDefault(), this.chooseArticle(e);
3399
+ }}
3400
+ >${e.title}</a
3401
+ >
3402
+ ${e.error ? t`<small class="error">${e.error}</small>` : n}
3403
+ ${e.problems ? t`<small class="problems"
3404
+ >⚠️ ${Z(e.problems)}</small
3405
+ >` : n}
3406
+ </td>
3407
+ <td>${Q(this.types, e.type)}</td>
3408
+ <td>${r[e.status]}</td>
3409
+ <td>${e.date.slice(0, 10)}</td>
3410
+ <td>${e.updated.slice(0, 10)}</td>
3411
+ </tr>`)}
3412
+ </tbody>
3413
+ </table>`;
3414
+ }
3415
+ renderPages() {
3416
+ let e = this.result;
3417
+ return !e || e.pages < 2 ? n : t`<nav class="article-browser-pages" aria-label="Pages">
3418
+ <button
3419
+ type="button"
3420
+ class="btn"
3421
+ ?disabled=${e.page <= 1}
3422
+ @click=${() => void this.goTo(e.page - 1)}
3423
+ >
3424
+ Previous
3425
+ </button>
3426
+ <span>Page ${e.page} of ${e.pages}</span>
3427
+ <button
3428
+ type="button"
3429
+ class="btn"
3430
+ ?disabled=${e.page >= e.pages}
3431
+ @click=${() => void this.goTo(e.page + 1)}
3432
+ >
3433
+ Next
3434
+ </button>
3435
+ </nav>`;
3436
+ }
3437
+ statusText() {
3438
+ if (this.error) return this.error;
3439
+ if (this.loading || !this.result) return "Loading…";
3440
+ let { total: e } = this.result;
3441
+ return `${e} ${e === 1 ? "article" : "articles"} found`;
3442
+ }
3443
+ render() {
3444
+ let e = (e) => e.map((e) => ({
3445
+ value: e,
3446
+ label: e
3447
+ })), n = [.../* @__PURE__ */ new Set([...Object.keys(this.types), ...this.filters.types])].map((e) => ({
3448
+ value: e,
3449
+ label: Q(this.types, e)
3450
+ }));
3451
+ return t`<dialog
3452
+ class="article-browser"
3453
+ aria-labelledby="article-browser-title"
3454
+ @close=${() => clearTimeout(this.searchTimer)}
3455
+ >
3456
+ <div class="article-browser-header">
3457
+ <h2 id="article-browser-title">All articles</h2>
3458
+ <button
3459
+ type="button"
3460
+ class="btn-icon"
3461
+ title="Close"
3462
+ @click=${() => this.close()}
3463
+ >
3464
+ ${_("close")}<span class="visually-hidden">Close</span>
3465
+ </button>
3466
+ </div>
3467
+ <div class="article-browser-controls" role="search">
3468
+ <div class="article-browser-field article-browser-search">
3469
+ <label for="article-browser-search">Search titles</label>
3470
+ <input
3471
+ type="search"
3472
+ id="article-browser-search"
3473
+ .value=${this.search}
3474
+ @input=${(e) => this.onSearch(e.target.value)}
3475
+ />
3476
+ </div>
3477
+ ${this.renderSelect("type", "Type", "All types", n)}
3478
+ ${this.renderSelect("author", "Author", "Any author", e(this.filters.authors))}
3479
+ ${this.renderSelect("tag", "Tag", "Any tag", e(this.filters.tags))}
3480
+ ${this.renderSelect("status", "Status", "Any status", on)}
3481
+ ${this.renderSelect("problems", "Problems", "Any article", an)}
3482
+ </div>
3483
+ <p
3484
+ class="article-browser-status ${this.error ? "error" : ""}"
3485
+ role="status"
3486
+ >
3487
+ ${this.statusText()}
3488
+ </p>
3489
+ <div class="article-browser-results">
3490
+ ${this.renderResults()} ${this.renderPages()}
3491
+ </div>
3492
+ </dialog>`;
3493
+ }
3494
+ });
3495
+ // src/client/theme/index.ts
3496
+ var ln = "edaha-editor-theme", un = () => typeof window.matchMedia == "function" ? window.matchMedia("(prefers-color-scheme: dark)") : void 0, dn = () => {
3497
+ let e = document.documentElement.dataset.theme;
3498
+ return e === "light" || e === "dark" ? e : un()?.matches ? "dark" : "light";
3499
+ }, fn = (e) => {
3500
+ document.documentElement.dataset.theme = e;
3501
+ try {
3502
+ localStorage.setItem(ln, e);
3503
+ } catch {}
3504
+ }, pn = () => {
3505
+ let e = dn() === "dark" ? "light" : "dark";
3506
+ return fn(e), e;
3507
+ }, mn = () => `Switch to the ${dn() === "dark" ? "light" : "dark"} theme`, hn = (e) => {
3508
+ let t = un();
3509
+ return t?.addEventListener("change", e), () => t?.removeEventListener("change", e);
3510
+ }, gn = "(max-width: 899.98px)", _n = () => typeof window.matchMedia == "function" ? window.matchMedia(gn) : void 0, vn = () => _n()?.matches ?? !1, yn = (e) => {
3511
+ let t = _n();
3512
+ return t?.addEventListener("change", e), () => t?.removeEventListener("change", e);
3513
+ }, bn = (e) => [
3514
+ e.slug,
3515
+ e.status,
3516
+ e.date.slice(0, 10)
3517
+ ].filter(Boolean).join(" · "), $ = {
3518
+ heading: "Save changes first?",
3519
+ message: "This article has changes that aren't saved.",
3520
+ choices: [
3521
+ {
3522
+ value: "save",
3523
+ label: "Save"
3524
+ },
3525
+ {
3526
+ value: "discard",
3527
+ label: "Don't save"
3528
+ },
3529
+ {
3530
+ value: "cancel",
3531
+ label: "Cancel"
3532
+ }
3533
+ ]
3534
+ }, xn = (e, t) => {
3535
+ let n = Object.keys(t), r = (e) => n.includes(e) ? n.indexOf(e) : n.length;
3536
+ return e.map((e) => ({
3537
+ ...e,
3538
+ label: t[e.type]?.labelPlural ?? e.type
3539
+ })).sort((e, t) => r(e.type) - r(t.type) || e.type.localeCompare(t.type));
3540
+ }, Sn = class extends e {
3541
+ static properties = {
3542
+ api: { attribute: !1 },
3543
+ hideTitle: {
3544
+ type: Boolean,
3545
+ attribute: "hide-title"
3546
+ },
3547
+ hideThemeSwitcher: {
3548
+ type: Boolean,
3549
+ attribute: "hide-theme-switcher"
3550
+ },
3551
+ recent: { state: !0 },
3552
+ types: { state: !0 },
3553
+ selected: { state: !0 },
3554
+ article: { state: !0 },
3555
+ editing: { state: !0 },
3556
+ formKey: { state: !0 },
3557
+ error: { state: !0 },
3558
+ searchText: { state: !0 },
3559
+ searchResult: { state: !0 },
3560
+ welcome: { state: !0 },
3561
+ metadata: { state: !0 },
3562
+ attention: { state: !0 },
3563
+ site: { state: !0 },
3564
+ unsaved: { state: !0 },
3565
+ navOpen: { state: !0 },
3566
+ narrow: { state: !0 },
3567
+ focusMode: { state: !0 }
3568
+ };
3569
+ wasCompact = !1;
3570
+ onBeforeUnload = (e) => {
3571
+ this.form()?.dirty && e.preventDefault();
3572
+ };
3573
+ stopWatchingTheme;
3574
+ stopWatchingNarrow;
3575
+ searchDelay = 250;
3576
+ searchTimer;
3577
+ searches = 0;
3578
+ onToast = (e) => this.toast(e.detail);
3579
+ constructor() {
3580
+ super(), this.api = new Ne(), this.hideTitle = !1, this.hideThemeSwitcher = !1, this.recent = [], this.types = {}, this.editing = !1, this.formKey = 0, this.error = "", this.searchText = "", this.navOpen = !1, this.narrow = !1, this.focusMode = !1;
3581
+ }
3582
+ get compact() {
3583
+ return this.narrow || this.focusMode;
3584
+ }
3585
+ createRenderRoot() {
3586
+ return this;
3587
+ }
3588
+ connectedCallback() {
3589
+ super.connectedCallback(), window.addEventListener("beforeunload", this.onBeforeUnload), this.addEventListener(H, this.onToast), this.stopWatchingTheme = hn(() => this.requestUpdate()), this.hideThemeSwitcher && delete document.documentElement.dataset.theme, this.narrow = vn(), this.stopWatchingNarrow = yn(() => this.narrow = vn()), this.refresh().then(() => this.openFromAddress());
3590
+ }
3591
+ async openFromAddress() {
3592
+ let [, e, t] = /^#([a-z0-9-]+)\/([a-z0-9-]+)$/.exec(window.location.hash) ?? [];
3593
+ e && t && await this.open({
3594
+ type: e,
3595
+ slug: t
3596
+ });
3597
+ }
3598
+ disconnectedCallback() {
3599
+ super.disconnectedCallback(), window.removeEventListener("beforeunload", this.onBeforeUnload), this.removeEventListener(H, this.onToast), this.stopWatchingTheme?.(), this.stopWatchingNarrow?.(), clearTimeout(this.searchTimer);
3600
+ }
3601
+ willUpdate() {
3602
+ let e = this.compact;
3603
+ this.wasCompact && !e && (this.navOpen = !1), this.wasCompact = e, this.toggleAttribute("compact", e), this.toggleAttribute("focus-mode", this.focusMode);
3604
+ }
3605
+ async openNav() {
3606
+ this.navOpen = !0, await this.updateComplete, this.querySelector(".nav-close")?.focus();
3607
+ }
3608
+ closeNav() {
3609
+ this.navOpen && (this.navOpen = !1, this.querySelector(".edaha-editor-nav")?.contains(document.activeElement) && this.querySelector(".nav-toggle")?.focus());
3610
+ }
3611
+ pickFile = (e) => this.querySelector("edaha-file-browser").pick(e);
3612
+ form() {
3613
+ return this.querySelector("edaha-article");
3614
+ }
3615
+ toast(e) {
3616
+ this.querySelector("edaha-toasts")?.show(e);
3617
+ }
3618
+ askUnsaved() {
3619
+ return new Promise((e) => {
3620
+ this.unsaved = (t) => {
3621
+ this.unsaved = void 0, e(t);
3622
+ };
3623
+ });
3624
+ }
3625
+ get dirty() {
3626
+ return this.form()?.dirty ?? !1;
3627
+ }
3628
+ async leaveForm() {
3629
+ let e = this.form();
3630
+ if (!e || !await e.hasChanges()) return !0;
3631
+ let t = await this.askUnsaved();
3632
+ return t === "save" ? e.save() : t === "discard";
3633
+ }
3634
+ async refresh() {
3635
+ try {
3636
+ [this.recent, this.types, this.welcome, this.metadata, this.attention, this.site] = await Promise.all([
3637
+ this.api.recent(),
3638
+ this.api.types(),
3639
+ this.api.query({
3640
+ sort: "updated",
3641
+ perPage: 6
3642
+ }),
3643
+ this.api.metadata(),
3644
+ this.api.query({
3645
+ problems: "any",
3646
+ sort: "title",
3647
+ perPage: 5
3648
+ }),
3649
+ this.api.site()
3650
+ ]), this.error = "";
3651
+ } catch (e) {
3652
+ this.error = e.message, this.toast({
3653
+ kind: "error",
3654
+ message: this.error
3655
+ });
3656
+ }
3657
+ this.searchText.trim() && await this.searchTitles();
3658
+ }
3659
+ async searchTitles() {
3660
+ clearTimeout(this.searchTimer);
3661
+ let e = ++this.searches, t = this.searchText.trim();
3662
+ if (!t) this.searchResult = void 0;
3663
+ else try {
3664
+ let n = await this.api.query({
3665
+ search: t,
3666
+ perPage: 10
3667
+ });
3668
+ e === this.searches && (this.searchResult = n);
3669
+ } catch (t) {
3670
+ if (e !== this.searches) return;
3671
+ this.error = t.message, this.toast({
3672
+ kind: "error",
3673
+ message: this.error
3674
+ });
3675
+ }
3676
+ }
3677
+ onSearchInput(e) {
3678
+ this.searchText = e, clearTimeout(this.searchTimer), this.searchTimer = setTimeout(() => void this.searchTitles(), this.searchDelay);
3679
+ }
3680
+ async openFiles() {
3681
+ await this.querySelector("edaha-file-browser")?.show();
3682
+ }
3683
+ async onFilesChanged({ file: e, articles: t }) {
3684
+ await this.refresh();
3685
+ let n = this.selected;
3686
+ n && [e, ...t].some(({ type: e, slug: t }) => e === n.type && t === n.slug) && (this.form()?.dirty ? this.toast({
3687
+ kind: "error",
3688
+ message: "The open article's files changed, but it has unsaved changes, so it still shows the old ones. Saving keeps its old references."
3689
+ }) : await this.open(n));
3690
+ }
3691
+ async openBrowser(e = {}) {
3692
+ await this.querySelector("edaha-article-browser")?.show(e);
3693
+ }
3694
+ async open(e) {
3695
+ if (await this.leaveForm()) try {
3696
+ this.article = await this.api.read(e), this.selected = e, this.editing = !0, this.formKey++, this.error = "";
3697
+ } catch (e) {
3698
+ this.error = e.message, this.toast({
3699
+ kind: "error",
3700
+ message: this.error
3701
+ });
3702
+ }
3703
+ }
3704
+ typeOptions() {
3705
+ let e = Object.entries(this.types).map(([e, { labelSingle: t }]) => ({
3706
+ value: e,
3707
+ label: t
3708
+ }));
3709
+ for (let { type: t } of this.recent) this.types[t] || e.push({
3710
+ value: t,
3711
+ label: t
3712
+ });
3713
+ return e;
3714
+ }
3715
+ async showWelcome() {
3716
+ this.closeNav(), await this.leaveForm() && (this.article = void 0, this.selected = void 0, this.editing = !1, await this.refresh());
3717
+ }
3718
+ async create() {
3719
+ await this.leaveForm() && (this.article = void 0, this.selected = void 0, this.editing = !0, this.formKey++);
3720
+ }
3721
+ async onSaved(e) {
3722
+ this.selected = e.detail, await this.refresh();
3723
+ }
3724
+ async onDeleted() {
3725
+ this.article = void 0, this.selected = void 0, this.editing = !1, await this.refresh();
3726
+ }
3727
+ renderUnsaved() {
3728
+ let e = this.unsaved;
3729
+ return e ? t`<div class="dialog-backdrop">
3730
+ <div
3731
+ class="dialog unsaved"
3732
+ role="alertdialog"
3733
+ aria-modal="true"
3734
+ aria-labelledby="unsaved-heading"
3735
+ aria-describedby="unsaved-message"
3736
+ >
3737
+ <h2 id="unsaved-heading">${$.heading}</h2>
3738
+ <p id="unsaved-message">${$.message}</p>
3739
+ ${$.choices.map(({ value: n, label: r }) => t`<button
3740
+ type="button"
3741
+ data-choice=${n}
3742
+ @click=${() => e(n)}
3743
+ >
3744
+ ${r}
3745
+ </button>`)}
3746
+ </div>
3747
+ </div>` : n;
3748
+ }
3749
+ renderWelcome() {
3750
+ let e = this.welcome;
3751
+ return t`<div class="welcome-prompt">
3752
+ <div class="welcome-prompt-box">
3753
+ <!-- "Write a new article" starts a new article; "edit an existing one" opens the article browser -->
3754
+ <p class="welcome-prompt-message">
3755
+ <button
3756
+ type="button"
3757
+ class="btn-link"
3758
+ @click=${() => void this.create()}
3759
+ >
3760
+ Write a new article
3761
+ </button>
3762
+ or
3763
+ <button
3764
+ type="button"
3765
+ class="btn-link"
3766
+ @click=${() => void this.openBrowser()}
3767
+ >
3768
+ edit an existing one</button
3769
+ >...
3770
+ </p>
3771
+ ${e?.articles.length ? t`<ul
3772
+ class="welcome-prompt-list"
3773
+ aria-label="Recently changed articles"
3774
+ >
3775
+ ${e.articles.map((e) => t`<li>
3776
+ <a
3777
+ href="#${e.type}/${e.slug}"
3778
+ @click=${(t) => {
3779
+ t.preventDefault(), this.open(e);
3780
+ }}
3781
+ >${e.title}</a
3782
+ >
3783
+ <small class="welcome-prompt-meta"
3784
+ >${Q(this.types, e.type)} · changed
3785
+ ${e.updated.slice(0, 10)}</small
3786
+ >
3787
+ </li>`)}
3788
+ </ul>` : n}
3789
+ ${e && e.total > e.articles.length ? t`<button
3790
+ type="button"
3791
+ class="btn-link welcome-prompt-browse"
3792
+ @click=${() => void this.openBrowser()}
3793
+ >
3794
+ Open article browser
3795
+ </button>` : n}
3796
+ ${this.renderAttention()}
3797
+ </div>
3798
+ </div>`;
3799
+ }
3800
+ renderAttention() {
3801
+ let e = this.attention;
3802
+ return e?.total ? t`<section
3803
+ class="welcome-attention"
3804
+ aria-labelledby="welcome-attention-title"
3805
+ >
3806
+ <h2 id="welcome-attention-title">Needs attention</h2>
3807
+ <ul class="welcome-prompt-list">
3808
+ ${e.articles.map((e) => {
3809
+ let [r] = e.problems;
3810
+ return t`<li>
3811
+ <a
3812
+ href="#${e.type}/${e.slug}"
3813
+ @click=${(t) => {
3814
+ t.preventDefault(), this.open(e);
3815
+ }}
3816
+ >${e.title}</a
3817
+ >
3818
+ <small class="welcome-prompt-meta"
3819
+ >⚠️
3820
+ ${Z(e.problems)}${r ? t`: "${r.path}" ${r.message}` : n}</small
3821
+ >
3822
+ </li>`;
3823
+ })}
3824
+ </ul>
3825
+ ${e.total > e.articles.length ? t`<button
3826
+ type="button"
3827
+ class="btn-link welcome-prompt-browse"
3828
+ @click=${() => void this.openBrowser({ problems: "any" })}
3829
+ >
3830
+ See all ${e.total} articles with problems
3831
+ </button>` : n}
3832
+ </section>` : n;
3833
+ }
3834
+ renderSearchResult(e, r) {
3835
+ let { total: i } = e;
3836
+ return t`<div class="edaha-editor-article-group search-results">
3837
+ <h2 class="edaha-editor-article-group-title" role="status">
3838
+ ${i} ${i === 1 ? "match" : "matches"}
3839
+ </h2>
3840
+ <ul class="edaha-editor-article-group-list">
3841
+ ${e.articles.map(r)}
3842
+ </ul>
3843
+ ${i > e.articles.length ? t`<button
3844
+ type="button"
3845
+ class="btn-link show-all"
3846
+ @click=${() => {
3847
+ this.closeNav(), this.openBrowser({ search: this.searchText.trim() });
3848
+ }}
3849
+ >
3850
+ See all results
3851
+ </button>` : n}
3852
+ </div>`;
3853
+ }
3854
+ renderGroups(e) {
3855
+ return xn(this.recent, this.types).map((r) => t`<div class="edaha-editor-article-group" data-type=${r.type}>
3856
+ <h2 class="edaha-editor-article-group-title">${r.label}</h2>
3857
+ <ul class="edaha-editor-article-group-list">
3858
+ ${r.articles.map(e)}
3859
+ </ul>
3860
+ ${r.total > r.articles.length ? t`<button
3861
+ type="button"
3862
+ class="btn-link show-all"
3863
+ @click=${() => {
3864
+ this.closeNav(), this.openBrowser({ type: r.type });
3865
+ }}
3866
+ >
3867
+ Show all<span class="visually-hidden"> ${r.label}</span>
3868
+ (${r.total})
3869
+ </button>` : n}
3870
+ </div>`);
3871
+ }
3872
+ render() {
3873
+ let e = (e) => this.selected?.type === e.type && this.selected.slug === e.slug, r = (r) => t`<li class="edaha-editor-article-group-item">
3874
+ <a
3875
+ href="#${r.type}/${r.slug}"
3876
+ class="edaha-editor-article-group-item-title"
3877
+ aria-current=${e(r) ? "page" : "false"}
3878
+ @click=${(e) => {
3879
+ e.preventDefault(), this.closeNav(), this.open(r);
3880
+ }}
3881
+ >${r.title}</a
3882
+ >
3883
+ <small class="edaha-editor-article-group-item-meta"
3884
+ >${bn(r)}</small
3885
+ >
3886
+ ${r.error ? t`<small class="error">${r.error}</small>` : n}
3887
+ </li>`;
3888
+ return t`
3889
+ <div class="edaha-editor-bar">
3890
+ <button
3891
+ type="button"
3892
+ class="btn-icon nav-toggle"
3893
+ title="Articles"
3894
+ aria-expanded=${this.navOpen ? "true" : "false"}
3895
+ aria-controls="edaha-editor-nav"
3896
+ @click=${() => void this.openNav()}
3897
+ >
3898
+ ${_("menu")}<span class="visually-hidden">Articles</span>
3899
+ </button>
3900
+ ${this.hideTitle ? n : t`<span class="edaha-editor-bar-title">edaha.md</span>`}
3901
+ </div>
3902
+ <div
3903
+ class="nav-backdrop ${a({ open: this.navOpen })}"
3904
+ @click=${() => this.closeNav()}
3905
+ ></div>
3906
+ <nav
3907
+ id="edaha-editor-nav"
3908
+ class="edaha-editor-nav ${a({ open: this.navOpen })}"
3909
+ aria-label="Articles"
3910
+ @keydown=${(e) => {
3911
+ e.key === "Escape" && this.closeNav();
3912
+ }}
3913
+ >
3914
+ <button
3915
+ type="button"
3916
+ class="btn-icon nav-close"
3917
+ title="Close articles"
3918
+ @click=${() => this.closeNav()}
3919
+ >
3920
+ ${_("close")}<span class="visually-hidden">Close articles</span>
3921
+ </button>
3922
+ ${this.hideThemeSwitcher ? n : t`<button
3923
+ type="button"
3924
+ class="theme-switcher"
3925
+ title=${mn()}
3926
+ @click=${() => {
3927
+ pn(), this.requestUpdate();
3928
+ }}
3929
+ >
3930
+ <span class="visually-hidden">${mn()}</span>
3931
+ </button>`}
3932
+ ${this.hideTitle ? t`<h1 class="visually-hidden">
3933
+ ${this.site?.name ?? "Articles"}
3934
+ </h1>` : t`<!-- Goes back to the welcome prompt; a button for keyboards and screen readers, but looking like the title -->
3935
+ <h1 class="edaha-title">
3936
+ <button
3937
+ type="button"
3938
+ class="edaha-title-button"
3939
+ title="Show the welcome prompt"
3940
+ @click=${() => void this.showWelcome()}
3941
+ >
3942
+ edaha.md<span class="leaf-device"></span>
3943
+ </button>
3944
+ </h1>`}
3945
+ <div class="edaha-editor-new">
3946
+ <button
3947
+ type="button"
3948
+ class="btn"
3949
+ @click=${() => {
3950
+ this.closeNav(), this.create();
3951
+ }}
3952
+ >
3953
+ New article
3954
+ </button>
3955
+ </div>
3956
+ <div class="edaha-editor-search" role="search">
3957
+ <label for="article-search" class="visually-hidden"
3958
+ >Search titles</label
3959
+ >
3960
+ <input
3961
+ type="search"
3962
+ id="article-search"
3963
+ placeholder="Search titles"
3964
+ .value=${this.searchText}
3965
+ @input=${(e) => this.onSearchInput(e.target.value)}
3966
+ @keydown=${(e) => {
3967
+ e.key === "Escape" && this.searchText && (e.stopPropagation(), this.searchText = "", this.searchTitles());
3968
+ }}
3969
+ />
3970
+ <button
3971
+ type="button"
3972
+ class="btn-icon"
3973
+ title="All articles"
3974
+ @click=${() => {
3975
+ this.closeNav(), this.openBrowser();
3976
+ }}
3977
+ >
3978
+ ${_("manage_search")}<span class="visually-hidden"
3979
+ >All articles</span
3980
+ >
3981
+ </button>
3982
+ <button
3983
+ type="button"
3984
+ class="btn-icon"
3985
+ title="Files"
3986
+ @click=${() => {
3987
+ this.closeNav(), this.openFiles();
3988
+ }}
3989
+ >
3990
+ ${_("folder_open")}<span class="visually-hidden">Files</span>
3991
+ </button>
3992
+ </div>
3993
+ <!-- Goes back to the welcome prompt, which is the editor's home -->
3994
+ <a
3995
+ href="#"
3996
+ class="edaha-editor-home edaha-editor-article-group-item-title"
3997
+ aria-current=${this.editing ? "false" : "page"}
3998
+ @click=${(e) => {
3999
+ e.preventDefault(), this.showWelcome();
4000
+ }}
4001
+ >Home</a
4002
+ >
4003
+ ${this.searchResult ? this.renderSearchResult(this.searchResult, r) : this.renderGroups(r)}
4004
+ </nav>
4005
+ <!-- Out of reach while the article list is open over it -->
4006
+ <section class="edaha-editor-composer" ?inert=${this.navOpen}>
4007
+ ${this.editing ? o(this.formKey, t`<edaha-article
4008
+ .api=${this.api}
4009
+ .article=${this.article}
4010
+ .typeOptions=${this.typeOptions()}
4011
+ .metadata=${this.metadata}
4012
+ .site=${this.site}
4013
+ .compact=${this.compact}
4014
+ .focusMode=${this.focusMode}
4015
+ .pickFile=${this.pickFile}
4016
+ @focus-mode-change=${(e) => this.focusMode = e.detail}
4017
+ @article-saved=${(e) => void this.onSaved(e)}
4018
+ @article-deleted=${() => void this.onDeleted()}
4019
+ ></edaha-article>`) : this.renderWelcome()}
4020
+ </section>
4021
+ <edaha-article-browser
4022
+ .api=${this.api}
4023
+ .types=${this.types}
4024
+ @article-choose=${(e) => void this.open(e.detail)}
4025
+ ></edaha-article-browser>
4026
+ <edaha-file-browser
4027
+ .api=${this.api}
4028
+ .types=${this.types}
4029
+ @files-changed=${(e) => void this.onFilesChanged(e.detail)}
4030
+ ></edaha-file-browser>
4031
+ ${this.renderUnsaved()}
4032
+ <edaha-toasts></edaha-toasts>
4033
+ `;
4034
+ }
4035
+ };
4036
+ x("edaha-editor", Sn);
4037
+ export { y as ApiError, Sn as EdahaEditor, Ne as EditorApi };