@wukazis/euphony 0.1.45
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/LICENSE +201 -0
- package/NOTICE +13 -0
- package/README.md +266 -0
- package/bin/euphony.js +4 -0
- package/dist/apple-touch-icon.png +0 -0
- package/dist/assets/harmony-render-5ErAOXX9.js +3285 -0
- package/dist/assets/local-data-worker-CHLGzNeW.js +2 -0
- package/dist/assets/main-CmldcHcT.js +4047 -0
- package/dist/examples/euphony-convo-100.jsonl +8 -0
- package/dist/examples/simple-harmony-convos.jsonl +8 -0
- package/dist/favicon-48x48.png +0 -0
- package/dist/favicon.ico +0 -0
- package/dist/favicon.svg +3 -0
- package/dist/global.css +38 -0
- package/dist/index.html +22 -0
- package/dist/web-app-manifest-192x192.png +0 -0
- package/dist/web-app-manifest-512x512.png +0 -0
- package/lib/chunks/conversation.js +612 -0
- package/lib/chunks/css/codex.js +1 -0
- package/lib/chunks/css/confirm-dialog.js +1 -0
- package/lib/chunks/css/conversation.js +1 -0
- package/lib/chunks/css/floating-toolbar.js +1 -0
- package/lib/chunks/css/input-dialog.js +1 -0
- package/lib/chunks/css/json-viewer.js +1 -0
- package/lib/chunks/css/menu.js +1 -0
- package/lib/chunks/css/message-code.js +1 -0
- package/lib/chunks/css/message-developer-content.js +1 -0
- package/lib/chunks/css/message-editor-popover.js +1 -0
- package/lib/chunks/css/message-hidden.js +1 -0
- package/lib/chunks/css/message-system-content.js +1 -0
- package/lib/chunks/css/message-text.js +1 -0
- package/lib/chunks/css/message-unsupported.js +1 -0
- package/lib/chunks/css/pagination.js +1 -0
- package/lib/chunks/css/preference-window.js +1 -0
- package/lib/chunks/css/search-window.js +1 -0
- package/lib/chunks/css/toast.js +1 -0
- package/lib/chunks/css/token-window.js +1 -0
- package/lib/chunks/css-inline.js +1 -0
- package/lib/chunks/dompurify.js +1 -0
- package/lib/chunks/harmony-types.js +1 -0
- package/lib/chunks/icon-cross.js +1 -0
- package/lib/chunks/icon-play.js +1 -0
- package/lib/chunks/marked.js +1 -0
- package/lib/chunks/prismjs.js +1 -0
- package/lib/chunks/shoelace.js +1131 -0
- package/lib/chunks/third-party.js +1 -0
- package/lib/chunks/utils.js +16 -0
- package/lib/components/app/app.d.ts +192 -0
- package/lib/components/app/local-data-worker.d.ts +35 -0
- package/lib/components/app/request-worker.d.ts +45 -0
- package/lib/components/app/url-manager.d.ts +25 -0
- package/lib/components/codex/codex.d.ts +50 -0
- package/lib/components/codex/codex.js +36 -0
- package/lib/components/confirm-dialog/confirm-dialog.d.ts +42 -0
- package/lib/components/confirm-dialog/confirm-dialog.js +41 -0
- package/lib/components/conversation/conversation.d.ts +259 -0
- package/lib/components/conversation/conversation.js +1 -0
- package/lib/components/floating-toolbar/floating-toolbar.d.ts +47 -0
- package/lib/components/floating-toolbar/floating-toolbar.js +32 -0
- package/lib/components/input-dialog/input-dialog.d.ts +43 -0
- package/lib/components/input-dialog/input-dialog.js +51 -0
- package/lib/components/json-viewer/json-viewer.d.ts +33 -0
- package/lib/components/json-viewer/json-viewer.js +8 -0
- package/lib/components/menu/menu.d.ts +38 -0
- package/lib/components/menu/menu.js +9 -0
- package/lib/components/message-code/message-code.d.ts +20 -0
- package/lib/components/message-code/message-code.js +10 -0
- package/lib/components/message-developer-content/message-developer-content.d.ts +45 -0
- package/lib/components/message-developer-content/message-developer-content.js +72 -0
- package/lib/components/message-editor-popover/message-editor-popover.d.ts +36 -0
- package/lib/components/message-editor-popover/message-editor-popover.js +85 -0
- package/lib/components/message-hidden/message-hidden.d.ts +38 -0
- package/lib/components/message-hidden/message-hidden.js +10 -0
- package/lib/components/message-system-content/message-system-content.d.ts +52 -0
- package/lib/components/message-system-content/message-system-content.js +74 -0
- package/lib/components/message-text/message-text.d.ts +36 -0
- package/lib/components/message-text/message-text.js +14 -0
- package/lib/components/message-unsupported/message-unsupported.d.ts +19 -0
- package/lib/components/message-unsupported/message-unsupported.js +26 -0
- package/lib/components/pagination/pagination.d.ts +29 -0
- package/lib/components/pagination/pagination.js +35 -0
- package/lib/components/preference-window/preference-window.d.ts +107 -0
- package/lib/components/preference-window/preference-window.js +319 -0
- package/lib/components/search-window/search-window.d.ts +44 -0
- package/lib/components/search-window/search-window.js +71 -0
- package/lib/components/toast/toast.d.ts +34 -0
- package/lib/components/toast/toast.js +77 -0
- package/lib/components/token-window/token-window.d.ts +96 -0
- package/lib/components/token-window/token-window.js +1 -0
- package/lib/config/config.d.ts +273 -0
- package/lib/euphony.d.ts +11 -0
- package/lib/euphony.js +1 -0
- package/lib/types/common-types.d.ts +176 -0
- package/lib/types/harmony-types.d.ts +72 -0
- package/lib/utils/api-manager.d.ts +42 -0
- package/lib/utils/codex-session.d.ts +7 -0
- package/lib/utils/dompurify-configs.d.ts +2 -0
- package/lib/utils/harmony-render.d.ts +4 -0
- package/lib/utils/marked-katex-extension.d.ts +22 -0
- package/lib/utils/patch-preview.d.ts +2 -0
- package/lib/utils/utils.d.ts +80 -0
- package/package.json +84 -0
- package/server-dist/node-main.js +1273 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import{v as e,i as t,n as s,r as i,a as o,b as n,x as l,w as a}from"../../chunks/third-party.js";import{p as r}from"../../chunks/prismjs.js";import{g as d}from"../../chunks/utils.js";import{g as c,a as p}from"../../chunks/harmony-types.js";import{p as h}from"../../chunks/css-inline.js";import{i as v}from"../../chunks/icon-play.js";import{c as m}from"../../chunks/css/message-developer-content.js";var g=Object.defineProperty,u=Object.getOwnPropertyDescriptor,b=(e,t,s,i)=>{for(var o,n=i>1?void 0:i?u(t,s):t,l=e.length-1;l>=0;l--)(o=e[l])&&(n=(i?o(t,s,n):o(n))||n);return i&&n&&g(t,s,n),n};let f=class extends o{constructor(){super(),this.message=null,this.shouldRenderMarkdown=!1,this.markdownAllowedTags=null,this.markdownAllowedAttributes=null,this.isEditable=!1,this.blockContents=[],this.getEditableTemplate=(e,t)=>n` <!-- Important to avoid new line and whitespace here -->
|
|
2
|
+
<!-- prettier-ignore -->
|
|
3
|
+
<div
|
|
4
|
+
class="message-text"
|
|
5
|
+
contenteditable="true"
|
|
6
|
+
.innerText=${e}
|
|
7
|
+
@input=${e=>{this.messageTextChanged(e,t)}}
|
|
8
|
+
></div>`}firstUpdated(){}willUpdate(e){if(e.has("message")||e.has("isEditable")){if(this.message){const e=c(this.message.content);if("developer"!==e)throw new Error(`Invalid message type, expect developer, but got: ${e}`)}this.resetBlockContents()}}async initData(){}messageTextChanged(e,t){const s={...t,newContent:e.target.innerText},i=new CustomEvent("message-developer-content-changed",{detail:s,bubbles:!0,composed:!0});this.dispatchEvent(i)}resetBlockContents(){if(null===this.message)throw new Error("Message is null");this.blockContents=[];const e=p(this.message.content),t=!this.isEditable;let s=[];"string"==typeof e.instructions&&(s=[e.instructions]);for(const[e,i]of s.entries())this.blockContents.push({label:`Instruction #${e}`,content:i,isContentHTML:!1,isCollapsed:t,editInfo:{location:"instruction",index:e}});if(e.tools)for(const s of Object.keys(e.tools)){const i=e.tools[s];let o=this.renderNamespaceTable(s,i.name,i.description??"",!1);for(const[e,t]of i.tools.entries()){let s=n``;s=n`${s}
|
|
9
|
+
<div class="cell-left">Name</div>
|
|
10
|
+
<div class="cell-right">${t.name}</div>`,s=n`${s}
|
|
11
|
+
<div class="cell-left">Description</div>
|
|
12
|
+
<div class="cell-right">${t.description}</div>`,t.parameters&&(s=n`${s}
|
|
13
|
+
<div class="cell-left">Parameters</div>
|
|
14
|
+
<div class="cell-right">
|
|
15
|
+
${JSON.stringify(t.parameters,null,2)}
|
|
16
|
+
</div>`),o=n`${o}
|
|
17
|
+
<div class="cell-left">Tool ${e}</div>
|
|
18
|
+
<div class="cell-right">
|
|
19
|
+
<div class="content">
|
|
20
|
+
<div class="config-table">${s}</div>
|
|
21
|
+
</div>
|
|
22
|
+
</div> `}o=n`<div class="config-table">${o}</div>`,this.blockContents.push({label:`Tool Namespace: ${s}`,content:o,isContentHTML:!0,isCollapsed:t,editableHTML:n`<div class="config-table">
|
|
23
|
+
${this.renderNamespaceTable(s,i.name,i.description??"",!0)}
|
|
24
|
+
</div>`})}}getHighlightedCode(e,t){if(!(t in r.languages))return n`${e}`;const s=r.languages[t],i=r.highlight(e,s,t);return n`${l(i)}`}renderNamespaceTable(e,t,s,i){return n`
|
|
25
|
+
<div class="cell-left">Name</div>
|
|
26
|
+
<div class="cell-right">
|
|
27
|
+
${i?this.getEditableTemplate(t,{location:"tool_namespace_name",index:e}):t}
|
|
28
|
+
</div>
|
|
29
|
+
<div class="cell-left">Description</div>
|
|
30
|
+
<div class="cell-right">
|
|
31
|
+
${i?this.getEditableTemplate(s,{location:"tool_namespace_description",index:e}):s}
|
|
32
|
+
</div>
|
|
33
|
+
`}render(){if(!this.message)return n``;let e=n``;for(const t of this.blockContents){let s=n``;if(s=t.isContentHTML?this.isEditable&&void 0!==t.editableHTML?n`${t.editableHTML}`:n`${t.content}`:this.isEditable&&void 0!==t.editInfo?this.getEditableTemplate(t.content,{location:"instruction",index:t.editInfo.index}):d(t.content,this.shouldRenderMarkdown,this.markdownAllowedTags,this.markdownAllowedAttributes),t.subBlocks&&t.subBlocks.length>0){let e=n``;for(const s of t.subBlocks){let t=n``;t=s.isContentHTML?n`${s.content}`:d(s.content,this.shouldRenderMarkdown,this.markdownAllowedTags,this.markdownAllowedAttributes),e=n`${e}
|
|
34
|
+
<div class="content-block">
|
|
35
|
+
<div class="label">
|
|
36
|
+
<button
|
|
37
|
+
class="svg-icon collapse-icon"
|
|
38
|
+
?is-collapsed=${s.isCollapsed}
|
|
39
|
+
@click=${e=>{e.preventDefault(),e.stopPropagation(),s.isCollapsed=!s.isCollapsed,this.requestUpdate()}}
|
|
40
|
+
>
|
|
41
|
+
${l(v)}
|
|
42
|
+
</button>
|
|
43
|
+
<span>${s.label}</span>
|
|
44
|
+
</div>
|
|
45
|
+
|
|
46
|
+
<!-- Important to avoid new line and whitespace here -->
|
|
47
|
+
<!-- prettier-ignore -->
|
|
48
|
+
<div class="message-text-container"
|
|
49
|
+
?is-hidden=${s.isCollapsed}
|
|
50
|
+
>${t}</div>
|
|
51
|
+
</div> `}s=n`${s}${e}`}e=n`${e}
|
|
52
|
+
<div class="content-block">
|
|
53
|
+
<div class="label">
|
|
54
|
+
<button
|
|
55
|
+
class="svg-icon collapse-icon"
|
|
56
|
+
?is-collapsed=${t.isCollapsed}
|
|
57
|
+
@click=${e=>{e.preventDefault(),e.stopPropagation(),t.isCollapsed=!t.isCollapsed,this.requestUpdate()}}
|
|
58
|
+
>
|
|
59
|
+
${l(v)}
|
|
60
|
+
</button>
|
|
61
|
+
<span>${t.label}</span>
|
|
62
|
+
</div>
|
|
63
|
+
|
|
64
|
+
<!-- Important to avoid new line and whitespace here -->
|
|
65
|
+
<!-- prettier-ignore -->
|
|
66
|
+
<div class="message-text-container"
|
|
67
|
+
?is-hidden=${t.isCollapsed}
|
|
68
|
+
>${s}</div>
|
|
69
|
+
</div> `}return n` <div class="message-content">${e}</div> `}};f.styles=[t`
|
|
70
|
+
${e(m)}
|
|
71
|
+
${e(h)}
|
|
72
|
+
`],b([s({attribute:!1})],f.prototype,"message",2),b([s({type:Boolean})],f.prototype,"shouldRenderMarkdown",2),b([s({type:Array})],f.prototype,"markdownAllowedTags",2),b([s({type:Array})],f.prototype,"markdownAllowedAttributes",2),b([s({type:Boolean})],f.prototype,"isEditable",2),b([i()],f.prototype,"blockContents",2),f=b([a("euphony-message-developer-content")],f);export{f as EuphonyMessageDeveloperContent};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { LitElement, PropertyValues } from 'lit';
|
|
2
|
+
import { Role, Message } from '../../types/harmony-types';
|
|
3
|
+
export interface MessageEditorUserSetData {
|
|
4
|
+
role: Role;
|
|
5
|
+
name: string | null;
|
|
6
|
+
recipient: string | null;
|
|
7
|
+
channel: string | null;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Floating editor used in conversation editing mode for quick message metadata
|
|
11
|
+
* edits (author role/name, recipient, and channel).
|
|
12
|
+
*/
|
|
13
|
+
export declare class EuphonyMessageEditorPopover extends LitElement {
|
|
14
|
+
/**
|
|
15
|
+
* Message being edited. The component copies its current values into local
|
|
16
|
+
* editable state when this property changes so users can cancel safely.
|
|
17
|
+
*/
|
|
18
|
+
message: Message | null;
|
|
19
|
+
selectedRole: Role;
|
|
20
|
+
authorName: string;
|
|
21
|
+
recipient: string;
|
|
22
|
+
channel: string;
|
|
23
|
+
constructor();
|
|
24
|
+
firstUpdated(): void;
|
|
25
|
+
willUpdate(changedProperties: PropertyValues<this>): void;
|
|
26
|
+
initData(): Promise<void>;
|
|
27
|
+
private saveButtonClick;
|
|
28
|
+
private cancelButtonClick;
|
|
29
|
+
render(): import('lit').TemplateResult<1>;
|
|
30
|
+
static styles: import('lit').CSSResult[];
|
|
31
|
+
}
|
|
32
|
+
declare global {
|
|
33
|
+
interface HTMLElementTagNameMap {
|
|
34
|
+
'euphony-message-editor-popover': EuphonyMessageEditorPopover;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import{v as e,i as t,n as s,r as i,a as n,x as o,b as l,w as a}from"../../chunks/third-party.js";import{i as r}from"../../chunks/icon-cross.js";import{R as c}from"../../chunks/harmony-types.js";import{c as p}from"../../chunks/css/message-editor-popover.js";const d='<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n<svg width="100%" height="100%" viewBox="0 0 68 67" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">\n <g id="icon-check">\n <path d="M26.302,66.557C28.206,66.557 29.72,65.727 30.794,64.066L66.39,7.768C67.22,6.498 67.513,5.473 67.513,4.447C67.513,2.055 65.95,0.443 63.509,0.443C61.751,0.443 60.774,1.029 59.7,2.738L26.106,56.645L8.431,32.816C7.308,31.303 6.233,30.668 4.622,30.668C2.181,30.668 0.423,32.377 0.423,34.818C0.423,35.844 0.862,36.967 1.692,38.041L21.663,63.969C23.03,65.727 24.397,66.557 26.302,66.557Z" style="fill-rule:nonzero;"/>\n </g>\n</svg>\n',h='<svg\n width="24"\n height="24"\n viewBox="0 0 24 24"\n fill="none"\n xmlns="http://www.w3.org/2000/svg"\n>\n <path\n fill-rule="evenodd"\n clip-rule="evenodd"\n d="M11.2929 9.29289C11.6834 8.90237 12.3166 8.90237 12.7071 9.29289L16.7071 13.2929C17.0976 13.6834 17.0976 14.3166 16.7071 14.7071C16.3166 15.0976 15.6834 15.0976 15.2929 14.7071L12 11.4142L8.70711 14.7071C8.31658 15.0976 7.68342 15.0976 7.29289 14.7071C6.90237 14.3166 6.90237 13.6834 7.29289 13.2929L11.2929 9.29289Z"\n fill="currentColor"\n />\n</svg>\n';var v=Object.defineProperty,u=Object.getOwnPropertyDescriptor,m=(e,t,s,i)=>{for(var n,o=i>1?void 0:i?u(t,s):t,l=e.length-1;l>=0;l--)(n=e[l])&&(o=(i?n(t,s,o):n(o))||o);return i&&o&&v(t,s,o),o};const w=[c.User,c.Assistant,c.System,c.Developer,c.Tool];let g=class extends n{constructor(){super(),this.message=null,this.selectedRole=c.User,this.authorName="",this.recipient="",this.channel=""}firstUpdated(){}willUpdate(e){if(e.has("message")){const e=this.message;if(!e)return;this.selectedRole=e.role,this.authorName=e.name??"",this.recipient=e.recipient??"",this.channel=e.channel??""}}async initData(){}saveButtonClick(){const e={role:this.selectedRole,name:""===this.authorName.trim()?null:this.authorName,recipient:""===this.recipient.trim()?null:this.recipient,channel:""===this.channel.trim()?null:this.channel};this.dispatchEvent(new CustomEvent("save-button-clicked",{detail:e,bubbles:!0,composed:!0}))}cancelButtonClick(){this.dispatchEvent(new Event("cancel-button-clicked",{bubbles:!0,composed:!0}))}render(){return l`
|
|
2
|
+
<div
|
|
3
|
+
class="message-editor-popover"
|
|
4
|
+
tabindex="0"
|
|
5
|
+
@click=${e=>{e.stopPropagation()}}
|
|
6
|
+
>
|
|
7
|
+
<div class="row-group">
|
|
8
|
+
<div class="row-item">
|
|
9
|
+
<div class="label">Role</div>
|
|
10
|
+
<div class="editor-item">
|
|
11
|
+
<span class="select-visible">
|
|
12
|
+
${this.selectedRole}
|
|
13
|
+
<span class="svg-icon icon-chevron">
|
|
14
|
+
${o(h)}
|
|
15
|
+
</span>
|
|
16
|
+
</span>
|
|
17
|
+
<select
|
|
18
|
+
.value=${this.selectedRole}
|
|
19
|
+
@change=${e=>{this.selectedRole=e.target.value}}
|
|
20
|
+
>
|
|
21
|
+
${w.map(e=>l`<option
|
|
22
|
+
value=${e}
|
|
23
|
+
?selected=${e===this.selectedRole}
|
|
24
|
+
>
|
|
25
|
+
${e}
|
|
26
|
+
</option>`)}
|
|
27
|
+
</select>
|
|
28
|
+
</div>
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
<div class="row-item field-row compact-field-row">
|
|
32
|
+
<div class="label">Channel</div>
|
|
33
|
+
<input
|
|
34
|
+
type="text"
|
|
35
|
+
placeholder="optional"
|
|
36
|
+
.value=${this.channel}
|
|
37
|
+
@input=${e=>{this.channel=e.target.value}}
|
|
38
|
+
/>
|
|
39
|
+
</div>
|
|
40
|
+
</div>
|
|
41
|
+
|
|
42
|
+
<div class="row-group">
|
|
43
|
+
<div class="row-item field-row">
|
|
44
|
+
<div class="label">Author</div>
|
|
45
|
+
<input
|
|
46
|
+
type="text"
|
|
47
|
+
placeholder="optional"
|
|
48
|
+
.value=${this.authorName}
|
|
49
|
+
@input=${e=>{this.authorName=e.target.value}}
|
|
50
|
+
/>
|
|
51
|
+
</div>
|
|
52
|
+
</div>
|
|
53
|
+
|
|
54
|
+
<div class="row-group">
|
|
55
|
+
<div class="row-item field-row">
|
|
56
|
+
<div class="label">Recipient</div>
|
|
57
|
+
<input
|
|
58
|
+
type="text"
|
|
59
|
+
placeholder="optional"
|
|
60
|
+
.value=${this.recipient}
|
|
61
|
+
@input=${e=>{this.recipient=e.target.value}}
|
|
62
|
+
/>
|
|
63
|
+
</div>
|
|
64
|
+
</div>
|
|
65
|
+
|
|
66
|
+
<div class="row-group">
|
|
67
|
+
<div class="row-item">
|
|
68
|
+
<button
|
|
69
|
+
class="text-button"
|
|
70
|
+
@click=${()=>{this.saveButtonClick()}}
|
|
71
|
+
>
|
|
72
|
+
<span class="svg-icon">${o(d)}</span>Save
|
|
73
|
+
</button>
|
|
74
|
+
<button
|
|
75
|
+
class="text-button"
|
|
76
|
+
@click=${()=>{this.cancelButtonClick()}}
|
|
77
|
+
>
|
|
78
|
+
<span class="svg-icon">${o(r)}</span>Cancel
|
|
79
|
+
</button>
|
|
80
|
+
</div>
|
|
81
|
+
</div>
|
|
82
|
+
</div>
|
|
83
|
+
`}};g.styles=[t`
|
|
84
|
+
${e(p)}
|
|
85
|
+
`],m([s({attribute:!1})],g.prototype,"message",2),m([i()],g.prototype,"selectedRole",2),m([i()],g.prototype,"authorName",2),m([i()],g.prototype,"recipient",2),m([i()],g.prototype,"channel",2),g=m([a("euphony-message-editor-popover")],g);export{g as EuphonyMessageEditorPopover};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { LitElement, PropertyValues } from 'lit';
|
|
2
|
+
import { Message } from '../../types/harmony-types';
|
|
3
|
+
/**
|
|
4
|
+
* Compact placeholder shown when a message is hidden by focus mode filters.
|
|
5
|
+
* Clicking it emits an event that the parent conversation uses to unhide the
|
|
6
|
+
* specific message instance.
|
|
7
|
+
*/
|
|
8
|
+
export declare class EuphonyMessageHidden extends LitElement {
|
|
9
|
+
/**
|
|
10
|
+
* The original message object. We only use it to derive a human-readable
|
|
11
|
+
* content type label (e.g. "text", "developer") for the placeholder text.
|
|
12
|
+
*/
|
|
13
|
+
message: Message | null;
|
|
14
|
+
constructor();
|
|
15
|
+
/**
|
|
16
|
+
* This method is called when the DOM is added for the first time.
|
|
17
|
+
* Present for consistency with other message components.
|
|
18
|
+
*/
|
|
19
|
+
firstUpdated(): void;
|
|
20
|
+
/**
|
|
21
|
+
* This method is called before new DOM is updated and rendered.
|
|
22
|
+
* Present for consistency with other message components.
|
|
23
|
+
* @param changedProperties Property that has been changed
|
|
24
|
+
*/
|
|
25
|
+
willUpdate(changedProperties: PropertyValues<this>): void;
|
|
26
|
+
/**
|
|
27
|
+
* Placeholder to match the common component interface used across message
|
|
28
|
+
* components in this codebase.
|
|
29
|
+
*/
|
|
30
|
+
initData(): Promise<void>;
|
|
31
|
+
render(): import('lit').TemplateResult<1>;
|
|
32
|
+
static styles: import('lit').CSSResult[];
|
|
33
|
+
}
|
|
34
|
+
declare global {
|
|
35
|
+
interface HTMLElementTagNameMap {
|
|
36
|
+
'euphony-message-hidden': EuphonyMessageHidden;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import{v as e,i as s,n as t,a,b as r,w as n}from"../../chunks/third-party.js";import{t as i}from"../../chunks/harmony-types.js";import{c as o}from"../../chunks/css/message-hidden.js";var d=Object.defineProperty,c=Object.getOwnPropertyDescriptor,p=(e,s,t,a)=>{for(var r,n=a>1?void 0:a?c(s,t):s,i=e.length-1;i>=0;i--)(r=e[i])&&(n=(a?r(s,t,n):r(n))||n);return a&&n&&d(s,t,n),n};let m=class extends a{constructor(){super(),this.message=null}firstUpdated(){}willUpdate(e){}async initData(){}render(){let e="";return this.message&&(e=(i(this.message.content)??"unsupported").replaceAll("_"," ").toLowerCase()),r`
|
|
2
|
+
<div
|
|
3
|
+
class="message-content"
|
|
4
|
+
@click=${()=>{this.dispatchEvent(new Event("hidden-message-clicked",{bubbles:!0,composed:!0}))}}
|
|
5
|
+
>
|
|
6
|
+
<div class="message-text">Show ${e} message</div>
|
|
7
|
+
</div>
|
|
8
|
+
`}};m.styles=[s`
|
|
9
|
+
${e(o)}
|
|
10
|
+
`],p([t({attribute:!1})],m.prototype,"message",2),m=p([n("euphony-message-hidden")],m);export{m as EuphonyMessageHidden};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { LitElement, PropertyValues, TemplateResult } from 'lit';
|
|
2
|
+
import { BlockContent } from '../../types/common-types';
|
|
3
|
+
import { Message } from '../../types/harmony-types';
|
|
4
|
+
interface EditMetadata {
|
|
5
|
+
location: 'model_identity' | 'conversation_start_date' | 'knowledge_cutoff' | 'valid_channels' | 'channel_required';
|
|
6
|
+
index: number | string;
|
|
7
|
+
}
|
|
8
|
+
export interface SystemContentEditPayload extends EditMetadata {
|
|
9
|
+
newContent: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Message system content element.
|
|
13
|
+
*/
|
|
14
|
+
export declare class EuphonyMessageSystemContent extends LitElement {
|
|
15
|
+
message: Message | null;
|
|
16
|
+
shouldRenderMarkdown: boolean;
|
|
17
|
+
markdownAllowedTags: string[] | null;
|
|
18
|
+
markdownAllowedAttributes: string[] | null;
|
|
19
|
+
isTranslation: boolean;
|
|
20
|
+
isEditable: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Optional URL to the current json/jsonl file (if any). This is used to
|
|
23
|
+
* resolve some relative paths in the asset pointers in the conversation. For
|
|
24
|
+
* example, `aquifer://foo` will be resolved to `dataFileURL/../assets/foo`.
|
|
25
|
+
* We won't resolve relative paths if `dataFileURL` is not provided.
|
|
26
|
+
*/
|
|
27
|
+
dataFileURL: string | null;
|
|
28
|
+
blockContents: BlockContent[];
|
|
29
|
+
constructor();
|
|
30
|
+
/**
|
|
31
|
+
* This method is called when the DOM is added for the first time
|
|
32
|
+
*/
|
|
33
|
+
firstUpdated(): void;
|
|
34
|
+
/**
|
|
35
|
+
* This method is called before new DOM is updated and rendered
|
|
36
|
+
* @param changedProperties Property that has been changed
|
|
37
|
+
*/
|
|
38
|
+
willUpdate(changedProperties: PropertyValues<this>): void;
|
|
39
|
+
initData(): Promise<void>;
|
|
40
|
+
messageTextChanged(e: InputEvent, editMetadata: EditMetadata): void;
|
|
41
|
+
resetBlockContents(): void;
|
|
42
|
+
getHighlightedCode(code: string, language: string): TemplateResult<1>;
|
|
43
|
+
getEditableTemplate: (content: string, editMetadata: EditMetadata) => TemplateResult<1>;
|
|
44
|
+
render(): TemplateResult<1>;
|
|
45
|
+
static styles: import('lit').CSSResult[];
|
|
46
|
+
}
|
|
47
|
+
declare global {
|
|
48
|
+
interface HTMLElementTagNameMap {
|
|
49
|
+
'euphony-message-system-content': EuphonyMessageSystemContent;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import{v as e,i as t,n as s,r as i,a as n,b as l,x as o,w as a}from"../../chunks/third-party.js";import{p as d}from"../../chunks/prismjs.js";import{g as c,a as r}from"../../chunks/harmony-types.js";import{g as h}from"../../chunks/utils.js";import{p}from"../../chunks/css-inline.js";import{i as v}from"../../chunks/icon-play.js";import{c as g}from"../../chunks/css/message-system-content.js";var m=Object.defineProperty,u=Object.getOwnPropertyDescriptor,f=(e,t,s,i)=>{for(var n,l=i>1?void 0:i?u(t,s):t,o=e.length-1;o>=0;o--)(n=e[o])&&(l=(i?n(t,s,l):n(l))||l);return i&&l&&m(t,s,l),l};let b=class extends n{constructor(){super(),this.message=null,this.shouldRenderMarkdown=!1,this.markdownAllowedTags=null,this.markdownAllowedAttributes=null,this.isTranslation=!1,this.isEditable=!1,this.dataFileURL=null,this.blockContents=[],this.getEditableTemplate=(e,t)=>l` <!-- Important to avoid new line and whitespace here -->
|
|
2
|
+
<!-- prettier-ignore -->
|
|
3
|
+
<div
|
|
4
|
+
class="message-text"
|
|
5
|
+
contenteditable="true"
|
|
6
|
+
.innerText=${e}
|
|
7
|
+
@input=${e=>{this.messageTextChanged(e,t)}}
|
|
8
|
+
></div>`}firstUpdated(){}willUpdate(e){if(e.has("message")||e.has("isEditable")){if(this.message){const e=c(this.message.content);if("system"!==e)throw new Error(`Invalid message type, expect system, but got: ${e}`)}this.resetBlockContents()}}async initData(){}messageTextChanged(e,t){const s={...t,newContent:e.target.innerText},i=new CustomEvent("message-system-content-changed",{detail:s,bubbles:!0,composed:!0});this.dispatchEvent(i)}resetBlockContents(){if(null===this.message)throw new Error("Message is null");this.blockContents=[];const e=r(this.message.content);if(e.model_identity&&this.blockContents.push({label:"Model Identity",content:e.model_identity,isContentHTML:!1,isCollapsed:!1,editInfo:{location:"model_identity",index:0}}),e.conversation_start_date&&this.blockContents.push({label:"Conversation Start Date",content:e.conversation_start_date,isContentHTML:!1,isCollapsed:!1,editInfo:{location:"conversation_start_date",index:0}}),e.knowledge_cutoff&&this.blockContents.push({label:"Knowledge Cutoff",content:e.knowledge_cutoff,isContentHTML:!1,isCollapsed:!1,editInfo:{location:"knowledge_cutoff",index:0}}),e.tools)for(const t in e.tools){let s=l``;s=l`${s}
|
|
9
|
+
<div class="cell-left">Name</div>
|
|
10
|
+
<div class="cell-right">${e.tools[t].name}</div>`,e.tools[t].description&&(s=l`${s}
|
|
11
|
+
<div class="cell-left">Description</div>
|
|
12
|
+
<div class="cell-right">
|
|
13
|
+
${e.tools[t].description}
|
|
14
|
+
</div>`);for(const[i,n]of e.tools[t].tools.entries()){let e=l``;e=l`${e}
|
|
15
|
+
<div class="cell-left">Name</div>
|
|
16
|
+
<div class="cell-right">${n.name}</div>`,e=l`${e}
|
|
17
|
+
<div class="cell-left">Description</div>
|
|
18
|
+
<div class="cell-right">${n.description}</div>`,n.parameters&&(e=l`${e}
|
|
19
|
+
<div class="cell-left">Parameters</div>
|
|
20
|
+
<div class="cell-right">
|
|
21
|
+
${JSON.stringify(n.parameters,null,2)}
|
|
22
|
+
</div>`),s=l`${s}
|
|
23
|
+
<div class="cell-left">Tool ${i}</div>
|
|
24
|
+
<div class="cell-right">
|
|
25
|
+
<div class="content">
|
|
26
|
+
<div class="config-table">${e}</div>
|
|
27
|
+
</div>
|
|
28
|
+
</div> `}s=l`<div class="config-table">${s}</div>`,this.blockContents.push({label:`Tool Namespace: ${t}`,content:s,isContentHTML:!0,isCollapsed:!0})}if(e.channel_config){const t=l`
|
|
29
|
+
<div class="config-table">
|
|
30
|
+
<div class="cell-left">Valid Channels</div>
|
|
31
|
+
<div class="cell-right">
|
|
32
|
+
${e.channel_config.valid_channels.join(", ")}
|
|
33
|
+
</div>
|
|
34
|
+
|
|
35
|
+
<div class="cell-left">Channel Required</div>
|
|
36
|
+
<div class="cell-right">
|
|
37
|
+
${e.channel_config.channel_required?"True":"False"}
|
|
38
|
+
</div>
|
|
39
|
+
</div>
|
|
40
|
+
`,s=l`
|
|
41
|
+
<div class="config-table">
|
|
42
|
+
<div class="cell-left">Valid Channels</div>
|
|
43
|
+
<div class="cell-right">
|
|
44
|
+
${this.getEditableTemplate(e.channel_config.valid_channels.join(", "),{location:"valid_channels",index:"valid_channels"})}
|
|
45
|
+
</div>
|
|
46
|
+
|
|
47
|
+
<div class="cell-left">Channel Required</div>
|
|
48
|
+
<div class="cell-right">
|
|
49
|
+
${this.getEditableTemplate(e.channel_config.channel_required?"True":"False",{location:"channel_required",index:"channel_required"})}
|
|
50
|
+
</div>
|
|
51
|
+
</div>
|
|
52
|
+
`;this.blockContents.push({label:"Channel Config",content:t,isContentHTML:!0,isCollapsed:!1,editableHTML:s})}}getHighlightedCode(e,t){if(!(t in d.languages))return l`${e}`;const s=d.languages[t],i=d.highlight(e,s,t);return l`${o(i)}`}render(){if(null===this.message)return l``;let e=l``;for(const t of this.blockContents){let s=l``;s=t.isContentHTML?this.isEditable&&void 0!==t.editableHTML?l`${t.editableHTML}`:l`${t.content}`:this.isEditable&&void 0!==t.editInfo?this.getEditableTemplate(t.content,{location:t.editInfo.location,index:t.editInfo.index}):h(t.content,this.shouldRenderMarkdown,this.markdownAllowedTags,this.markdownAllowedAttributes),e=l`${e}
|
|
53
|
+
<div class="content-block">
|
|
54
|
+
<div class="label">
|
|
55
|
+
<button
|
|
56
|
+
class="svg-icon collapse-icon"
|
|
57
|
+
?is-collapsed=${t.isCollapsed}
|
|
58
|
+
@click=${e=>{e.preventDefault(),e.stopPropagation(),t.isCollapsed=!t.isCollapsed,this.requestUpdate()}}
|
|
59
|
+
>
|
|
60
|
+
${o(v)}
|
|
61
|
+
</button>
|
|
62
|
+
<span>${t.label}</span>
|
|
63
|
+
</div>
|
|
64
|
+
|
|
65
|
+
<!-- Important to avoid new line and whitespace here -->
|
|
66
|
+
<!-- prettier-ignore -->
|
|
67
|
+
<div class="message-text-container"
|
|
68
|
+
?is-hidden=${t.isCollapsed}
|
|
69
|
+
?is-translation=${this.isTranslation&&t.label.includes("Instruction")}
|
|
70
|
+
>${s}</div>
|
|
71
|
+
</div> `}return l` <div class="message-content">${e}</div> `}};b.styles=[t`
|
|
72
|
+
${e(g)}
|
|
73
|
+
${e(p)}
|
|
74
|
+
`],f([s({attribute:!1})],b.prototype,"message",2),f([s({type:Boolean})],b.prototype,"shouldRenderMarkdown",2),f([s({type:Array})],b.prototype,"markdownAllowedTags",2),f([s({type:Array})],b.prototype,"markdownAllowedAttributes",2),f([s({type:Boolean})],b.prototype,"isTranslation",2),f([s({type:Boolean})],b.prototype,"isEditable",2),f([s({type:String,attribute:"data-file-url"})],b.prototype,"dataFileURL",2),f([i()],b.prototype,"blockContents",2),b=f([a("euphony-message-system-content")],b);export{b as EuphonyMessageSystemContent};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { LitElement, PropertyValues } from 'lit';
|
|
2
|
+
import { Message } from '../../types/harmony-types';
|
|
3
|
+
/**
|
|
4
|
+
* Message text element.
|
|
5
|
+
*/
|
|
6
|
+
export declare class EuphonyMessageText extends LitElement {
|
|
7
|
+
message: Message | null;
|
|
8
|
+
shouldRenderMarkdown: boolean;
|
|
9
|
+
markdownAllowedTags: string[] | null;
|
|
10
|
+
markdownAllowedAttributes: string[] | null;
|
|
11
|
+
isTranslation: boolean;
|
|
12
|
+
isEditable: boolean;
|
|
13
|
+
constructor();
|
|
14
|
+
/**
|
|
15
|
+
* This method is called when the DOM is added for the first time
|
|
16
|
+
*/
|
|
17
|
+
firstUpdated(): void;
|
|
18
|
+
/**
|
|
19
|
+
* This method is called before new DOM is updated and rendered
|
|
20
|
+
* @param changedProperties Property that has been changed
|
|
21
|
+
*/
|
|
22
|
+
willUpdate(changedProperties: PropertyValues<this>): void;
|
|
23
|
+
initData(): Promise<void>;
|
|
24
|
+
messageTextChanged(e: InputEvent): void;
|
|
25
|
+
/**
|
|
26
|
+
* Generates an HTML template for an editable content.
|
|
27
|
+
*/
|
|
28
|
+
getEditableTemplate: (content: string) => import('lit').TemplateResult<1>;
|
|
29
|
+
render(): import('lit').TemplateResult<1>;
|
|
30
|
+
static styles: import('lit').CSSResult[];
|
|
31
|
+
}
|
|
32
|
+
declare global {
|
|
33
|
+
interface HTMLElementTagNameMap {
|
|
34
|
+
'euphony-message-text': EuphonyMessageText;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import{v as t,i as e,n as s,a,b as o,w as r}from"../../chunks/third-party.js";import{g as n,a as i}from"../../chunks/harmony-types.js";import{g as l}from"../../chunks/utils.js";import{c as d}from"../../chunks/css/message-text.js";var p=Object.defineProperty,h=Object.getOwnPropertyDescriptor,m=(t,e,s,a)=>{for(var o,r=a>1?void 0:a?h(e,s):e,n=t.length-1;n>=0;n--)(o=t[n])&&(r=(a?o(e,s,r):o(r))||r);return a&&r&&p(e,s,r),r};let g=class extends a{constructor(){super(),this.message=null,this.shouldRenderMarkdown=!1,this.markdownAllowedTags=null,this.markdownAllowedAttributes=null,this.isTranslation=!1,this.isEditable=!1,this.getEditableTemplate=t=>o` <!-- Important to avoid new line and whitespace here -->
|
|
2
|
+
<!-- prettier-ignore -->
|
|
3
|
+
<div
|
|
4
|
+
class="message-text"
|
|
5
|
+
contenteditable="true"
|
|
6
|
+
.innerText=${t}
|
|
7
|
+
@input=${t=>{this.messageTextChanged(t)}}
|
|
8
|
+
></div>`}firstUpdated(){}willUpdate(t){if(t.has("message")&&this.message){const t=n(this.message.content);if("text"!==t)throw new Error(`Invalid message type, expect text, but got: ${t}`)}}async initData(){}messageTextChanged(t){const e=t.target.innerText,s=new CustomEvent("message-text-changed",{detail:e,bubbles:!0,composed:!0});this.dispatchEvent(s)}render(){if(null===this.message)return o``;const t=i(this.message.content).text;let e=o``;return e=this.isEditable?this.getEditableTemplate(t):l(t,this.shouldRenderMarkdown,this.markdownAllowedTags,this.markdownAllowedAttributes),o`
|
|
9
|
+
<div class="message-content" ?is-translation=${this.isTranslation}>
|
|
10
|
+
${e}
|
|
11
|
+
</div>
|
|
12
|
+
`}};g.styles=[e`
|
|
13
|
+
${t(d)}
|
|
14
|
+
`],m([s({attribute:!1})],g.prototype,"message",2),m([s({type:Boolean})],g.prototype,"shouldRenderMarkdown",2),m([s({type:Array})],g.prototype,"markdownAllowedTags",2),m([s({type:Array})],g.prototype,"markdownAllowedAttributes",2),m([s({type:Boolean})],g.prototype,"isTranslation",2),m([s({type:Boolean})],g.prototype,"isEditable",2),g=m([r("euphony-message-text")],g);export{g as EuphonyMessageText};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { LitElement, PropertyValues } from 'lit';
|
|
2
|
+
import { Message } from '../../types/harmony-types';
|
|
3
|
+
export declare class EuphonyMessageUnsupported extends LitElement {
|
|
4
|
+
message: Message | null;
|
|
5
|
+
isCollapsed: boolean;
|
|
6
|
+
firstUpdated(): void;
|
|
7
|
+
willUpdate(changedProperties: PropertyValues<this>): void;
|
|
8
|
+
initData(): Promise<void>;
|
|
9
|
+
private getHighlightedCode;
|
|
10
|
+
private getRawContentJSON;
|
|
11
|
+
private getContentTypeLabel;
|
|
12
|
+
render(): import('lit').TemplateResult<1>;
|
|
13
|
+
static styles: import('lit').CSSResult[];
|
|
14
|
+
}
|
|
15
|
+
declare global {
|
|
16
|
+
interface HTMLElementTagNameMap {
|
|
17
|
+
'euphony-message-unsupported': EuphonyMessageUnsupported;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import{v as s,i as e,n as t,r as n,a,b as i,x as o,w as r}from"../../chunks/third-party.js";import{p}from"../../chunks/prismjs.js";import{p as l}from"../../chunks/css-inline.js";import{i as c}from"../../chunks/icon-play.js";import{c as d}from"../../chunks/css/message-unsupported.js";var g=Object.defineProperty,u=Object.getOwnPropertyDescriptor,h=(s,e,t,n)=>{for(var a,i=n>1?void 0:n?u(e,t):e,o=s.length-1;o>=0;o--)(a=s[o])&&(i=(n?a(e,t,i):a(i))||i);return n&&i&&g(e,t,i),i};let m=class extends a{constructor(){super(...arguments),this.message=null,this.isCollapsed=!0}firstUpdated(){}willUpdate(s){s.has("message")&&(this.isCollapsed=!0)}async initData(){}getHighlightedCode(s,e){if(!(e in p.languages))return i`${s}`;const t=p.languages[e],n=p.highlight(s,t,e);return i`${o(n)}`}getRawContentJSON(){if(!this.message)return"";try{return JSON.stringify(this.message.content,null,2)}catch{return String(this.message.content)}}getContentTypeLabel(){if(!this.message)return"unknown";const s=this.message.content;return"object"==typeof s&&null!==s&&"content_type"in s?s.content_type??"unknown":"unknown"}render(){if(!this.message)return i``;const s=this.getRawContentJSON();return i`
|
|
2
|
+
<div class="message-content">
|
|
3
|
+
<div class="error-label">
|
|
4
|
+
<span>Unsupported message content type: ${this.getContentTypeLabel()}</span>
|
|
5
|
+
</div>
|
|
6
|
+
<div class="content-block">
|
|
7
|
+
<div class="label">
|
|
8
|
+
<button
|
|
9
|
+
class="svg-icon collapse-icon"
|
|
10
|
+
?is-collapsed=${this.isCollapsed}
|
|
11
|
+
@click=${s=>{s.preventDefault(),s.stopPropagation(),this.isCollapsed=!this.isCollapsed}}
|
|
12
|
+
>
|
|
13
|
+
${o(c)}
|
|
14
|
+
</button>
|
|
15
|
+
<span>Raw Content</span>
|
|
16
|
+
</div>
|
|
17
|
+
|
|
18
|
+
<div class="message-text-container" ?is-hidden=${this.isCollapsed}>
|
|
19
|
+
<pre class="message-pre"><code>${this.getHighlightedCode(s,"json")}</code></pre>
|
|
20
|
+
</div>
|
|
21
|
+
</div>
|
|
22
|
+
</div>
|
|
23
|
+
`}};m.styles=[e`
|
|
24
|
+
${s(d)}
|
|
25
|
+
${s(l)}
|
|
26
|
+
`],h([t({attribute:!1})],m.prototype,"message",2),h([n()],m.prototype,"isCollapsed",2),m=h([r("euphony-message-unsupported")],m);export{m as EuphonyMessageUnsupported};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { LitElement, PropertyValues } from 'lit';
|
|
2
|
+
/**
|
|
3
|
+
* Pagination element.
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
export declare class NightjarPagination extends LitElement {
|
|
7
|
+
curPage: number;
|
|
8
|
+
totalPageNum: number;
|
|
9
|
+
pageWindowSize: number;
|
|
10
|
+
itemsPerPage: number;
|
|
11
|
+
itemsPerPageOptions: number[];
|
|
12
|
+
constructor();
|
|
13
|
+
/**
|
|
14
|
+
* This method is called before new DOM is updated and rendered
|
|
15
|
+
* @param changedProperties Property that has been changed
|
|
16
|
+
*/
|
|
17
|
+
willUpdate(changedProperties: PropertyValues<this>): void;
|
|
18
|
+
initData(): Promise<void>;
|
|
19
|
+
pageButtonClicked(name: string): void;
|
|
20
|
+
itemsPerPageChanged(e: InputEvent): void;
|
|
21
|
+
getPageButtonTemplate: (name: string) => import('lit').TemplateResult<1>;
|
|
22
|
+
render(): import('lit').TemplateResult<1>;
|
|
23
|
+
static styles: import('lit').CSSResult[];
|
|
24
|
+
}
|
|
25
|
+
declare global {
|
|
26
|
+
interface HTMLElementTagNameMap {
|
|
27
|
+
'nightjar-pagination': NightjarPagination;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import{v as t,i as e,n as s,a,b as i,w as o}from"../../chunks/third-party.js";import{c as r}from"../../chunks/css/pagination.js";var g=Object.defineProperty,n=Object.getOwnPropertyDescriptor,p=(t,e,s,a)=>{for(var i,o=a>1?void 0:a?n(e,s):e,r=t.length-1;r>=0;r--)(i=t[r])&&(o=(a?i(e,s,o):i(o))||o);return a&&o&&g(e,s,o),o};let P=class extends a{constructor(){super(),this.curPage=1,this.totalPageNum=10,this.pageWindowSize=5,this.itemsPerPage=10,this.itemsPerPageOptions=[10,25,50,100],this.getPageButtonTemplate=t=>i` <button
|
|
2
|
+
class="page-button"
|
|
3
|
+
?is-cur-page=${this.curPage===parseInt(t)}
|
|
4
|
+
@click=${()=>{this.pageButtonClicked(t)}}
|
|
5
|
+
>
|
|
6
|
+
${t}
|
|
7
|
+
</button>`}willUpdate(t){if(t.has("itemsPerPage")&&!this.itemsPerPageOptions.includes(this.itemsPerPage)){const t=[...this.itemsPerPageOptions];t.push(this.itemsPerPage),t.sort((t,e)=>t-e),this.itemsPerPageOptions=t}}async initData(){}pageButtonClicked(t){let e=this.curPage;if("Prev"===t)this.curPage>1&&(e-=1);else if("Next"===t)this.curPage<this.totalPageNum&&(e+=1);else{const s=parseInt(t);this.curPage!==s&&(e=s)}const s=new CustomEvent("page-clicked",{detail:e,bubbles:!0,composed:!0});this.dispatchEvent(s)}itemsPerPageChanged(t){const e=t.target,s=parseInt(e.value);if(s!==this.itemsPerPage){this.itemsPerPage=s;const t=new CustomEvent("items-per-page-changed",{detail:s,bubbles:!0,composed:!0});this.dispatchEvent(t)}}render(){let t=i``;if(this.totalPageNum<=this.pageWindowSize)for(let e=0;e<Math.max(this.totalPageNum,1);e++)t=i`${t}
|
|
8
|
+
${this.getPageButtonTemplate(`${e+1}`)}`;else{const e=Math.floor((this.pageWindowSize-1)/2);let s=this.curPage-e,a=this.curPage+e;s<1?(s=1,a=this.pageWindowSize):a>this.totalPageNum&&(s=this.totalPageNum-this.pageWindowSize+1,a=this.totalPageNum),this.curPage>1&&(t=i`${t} ${this.getPageButtonTemplate("Prev")} `),s>1&&(t=i`${t} ${this.getPageButtonTemplate("1")}`,s>2&&(t=i`${t} <span>...</span>`));for(let e=s;e<a+1;e++)t=i`${t}
|
|
9
|
+
${this.getPageButtonTemplate(e.toString())} `;a<this.totalPageNum&&(a<this.totalPageNum-1&&(t=i`${t}<span>...</span>`),t=i`${t}
|
|
10
|
+
${this.getPageButtonTemplate(this.totalPageNum.toString())}`),this.curPage<this.totalPageNum&&(t=i`${t} ${this.getPageButtonTemplate("Next")} `)}const e=i`
|
|
11
|
+
<div class="select-container">
|
|
12
|
+
<span>Items per page:</span>
|
|
13
|
+
<div class="item-select-wrapper">
|
|
14
|
+
<select
|
|
15
|
+
id="item-per-page-select"
|
|
16
|
+
value="${this.itemsPerPage}"
|
|
17
|
+
@change=${t=>{this.itemsPerPageChanged(t)}}
|
|
18
|
+
>
|
|
19
|
+
${this.itemsPerPageOptions.map(t=>i`<option
|
|
20
|
+
value="${t}"
|
|
21
|
+
?selected=${t==this.itemsPerPage}
|
|
22
|
+
>
|
|
23
|
+
${t}
|
|
24
|
+
</option>`)}
|
|
25
|
+
</select>
|
|
26
|
+
</div>
|
|
27
|
+
</div>
|
|
28
|
+
`;return i`
|
|
29
|
+
<div class="pagination">
|
|
30
|
+
<div class="page-buttons">${t}</div>
|
|
31
|
+
${e}
|
|
32
|
+
</div>
|
|
33
|
+
`}};P.styles=[e`
|
|
34
|
+
${t(r)}
|
|
35
|
+
`],p([s({type:Number})],P.prototype,"curPage",2),p([s({type:Number})],P.prototype,"totalPageNum",2),p([s({type:Number})],P.prototype,"pageWindowSize",2),p([s({type:Number})],P.prototype,"itemsPerPage",2),p([s({type:Array})],P.prototype,"itemsPerPageOptions",2),P=p([o("nightjar-pagination")],P);export{P as NightjarPagination};
|