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
51 changes: 41 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ Because they are standard custom elements, the components work in any page or fr
## Install

```bash
pnpm add etherpad-webcomponents
# or: npm install etherpad-webcomponents
pnpm add @samtv12345/etherpad-webcomponents
# or: npm install @samtv12345/etherpad-webcomponents
```

## Usage
Expand All @@ -23,10 +23,10 @@ Import the whole library, or just the components you need (each is individually

```js
// everything
import 'etherpad-webcomponents';
import '@samtv12345/etherpad-webcomponents';

// or a single component
import 'etherpad-webcomponents/EpButton.js';
import '@samtv12345/etherpad-webcomponents/EpButton.js';
```

```html
Expand All @@ -42,7 +42,7 @@ import 'etherpad-webcomponents/EpButton.js';
The named exports (classes) are also available for programmatic use:

```js
import { EpButton, EpTheme, themes } from 'etherpad-webcomponents';
import { EpButton, EpTheme, themes } from '@samtv12345/etherpad-webcomponents';
```

---
Expand All @@ -64,18 +64,49 @@ import { EpButton, EpTheme, themes } from '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-theme>` | `EpTheme` | `name` — applies a token set to its subtree | — |
| `<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` |

### Theming

Components read CSS custom properties (`--text-color`, `--primary-color`, `--bg-soft-color`, …). Wrap a subtree in `<ep-theme name="…">` to apply a token set. Built-in themes: **`colibris`** (default, matches Etherpad's skin), **`colibris-dark`**, **`high-contrast`**, and **`warm`**. Register your own at runtime:
Components only read CSS custom properties, so every colour, radius and shadow can be changed without touching the components. Built-in themes: **`colibris`** (default, Etherpad's light-green skin), **`colibris-dark`**, **`high-contrast`** and **`warm`**.

| Token | Used for |
| --- | --- |
| `--bg-color`, `--bg-soft-color`, `--light-color`, `--super-light-color` | surfaces |
| `--text-color`, `--text-soft-color`, `--dark-color`, `--super-dark-color` | text, icons |
| `--middle-color` | borders |
| `--primary-color`, `--primary-text-color` | accent and text on the accent |
| `--danger-color`, `--success-color`, `--warning-color` | states |
| `--focus-color` | focus ring |
| `--radius`, `--radius-large`, `--shadow` | shape and elevation |
| `--main-font-family` | font |

A theme only needs to state what differs from its base:

```js
import { EpTheme } from 'etherpad-webcomponents';
EpTheme.registerTheme('brand', { '--primary-color': '#ff5722', /* …all ThemeTokens */ });
import { defineTheme } from '@samtv12345/etherpad-webcomponents';

defineTheme('acme', { '--primary-color': '#7c3aed' }); // based on colibris
defineTheme('acme-dark', { '--primary-color': '#a78bfa' }, 'colibris-dark');
```

```html
<!-- fixed theme -->
<ep-theme name="acme">…</ep-theme>

<!-- follow the operating system -->
<ep-theme name="auto" light="acme" dark="acme-dark">…</ep-theme>
```

`<ep-theme>` sets `data-scheme="light|dark"` on itself, fires `ep-theme-change` and updates live when a theme is redefined. Single tokens can be overridden per element with the `tokens` property. Without the element:

- `applyTheme(document.documentElement, 'acme')` sets the tokens on any element (and removes tokens of the previous call that the new set lacks),
- `themeToCss('acme', ':root')` returns the tokens as a CSS rule, e.g. for rendering them server-side.

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

### 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 All @@ -99,7 +130,7 @@ const pending = ed.prepareUserChangeset(); // { changeset, apool } to send to
The lower-level engine pieces are also exported for advanced use:

```js
import { AceEditor, AttributePool, makeChangesetTracker } from 'etherpad-webcomponents';
import { AceEditor, AttributePool, makeChangesetTracker } from '@samtv12345/etherpad-webcomponents';
```

---
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
"./EpToolbarSelect.js": "./dist/EpToolbarSelect.js",
"./EpSelect.js": "./dist/EpSelect.js",
"./EpUserBadge.js": "./dist/EpUserBadge.js",
"./EpTabs.js": "./dist/EpTabs.js",
"./EpTheme.js": "./dist/EpTheme.js",
"./themes.js": "./dist/themes.js",
"./EpEditor.js": "./dist/EpEditor.js",
"./editor/AceEditor.js": "./dist/editor/AceEditor.js",
"./editor/AttributePool.js": "./dist/editor/AttributePool.js",
Expand Down
8 changes: 4 additions & 4 deletions src/EpButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class EpButton extends LitElement {
button {
font-family: var(--ep-font);
padding: 5px 20px;
border-radius: 4px;
border-radius: var(--radius, 4px);
font-size: 14px;
font-weight: 700;
cursor: pointer;
Expand All @@ -34,7 +34,7 @@ export class EpButton extends LitElement {
}

button:focus-visible {
outline: 2px solid var(--dark-color, #576273);
outline: 2px solid var(--focus-color, var(--dark-color, #576273));
outline-offset: 2px;
}

Expand All @@ -59,7 +59,7 @@ export class EpButton extends LitElement {
background with bg-coloured (white) text. */
:host([variant="primary"]) button {
background: var(--primary-color, #64d29b);
color: var(--bg-color, #ffffff);
color: var(--primary-text-color, var(--bg-color, #ffffff));
border: none;
transition: filter 0.15s ease, opacity 0.15s ease;
}
Expand Down Expand Up @@ -90,7 +90,7 @@ export class EpButton extends LitElement {
color: var(--text-color, #485365);
border: none;
padding: 4px;
border-radius: 3px;
border-radius: calc(var(--radius, 4px) - 1px);
min-width: 28px;
min-height: 28px;
justify-content: center;
Expand Down
4 changes: 2 additions & 2 deletions src/EpCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export class EpCard extends LitElement {

.card {
background: var(--bg-color, white);
border-radius: 5px;
box-shadow: 0 0 0 1px rgba(99, 114, 130, 0.16), 0 8px 16px rgba(27, 39, 51, 0.08);
border-radius: var(--radius-large, 5px);
box-shadow: var(--shadow, 0 0 0 1px rgba(99, 114, 130, 0.16), 0 8px 16px rgba(27, 39, 51, 0.08));
overflow: hidden;
}

Expand Down
4 changes: 2 additions & 2 deletions src/EpCheckbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class EpCheckbox extends LitElement {
}

:host(:focus-within) .track {
outline: 2px solid var(--dark-color, #576273);
outline: 2px solid var(--focus-color, var(--dark-color, #576273));
outline-offset: 2px;
}

Expand All @@ -112,7 +112,7 @@ export class EpCheckbox extends LitElement {
<div class="track" @click="${this._toggle}">
<div class="thumb"></div>
</div>
<input type="checkbox"
<input type="checkbox" role="switch"
.checked="${this.checked}"
?disabled="${this.disabled}"
@change="${this._toggle}"
Expand Down
4 changes: 2 additions & 2 deletions src/EpColorPicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class EpColorPicker extends LitElement {
background: var(--bg-color, white);
border: 1px solid var(--middle-color, #d2d2d2);
border-radius: 5px;
box-shadow: 0 0 0 1px rgba(99, 114, 130, 0.16), 0 8px 16px rgba(27, 39, 51, 0.08);
box-shadow: var(--shadow, 0 0 0 1px rgba(99, 114, 130, 0.16), 0 8px 16px rgba(27, 39, 51, 0.08));
}

.swatch {
Expand All @@ -74,7 +74,7 @@ export class EpColorPicker extends LitElement {
.swatch:hover { transform: scale(1.1); }

.swatch:focus-visible {
outline: 2px solid var(--dark-color, #576273);
outline: 2px solid var(--focus-color, var(--dark-color, #576273));
outline-offset: 2px;
}

Expand Down
4 changes: 2 additions & 2 deletions src/EpDropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export class EpDropdown extends LitElement {
overflow-y: auto;
background: var(--bg-color, white);
border: 1px solid var(--middle-color, #d2d2d2);
border-radius: 5px;
box-shadow: 0 0 0 1px rgba(99, 114, 130, 0.16), 0 8px 16px rgba(27, 39, 51, 0.08);
border-radius: var(--radius-large, 5px);
box-shadow: var(--shadow, 0 0 0 1px rgba(99, 114, 130, 0.16), 0 8px 16px rgba(27, 39, 51, 0.08));
z-index: 9999;
padding: 4px 0;
opacity: 0;
Expand Down
2 changes: 1 addition & 1 deletion src/EpDropdownItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class EpDropdownItem extends LitElement {

.item:focus-visible {
background: var(--bg-soft-color, #f2f3f4);
outline: 2px solid var(--dark-color, #576273);
outline: 2px solid var(--focus-color, var(--dark-color, #576273));
outline-offset: -2px;
}

Expand Down
6 changes: 3 additions & 3 deletions src/EpInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class EpInput extends LitElement {
margin: 0;
padding: 8px 10px;
border: 1px solid var(--middle-color, #d2d2d2);
border-radius: 3px;
border-radius: calc(var(--radius, 4px) - 1px);
font-size: 14px;
background: var(--bg-soft-color, #f2f3f4);
color: var(--text-color, #485365);
Expand Down Expand Up @@ -65,13 +65,13 @@ export class EpInput extends LitElement {

:host([error]) input,
:host([error]) textarea {
border-color: #d1242f;
border-color: var(--danger-color, #d1242f);
}

.error-text {
font-family: var(--ep-font);
font-size: 12px;
color: #d1242f;
color: var(--danger-color, #d1242f);
margin-top: 4px;
}
`;
Expand Down
12 changes: 6 additions & 6 deletions src/EpModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export class EpModal extends LitElement {
.dialog {
position: relative; z-index: 1;
background: var(--bg-color, white);
border-radius: 5px;
box-shadow: 0 0 0 1px rgba(99, 114, 130, 0.16), 0 8px 16px rgba(27, 39, 51, 0.08);
border-radius: var(--radius-large, 5px);
box-shadow: var(--shadow, 0 0 0 1px rgba(99, 114, 130, 0.16), 0 8px 16px rgba(27, 39, 51, 0.08));
max-width: 480px; width: calc(100vw - 32px);
max-height: calc(100vh - 64px); overflow: auto;
animation: ep-modal-scale-in 0.2s ease; outline: none;
Expand All @@ -58,14 +58,14 @@ export class EpModal extends LitElement {
background: none; border: none; cursor: pointer; padding: 4px;
margin: -4px -4px 0 8px; color: var(--text-soft-color, #576273);
opacity: 0.5; transition: opacity 0.15s ease; font-size: 18px; line-height: 1;
display: flex; align-items: center; justify-content: center; border-radius: 4px;
display: flex; align-items: center; justify-content: center; border-radius: var(--radius, 4px);
}
.close-btn:hover, .close-btn:focus-visible { opacity: 1; }
.close-btn:focus-visible { outline: 2px solid var(--primary-color, #64d29b); outline-offset: 2px; }
.body { padding: 20px 25px; line-height: 1.6; }
.actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 0 25px 20px; }
.actions ::slotted(button), .actions button {
padding: 5px 20px; border-radius: 4px; font-size: 14px; font-weight: 700;
padding: 5px 20px; border-radius: var(--radius, 4px); font-size: 14px; font-weight: 700;
text-transform: uppercase; cursor: pointer;
transition: background 0.15s ease, border-color 0.15s ease;
font-family: inherit; line-height: 1.5;
Expand All @@ -76,7 +76,7 @@ export class EpModal extends LitElement {
.btn-confirm:hover { background: var(--dark-color, #576273); }
.prompt-input {
width: 100%; box-sizing: border-box; padding: 8px 10px;
border: 1px solid var(--middle-color, #d2d2d2); border-radius: 3px;
border: 1px solid var(--middle-color, #d2d2d2); border-radius: calc(var(--radius, 4px) - 1px);
font-size: 14px; font-family: inherit;
background: var(--bg-soft-color, #f2f3f4); color: var(--text-color, #485365);
margin-top: 12px; outline: none; transition: border-color 0.15s ease;
Expand Down Expand Up @@ -207,7 +207,7 @@ export class EpModal extends LitElement {
const input = document.createElement('input');
input.type = 'text';
input.placeholder = options.placeholder ?? '';
input.style.cssText = 'width:100%;box-sizing:border-box;padding:8px 10px;border:1px solid var(--middle-color,#d2d2d2);border-radius:3px;font-size:14px;margin-top:12px;outline:none;background:var(--bg-soft-color,#f2f3f4);color:var(--text-color,#485365);';
input.style.cssText = 'width:100%;box-sizing:border-box;padding:8px 10px;border:1px solid var(--middle-color,#d2d2d2);border-radius:calc(var(--radius, 4px) - 1px);font-size:14px;margin-top:12px;outline:none;background:var(--bg-soft-color,#f2f3f4);color:var(--text-color,#485365);';
container.append(msg, input);
modal.appendChild(container);
const actions = document.createElement('div');
Expand Down
12 changes: 6 additions & 6 deletions src/EpNotification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ export class EpNotification extends LitElement {
static styles = css`
:host {
--ep-font: var(--main-font-family, Quicksand, Cantarell, "Open Sans", "Helvetica Neue", sans-serif);
--ep-radius: 5px;
--ep-shadow: 0 0 0 1px rgba(99, 114, 130, 0.16), 0 8px 16px rgba(27, 39, 51, 0.08);
--ep-radius: var(--radius-large, 5px);
--ep-shadow: var(--shadow, 0 0 0 1px rgba(99, 114, 130, 0.16), 0 8px 16px rgba(27, 39, 51, 0.08));

display: block;
pointer-events: auto;
Expand Down Expand Up @@ -86,11 +86,11 @@ export class EpNotification extends LitElement {
}

:host([type="success"]) .notification {
border-left-color: var(--primary-color, #64d29b);
border-left-color: var(--success-color, var(--primary-color, #64d29b));
}

:host([type="error"]) .notification {
border-left-color: #d1242f;
border-left-color: var(--danger-color, #d1242f);
}

:host([type="info"]) .notification {
Expand All @@ -104,8 +104,8 @@ export class EpNotification extends LitElement {
margin-top: 1px;
}

:host([type="success"]) .icon { color: var(--primary-color, #64d29b); }
:host([type="error"]) .icon { color: #d1242f; }
:host([type="success"]) .icon { color: var(--success-color, var(--primary-color, #64d29b)); }
:host([type="error"]) .icon { color: var(--danger-color, #d1242f); }
:host([type="info"]) .icon { color: var(--dark-color, #576273); }

.body { flex: 1; min-width: 0; word-wrap: break-word; }
Expand Down
6 changes: 3 additions & 3 deletions src/EpSelect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class EpSelect extends LitElement {
height: 28px;
line-height: 28px;
padding: 0 25px 0 10px;
border-radius: 3px;
border-radius: calc(var(--radius, 4px) - 1px);
border: 1px solid var(--bg-soft-color, #f2f3f4);
background-color: var(--bg-soft-color, #f2f3f4);
color: var(--text-color, #485365);
Expand Down Expand Up @@ -81,8 +81,8 @@ export class EpSelect extends LitElement {
min-width: 100%;
box-sizing: border-box;
background-color: var(--bg-soft-color, #f2f3f4);
border-radius: 3px;
box-shadow: 0 0 0 1px rgba(68, 68, 68, 0.11), 0 8px 16px rgba(27, 39, 51, 0.12);
border-radius: calc(var(--radius, 4px) - 1px);
box-shadow: var(--shadow, 0 0 0 1px rgba(68, 68, 68, 0.11), 0 8px 16px rgba(27, 39, 51, 0.12));
opacity: 0;
pointer-events: none;
max-height: 0;
Expand Down
Loading
Loading