g-comments 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/README.md +40 -5
- package/dist/{chunk-X6RAR374.cjs → chunk-IBNNENCZ.cjs} +14 -2
- package/dist/chunk-IBNNENCZ.cjs.map +1 -0
- package/dist/{chunk-6E3M3PQN.js → chunk-WACVXJHD.js} +14 -2
- package/dist/chunk-WACVXJHD.js.map +1 -0
- package/dist/element.d.ts +58 -5
- package/dist/element.js +22 -18
- package/dist/element.js.map +1 -1
- package/dist/index.cjs +16 -16
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/{messages-BlBkT6Kr.d.cts → messages-C9bMljl3.d.cts} +51 -1
- package/dist/{messages-BlBkT6Kr.d.ts → messages-C9bMljl3.d.ts} +51 -1
- package/dist/react.cjs +232 -35
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +20 -5
- package/dist/react.d.ts +20 -5
- package/dist/react.js +202 -6
- package/dist/react.js.map +1 -1
- package/package.json +9 -9
- package/dist/chunk-6E3M3PQN.js.map +0 -1
- package/dist/chunk-X6RAR374.cjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,23 @@ All notable changes to `g-comments` are listed here. The format follows
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.2.0] - 2026-10-20
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- `theme="forum"` (provider, `<Comments>`, `<discourse-comments>`): applies the
|
|
14
|
+
forum's own palettes, fonts and "Embedded CSS" to the widget, from the
|
|
15
|
+
plugin's `GET /comments/theme`. Forum colours are exposed as
|
|
16
|
+
`--gc-forum-<name>`; tokens you set still win.
|
|
17
|
+
- `client.theme()` and `useForumTheme()` return the same data for sites that
|
|
18
|
+
style their own UI after the forum.
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
|
|
22
|
+
- The custom elements attach their default styles as `<style>` elements
|
|
23
|
+
instead of constructed stylesheets, so a stylesheet added to the shadow root
|
|
24
|
+
later (such as the forum's) wins ties.
|
|
25
|
+
|
|
9
26
|
## [0.1.0] - Unreleased
|
|
10
27
|
|
|
11
28
|
First release, against the `discourse-comments` forum plugin.
|
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@ import "g-comments/styles.css";
|
|
|
28
28
|
// Once, near the root of the app.
|
|
29
29
|
<DiscourseComments
|
|
30
30
|
forum="https://forum.example.com"
|
|
31
|
-
theme="auto" // "light" | "dark" | "auto" (prefers-color-scheme) | "inherit"
|
|
31
|
+
theme="auto" // "light" | "dark" | "auto" (prefers-color-scheme) | "inherit" | "forum"
|
|
32
32
|
locale="en" // "pt-BR" is bundled too; `messages` overrides single strings
|
|
33
33
|
appearance={{ variables: { accent: "var(--brand)", radius: "0" } }}
|
|
34
34
|
onEvent={(event) => analytics.track(event.type, event)}
|
|
@@ -166,7 +166,40 @@ colour scheme.
|
|
|
166
166
|
`theme` sets `data-gc-theme` on the root: `light`, `dark`, or `auto`, which
|
|
167
167
|
switches with `prefers-color-scheme`. `inherit` sets nothing and derives the
|
|
168
168
|
neutral colours from the page's text colour, for sites that theme the widget
|
|
169
|
-
themselves.
|
|
169
|
+
themselves. `forum` applies the forum's own look (below). The layout works
|
|
170
|
+
down to 320px wide.
|
|
171
|
+
|
|
172
|
+
### Use the forum's look
|
|
173
|
+
|
|
174
|
+
```tsx
|
|
175
|
+
<DiscourseComments forum="https://forum.example.com" theme="forum">
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
`theme="forum"` loads the forum's theme once per forum (`GET /comments/theme`)
|
|
179
|
+
and installs it where the widget lives: the page's `<head>`, or the custom
|
|
180
|
+
element's shadow root. Three things arrive:
|
|
181
|
+
|
|
182
|
+
- **Colours.** Every custom property the forum's colour definitions emit is
|
|
183
|
+
available on the widget root as `--gc-forum-<name>` (`--gc-forum-primary`,
|
|
184
|
+
`--gc-forum-tertiary`, `--gc-forum-primary-low`, …), and the widget tokens
|
|
185
|
+
default to them: `fg` ← `primary`, `fgMuted` ← `primary-medium`, `bg` ←
|
|
186
|
+
`secondary`, `bgSubtle` ← `primary-very-low`, `border` ← `primary-low`,
|
|
187
|
+
`accent` ← `tertiary`, `accentFg` ← `secondary`, `danger` ← `danger`. When
|
|
188
|
+
the theme has a dark palette it applies under `prefers-color-scheme: dark`.
|
|
189
|
+
- **Fonts.** `--gc-font` defaults to the forum's body font;
|
|
190
|
+
`--gc-forum-font-body`, `--gc-forum-font-heading` and
|
|
191
|
+
`--gc-forum-font-monospace` carry the stacks, and `@font-face` rules are
|
|
192
|
+
added to the page for fonts the forum serves.
|
|
193
|
+
- **Theme CSS.** The default theme's "Embedded CSS" (Admin → Customize →
|
|
194
|
+
Themes → Edit CSS/HTML → Embedded) is loaded as a stylesheet, so forum
|
|
195
|
+
admins can style the `gc-*` classes without touching the site.
|
|
196
|
+
|
|
197
|
+
Precedence: tokens you set (`appearance.variables`, or `--gc-*` on the root
|
|
198
|
+
or an ancestor) win over the forum's, which win over the defaults. The forum's
|
|
199
|
+
stylesheet is appended after the page's, so plain CSS rules tie-break in the
|
|
200
|
+
forum's favour; out-specify them (`.blog .gc-comment`) where the site must
|
|
201
|
+
win. `useForumTheme()` returns the same data for sites that style their own
|
|
202
|
+
UI after the forum.
|
|
170
203
|
|
|
171
204
|
## Custom elements (no framework)
|
|
172
205
|
|
|
@@ -193,7 +226,7 @@ Attributes mirror the React props, in kebab-case:
|
|
|
193
226
|
| `identifier`, `url`, `title` | same | thread identity; `url` and `title` default to the page |
|
|
194
227
|
| `sort` | `sort` | `best`, `hot`, `newest`, `oldest` |
|
|
195
228
|
| `sign-in` | `signIn` | `inline` (default), `on-submit`, `manual` |
|
|
196
|
-
| `theme` | `theme` | `auto` (default), `light`, `dark`, `inherit` |
|
|
229
|
+
| `theme` | `theme` | `auto` (default), `light`, `dark`, `inherit`, `forum` |
|
|
197
230
|
| `locale` | `locale` | `en`, `pt-BR` |
|
|
198
231
|
| `max-depth` | `maxDepth` | number, default 2 |
|
|
199
232
|
| `read-only`, `unstyled`, `debug` | same | boolean: present means true (`"false"` is false) |
|
|
@@ -245,8 +278,10 @@ discourse-comments::part(gc-comment--pinned) {
|
|
|
245
278
|
```
|
|
246
279
|
|
|
247
280
|
`unstyled` drops the default stylesheet's effect (the classes and parts stay),
|
|
248
|
-
|
|
249
|
-
|
|
281
|
+
`theme="inherit"` derives the neutral colours from the page's text colour, and
|
|
282
|
+
`theme="forum"` loads the forum's palettes, fonts and theme CSS into the shadow
|
|
283
|
+
root (see "Use the forum's look"). The count element has no styles of its own
|
|
284
|
+
and inherits the page's font.
|
|
250
285
|
|
|
251
286
|
`defineElements({ comments: "my-comments", count: "my-count" })` registers the
|
|
252
287
|
same elements under other names; names that are already defined are left
|
|
@@ -2660,6 +2660,7 @@ function createClientWithInternals(options, internals) {
|
|
|
2660
2660
|
const realtime = internals.realtime ?? new MessageBusPoller({ base: forum.base, fetch: http.fetch, log });
|
|
2661
2661
|
const batcher = new CountsBatcher(http);
|
|
2662
2662
|
let configGeneration = 0;
|
|
2663
|
+
let themePromise = null;
|
|
2663
2664
|
let degradedRecheck;
|
|
2664
2665
|
let degradedChecks = 0;
|
|
2665
2666
|
function config() {
|
|
@@ -2778,6 +2779,16 @@ function createClientWithInternals(options, internals) {
|
|
|
2778
2779
|
}
|
|
2779
2780
|
return http.request("POST", `${threadPath(threadId)}/attachments`, { form });
|
|
2780
2781
|
}
|
|
2782
|
+
function theme() {
|
|
2783
|
+
if (lifetime.signal.aborted) {
|
|
2784
|
+
return Promise.reject(disposedError());
|
|
2785
|
+
}
|
|
2786
|
+
themePromise ??= http.request("GET", "/theme").catch((error) => {
|
|
2787
|
+
themePromise = null;
|
|
2788
|
+
throw error;
|
|
2789
|
+
});
|
|
2790
|
+
return themePromise;
|
|
2791
|
+
}
|
|
2781
2792
|
const client = {
|
|
2782
2793
|
forum: forum.base,
|
|
2783
2794
|
forumOrigin: forum.origin,
|
|
@@ -2786,6 +2797,7 @@ function createClientWithInternals(options, internals) {
|
|
|
2786
2797
|
threads: { open },
|
|
2787
2798
|
attachments: { upload },
|
|
2788
2799
|
config,
|
|
2800
|
+
theme,
|
|
2789
2801
|
counts: (refs) => batcher.request(refs),
|
|
2790
2802
|
count: async (ref) => (await batcher.request([ref]))[encodeRef(ref)] ?? 0,
|
|
2791
2803
|
preview: async (body) => (await http.request("POST", "/preview", { json: { raw: body } })).html,
|
|
@@ -3073,5 +3085,5 @@ exports.memoryStorage = memoryStorage;
|
|
|
3073
3085
|
exports.normalizeForum = normalizeForum;
|
|
3074
3086
|
exports.ptBR = ptBR;
|
|
3075
3087
|
exports.resolveLocale = resolveLocale;
|
|
3076
|
-
//# sourceMappingURL=chunk-
|
|
3077
|
-
//# sourceMappingURL=chunk-
|
|
3088
|
+
//# sourceMappingURL=chunk-IBNNENCZ.cjs.map
|
|
3089
|
+
//# sourceMappingURL=chunk-IBNNENCZ.cjs.map
|