useyuva 0.0.7 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +98 -6
- package/dist/esm/analytics.js +1 -0
- package/dist/esm/chat.js +2 -2
- package/dist/esm/client-p9899hvt.js +1 -0
- package/dist/esm/docs.js +4 -61
- package/dist/esm/index-8hzbxjv3.js +12 -0
- package/dist/esm/index-98r96a7e.js +2 -0
- package/dist/esm/index-c6q8br7d.js +2 -0
- package/dist/esm/index-gk84nm8f.js +2 -0
- package/dist/esm/index-rdzxvj2r.js +2 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/nuxt/module.js +7 -3
- package/dist/esm/nuxt/runtime/analytics.js +6 -0
- package/dist/esm/nuxt/runtime/components.js +32 -0
- package/dist/esm/nuxt/runtime/plugin.js +11 -0
- package/dist/esm/react.js +2 -1
- package/dist/esm/subscribe.js +33 -0
- package/dist/esm/thread-btm71nxt.js +61 -0
- package/dist/esm/yuva-chat-zzebx8pk.js +193 -0
- package/dist/types/analytics/core.d.ts +47 -0
- package/dist/types/analytics/handle.d.ts +3 -0
- package/dist/types/analytics.d.ts +1 -0
- package/dist/types/client/api.d.ts +11 -0
- package/dist/types/client/client.d.ts +6 -1
- package/dist/types/docs/base.d.ts +3 -2
- package/dist/types/docs/define.d.ts +1 -0
- package/dist/types/docs/discussions.d.ts +4 -13
- package/dist/types/docs/dom.d.ts +1 -0
- package/dist/types/docs/thread.d.ts +71 -0
- package/dist/types/docs.d.ts +2 -2
- package/dist/types/i18n.d.ts +2 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/types/locales/de/docs.d.ts +2 -0
- package/dist/types/locales/de/loader.d.ts +2 -0
- package/dist/types/locales/de/panel.d.ts +2 -0
- package/dist/types/locales/de/subscribe.d.ts +2 -0
- package/dist/types/locales/de/thread.d.ts +2 -0
- package/dist/types/locales/en/subscribe.d.ts +2 -0
- package/dist/types/locales/en/thread.d.ts +2 -0
- package/dist/types/locales/tr/subscribe.d.ts +2 -0
- package/dist/types/locales/tr/thread.d.ts +2 -0
- package/dist/types/nuxt/module.d.ts +8 -1
- package/dist/types/nuxt/runtime/analytics.d.ts +2 -0
- package/dist/types/nuxt/runtime/components.d.ts +34 -0
- package/dist/types/nuxt/runtime/plugin.d.ts +6 -0
- package/dist/types/react.d.ts +18 -0
- package/dist/types/schema.gen.d.ts +15384 -5025
- package/dist/types/subscribe/element.d.ts +34 -0
- package/dist/types/subscribe.d.ts +4 -0
- package/dist/types/translate.d.ts +5 -0
- package/dist/widget/yuva-docs-thread-8st0egsq.js +61 -0
- package/dist/widget/yuva-subscribe-client-s3cx942g.js +11 -0
- package/dist/yuva-analytics.js +1 -0
- package/dist/yuva-chat.js +6 -6
- package/dist/yuva-docs.js +8 -65
- package/dist/yuva-subscribe.js +33 -0
- package/dist/yuva.js +2 -2
- package/package.json +27 -4
- package/dist/esm/index-cmr5w646.js +0 -2
- package/dist/esm/index-dj5dhqc1.js +0 -12
- package/dist/esm/yuva-chat-acme1k5r.js +0 -193
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function translate(messages,descriptor,fallback){let entry=messages[descriptor.id]??fallback[descriptor.id],values=descriptor.values??{};if(typeof entry==="string")return entry;if(Array.isArray(entry))return entry.map((part)=>typeof part==="string"?part:Array.isArray(part)?String(values[part[0]]??""):"").join("");return descriptor.message??descriptor.id}var rtlLanguages=new Set(["ar","fa","he","ur"]),sourceLocale="en";function localeIn(catalogs,candidates){for(let candidate of candidates){if(!candidate)continue;let tag=candidate.toLowerCase();if(catalogs[tag])return tag;let language=tag.split(/[-_]/)[0]??"";if(catalogs[language])return language}return sourceLocale}function directionOf(locale){return rtlLanguages.has(locale.split(/[-_]/)[0]??"")?"rtl":"ltr"}function launcherOf(inbox){return{position:inbox.chat.launcher_position,color:inbox.chat.launcher_color??inbox.branding.color}}function contrastOn(color){let n=Number.parseInt(color.slice(1),16),[r,g,b]=[n>>16&255,n>>8&255,n&255].map((c)=>{let s=c/255;return s<=0.03928?s/12.92:((s+0.055)/1.055)**2.4});return 0.2126*r+0.7152*g+0.0722*b>0.4?"#111827":"#ffffff"}function storageKey(channel){return`yuva:${channel}`}function readStored(channel){try{let raw=localStorage.getItem(storageKey(channel));return raw?JSON.parse(raw):{}}catch{return{}}}function writeStored(channel,state){try{localStorage.setItem(storageKey(channel),JSON.stringify(state))}catch{}}
|
|
2
|
+
export{translate,localeIn,directionOf,launcherOf,contrastOn,readStored,writeStored};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{translate,localeIn}from"./index-98r96a7e.js";var messages=JSON.parse('{"6I7cJR":["Open chat"],"OkHvGB":["Open chat, ",["count"]," unread"],"pqZJT2":["Close chat"]}');var messages2=JSON.parse('{"6I7cJR":["Chat öffnen"],"OkHvGB":["Chat öffnen, ",["count"]," ungelesen"],"pqZJT2":["Chat schließen"]}');var messages3=JSON.parse('{"6I7cJR":["Sohbeti aç"],"OkHvGB":["Sohbeti aç, ",["count"]," okunmamış"],"pqZJT2":["Sohbeti kapat"]}');var catalogs={en:messages,tr:messages3,de:messages2};function resolveLocale(...candidates){return localeIn(catalogs,candidates)}function catalogFor(locale){return catalogs[locale]??messages}function translatePlain(messages2,descriptor,fallback=messages){return translate(messages2,descriptor,fallback)}
|
|
2
|
+
export{resolveLocale,catalogFor,translatePlain};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
class ApiError2 extends Error{status;code;constructor(status,code){super(`${status} ${code}`);this.status=status;this.code=code}}async function call(fetcher,server,path,{method="GET",json,body,headers={},token,blob}={}){if(headers={...headers},token)headers.Authorization=`Bearer ${token}`;let payload=body;if(json!==void 0)headers["Content-Type"]="application/json",payload=JSON.stringify(json);let response;try{response=await fetcher(server+path,{method,headers,body:payload,credentials:"omit"})}catch{throw new ApiError2(0,"network")}if(!response.ok){let code="error";try{code=(await response.json()).code??code}catch{}throw new ApiError2(response.status,code)}if(response.status===204)return;return blob?await response.blob():await response.json()}function mailingLists(fetcher,server,channel){return call(fetcher,server,`/client/v1/channels/${encodeURIComponent(channel)}/lists`)}function createSubscription(fetcher,server,channel,input){return call(fetcher,server,`/client/v1/channels/${encodeURIComponent(channel)}/subscriptions`,{method:"POST",json:input})}
|
|
2
|
+
export{ApiError2,call,mailingLists,createSubscription};
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{readerConnectUrl2,openReaderPopup2,YuvaClient2,createYuvaClient2}from"./index-8hzbxjv3.js";import{ApiError2}from"./index-gk84nm8f.js";export{ApiError2 as ApiError,YuvaClient2 as YuvaClient,createYuvaClient2 as createYuvaClient,openReaderPopup2 as openReaderPopup,readerConnectUrl2 as readerConnectUrl};
|
package/dist/esm/nuxt/module.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { addComponent, defineNuxtModule } from "@nuxt/kit";
|
|
2
|
-
const components = ["YuvaChat", "YuvaDiscussions", "YuvaPageFeedback"];
|
|
1
|
+
import { addComponent, addImports, addPlugin, defineNuxtModule } from "@nuxt/kit";
|
|
2
|
+
const components = ["YuvaChat", "YuvaDiscussions", "YuvaPageFeedback", "YuvaSubscribe"];
|
|
3
3
|
export default defineNuxtModule({
|
|
4
4
|
meta: { name: "useyuva", configKey: "yuva" },
|
|
5
5
|
defaults: { server: "", channel: "", locale: "" },
|
|
@@ -8,7 +8,8 @@ export default defineNuxtModule({
|
|
|
8
8
|
nuxt.options.runtimeConfig.public.yuva = {
|
|
9
9
|
server: current.server || options.server || "",
|
|
10
10
|
channel: current.channel || options.channel || "",
|
|
11
|
-
locale: current.locale || options.locale || ""
|
|
11
|
+
locale: current.locale || options.locale || "",
|
|
12
|
+
analytics: current.analytics || options.analytics
|
|
12
13
|
};
|
|
13
14
|
const compilerOptions = nuxt.options.vue.compilerOptions ??= {};
|
|
14
15
|
const isCustomElement = compilerOptions.isCustomElement;
|
|
@@ -16,5 +17,8 @@ export default defineNuxtModule({
|
|
|
16
17
|
nuxt.options.build.transpile.push("useyuva");
|
|
17
18
|
for (const name of components)
|
|
18
19
|
addComponent({ name, export: name, filePath: "useyuva/nuxt/components" });
|
|
20
|
+
addImports({ name: "useYuvaAnalytics", from: "useyuva/nuxt/analytics" });
|
|
21
|
+
if (nuxt.options.runtimeConfig.public.yuva.analytics)
|
|
22
|
+
addPlugin({ src: "useyuva/nuxt/plugin", mode: "client" });
|
|
19
23
|
}
|
|
20
24
|
});
|
|
@@ -9,6 +9,15 @@ const shared = {
|
|
|
9
9
|
};
|
|
10
10
|
const docsProps = { ...shared, page: String, pageTitle: String };
|
|
11
11
|
const chatProps = { ...shared, layout: String, open: Boolean };
|
|
12
|
+
const subscribeProps = {
|
|
13
|
+
...shared,
|
|
14
|
+
lists: Array,
|
|
15
|
+
layout: String,
|
|
16
|
+
name: String,
|
|
17
|
+
buttonText: String,
|
|
18
|
+
consent: String,
|
|
19
|
+
privacyUrl: String
|
|
20
|
+
};
|
|
12
21
|
function setup(tag, load, props, attributes, listeners) {
|
|
13
22
|
const config = useRuntimeConfig().public.yuva;
|
|
14
23
|
const element = ref(null);
|
|
@@ -86,3 +95,26 @@ export const YuvaChat = defineComponent({
|
|
|
86
95
|
return render;
|
|
87
96
|
}
|
|
88
97
|
});
|
|
98
|
+
export const YuvaSubscribe = defineComponent({
|
|
99
|
+
name: "YuvaSubscribe",
|
|
100
|
+
props: subscribeProps,
|
|
101
|
+
emits: {
|
|
102
|
+
subscribe: (_) => true,
|
|
103
|
+
error: (_) => true
|
|
104
|
+
},
|
|
105
|
+
setup(props, { emit, expose }) {
|
|
106
|
+
const { element, render } = setup("yuva-subscribe", () => import("../../subscribe.js"), props, (p) => ({
|
|
107
|
+
lists: p.lists?.join(","),
|
|
108
|
+
layout: p.layout,
|
|
109
|
+
name: p.name,
|
|
110
|
+
"button-text": p.buttonText,
|
|
111
|
+
consent: p.consent,
|
|
112
|
+
"privacy-url": p.privacyUrl
|
|
113
|
+
}), {
|
|
114
|
+
onYuvaSubscribe: detail((d) => emit("subscribe", d)),
|
|
115
|
+
onYuvaSubscribeError: detail((d) => emit("error", d))
|
|
116
|
+
});
|
|
117
|
+
expose({ element });
|
|
118
|
+
return render;
|
|
119
|
+
}
|
|
120
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { defineNuxtPlugin, useRuntimeConfig } from "#imports";
|
|
2
|
+
import { createAnalytics } from "../../analytics.js";
|
|
3
|
+
export default defineNuxtPlugin(() => {
|
|
4
|
+
const config = useRuntimeConfig().public.yuva;
|
|
5
|
+
const options = config?.analytics;
|
|
6
|
+
if (!options?.key)
|
|
7
|
+
return;
|
|
8
|
+
return {
|
|
9
|
+
provide: { yuvaAnalytics: createAnalytics({ ...options, server: options.server || config?.server || "" }) }
|
|
10
|
+
};
|
|
11
|
+
});
|
package/dist/esm/react.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
import{createContext,createElement,useCallback,useContext,useEffect,useRef,useState}from"react";var current,pending=[],call=(name)=>(...args)=>current?current[name](...args):void pending.push([name,args]),analytics={pageview:call("pageview"),track:call("track"),notFound:call("notFound"),consent:call("consent"),optOut:call("optOut"),optIn:call("optIn")};function attachAnalytics(instance){if(current=instance,instance)for(let[name,args]of pending.splice(0))instance[name](...args)}var YuvaContext=createContext(null);function YuvaProvider({client,connect=!0,children}){return useEffect(()=>{if(!connect)return;return client.connect().catch(()=>{return}),()=>client.disconnect()},[client,connect]),createElement(YuvaContext.Provider,{value:client},children)}function useYuva(){let client=useContext(YuvaContext);if(!client)throw Error("Yuva: wrap your components in <YuvaProvider client={...}>");return client}var time=(value)=>Date.parse(value),byCreated=(a,b)=>time(a.created_at)-time(b.created_at),byActivity=(a,b)=>time(b.last_message_at??b.created_at)-time(a.last_message_at??a.created_at),initial={items:[],loading:!0,error:null};function useConversations(){let client=useYuva(),[state,setState]=useState(initial),cursor=useRef(void 0),current=useRef(state);useEffect(()=>{current.current=state});let load=useCallback(async(more)=>{setState((s)=>({...s,loading:!0}));try{let page=await client.listConversations({limit:50,cursor:more?cursor.current:void 0});cursor.current=page.next_cursor,setState((s)=>{let items=new Map((more?s.items:[]).map((c)=>[c.id,c]));for(let conversation of page.items)items.set(conversation.id,conversation);return{items:[...items.values()].sort(byActivity),cursor:page.next_cursor,loading:!1,error:null}})}catch(error){setState((s)=>({...s,loading:!1,error}))}},[client]);return useEffect(()=>{load(!1);let offSession=client.on("session",({renewed})=>void(renewed&&load(!1))),offEvent=client.on("event",(message)=>{if(message.type==="resync_required")return void load(!1);if(message.type==="conversation.created")setState((s)=>s.items.some((c)=>c.id===message.data.id)?s:{...s,items:[message.data,...s.items].sort(byActivity)});else if(message.type==="conversation.updated")setState((s)=>({...s,items:s.items.map((c)=>c.id===message.conversation_id?{...c,status:message.data.status}:c)}));else if(message.type==="message.created"){let m=message.data;if(!current.current.items.some((c)=>c.id===m.conversation_id))return void load(!1);setState((s)=>{let items=s.items.map((c)=>c.id===m.conversation_id?{...c,last_message:{id:m.id,author_type:m.author.type,text:m.body.slice(0,140),created_at:m.created_at},last_message_at:m.created_at,unread:c.unread||m.author.type!=="contact"}:c);return{...s,items:items.sort(byActivity)}})}});return()=>{offSession(),offEvent()}},[client,load]),{conversations:state.items,loading:state.loading,error:state.error,hasMore:!!state.cursor,loadMore:()=>load(!0),reload:()=>load(!1)}}function useMessages(conversationId){let client=useYuva(),[state,setState]=useState(initial),cursor=useRef(void 0),upsert=useCallback((message)=>{setState((s)=>{let items=s.items.filter((m)=>m.id!==message.id&&(!message.client_id||m.client_id!==message.client_id));return{...s,items:[...items,message].sort(byCreated)}})},[]),load=useCallback(async(older)=>{if(!conversationId){cursor.current=void 0,setState({items:[],loading:!1,error:null});return}if(older&&!cursor.current)return;setState((s)=>({...s,loading:!0}));try{let page=await client.listMessages(conversationId,{order:"desc",limit:30,cursor:older?cursor.current:void 0});cursor.current=page.next_cursor,setState((s)=>{let items=new Map((older?s.items:[]).map((m)=>[m.id,m]));for(let message of page.items)items.set(message.id,message);return{items:[...items.values()].sort(byCreated),cursor:page.next_cursor,loading:!1,error:null}})}catch(error){setState((s)=>({...s,loading:!1,error}))}},[client,conversationId]);return useEffect(()=>{if(load(!1),!conversationId)return;let offSession=client.on("session",({renewed})=>void(renewed&&load(!1))),offEvent=client.on("event",(message)=>{if(message.type==="resync_required")load(!1);else if((message.type==="message.created"||message.type==="message.updated")&&message.data.conversation_id===conversationId)upsert(message.data)});return()=>{offSession(),offEvent()}},[client,conversationId,load,upsert]),{messages:state.items,loading:state.loading,error:state.error,hasMore:!!state.cursor,loadOlder:()=>load(!0),async send(input){if(!conversationId)throw Error("Yuva: no conversation; start one with client.startConversation()");let message=await client.sendMessage(conversationId,typeof input==="string"?{body:input}:input);return upsert(message),message},async markRead(){if(conversationId)await client.markRead(conversationId)}}}function useYuvaElement(tag,load,props,extra,handlers){let[element,setElement]=useState(null),latest=useRef(handlers),loader=useRef(load);useEffect(()=>{latest.current=handlers});let{channel,server,locale,dir,identityToken,className,style}=props;useEffect(()=>{loader.current()},[]);let attributes=JSON.stringify({server,locale,dir,...extra,"identity-token":typeof identityToken==="string"?identityToken:void 0,channel});useEffect(()=>{if(!element)return;for(let[name,value]of Object.entries(JSON.parse(attributes)))if(value)element.setAttribute(name,value);else element.removeAttribute(name)},[element,attributes]),useEffect(()=>{if(!element||typeof identityToken!=="function")return;let current=!0;return customElements.whenDefined(tag).then(()=>{if(current)element.setIdentityToken(identityToken)}),()=>{current=!1}},[element,tag,identityToken]);let events=Object.keys(handlers).join(" ");return useEffect(()=>{if(!element)return;let listeners=events.split(" ").map((type)=>{let listener=(event)=>latest.current[type]?.(event.detail);return element.addEventListener(type,listener),()=>element.removeEventListener(type,listener)});return()=>listeners.forEach((off)=>off())},[element,events]),createElement(tag,{ref:setElement,className,style})}var loadDocs=()=>import("./docs.js");function YuvaPageFeedback({onRating,onFeedback,...props}){return useYuvaElement("yuva-page-feedback",loadDocs,props,{page:props.page,"page-title":props.pageTitle},{"yuva-rating":onRating,"yuva-feedback":onFeedback})}function YuvaDiscussions({onDiscussion,onPost,onReader,...props}){return useYuvaElement("yuva-discussions",loadDocs,props,{page:props.page,"page-title":props.pageTitle},{"yuva-discussion":onDiscussion,"yuva-post":onPost,"yuva-reader":onReader})}function YuvaSubscribe({onSubscribe,onError,...props}){return useYuvaElement("yuva-subscribe",()=>import("./subscribe.js"),props,{lists:props.lists?.join(","),layout:props.layout,name:props.name,"button-text":props.buttonText,consent:props.consent,"privacy-url":props.privacyUrl},{"yuva-subscribe":onSubscribe,"yuva-subscribe-error":onError})}function YuvaAnalytics({server,publicKey:key,hash,consent,manual,outbound,files,chat}){return useEffect(()=>{let instance,mounted=!0;return import("./analytics.js").then(({createAnalytics})=>{if(!mounted)return;instance=createAnalytics({server,key,hash,consent,manual,outbound,files,chat}),attachAnalytics(instance)}),()=>{mounted=!1,instance?.destroy(),attachAnalytics(void 0)}},[server,key,hash,consent,manual,outbound,files,chat]),null}function useYuvaAnalytics(){return analytics}export{YuvaAnalytics,YuvaDiscussions,YuvaPageFeedback,YuvaProvider,YuvaSubscribe,useConversations,useMessages,useYuva,useYuvaAnalytics};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import{el}from"./index-rdzxvj2r.js";import{ApiError2,call,mailingLists,createSubscription}from"./index-gk84nm8f.js";import{translate,localeIn,directionOf,contrastOn}from"./index-98r96a7e.js";var messages=JSON.parse('{"-g5O6h":["Choose at least one list."],"1w51t9":["Subscribing…"],"EDl9kS":["Subscribe"],"E_LjOR":["Enter your name."],"E_qvzP":["Enter a valid e-mail address."],"GQVIIl":["You seem to be offline."],"ScJ9fj":["Privacy policy"],"XJURKP":["E-mail address"],"YnOaHp":["Your name (optional)"],"dMJfG5":["I want to receive e-mails about ",["list"]," from ",["inbox"],". I can unsubscribe at any time."],"eku1-t":["Your account has no e-mail address yet."],"h16FyT":["Lists"],"jWgNnM":["Could not subscribe. Try again."],"lDEbTy":["Tick the box to agree."],"q8yluz":["Your name"],"rgySXy":["Thanks! You are subscribed."],"tzsBOP":["Too many attempts. Wait a moment and try again."],"x6dU53":["Check your inbox to confirm."],"y3k2zM":["Almost done. Check your inbox and confirm your subscription."]}');var messages2=JSON.parse('{"-g5O6h":["Wählen Sie mindestens eine Liste."],"1w51t9":["Wird angemeldet…"],"EDl9kS":["Abonnieren"],"E_LjOR":["Geben Sie Ihren Namen ein."],"E_qvzP":["Geben Sie eine gültige E-Mail-Adresse ein."],"GQVIIl":["Sie scheinen offline zu sein."],"ScJ9fj":["Datenschutzerklärung"],"XJURKP":["E-Mail-Adresse"],"YnOaHp":["Ihr Name (optional)"],"dMJfG5":["Ich möchte E-Mails von ",["inbox"]," zu ",["list"]," erhalten. Ich kann mich jederzeit abmelden."],"eku1-t":["Ihr Konto hat noch keine E-Mail-Adresse."],"h16FyT":["Listen"],"jWgNnM":["Anmeldung fehlgeschlagen. Versuchen Sie es erneut."],"lDEbTy":["Setzen Sie das Häkchen, um zuzustimmen."],"q8yluz":["Ihr Name"],"rgySXy":["Danke! Sie sind angemeldet."],"tzsBOP":["Zu viele Versuche. Warten Sie einen Moment und versuchen Sie es erneut."],"x6dU53":["Sehen Sie zur Bestätigung in Ihr Postfach."],"y3k2zM":["Fast geschafft. Sehen Sie in Ihr Postfach und bestätigen Sie Ihr Abonnement."]}');var messages3=JSON.parse('{"-g5O6h":["En az bir liste seçin."],"1w51t9":["Abone olunuyor…"],"EDl9kS":["Abone ol"],"E_LjOR":["Adınızı girin."],"E_qvzP":["Geçerli bir e-posta adresi girin."],"GQVIIl":["Çevrimdışı görünüyorsunuz."],"ScJ9fj":["Gizlilik politikası"],"XJURKP":["E-posta adresi"],"YnOaHp":["Adınız (isteğe bağlı)"],"dMJfG5":[["list"]," hakkında ",["inbox"]," tarafından gönderilen e-postaları almak istiyorum. Aboneliğimi istediğim zaman bırakabilirim."],"eku1-t":["Hesabınızda henüz bir e-posta adresi yok."],"h16FyT":["Listeler"],"jWgNnM":["Abone olunamadı. Yeniden deneyin."],"lDEbTy":["Onaylamak için kutuyu işaretleyin."],"q8yluz":["Adınız"],"rgySXy":["Teşekkürler! Abone oldunuz."],"tzsBOP":["Çok fazla deneme. Biraz bekleyip tekrar deneyin."],"x6dU53":["Onaylamak için gelen kutunuza bakın."],"y3k2zM":["Neredeyse bitti. Gelen kutunuza bakın ve aboneliğinizi onaylayın."]}');var catalogs={en:messages,tr:messages3,de:messages2},tokenMinimumAge=2100,fetcher=(url,init)=>fetch(url,init),Base=typeof HTMLElement>"u"?class{}:HTMLElement,scriptSrc=typeof document<"u"&&document.currentScript instanceof HTMLScriptElement?document.currentScript.src:"",styles=`
|
|
2
|
+
:host{display:block;line-height:1.5}
|
|
3
|
+
:host([hidden]),[hidden]{display:none!important}
|
|
4
|
+
*{box-sizing:border-box}
|
|
5
|
+
p,form,fieldset{margin:0}
|
|
6
|
+
.frame,form,.row,fieldset,.text{display:flex;flex-direction:column}
|
|
7
|
+
.frame{--a:var(--yuva-accent,var(--brand,#2563eb));--on:var(--yuva-on-accent,var(--brand-on,#fff));--r:var(--yuva-radius,8px);--d:#dc2626;font-family:var(--yuva-font,inherit);gap:10px}
|
|
8
|
+
@media (prefers-color-scheme:dark){.frame{--d:#f87171}}
|
|
9
|
+
form{gap:10px}
|
|
10
|
+
.row,fieldset{gap:8px}
|
|
11
|
+
.inline .row{flex-flow:row wrap}
|
|
12
|
+
.inline .row input{flex:1 1 180px}
|
|
13
|
+
input{inline-size:100%;padding:8px 10px;border:1px solid rgb(127 127 127/.35);border-radius:var(--r);background:none;color:inherit;font:inherit}
|
|
14
|
+
[aria-invalid=true]{border-color:var(--d)}
|
|
15
|
+
[type=checkbox]{inline-size:18px;block-size:18px;margin:2px 0 0;flex:none;accent-color:var(--a)}
|
|
16
|
+
[role=switch]{appearance:none;position:relative;inline-size:36px;block-size:20px;margin:1px 0 0;border-radius:10px;background:rgb(127 127 127/.45);cursor:pointer;transition:background .15s}
|
|
17
|
+
[role=switch]::before{content:"";position:absolute;inset-block-start:2px;inset-inline-start:2px;inline-size:16px;block-size:16px;border-radius:50%;background:#fff;box-shadow:0 1px 2px rgb(0 0 0/.3);transition:inset-inline-start .15s}
|
|
18
|
+
[role=switch]:checked{background:var(--a)}
|
|
19
|
+
[role=switch]:checked::before{inset-inline-start:18px;background:var(--on)}
|
|
20
|
+
[role=switch]:disabled{opacity:.5;cursor:default}
|
|
21
|
+
button{padding:8px 16px;border:0;border-radius:var(--r);background:var(--a);color:var(--on);font:inherit;font-weight:600;cursor:pointer}
|
|
22
|
+
button:disabled{opacity:.6;cursor:default}
|
|
23
|
+
:focus-visible{outline:2px solid var(--a);outline-offset:2px}
|
|
24
|
+
fieldset{padding:0;border:0}
|
|
25
|
+
legend{padding:0;margin-block-end:4px;font-weight:600}
|
|
26
|
+
.check{display:flex;gap:8px;align-items:flex-start;cursor:pointer}
|
|
27
|
+
.muted,.consent,.error{font-size:.9em}
|
|
28
|
+
.muted{opacity:.72}
|
|
29
|
+
.consent a{color:inherit}
|
|
30
|
+
.error{color:var(--d)}
|
|
31
|
+
.trap{position:absolute;inset-inline-start:-1e4px;inline-size:1px;overflow:hidden}
|
|
32
|
+
@media (max-width:480px){input{font-size:16px}}
|
|
33
|
+
`;class YuvaSubscribeElement extends Base{static observedAttributes=["channel","server","locale","dir","lists","layout","name","button-text","consent","privacy-url","identity-token"];static loadClient=null;#root;#messages=messages;#connected=!1;#generation=0;#phase="loading";#refused=!1;#inbox=null;#offered=[];#chosen=new Set;#token="";#tokenAt=0;#confirmation=!1;#error="";#emailError="";#nameError="";#consentError="";#identity=null;#client=null;#busy=new Set;#email=el("input");#name=el("input");#trap=el("input");#consent=el("input");#status=el("p");constructor(){super();this.#root=this.attachShadow({mode:"open"}),this.#email.type="email",this.#email.autocomplete="email",this.#email.required=!0,this.#email.maxLength=320,this.#email.id="email",this.#name.autocomplete="name",this.#name.maxLength=200,this.#name.id="name",this.#trap.name="website",this.#trap.tabIndex=-1,this.#trap.autocomplete="off",this.#consent.type="checkbox",this.#consent.id="consent",this.#consent.addEventListener("change",()=>{this.#consentError="",this.#render()});for(let input of[this.#email,this.#name])input.setAttribute("part","field"),input.dir="auto";this.#status.setAttribute("part","status"),this.#status.setAttribute("role","status"),this.#status.setAttribute("aria-live","polite")}get channel(){return this.getAttribute("channel")}set channel(value){this.#attribute("channel",value)}get server(){return(this.getAttribute("server")||(scriptSrc?new URL(scriptSrc).origin:location.origin)).replace(/\/+$/,"")}set server(value){this.#attribute("server",value)}get locale(){return localeIn(catalogs,[this.getAttribute("locale"),navigator.language])}set locale(value){this.#attribute("locale",value)}get lists(){return this.#offered.map((item)=>item.list)}setIdentityToken(source){if(this.#identity=source,this.#connected)this.#load()}connectedCallback(){this.#connected=!0,this.#load()}disconnectedCallback(){this.#connected=!1}attributeChangedCallback(name,previous,value){if(!this.#connected||previous===value)return;if(["channel","server","lists","identity-token"].includes(name))return void this.#load();this.#render()}#attribute(name,value){if(value===null||value===void 0||value==="")this.removeAttribute(name);else this.setAttribute(name,value)}#t(descriptor){return translate(this.#messages,descriptor,messages)}get#identified(){return!!this.#identity||this.hasAttribute("identity-token")}async#identityToken(){return this.#identity?await this.#identity()??null:this.getAttribute("identity-token")}#wanted(lists){let ids=(this.getAttribute("lists")??"").split(",").map((id)=>id.trim()).filter((id)=>id&&id!=="all");if(ids.length===0)return lists;let found=ids.map((id)=>lists.find((list)=>list.id===id)).filter((list)=>!!list);if(found.length<ids.length)console.warn(`Yuva: some lists in "${ids.join(",")}" are not public lists`);return found}async#load(){let generation=++this.#generation,channel=this.channel;if(this.#refused=!1,this.#phase="loading",this.#offered=[],this.#error="",this.#client=null,this.#render(),!channel)return;let server=this.server;try{let inbox=call(fetcher,server,`/client/v1/channels/${encodeURIComponent(channel)}`),offered=null;if(this.#identified&&YuvaSubscribeElement.loadClient&&await this.#identityToken()){let{createYuvaClient}=await YuvaSubscribeElement.loadClient(),client=createYuvaClient({server,channel,identityToken:()=>this.#identityToken()});try{let{items}=await client.subscriptions(),wanted=new Set(this.#wanted(items.map((item)=>item.list)));offered=items.filter((item)=>wanted.has(item.list)),this.#client=client}catch(error){if(!(error instanceof ApiError2)||error.code!=="identity_required")throw error}}if(!offered){let{lists,form_token}=await mailingLists(fetcher,server,channel);offered=this.#wanted(lists).map((list)=>({list})),this.#token=form_token,this.#tokenAt=Date.now()}if(this.#inbox=await inbox,generation!==this.#generation)return;if(this.#offered=offered,this.#chosen=new Set(offered.length===1?[offered[0].list.id]:[]),this.#phase="idle",offered.length===0)console.warn(`Yuva: channel ${channel} has no public mailing lists to offer`)}catch(error){if(generation!==this.#generation)return;if(this.#refusal(error))return;this.#phase="idle",this.#error=this.#errorText(error)}this.#render()}#refusal(error){let refused=error instanceof ApiError2&&(error.status===404||error.code==="origin_not_allowed"||error.code==="page_origin");if(refused)this.#refused=!0,console.warn(`Yuva: channel ${this.channel} is unknown, offers no such list or does not allow ${location.origin}`),this.#render();return refused}#errorText(error){let code=error instanceof ApiError2?error.code:"";if(code==="rate_limited")return this.#t({id:"tzsBOP"});if(code==="network")return this.#t({id:"GQVIIl"});if(code==="no_email")return this.#t({id:"eku1-t"});return this.#t({id:"jWgNnM"})}#emit(type,detail){this.dispatchEvent(new CustomEvent(type,{detail,bubbles:!0,composed:!0}))}#failed(error){this.#emit("yuva-subscribe-error",{code:error instanceof ApiError2?error.code:"error"})}consentText(lists=this.#selected()){let custom=this.getAttribute("consent")?.trim();if(custom)return custom;let names=(lists.length?lists:this.lists).map((list)=>list.name),list=new Intl.ListFormat(this.locale,{type:"conjunction"}).format(names),inbox=this.#inbox?.name??"";return this.#t({id:"dMJfG5",values:{list,inbox}})}#selected(){return this.lists.filter((list)=>this.#chosen.has(list.id))}async#submit(){if(this.#phase!=="idle"||!this.channel)return;let lists=this.#selected(),email=this.#email.value.trim(),name=this.#name.value.trim(),asksName=this.getAttribute("name");if(this.#error=lists.length===0?this.#t({id:"-g5O6h"}):"",this.#emailError=this.#email.checkValidity()&&email?"":this.#t({id:"E_qvzP"}),this.#nameError=asksName==="required"&&!name?this.#t({id:"E_LjOR"}):"",this.#consentError=this.#consent.checked?"":this.#t({id:"lDEbTy"}),this.#error||this.#emailError||this.#nameError||this.#consentError){this.#render();let invalid=[this.#emailError&&this.#email,this.#nameError&&this.#name,this.#consentError&&this.#consent];for(let input of invalid)if(input)return input.focus();return}let channel=this.channel,generation=this.#generation,consent_text=this.consentText(lists);this.#phase="submitting",this.#render();let send=async(retry)=>{let wait=this.#tokenAt+tokenMinimumAge-Date.now();if(wait>0)await new Promise((resolve)=>setTimeout(resolve,wait));try{let{confirmation}=await createSubscription(fetcher,this.server,channel,{email,name:asksName==="optional"||asksName==="required"?name||void 0:void 0,list_ids:lists.map((list)=>list.id),locale:this.locale,page_url:location.href.split("#")[0].slice(0,2000),consent_text,form_token:this.#token,website:this.#trap.value||void 0});return this.#confirmation=confirmation,!0}catch(error){if(retry&&error instanceof ApiError2&&error.code==="form_token"){let fresh=await mailingLists(fetcher,this.server,channel);return this.#token=fresh.form_token,this.#tokenAt=Date.now(),send(!1)}throw error}};try{await send(!0)}catch(error){if(generation!==this.#generation)return;if(this.#failed(error),this.#phase="idle",this.#refusal(error))return;if(error instanceof ApiError2&&error.code==="invalid_email")return this.#emailError=this.#t({id:"E_qvzP"}),this.#render(),this.#email.focus();return this.#error=this.#errorText(error),this.#render()}if(generation!==this.#generation)return;this.#phase="done",this.#emit("yuva-subscribe",{lists:lists.map((list)=>list.id),confirmation:this.#confirmation}),this.#render()}async#toggle(item,on){let client=this.#client;if(!client||this.#busy.has(item.list.id))return;this.#busy.add(item.list.id),this.#error="",this.#render();try{if(on){let{state}=await client.subscribeList(item.list.id,{consent_text:this.consentText([item.list]),page_url:location.href.split("#")[0].slice(0,2000)});item.state=state,this.#emit("yuva-subscribe",{lists:[item.list.id],confirmation:state==="pending"})}else await client.unsubscribeList(item.list.id),item.state="unsubscribed"}catch(error){this.#failed(error),this.#error=this.#errorText(error)}if(this.#busy.delete(item.list.id),client===this.#client)this.#render()}#errorFor(input,text){if(input.setAttribute("aria-invalid",String(!!text)),!text)return input.removeAttribute("aria-describedby"),null;let id=`${input.id}-error`;input.setAttribute("aria-describedby",id);let error=el("p","error",text);return error.id=id,error}#check(text,checked,onChange,key){let label=el("label","check"),box=el("input");box.type="checkbox",box.checked=checked,box.dataset.key=key,box.addEventListener("change",()=>onChange(box.checked));let body=el("span","text");return body.append(...text),label.append(box,body),label}#lists(identity){if(!identity&&this.#offered.length<2)return null;let group=el("fieldset");group.append(el("legend","",this.#t({id:"h16FyT"})));for(let item of this.#offered){let text=[el("span","",item.list.name)];if(item.list.description)text.push(el("span","muted",item.list.description));if(identity){if(text.push(el("span","muted consent",this.consentText([item.list]))),item.state==="pending")text.push(el("span","muted",this.#t({id:"x6dU53"})))}let on=identity?item.state==="subscribed"||item.state==="pending":this.#chosen.has(item.list.id),label=this.#check(text,on,(checked)=>{if(identity)return void this.#toggle(item,checked);if(checked)this.#chosen.add(item.list.id);else this.#chosen.delete(item.list.id);this.#error="",this.#render()},item.list.id),box=label.querySelector("input");if(identity)box.setAttribute("role","switch"),box.setAttribute("aria-checked",String(box.checked)),box.addEventListener("keydown",(event)=>{if(event.key!=="Enter")return;event.preventDefault(),box.click()}),box.disabled=this.#busy.has(item.list.id);else box.disabled=this.#phase==="submitting";group.append(label)}return group}#form(){let form=el("form",this.getAttribute("layout")==="inline"?"inline":"");form.noValidate=!0,form.addEventListener("submit",(event)=>{event.preventDefault(),this.#submit()});let busy=this.#phase==="submitting",lists=this.#lists(!1);if(lists)form.append(lists);let row=el("div","row"),errors=[],asksName=this.getAttribute("name");if(asksName==="optional"||asksName==="required"){this.#name.placeholder=asksName==="required"?this.#t({id:"q8yluz"}):this.#t({id:"YnOaHp"}),this.#name.setAttribute("aria-label",this.#name.placeholder),this.#name.required=asksName==="required",this.#name.disabled=busy,row.append(this.#name);let error=this.#errorFor(this.#name,this.#nameError);if(error)errors.push(error)}this.#email.placeholder=this.#t({id:"XJURKP"}),this.#email.setAttribute("aria-label",this.#email.placeholder),this.#email.disabled=busy,row.append(this.#email);let emailError=this.#errorFor(this.#email,this.#emailError);if(emailError)errors.push(emailError);let button=el("button","",busy?this.#t({id:"1w51t9"}):this.getAttribute("button-text")||this.#t({id:"EDl9kS"}));button.type="submit",button.disabled=busy,button.setAttribute("part","button"),row.append(button);let trap=el("div","trap");trap.setAttribute("aria-hidden","true"),trap.append(this.#trap);let consentText=el("span","",this.consentText()),consent=el("label","check consent");consent.setAttribute("part","consent"),this.#consent.disabled=busy;let body=el("span");body.append(consentText);let privacy=this.getAttribute("privacy-url");if(privacy&&/^https?:\/\//i.test(privacy)){let link=el("a","",this.#t({id:"ScJ9fj"}));link.href=privacy,link.target="_blank",link.rel="noopener noreferrer",body.append(" ",link)}consent.append(this.#consent,body);let consentError=this.#errorFor(this.#consent,this.#consentError);if(form.append(row,...errors,consent),consentError)form.append(consentError);return form.append(trap),form}#render(){if(this.#refused||!this.channel||this.#phase!=="loading"&&this.#offered.length===0&&!this.#error){this.#root.replaceChildren();return}let locale=this.locale;this.#messages=catalogs[locale]??messages;let dir=this.getAttribute("dir"),wrapper=el("div","frame");wrapper.dir=dir==="rtl"||dir==="ltr"?dir:directionOf(locale),wrapper.lang=locale;let brand=this.#inbox?.chat.launcher_color??this.#inbox?.branding.color;if(brand&&/^#[0-9a-f]{6}$/i.test(brand))wrapper.style.setProperty("--brand",brand),wrapper.style.setProperty("--brand-on",contrastOn(brand));let status="";if(this.#phase==="done")status=this.#confirmation?this.#t({id:"y3k2zM"}):this.#t({id:"rgySXy"});if(this.#status.textContent=status,this.#phase==="idle"||this.#phase==="submitting"){let content=this.#client?this.#lists(!0):this.#form();if(content)wrapper.append(content)}if(wrapper.append(this.#status),this.#error){let error=el("p","error",this.#error);error.setAttribute("role","alert"),wrapper.append(error)}let focusedKey,focused=null;try{focused=this.#root.activeElement}catch{}if(focused instanceof HTMLInputElement)focusedKey=focused.dataset.key;let style=el("style");style.textContent=styles,this.#root.replaceChildren(style,wrapper);let again=focusedKey?this.#root.querySelector(`[data-key="${focusedKey}"]`):focused;if(again instanceof HTMLElement&&again.isConnected)again.focus({preventScroll:!0})}}function defineSubscribe(){if(typeof customElements>"u")return;if(!customElements.get("yuva-subscribe"))customElements.define("yuva-subscribe",YuvaSubscribeElement)}YuvaSubscribeElement.loadClient=()=>import("./client-p9899hvt.js");defineSubscribe();export{YuvaSubscribeElement,defineSubscribe};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import{el}from"./index-rdzxvj2r.js";import{inlineNodes}from"./index-jdxce2se.js";import{translate}from"./index-98r96a7e.js";var messages=JSON.parse('{"2Hlmdt":["Write a reply…"],"3CApMv":["All discussions"],"3PqJQG":["Nothing to preview."],"4-S4QM":["Unmark as answer"],"5lWFkC":["Sign in"],"8wRl7c":["The opening post was deleted."],"99w-GZ":["Sign in to start a discussion. Your name is shown with your post."],"F_vGso":["Your reply"],"HkXOWm":["This reply was deleted."],"Hw3P48":["Replies: ",["0"]],"ImOQa9":["Reply"],"JfAIiv":["This discussion is locked. New replies are closed."],"Kl3TuI":["Get an e-mail when someone replies or an answer is accepted."],"Klsidc":["Delete this reply?"],"MHrjPM":["Title"],"MKEPCY":["Follow"],"NjUiZ4":["Ask a question, share an idea or describe a problem with this page."],"NrGspR":["Thanks! Your discussion will appear for everyone once the team approves it."],"OVijcR":["Remove your vote (",["0"]," votes)"],"PL0621":["Sign in to reply, vote and follow this discussion."],"PN38hZ":["Your question or idea"],"PZ_kxo":["Keep"],"Pwqkdw":["Loading…"],"RqsQKK":["Your first posts are checked by the team before they appear for everyone."],"Sad2tK":["Sending…"],"VGqKyv":["This discussion is no longer available."],"Vwy_nT":["Markdown is supported."],"YZayoP":["Thanks! Your reply will appear for everyone once the team approves it."],"cnGeoo":["Delete"],"dEgA5A":["Cancel"],"dNOvhg":["Upvote (",["0"]," votes)"],"ePK91l":["Edit"],"i4_LY_":["Write"],"jhu92n":["Mark as answer"],"k4b5_X":["edited"],"n5vqdp":["Start discussion"],"qzVesX":["Edit your post"],"rAl91-":["Delete this discussion?"],"rdUucN":["Preview"],"tfDRzk":["Save"],"y-KXxN":["Accepted answer"],"y6sq5j":["Following"],"z1qf6l":["Start a discussion"]}');var messages2=JSON.parse('{"2Hlmdt":["Antwort schreiben…"],"3CApMv":["Alle Diskussionen"],"3PqJQG":["Noch nichts für die Vorschau."],"4-S4QM":["Antwortmarkierung entfernen"],"5lWFkC":["Anmelden"],"8wRl7c":["Der erste Beitrag wurde gelöscht."],"99w-GZ":["Melden Sie sich an, um eine Diskussion zu starten. Ihr Name wird mit Ihrem Beitrag angezeigt."],"F_vGso":["Ihre Antwort"],"HkXOWm":["Diese Antwort wurde gelöscht."],"Hw3P48":["Antworten: ",["0"]],"ImOQa9":["Antworten"],"JfAIiv":["Diese Diskussion ist gesperrt. Neue Antworten sind nicht möglich."],"Kl3TuI":["Erhalten Sie eine E-Mail, wenn jemand antwortet oder eine Antwort akzeptiert wird."],"Klsidc":["Diese Antwort löschen?"],"MHrjPM":["Titel"],"MKEPCY":["Folgen"],"NjUiZ4":["Stellen Sie eine Frage, teilen Sie eine Idee oder beschreiben Sie ein Problem mit dieser Seite."],"NrGspR":["Danke! Ihre Diskussion ist für alle sichtbar, sobald das Team sie freigibt."],"OVijcR":["Stimme zurückziehen (",["0"]," Stimmen)"],"PL0621":["Melden Sie sich an, um zu antworten, abzustimmen und dieser Diskussion zu folgen."],"PN38hZ":["Ihre Frage oder Idee"],"PZ_kxo":["Behalten"],"Pwqkdw":["Wird geladen…"],"RqsQKK":["Ihre ersten Beiträge prüft das Team, bevor sie für alle sichtbar sind."],"Sad2tK":["Wird gesendet…"],"VGqKyv":["Diese Diskussion ist nicht mehr verfügbar."],"Vwy_nT":["Markdown wird unterstützt."],"YZayoP":["Danke! Ihre Antwort ist für alle sichtbar, sobald das Team sie freigibt."],"cnGeoo":["Löschen"],"dEgA5A":["Abbrechen"],"dNOvhg":["Zustimmen (",["0"]," Stimmen)"],"ePK91l":["Bearbeiten"],"i4_LY_":["Schreiben"],"jhu92n":["Als Antwort markieren"],"k4b5_X":["bearbeitet"],"n5vqdp":["Diskussion starten"],"qzVesX":["Beitrag bearbeiten"],"rAl91-":["Diese Diskussion löschen?"],"rdUucN":["Vorschau"],"tfDRzk":["Speichern"],"y-KXxN":["Akzeptierte Antwort"],"y6sq5j":["Gefolgt"],"z1qf6l":["Diskussion starten"]}');var messages3=JSON.parse('{"2Hlmdt":["Bir yanıt yazın…"],"3CApMv":["Tüm tartışmalar"],"3PqJQG":["Önizlenecek bir şey yok."],"4-S4QM":["Yanıt işaretini kaldır"],"5lWFkC":["Giriş yap"],"8wRl7c":["Açılış gönderisi silindi."],"99w-GZ":["Tartışma başlatmak için giriş yapın. Adınız gönderinizle birlikte gösterilir."],"F_vGso":["Yanıtınız"],"HkXOWm":["Bu yanıt silindi."],"Hw3P48":["Yanıtlar: ",["0"]],"ImOQa9":["Yanıtla"],"JfAIiv":["Bu tartışma kilitli. Yeni yanıt yazılamaz."],"Kl3TuI":["Biri yanıt yazdığında ya da bir yanıt kabul edildiğinde e-posta alın."],"Klsidc":["Bu yanıt silinsin mi?"],"MHrjPM":["Başlık"],"MKEPCY":["Takip et"],"NjUiZ4":["Bir soru sorun, bir fikir paylaşın ya da bu sayfadaki bir sorunu anlatın."],"NrGspR":["Teşekkürler! Tartışmanız ekip onayladığında herkese görünecek."],"OVijcR":["Oyunuzu geri alın (",["0"]," oy)"],"PL0621":["Bu tartışmada yanıt yazmak, oy vermek ve takip etmek için giriş yapın."],"PN38hZ":["Sorunuz ya da fikriniz"],"PZ_kxo":["Kalsın"],"Pwqkdw":["Yükleniyor…"],"RqsQKK":["İlk gönderileriniz herkese görünmeden önce ekip tarafından kontrol edilir."],"Sad2tK":["Gönderiliyor…"],"VGqKyv":["Bu tartışma artık mevcut değil."],"Vwy_nT":["Markdown desteklenir."],"YZayoP":["Teşekkürler! Yanıtınız ekip onayladığında herkese görünecek."],"cnGeoo":["Sil"],"dEgA5A":["Vazgeç"],"dNOvhg":["Oy ver (",["0"]," oy)"],"ePK91l":["Düzenle"],"i4_LY_":["Yaz"],"jhu92n":["Yanıt olarak işaretle"],"k4b5_X":["düzenlendi"],"n5vqdp":["Tartışmayı başlat"],"qzVesX":["Gönderinizi düzenleyin"],"rAl91-":["Bu tartışma silinsin mi?"],"rdUucN":["Önizleme"],"tfDRzk":["Kaydet"],"y-KXxN":["Kabul edilen yanıt"],"y6sq5j":["Takip ediliyor"],"z1qf6l":["Tartışma başlat"]}');var linkPattern=/\[([^\]\n]+)\]\(([^)\s]+)\)/g;function inline(text){let nodes=[],last=0;for(let match of text.matchAll(linkPattern)){let index=match.index??0;if(index>last)nodes.push(...inlineNodes(text.slice(last,index)));let[whole,label="",href=""]=match,url=null;try{url=new URL(href)}catch{}if(url&&(url.protocol==="http:"||url.protocol==="https:")){let a=document.createElement("a");a.href=url.href,a.target="_blank",a.rel="nofollow ugc noopener",a.append(...inlineNodes(label)),nodes.push(a)}else nodes.push(document.createTextNode(whole));last=index+whole.length}if(last<text.length)nodes.push(...inlineNodes(text.slice(last)));return nodes}function block(tag,lines){let element=document.createElement(tag);return element.append(...inline(lines.join(" "))),element}function preview(markdown){let fragment=document.createDocumentFragment(),lines=markdown.replace(/\r\n?/g,`
|
|
2
|
+
`).split(`
|
|
3
|
+
`),paragraph=[],list=null,quote=[],flush=()=>{if(paragraph.length)fragment.append(block("p",paragraph));if(quote.length){let element=document.createElement("blockquote");element.append(preview(quote.join(`
|
|
4
|
+
`))),fragment.append(element)}paragraph=[],quote=[],list=null};for(let i=0;i<lines.length;i++){let line=lines[i]??"",fence=/^\s*(```|~~~)/.exec(line);if(fence){flush();let code=[];while(++i<lines.length&&!(lines[i]??"").trimStart().startsWith(fence[1]??"```"))code.push(lines[i]??"");let pre=document.createElement("pre");pre.append(Object.assign(document.createElement("code"),{textContent:code.join(`
|
|
5
|
+
`)})),fragment.append(pre);continue}if(/^\s*$/.test(line)){flush();continue}let quoted=/^\s*>\s?(.*)$/.exec(line);if(quoted){if(paragraph.length||list)flush();quote.push(quoted[1]??"");continue}let heading=/^\s*(#{1,6})\s+(.*)$/.exec(line);if(heading){flush(),fragment.append(block(`h${Math.min(6,(heading[1]?.length??1)+2)}`,[heading[2]??""]));continue}let item=/^\s*(?:([-*+])|(\d+)[.)])\s+(.*)$/.exec(line);if(item){let tag=item[1]?"ul":"ol";if(paragraph.length||quote.length||list&&list.tagName.toLowerCase()!==tag)flush();if(!list)list=document.createElement(tag),fragment.append(list);list.append(block("li",[item[3]??""]));continue}if(quote.length)flush();if(list&&/^\s{2,}/.test(line)){list.lastElementChild?.append(" ",...inline(line.trim()));continue}list=null,paragraph.push(line.trim())}return flush(),fragment}var editWindow=1800000,catalogs={en:messages,tr:messages3,de:messages2},svg=(path)=>`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${path}</svg>`,checkCircle=svg('<circle cx="12" cy="12" r="9"/><path d="M8 12l3 3 5-6"/>'),backIcon=svg('<path d="M19 12H5M12 19l-7-7 7-7"/>'),bell=svg('<path d="M18 8a6 6 0 10-12 0c0 7-3 9-3 9h18s-3-2-3-9M13.7 21a2 2 0 01-3.4 0"/>'),styles=`
|
|
6
|
+
.thread { display: flex; flex-direction: column; gap: 12px; }
|
|
7
|
+
.thread-head { display: flex; flex-direction: column; gap: 8px; }
|
|
8
|
+
.post { display: flex; gap: 12px; padding: 14px; border: 1px solid var(--yuva-border); border-radius: 12px; }
|
|
9
|
+
.post.accepted { border-color: var(--yuva-success); box-shadow: inset 0 0 0 1px var(--yuva-success); }
|
|
10
|
+
.post.pending { border-style: dashed; }
|
|
11
|
+
.side { display: flex; flex-direction: column; align-items: center; gap: 6px; }
|
|
12
|
+
.vote {
|
|
13
|
+
display: inline-flex; flex-direction: column; align-items: center; gap: 0; min-inline-size: 40px; padding: 4px 6px;
|
|
14
|
+
border: 1px solid var(--yuva-border); border-radius: 8px; background: none; cursor: pointer; font-size: 0.85em; font-weight: 600;
|
|
15
|
+
}
|
|
16
|
+
.vote:hover:not(:disabled) { border-color: var(--yuva-accent); }
|
|
17
|
+
.vote[aria-pressed="true"] { border-color: var(--yuva-accent); color: var(--yuva-accent); background: var(--yuva-soft); }
|
|
18
|
+
.post-body { flex: 1; min-inline-size: 0; display: flex; flex-direction: column; gap: 8px; }
|
|
19
|
+
.post-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: 0.88em; }
|
|
20
|
+
.name { font-weight: 600; }
|
|
21
|
+
.answer-label { display: flex; align-items: center; gap: 6px; color: var(--yuva-success); font-weight: 600; font-size: 0.85em; }
|
|
22
|
+
.tools { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; }
|
|
23
|
+
.children { display: flex; flex-direction: column; gap: 10px; margin-block-start: 4px; padding-inline-start: 14px; border-inline-start: 2px solid var(--yuva-border); }
|
|
24
|
+
.children .post { padding: 10px 0; border: 0; box-shadow: none; }
|
|
25
|
+
.children .post + .post { border-block-start: 1px solid var(--yuva-border); border-radius: 0; }
|
|
26
|
+
.deleted { font-style: italic; opacity: 0.65; }
|
|
27
|
+
.signin { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; padding: 14px; border: 1px solid var(--yuva-border); border-radius: 12px; }
|
|
28
|
+
.composer { display: flex; flex-direction: column; border: 1px solid var(--yuva-border); border-radius: 12px; overflow: hidden; }
|
|
29
|
+
.composer:focus-within { border-color: var(--yuva-accent); }
|
|
30
|
+
.composer .ctabs { display: flex; gap: 4px; padding: 0 8px; border-block-end: 1px solid var(--yuva-border); }
|
|
31
|
+
.composer .ctab { padding: 7px 10px; border: 0; border-block-end: 2px solid transparent; background: none; cursor: pointer; font-size: 0.88em; opacity: 0.75; margin-block-end: -1px; }
|
|
32
|
+
.composer .ctab[aria-selected="true"] { border-block-end-color: var(--yuva-accent); font-weight: 600; opacity: 1; }
|
|
33
|
+
.composer .ctab:focus-visible { outline: 2px solid var(--yuva-accent); outline-offset: -2px; }
|
|
34
|
+
.composer textarea, .composer .preview { border: 0; border-radius: 0; min-block-size: 110px; padding: 10px 12px; }
|
|
35
|
+
.composer textarea:focus-visible { outline: none; }
|
|
36
|
+
.composer .preview { overflow-wrap: anywhere; }
|
|
37
|
+
.composer .foot { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; padding: 8px 10px; border-block-start: 1px solid var(--yuva-border); }
|
|
38
|
+
.composer .hint { font-size: 0.8em; opacity: 0.7; }
|
|
39
|
+
.composer .buttons { display: flex; gap: 8px; margin-inline-start: auto; }
|
|
40
|
+
.field-title { font-size: 1.05em; font-weight: 600; }
|
|
41
|
+
.form { display: flex; flex-direction: column; gap: 10px; }
|
|
42
|
+
.md { overflow-wrap: anywhere; }
|
|
43
|
+
.md > :first-child { margin-block-start: 0; }
|
|
44
|
+
.md > :last-child { margin-block-end: 0; }
|
|
45
|
+
.md p, .md ul, .md ol, .md pre, .md blockquote, .md table { margin: 0 0 0.75em; }
|
|
46
|
+
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { margin: 0.9em 0 0.4em; font-size: 1em; font-weight: 600; }
|
|
47
|
+
.md h1, .md h3 { font-size: 1.1em; }
|
|
48
|
+
.md ul, .md ol { padding-inline-start: 1.5em; }
|
|
49
|
+
.md a { color: var(--yuva-accent); }
|
|
50
|
+
.md code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.88em; padding: 1px 5px; border-radius: 5px; background: var(--yuva-soft); }
|
|
51
|
+
.md pre { padding: 10px 12px; border-radius: 8px; background: var(--yuva-soft); overflow-x: auto; }
|
|
52
|
+
.md pre code { padding: 0; background: none; }
|
|
53
|
+
.md blockquote { padding-inline-start: 12px; border-inline-start: 3px solid var(--yuva-border); opacity: 0.85; }
|
|
54
|
+
.md table { border-collapse: collapse; display: block; overflow-x: auto; }
|
|
55
|
+
.md th, .md td { border: 1px solid var(--yuva-border); padding: 4px 8px; }
|
|
56
|
+
.md img { max-inline-size: 100%; }
|
|
57
|
+
.md hr { border: 0; border-block-start: 1px solid var(--yuva-border); }
|
|
58
|
+
@media (max-width: 560px) {
|
|
59
|
+
.post { padding: 12px; gap: 10px; }
|
|
60
|
+
}
|
|
61
|
+
`;class Composer{area=el("textarea");previewing=!1;constructor(rows){this.area.rows=rows,this.area.maxLength=20000,this.area.dir="auto"}get value(){return this.area.value.trim()}clear(){this.area.value="",this.previewing=!1}}function createThread(host){let s=host.s,t=(descriptor)=>translate(catalogs[host.locale()]??messages,descriptor,messages),reply=new Composer(4),draft=new Composer(6),title=el("input"),inline=null,edit=null;title.maxLength=200,title.dir="auto",title.className="field-title";for(let area of[reply.area,draft.area])area.addEventListener("input",()=>syncSend());title.addEventListener("input",()=>syncSend());function syncSend(){for(let button of host.root.querySelectorAll("[data-requires]")){let needs=button.dataset.requires,busy=s.busy.has(button.dataset.busy??""),ok=needs==="start"?title.value.trim().length>=3&&draft.value!=="":needs==="reply"?reply.value!=="":needs==="inline"?!!inline?.composer.value:needs==="edit"?!!edit?.composer.value&&(!!edit.post||edit.title.value.trim().length>=3):!0;button.disabled=busy||!ok}}async function start(){let heading=title.value.trim(),body=draft.value;if(heading.length<3||!body)return;let page=host.page(),discussion=await host.act("start",()=>host.client().startDiscussion({page_url:page,page_title:host.pageTitle()||void 0,title:heading,body}));if(!discussion)return;if(host.forget(),host.emit("yuva-discussion",{page,discussion_id:discussion.id,state:discussion.state}),host.page()!==page)return;title.value="",draft.clear(),s.items=[discussion,...s.items.filter((d)=>d.id!==discussion.id)],s.notice=discussion.state==="pending"?t({id:"NrGspR"}):"",s.thread={discussion,posts:[]},await host.open(discussion.id,!0)}async function send(composer,parent){let thread=s.thread,body=composer.value;if(!thread||!body)return;let page=host.page(),id=thread.discussion.id,post=await host.act(parent?`reply-${parent}`:"reply",()=>host.client().replyToDiscussion(id,{body,parent_post_id:parent}));if(!post)return;if(host.forget(),host.emit("yuva-post",{page,discussion_id:id,post_id:post.id,state:post.state}),composer.clear(),parent)inline=null;if(s.notice=post.state==="pending"?t({id:"YZayoP"}):"",s.thread?.discussion.id===id)s.thread={...s.thread,posts:[...s.thread.posts,post]},s.focus=`post-${post.id}`,host.render(),host.open(id,!1)}async function vote(post,opening){if(!s.writer)return void host.signIn();let updated=await host.act(`vote-${post.id}`,()=>host.client().voteDiscussionPost(post.id,!post.voted));if(!updated||!s.thread)return;if(host.forget(),opening){let discussion={...s.thread.discussion,votes:updated.votes,voted:updated.voted};s.thread={...s.thread,discussion},s.items=s.items.map((d)=>d.id===discussion.id?discussion:d)}else s.thread={...s.thread,posts:s.thread.posts.map((p)=>p.id===updated.id?{...p,...updated}:p)}}async function follow(){let thread=s.thread;if(!thread)return;if(!s.writer)return void host.signIn();let following=!thread.discussion.following;if(await host.act("follow",()=>host.client().followDiscussion(thread.discussion.id,following).then(()=>!0))&&s.thread?.discussion.id===thread.discussion.id)s.thread={...s.thread,discussion:{...s.thread.discussion,following}}}async function accept(post){let thread=s.thread;if(!thread)return;let discussion=await host.act(`accept-${post?.id??"clear"}`,()=>host.client().acceptDiscussionAnswer(thread.discussion.id,post?.id??null));if(!discussion)return;host.forget(),s.focus=post?`post-${post.id}`:"thread-title",await host.open(discussion.id,!1)}async function saveEdit(){let current=edit,thread=s.thread;if(!current||!thread)return;let body=current.composer.value,opening=!current.post,heading=current.title.value.trim();if(!body||opening&&heading.length<3)return;let postId=current.post?.id??thread.discussion.opening_post_id;if(!await host.act(`edit-${postId}`,()=>host.client().editDiscussionPost(postId,opening?{body,title:heading}:{body})))return;host.forget(),edit=null,s.focus=opening?"thread-title":`post-${postId}`,await host.open(thread.discussion.id,!1)}async function remove(postId,opening){let thread=s.thread;if(!thread)return;let done=await host.act(`delete-${postId}`,()=>host.client().deleteDiscussionPost(postId).then(()=>!0));if(s.confirm="",!done)return;if(host.forget(),opening)try{await host.client().getDiscussion(thread.discussion.id)}catch{return s.items=s.items.filter((d)=>d.id!==thread.discussion.id),s.thread=null,host.toList()}await host.open(thread.discussion.id,!1)}function md(html){let body=el("div","md");body.dir="auto",body.innerHTML=html;for(let link of body.querySelectorAll("a[href]"))link.setAttribute("target","_blank");return body}function composerBox(composer,options){let box=el("div","composer"),tabs=el("div","ctabs");tabs.setAttribute("role","tablist"),tabs.setAttribute("aria-label",options.label);let panelId=`p-${options.focusKey}`,write=host.button("ctab",t({id:"i4_LY_"}),`${options.focusKey}-write`,()=>{composer.previewing=!1,s.focus=options.focusKey,host.render()}),show=host.button("ctab",t({id:"rdUucN"}),`${options.focusKey}-preview`,()=>{composer.previewing=!0,host.render()});for(let[tab,selected]of[[write,!composer.previewing],[show,composer.previewing]])tab.setAttribute("role","tab"),tab.setAttribute("aria-selected",String(selected)),tab.setAttribute("aria-controls",panelId),tab.tabIndex=selected?0:-1,tab.addEventListener("keydown",(event)=>{if(event.key!=="ArrowLeft"&&event.key!=="ArrowRight")return;event.preventDefault(),composer.previewing=!composer.previewing,s.focus=`${options.focusKey}-${composer.previewing?"preview":"write"}`,host.render()});if(tabs.append(write,show),box.append(tabs),composer.previewing){let panel=el("div","preview md");if(panel.dir="auto",panel.id=panelId,panel.setAttribute("role","tabpanel"),panel.setAttribute("aria-label",t({id:"rdUucN"})),composer.value)panel.append(preview(composer.area.value));else panel.append(el("p","muted",t({id:"3PqJQG"})));box.append(panel)}else composer.area.id=panelId,composer.area.placeholder=options.placeholder,composer.area.setAttribute("aria-label",options.label),composer.area.dataset.key=options.focusKey,composer.area.disabled=s.busy.has(options.busy),composer.area.onkeydown=(event)=>{if(event.key==="Enter"&&(event.metaKey||event.ctrlKey))event.preventDefault(),options.onSubmit();else if(event.key==="Escape"&&options.onCancel)options.onCancel()},box.append(composer.area);let foot=el("div","foot");foot.append(el("span","hint",t({id:"Vwy_nT"})));let buttons=el("div","buttons");if(options.onCancel)buttons.append(host.button("ghost",t({id:"dEgA5A"}),`${options.focusKey}-cancel`,options.onCancel));let submit=host.button("send",s.busy.has(options.busy)?t({id:"Sad2tK"}):options.submit,`${options.focusKey}-submit`,options.onSubmit);return submit.dataset.requires=options.requires,submit.dataset.busy=options.busy,buttons.append(submit),foot.append(buttons),box.append(foot),box}function signInBox(text){let box=el("div","signin");return box.append(el("p","",text)),box.append(host.button("send",t({id:"5lWFkC"}),"sign-in-box",()=>void host.signIn())),box}function back(){let button=host.button("plain",t({id:"3CApMv"}),"back",()=>host.toList(),backIcon);button.style.alignSelf="flex-start",button.style.display="inline-flex",button.style.gap="6px",button.style.alignItems="center";let arrow=button.querySelector("svg");if(arrow&&host.direction()==="rtl")arrow.style.transform="scaleX(-1)";return button}function newView(){let form=el("div","form");if(form.append(el("h3","",t({id:"z1qf6l"}))),!s.writer)return form.append(signInBox(t({id:"99w-GZ"}))),[back(),form];if(title.placeholder=t({id:"MHrjPM"}),title.setAttribute("aria-label",t({id:"MHrjPM"})),title.dataset.key="new-title",title.disabled=s.busy.has("start"),form.append(title),form.append(composerBox(draft,{label:t({id:"PN38hZ"}),placeholder:t({id:"NjUiZ4"}),submit:t({id:"n5vqdp"}),busy:"start",requires:"start",focusKey:"new-body",onSubmit:()=>void start(),onCancel:()=>host.toList()})),host.mode()==="moderated"&&s.reader)form.append(el("p","muted",t({id:"RqsQKK"})));return[back(),form]}function editable(post){return!!post.mine&&!s.thread?.discussion.locked&&Date.now()-Date.parse(post.created_at)<editWindow}function postTools(post,top){let thread=s.thread;if(!thread)return null;let discussion=thread.discussion,opening=!post,id=post?.id??discussion.opening_post_id,mine=opening?!!discussion.mine:!!post.mine,deleted=opening?!!discussion.deleted:post.deleted,tools=el("div","tools");if(deleted)return null;if(!opening&&top&&!discussion.locked&&s.writer&&post.state==="published")tools.append(host.button("plain",t({id:"ImOQa9"}),`reply-to-${post.id}`,()=>{inline=inline?.target===top.id?inline:{target:top.id,composer:new Composer(3)},inline.composer.area.oninput=()=>syncSend(),s.focus=`inline-${top.id}`,host.render()}));if(!opening&&discussion.mine&&!post.parent_post_id&&post.state==="published"&&!discussion.locked){let accepted=discussion.answer_post_id===post.id,button=host.button("plain",accepted?t({id:"4-S4QM"}):t({id:"jhu92n"}),`accept-${post.id}`,()=>void accept(accepted?null:post),accepted?"":checkCircle);button.style.display="inline-flex",button.style.gap="4px",button.style.alignItems="center",button.disabled=s.busy.has(`accept-${post.id}`)||s.busy.has("accept-clear"),tools.append(button)}if(mine&&editable(opening?discussion:post))tools.append(host.button("plain",t({id:"ePK91l"}),`edit-${id}`,()=>{let composer=new Composer(opening?6:4);composer.area.value=opening?discussion.body:post.body,composer.area.oninput=()=>syncSend();let heading=el("input");heading.className="field-title",heading.maxLength=200,heading.dir="auto",heading.value=discussion.title,heading.oninput=()=>syncSend(),edit={post,composer,title:heading},s.focus=opening?"edit-title":`edit-body-${id}`,host.render()}));if(mine)if(s.confirm===id){let yes=host.button("plain danger",t({id:"cnGeoo"}),`delete-yes-${id}`,()=>void remove(id,opening));yes.disabled=s.busy.has(`delete-${id}`),tools.append(el("span","muted",opening?t({id:"rAl91-"}):t({id:"Klsidc"})),yes,host.button("plain",t({id:"PZ_kxo"}),`delete-no-${id}`,()=>{s.confirm="",s.focus=`delete-${id}`,host.render()}))}else tools.append(host.button("plain",t({id:"cnGeoo"}),`delete-${id}`,()=>{s.confirm=id,s.focus=`delete-no-${id}`,host.render()}));return tools.childElementCount?tools:null}function voteButton(target,opening){let button=host.button("vote",String(target.votes),`vote-${target.id}`,()=>void vote(target,opening),host.icons.up);return button.setAttribute("aria-pressed",String(!!target.voted)),button.setAttribute("aria-label",target.voted?t({id:"OVijcR",values:{0:target.votes}}):t({id:"dNOvhg",values:{0:target.votes}})),button.disabled=!!target.mine||!!s.thread?.discussion.locked||s.busy.has(`vote-${target.id}`),button}function postCard(post,top,children=[]){let accepted=s.thread.discussion.answer_post_id===post.id,card=el("article",`post${accepted?" accepted":""}${post.state==="pending"?" pending":""}`);card.dataset.key=`post-${post.id}`,card.tabIndex=-1,card.setAttribute("aria-label",host.authorName(post.author));let side=el("div","side");if(!post.deleted)side.append(voteButton(post,!1));if(!top||top.id===post.id)card.append(side);let body=el("div","post-body");if(accepted){let label=el("div","answer-label");label.innerHTML=checkCircle,label.append(t({id:"y-KXxN"})),body.append(label)}if(body.append(postHead(post.author,post.created_at,post.edited_at,post.state,post.deleted)),edit?.post?.id===post.id)body.append(editForm());else if(post.deleted)body.append(el("p","deleted",t({id:"HkXOWm"})));else body.append(md(post.body_html));let tools=postTools(post,top);if(tools)body.append(tools);if(children.length||inline?.target===post.id){let nested=el("div","children");for(let child of children)nested.append(postCard(child,post));if(inline?.target===post.id){let current=inline;nested.append(composerBox(current.composer,{label:t({id:"F_vGso"}),placeholder:t({id:"2Hlmdt"}),submit:t({id:"ImOQa9"}),busy:`reply-${post.id}`,requires:"inline",focusKey:`inline-${post.id}`,onSubmit:()=>void send(current.composer,post.id),onCancel:()=>{inline=null,s.focus=`reply-to-${post.id}`,host.render()}}))}body.append(nested)}return card.append(body),card}function postHead(author,created,edited,state,deleted){let head=el("div","post-head");if(!deleted){if(head.append(host.avatar(author,!0),el("span","name",host.authorName(author))),author.kind==="member"&&!author.deleted)head.append(host.badge("team"))}if(head.append(host.time(created)),edited&&!deleted)head.append(el("span","muted",t({id:"k4b5_X"})));if(state==="pending")head.append(host.badge("pending"));return head}function editForm(){let current=edit,form=el("div","form");if(!current.post)current.title.setAttribute("aria-label",t({id:"MHrjPM"})),current.title.dataset.key="edit-title",form.append(current.title);let id=current.post?.id??s.thread.discussion.opening_post_id;return form.append(composerBox(current.composer,{label:t({id:"qzVesX"}),placeholder:"",submit:t({id:"tfDRzk"}),busy:`edit-${id}`,requires:"edit",focusKey:`edit-body-${id}`,onSubmit:()=>void saveEdit(),onCancel:()=>{edit=null,s.focus=`edit-${id}`,host.render()}})),form}function threadView(){let nodes=[back()],thread=s.thread;if(!thread||s.threadState==="missing"){let box=el("div","empty");return box.append(el("p","",s.threadState==="loading"?t({id:"Pwqkdw"}):t({id:"VGqKyv"}))),nodes.push(box),nodes}let discussion=thread.discussion,view=el("div","thread"),head=el("div","thread-head");if(edit&&!edit.post)head.append(postHead(discussion.author,discussion.created_at,discussion.edited_at,discussion.state,!1)),head.append(editForm()),view.append(head);else{let heading=el("h3","",discussion.title);heading.dir="auto",heading.tabIndex=-1,heading.dataset.key="thread-title",head.append(heading);let meta=el("div","meta");if(discussion.answer_post_id)meta.append(host.badge("answered"));if(discussion.state==="pending")meta.append(host.badge("pending"));if(discussion.locked)meta.append(host.badge("locked"));if(meta.childElementCount)head.append(meta);view.append(head);let opening=el("article",`post${discussion.state==="pending"?" pending":""}`),side=el("div","side");if(!discussion.deleted)side.append(voteButton({id:discussion.opening_post_id,votes:discussion.votes,voted:discussion.voted,mine:discussion.mine},!0));let body=el("div","post-body");body.append(postHead(discussion.author,discussion.created_at,discussion.edited_at,discussion.state,!!discussion.deleted)),body.append(discussion.deleted?el("p","deleted",t({id:"8wRl7c"})):md(discussion.body_html));let tools=postTools(null,null);if(tools)body.append(tools);opening.append(side,body),view.append(opening)}let actions=el("div","bar"),followButton=host.button("ghost",discussion.following?t({id:"y6sq5j"}):t({id:"MKEPCY"}),"follow",()=>void follow(),bell);followButton.setAttribute("aria-pressed",String(!!discussion.following)),followButton.title=t({id:"Kl3TuI"}),followButton.disabled=s.busy.has("follow");let count=el("span","muted",t({id:"Hw3P48",values:{0:discussion.reply_count}}));if(actions.append(count,followButton),view.append(actions),s.threadState==="loading"&&!thread.posts.length&&discussion.reply_count>0){let skeleton=el("div","skeleton");skeleton.setAttribute("aria-busy","true"),skeleton.setAttribute("aria-label",t({id:"Pwqkdw"})),view.append(skeleton)}let tops=thread.posts.filter((p)=>!p.parent_post_id),replies=el("div","thread");for(let top of tops)replies.append(postCard(top,top,thread.posts.filter((p)=>p.parent_post_id===top.id)));if(tops.length)view.append(replies);if(s.notice)view.append(host.noticeBox(s.notice));if(discussion.locked)view.append(host.noticeBox(t({id:"JfAIiv"}),host.icons.lock));else if(!s.writer)view.append(signInBox(t({id:"PL0621"})));else view.append(composerBox(reply,{label:t({id:"F_vGso"}),placeholder:t({id:"2Hlmdt"}),submit:t({id:"ImOQa9"}),busy:"reply",requires:"reply",focusKey:"reply",onSubmit:()=>void send(reply)}));return nodes.push(view),nodes}return{threadView,newView,syncSend,close(){inline=null,edit=null},reset(){inline=null,edit=null,reply.clear()}}}export{createThread,styles};
|