Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ import { EpButton, EpTheme, themes } from '@samtv12345/etherpad-webcomponents';
| `<ep-toast-container>` / `<ep-toast-item>` | `EpToastContainer` / `EpToastItem` | `position`, `type`, `message`, `duration` | — |
| `<ep-toolbar-select>` | `EpToolbarSelect` | `options[]`, `value`, `icon-class`, `label`, `placeholder` | `ep-toolbar-select:change` |
| `<ep-user-badge>` | `EpUserBadge` | `name`, `color`, `size`, `online` | — |
| `<ep-avatar>` | `EpAvatar` | `name`, `color`, `src`, `size`, `status` (`online`/`idle`/`offline`) | — |
| `<ep-toolbar>` / `<ep-toolbar-button>` / `<ep-toolbar-separator>` | `EpToolbar` / `EpToolbarButton` / `EpToolbarSeparator` | toolbar: `label`, `breakpoint`, `more-label`, slot `end`; button: `key`, `label`, `toggle`, `pressed`, `active`, `expanded`, `badge`, `priority="low"` | `ep-toolbar-action` |
| `<ep-user-list>` | `EpUserList` | `.users` (`{ id, name, color, self, status }`), `heading`, `selectable`, `readonly` | `ep-user-rename`, `ep-user-color-request`, `ep-user-select` |
| `<ep-chat-panel>` | `EpChatPanel` | `.messages` or slotted `<ep-chat-message slot="messages">`, `show-close`, `show-sticky`, `sticky`, `has-more`, `loading`, `readonly`, `floating` | `ep-chat-send`, `ep-chat-close`, `ep-chat-sticky`, `ep-chat-load-more` |
| `<ep-popup>` | `EpPopup` | `open`, `heading`, `anchor`, `align`, `persistent`, slot `footer`; `show()`/`hide()`/`toggle()` | `ep-popup-open`, `ep-popup-close` |
| `<ep-settings-section>` / `<ep-settings-row>` | `EpSettingsSection` / `EpSettingsRow` | section: `heading`, `description`; row: `label`, `description`, `stacked`, `divided`, `disabled` | — |
| `<ep-segmented>` | `EpSegmented` | `.options` (`{ value, label, icon?, disabled? }`), `value`, `label` | `ep-change` |
| `<ep-tabs>` / `<ep-tab>` | `EpTabs` / `EpTab` | `value`, `variant` (`underline`/`pills`); tab: `value`, `label`, `disabled` | `ep-tab-change` |
| `<ep-theme>` | `EpTheme` | `name` (incl. `auto`), `light`, `dark`, `.tokens` — applies a token set to its subtree | `ep-theme-change` |
| `<ep-editor>` | `EpEditor` | `content`, `readonly`, `wrap`, `author-id` | `ready`, `content-changed`, `selection-changed` |
Expand Down Expand Up @@ -107,6 +114,10 @@ defineTheme('acme-dark', { '--primary-color': '#a78bfa' }, 'colibris-dark');

`@samtv12345/etherpad-webcomponents/themes.js` contains only these functions and the token sets, without any custom element.

### Pad building blocks

The pad, timeslider and sheet pages are put together from `ep-toolbar`, `ep-popup` + `ep-settings-*`, `ep-user-list` and `ep-chat-panel`; the story **Pad/Layout** shows them together. All of them only emit events – the app decides what a toolbar action, a sent chat message or a rename does. Every visible text is an attribute, so pages can pass in their translations. Toolbar colours can be set separately via `--toolbar-bg-color`, `--toolbar-text-color`, `--toolbar-border-color`, `--toolbar-hover-color`, `--toolbar-active-color` and `--toolbar-active-text-color`.

### The editor (`<ep-editor>`)

`<ep-editor>` embeds Etherpad's Ace editor engine (under `src/editor/`: `Changeset`, `AttributePool`, `changesettracker`, content collector, op assemblers, etc.) as a self-contained element. It supports bold/italic/underline/strikethrough, ordered & unordered lists, indentation, undo/redo, and changeset-based collaboration.
Expand Down
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
"./EpSelect.js": "./dist/EpSelect.js",
"./EpUserBadge.js": "./dist/EpUserBadge.js",
"./EpTabs.js": "./dist/EpTabs.js",
"./EpAvatar.js": "./dist/EpAvatar.js",
"./EpToolbar.js": "./dist/EpToolbar.js",
"./EpUserList.js": "./dist/EpUserList.js",
"./EpChatPanel.js": "./dist/EpChatPanel.js",
"./EpSettings.js": "./dist/EpSettings.js",
"./EpPopup.js": "./dist/EpPopup.js",
"./EpSegmented.js": "./dist/EpSegmented.js",
"./EpTheme.js": "./dist/EpTheme.js",
"./themes.js": "./dist/themes.js",
"./EpEditor.js": "./dist/EpEditor.js",
Expand Down
94 changes: 94 additions & 0 deletions src/EpAvatar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { LitElement, html, css, nothing } from 'lit';
import { customElement, property, state } from 'lit/decorators.js';
import { styleMap } from 'lit/directives/style-map.js';
import { initialsOf, readableTextOn, safeColor } from './internal/color.js';

/**
* Round user avatar: a picture if `src` is set and loads, otherwise the
* initials on the author colour (with readable text colour).
*/
@customElement('ep-avatar')
export class EpAvatar extends LitElement {
static styles = css`
:host {
--ep-avatar-size: 28px;
display: inline-block;
position: relative;
width: var(--ep-avatar-size);
height: var(--ep-avatar-size);
flex-shrink: 0;
font-family: var(--main-font-family, Quicksand, Cantarell, "Open Sans", "Helvetica Neue", sans-serif);
}
:host([size="small"]) { --ep-avatar-size: 20px; }
:host([size="large"]) { --ep-avatar-size: 40px; }

.circle {
width: 100%;
height: 100%;
border-radius: 50%;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
font-weight: 700;
font-size: calc(var(--ep-avatar-size) * 0.4);
line-height: 1;
user-select: none;
box-sizing: border-box;
}
img { width: 100%; height: 100%; object-fit: cover; display: block; }

.status {
position: absolute;
right: -1px;
bottom: -1px;
width: calc(var(--ep-avatar-size) * 0.3);
height: calc(var(--ep-avatar-size) * 0.3);
min-width: 7px;
min-height: 7px;
border-radius: 50%;
border: 2px solid var(--bg-color, #ffffff);
box-sizing: content-box;
}
.status.online { background: var(--success-color, var(--primary-color, #64d29b)); }
.status.idle { background: var(--warning-color, #d4a72c); }
.status.offline { background: var(--middle-color, #d2d2d2); }
`;

@property() name = '';
/** Background colour (author colour). */
@property() color = '';
/** Optional picture URL. */
@property() src = '';
@property({ reflect: true }) size: 'small' | 'medium' | 'large' = 'medium';
/** Small status dot: `online`, `idle`, `offline` or empty for none. */
@property({ reflect: true }) status: '' | 'online' | 'idle' | 'offline' = '';

@state() private _imgFailed = false;

updated(changed: Map<string, unknown>) {
if (changed.has('src')) this._imgFailed = false;
}

render() {
const color = safeColor(this.color);
const bg = color || 'var(--text-soft-color, #576273)';
const fg = color ? readableTextOn(color) : 'var(--bg-color, #ffffff)';
const showImg = this.src && !this._imgFailed;
return html`
<div class="circle" part="circle" role="img" aria-label=${this.name || nothing}
style=${styleMap({ background: bg, color: fg })}>
${showImg
? html`<img src=${this.src} alt="" @error=${() => { this._imgFailed = true; }} />`
: html`<span aria-hidden="true">${initialsOf(this.name)}</span>`}
</div>
${this.status ? html`<span class="status ${this.status}" part="status"></span>` : nothing}
`;
}
}

declare global {
interface HTMLElementTagNameMap {
'ep-avatar': EpAvatar;
}
}
4 changes: 3 additions & 1 deletion src/EpChatMessage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { LitElement, html, css } from 'lit';
import { customElement, property } from 'lit/decorators.js';
import { styleMap } from 'lit/directives/style-map.js';
import { safeColor } from './internal/color.js';

@customElement('ep-chat-message')
export class EpChatMessage extends LitElement {
Expand Down Expand Up @@ -47,7 +49,7 @@ export class EpChatMessage extends LitElement {

render() {
return html`
<b class="author" style="${this.authorColor ? `color: ${this.authorColor}` : ''}">${this.author}</b>${this.time ? html`<span class="time">${this.time}</span>` : html`<span class="time"></span>`}<span class="body"><slot></slot></span>
<b class="author" style=${styleMap({ color: safeColor(this.authorColor) })}>${this.author}</b>${this.time ? html`<span class="time">${this.time}</span>` : html`<span class="time"></span>`}<span class="body"><slot></slot></span>
`;
}
}
Expand Down
Loading
Loading