@serene-pub/core-catalog 0.6.0-pr-1 → 0.6.0-pr-2
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/dist/components/authors-note.source.json +1 -1
- package/dist/components/lore-entries.source.json +1 -1
- package/dist/components/messages.source.json +1 -1
- package/dist/components/scene-portraits.source.json +1 -1
- package/dist/components/stats.source.json +1 -1
- package/dist/components/world-state.source.json +1 -1
- package/package.json +8 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"slug":"authors-note","framework":"svelte","entry":"sessions/authors-note/authors-note.ts","files":{"sessions/authors-note/AuthorsNote.svelte":"<script lang=\"ts\">\n\t/**\n\t * Core's Author's note widget as a remote component (2026-10-02, AN1):\n\t * the component context, as the native widget context, around\n\t * `AuthorsNoteWidget`. It reads no section at all — everything is asked\n\t * of the page — so it asks as soon as it mounts.\n\t */\n\timport { setContext, untrack } from \"svelte\"\n\timport type { ComponentContext } from \"@serene-pub/sdk/component\"\n\timport { WIDGET_CONTEXT_KEY } from \"@serene-pub/core-catalog/widgets\"\n\timport AuthorsNoteWidget from \"./AuthorsNoteWidget.svelte\"\n\timport { widgetRefFromComponent } from \"../shared/widgetRef.svelte\"\n\n\tlet { ctx }: { ctx: ComponentContext } = $props()\n\n\t// The context is the mount's, handed once: its sections move, it does not.\n\tsetContext(\n\t\tWIDGET_CONTEXT_KEY,\n\t\twidgetRefFromComponent(\n\t\t\tuntrack(() => ctx),\n\t\t\t{ id: \"authors-note\", instanceId: \"authors-note\", title: \"Author's note\" }\n\t\t)\n\t)\n</script>\n\n<AuthorsNoteWidget />\n","sessions/authors-note/AuthorsNoteWidget.svelte":"<script lang=\"ts\">\n\t/**\n\t * The author's note (2026-10-02, AN1; Chat only, owner ruling): the\n\t * session's own note to the model — what is true now, where the story\n\t * should lean — placed `depth` messages before the reply on every\n\t * `interval`-th reply. Not the post-history reminder, which is the\n\t * pipeline's and the card's; this widget never shows or edits that.\n\t *\n\t * Everything is asked of the page: `authors-note` reads the note, whether\n\t * the viewer may change it (the session's owner), and what the newest\n\t * reply's prompt did with it; `set-authors-note` saves it, whole. It asks\n\t * again when a generation ends, so the last-reply line follows the\n\t * conversation, and when the session's genre fields change\n\t * (`genreFields:changed`), so a note saved in Edit Session or another tab\n\t * shows here.\n\t *\n\t * Saved explicitly (STYLE-GUIDE §6.14): edits wait for **Save**; dirty is\n\t * derived (the draft differs from what is saved, never \"touched\"); a\n\t * re-read moves the saved snapshot and keeps what is being typed.\n\t * What goes wrong is said here, in this widget (R77) — never a toast.\n\t *\n\t * The markup carries no look: its elements carry `authors-note.*` widget\n\t * parts and the default widget stylesheet draws them (STYLE-GUIDE §6.16).\n\t */\n\timport { untrack } from \"svelte\"\n\timport type { AuthorsNoteV1, AuthorsNoteValueV1 } from \"@serene-pub/sdk/component\"\n\timport {\n\t\tAUTHORS_NOTE_DEFAULTS,\n\t\tAUTHORS_NOTE_ROLES,\n\t\tauthorsNoteDirty,\n\t\tauthorsNoteLastReplyLine,\n\t\treadAuthorsNote\n\t} from \"@serene-pub/core-catalog/authors-note\"\n\timport { useWidgetContext } from \"../shared/context\"\n\n\tconst widget = useWidgetContext()\n\tconst t = (source: string): string => widget?.current?.t(source) ?? source\n\n\t/** What the page last answered. */\n\tlet answer = $state<AuthorsNoteV1 | null>(null)\n\t/** The form's own copy; Save sends it whole. */\n\tlet draft = $state<AuthorsNoteValueV1>({ ...AUTHORS_NOTE_DEFAULTS })\n\tlet readError = $state<string | null>(null)\n\tlet saveError = $state<string | null>(null)\n\tlet saving = $state(false)\n\n\tconst saved = $derived(answer ? readAuthorsNote(answer.note) : AUTHORS_NOTE_DEFAULTS)\n\tconst dirty = $derived(answer ? authorsNoteDirty(draft, saved) : false)\n\tconst canEdit = $derived(answer?.canEdit === true)\n\tconst lastLine = $derived(answer ? authorsNoteLastReplyLine(answer.lastReply, t) : null)\n\n\tconst reason = (e: unknown) => (e instanceof Error ? e.message : String(e))\n\n\t/**\n\t * Take the page's answer as the saved snapshot. A clean form follows it;\n\t * an edited one keeps the person's edits (§6.14 — a push never lies).\n\t */\n\tfunction adopt(next: AuthorsNoteV1) {\n\t\tconst wasDirty = answer ? authorsNoteDirty(draft, readAuthorsNote(answer.note)) : false\n\t\tanswer = next\n\t\tif (!wasDirty) draft = readAuthorsNote(next.note)\n\t}\n\n\tlet asked = 0\n\tfunction ask() {\n\t\tconst ctx = untrack(() => widget?.current)\n\t\tif (!ctx) return\n\t\tconst ticket = ++asked\n\t\tctx.request(\"authors-note\", {}).then(\n\t\t\t(res) => {\n\t\t\t\tif (ticket !== asked) return\n\t\t\t\treadError = null\n\t\t\t\tadopt(res)\n\t\t\t},\n\t\t\t(e) => {\n\t\t\t\tif (ticket !== asked) return\n\t\t\t\treadError = reason(e)\n\t\t\t}\n\t\t)\n\t}\n\n\t$effect(() => untrack(() => ask()))\n\n\t// A reply finished: what it did with the note is on its receipt now.\n\t$effect(() =>\n\t\tuntrack(() =>\n\t\t\twidget?.current?.on(\"generation:end\", (e) => {\n\t\t\t\tif (e.kind === \"generation:end\") ask()\n\t\t\t})\n\t\t)\n\t)\n\n\t// The note was saved somewhere else — Edit Session, or this widget in\n\t// another tab: read it again (a clean form follows it, an edited one\n\t// keeps the person's edits).\n\t$effect(() =>\n\t\tuntrack(() =>\n\t\t\twidget?.current?.on(\"genreFields:changed\", (e) => {\n\t\t\t\tif (e.kind === \"genreFields:changed\") ask()\n\t\t\t})\n\t\t)\n\t)\n\n\tasync function save() {\n\t\tconst ctx = untrack(() => widget?.current)\n\t\tif (!ctx || !canEdit || !dirty || saving) return\n\t\tsaving = true\n\t\tsaveError = null\n\t\tconst sent = readAuthorsNote(draft)\n\t\ttry {\n\t\t\tconst now = await ctx.request(\"set-authors-note\", { note: sent })\n\t\t\t// The saved row is what the page answered; the form is clean against it.\n\t\t\tanswer = now\n\t\t\tdraft = readAuthorsNote(now.note)\n\t\t} catch (e) {\n\t\t\tsaveError = t(\"Not saved: {reason}\").replace(\"{reason}\", reason(e))\n\t\t} finally {\n\t\t\tsaving = false\n\t\t}\n\t}\n\n\tfunction discard() {\n\t\tdraft = { ...saved }\n\t\tsaveError = null\n\t}\n\n\tconst setNumber = (key: \"depth\" | \"interval\", raw: string) => {\n\t\tconst n = raw.trim() === \"\" ? NaN : Number(raw)\n\t\tdraft = { ...draft, [key]: Number.isFinite(n) ? n : draft[key] }\n\t}\n</script>\n\n<div data-widget-part=\"authors-note.root\" data-widget=\"authors-note\" data-dirty={dirty ? \"\" : undefined}>\n\t{#if readError}\n\t\t<p data-widget-part=\"authors-note.alert\" role=\"alert\">\n\t\t\t{t(\"Could not read the author's note: {reason}\").replace(\"{reason}\", readError)}\n\t\t</p>\n\t{/if}\n\t{#if !answer}\n\t\t{#if !readError}\n\t\t\t<p data-widget-part=\"authors-note.note\">{t(\"Reading the author's note…\")}</p>\n\t\t{/if}\n\t{:else if !answer.offered}\n\t\t<p data-widget-part=\"authors-note.note\">\n\t\t\t{t(\"This kind of session has no author's note.\")}\n\t\t</p>\n\t{:else}\n\t\t{#if !canEdit}\n\t\t\t<p data-widget-part=\"authors-note.note\">\n\t\t\t\t{t(\"Only the session's owner can change the author's note.\")}\n\t\t\t</p>\n\t\t{/if}\n\t\t<label data-widget-part=\"authors-note.field\">\n\t\t\t<span data-widget-part=\"authors-note.label label\">{t(\"Note\")}</span>\n\t\t\t<textarea\n\t\t\t\tdata-widget-part=\"authors-note.text\"\n\t\t\t\trows=\"5\"\n\t\t\t\tplaceholder={t(\"What is true now, or where the story should go.\")}\n\t\t\t\tdisabled={!canEdit}\n\t\t\t\tvalue={draft.text}\n\t\t\t\toninput={(e) => (draft = { ...draft, text: e.currentTarget.value })}\n\t\t\t></textarea>\n\t\t</label>\n\t\t<div data-widget-part=\"authors-note.numbers\">\n\t\t\t<label data-widget-part=\"authors-note.field\">\n\t\t\t\t<span data-widget-part=\"authors-note.label label\">{t(\"Messages from the end\")}</span>\n\t\t\t\t<input\n\t\t\t\t\ttype=\"number\"\n\t\t\t\t\tdata-widget-part=\"authors-note.number\"\n\t\t\t\t\tmin=\"0\"\n\t\t\t\t\tstep=\"1\"\n\t\t\t\t\tdisabled={!canEdit}\n\t\t\t\t\tvalue={String(draft.depth)}\n\t\t\t\t\toninput={(e) => setNumber(\"depth\", e.currentTarget.value)}\n\t\t\t\t/>\n\t\t\t</label>\n\t\t\t<label data-widget-part=\"authors-note.field\">\n\t\t\t\t<span data-widget-part=\"authors-note.label label\">{t(\"Every how many replies\")}</span>\n\t\t\t\t<input\n\t\t\t\t\ttype=\"number\"\n\t\t\t\t\tdata-widget-part=\"authors-note.number\"\n\t\t\t\t\tmin=\"1\"\n\t\t\t\t\tstep=\"1\"\n\t\t\t\t\tdisabled={!canEdit}\n\t\t\t\t\tvalue={String(draft.interval)}\n\t\t\t\t\toninput={(e) => setNumber(\"interval\", e.currentTarget.value)}\n\t\t\t\t/>\n\t\t\t</label>\n\t\t</div>\n\t\t<p data-widget-part=\"authors-note.help\">\n\t\t\t{t(\"0 messages puts it right before the reply. Every 1 reply adds it each time.\")}\n\t\t</p>\n\t\t<sp-accordion data-widget-part=\"authors-note.advanced\">\n\t\t\t<sp-accordion-item value=\"advanced\" heading={t(\"Advanced\")} level=\"4\">\n\t\t\t\t<span data-widget-part=\"authors-note.role\">\n\t\t\t\t\t<sp-combobox\n\t\t\t\t\t\tdata-widget-part=\"authors-note.role-field\"\n\t\t\t\t\t\tlabel={t(\"Sent as\")}\n\t\t\t\t\t\tvalue={draft.role}\n\t\t\t\t\t\tdisabled={!canEdit}\n\t\t\t\t\t\tonchange={(e: CustomEvent<{ value: string }>) => {\n\t\t\t\t\t\t\tconst next = AUTHORS_NOTE_ROLES.find((r) => r.value === e.detail.value)\n\t\t\t\t\t\t\tif (next) draft = { ...draft, role: next.value }\n\t\t\t\t\t\t}}\n\t\t\t\t\t>\n\t\t\t\t\t\t{#each AUTHORS_NOTE_ROLES as r (r.value)}\n\t\t\t\t\t\t\t<sp-option value={r.value}>{t(r.label)}</sp-option>\n\t\t\t\t\t\t{/each}\n\t\t\t\t\t</sp-combobox>\n\t\t\t\t</span>\n\t\t\t</sp-accordion-item>\n\t\t</sp-accordion>\n\t\t{#if saveError}\n\t\t\t<p data-widget-part=\"authors-note.alert\" role=\"alert\">{saveError}</p>\n\t\t{/if}\n\t\t{#if canEdit}\n\t\t\t<div data-widget-part=\"authors-note.actions toolbar\">\n\t\t\t\t{#if dirty}\n\t\t\t\t\t<span data-widget-part=\"authors-note.unsaved\">{t(\"Unsaved changes\")}</span>\n\t\t\t\t\t<button type=\"button\" data-widget-part=\"authors-note.discard\" disabled={saving} onclick={discard}>\n\t\t\t\t\t\t{t(\"Discard\")}\n\t\t\t\t\t</button>\n\t\t\t\t{/if}\n\t\t\t\t<button\n\t\t\t\t\ttype=\"button\"\n\t\t\t\t\tdata-widget-part=\"authors-note.save\"\n\t\t\t\t\tdisabled={!dirty || saving}\n\t\t\t\t\tonclick={save}\n\t\t\t\t>\n\t\t\t\t\t{saving ? t(\"Saving…\") : t(\"Save\")}\n\t\t\t\t</button>\n\t\t\t</div>\n\t\t{/if}\n\t\t{#if lastLine}\n\t\t\t<p data-widget-part=\"authors-note.last-reply\" data-applied={answer.lastReply?.included ? \"\" : undefined}>\n\t\t\t\t{lastLine}\n\t\t\t</p>\n\t\t{/if}\n\t{/if}\n</div>\n","sessions/authors-note/authors-note.ts":"/**\n * Core's `authors-note` component (2026-10-02, AN1): the session's author's\n * note — its text, how far back it goes, how often it repeats — saved\n * explicitly, and what the newest reply did with it. `npm run build`\n * compiles it with the CLI's component bundler to\n * `dist/components/authors-note.js`, the module the app serves at\n * `/core-ui/authors-note`.\n */\nimport { svelteComponent } from '@serene-pub/component-client/svelte'\nimport AuthorsNote from './AuthorsNote.svelte'\n\nexport default svelteComponent(AuthorsNote)\n","sessions/shared/context.ts":"/**\n * Core's widgets read their widget context with their own `getContext`, so\n * the lookup resolves in whichever Svelte runtime renders them — the\n * component's, in the page's UI worker. The key and the context's shape are\n * the host's contract (`@serene-pub/core-catalog/widgets`). Shared by every\n * core widget (R21); the conversation was the first.\n */\nimport { getContext } from 'svelte'\nimport { WIDGET_CONTEXT_KEY, type WidgetContextRef } from '@serene-pub/core-catalog/widgets'\n\n/** The widget context, if a host provides one; undefined outside a host (tests, a bare mount). */\nexport function useWidgetContext(): WidgetContextRef | undefined {\n\treturn getContext<WidgetContextRef | undefined>(WIDGET_CONTEXT_KEY)\n}\n","sessions/shared/widgetRef.svelte.ts":"/**\n * A remote's widget context (C0b): the component context a UI worker hands\n * a component, as the native `WidgetContext` core's widgets read\n * (`useWidgetContext`). So a core widget — written against the native\n * context — runs in a worker with no change to its source: the same\n * sections, the same verbs, reaching the host over the component's port.\n * Shared by every core widget (R21); the conversation was the first.\n */\nimport {\n\tEMPTY_TURN_ORDER,\n\tWIDGET_PROTOCOL,\n\ttype ComponentContext,\n\ttype LayoutV1,\n\ttype ViewerV1,\n\ttype WidgetEvent,\n\ttype WidgetEventKind\n} from \"@serene-pub/sdk/component\"\nimport {\n\tWIDGET_SCOPED_SECTIONS,\n\ttype WidgetContext,\n\ttype WidgetContextRef,\n\ttype WidgetScopedData\n} from \"@serene-pub/core-catalog/widgets\"\n\n/** Every scoped section's posted name — the SDK's one table, read once. */\nconst SCOPED_NAMES = Object.values(WIDGET_SCOPED_SECTIONS)\n\nconst NOBODY: ViewerV1 = { userId: null, isAdmin: false, isGuest: false }\n\n/**\n * A remote's context carries its saved view state besides: what it saved\n * last mount (`state`) and the host's save-state channel (`saveState`) —\n * read by core's widgets off the context where a remote has them.\n */\ntype RemoteWidgetContext = WidgetContext & {\n\tstate: unknown\n\tsaveState: (state: unknown) => void\n}\n\n/** The granted scoped sections as the envelope carries them: `{ <name>: { v1 } }`, absent when not granted. */\nfunction scopedData(scoped: ComponentContext[\"scoped\"]): WidgetScopedData {\n\tconst out: Record<string, { v1: unknown }> = {}\n\tfor (const name of SCOPED_NAMES) if (scoped[name] !== undefined) out[name] = { v1: scoped[name] }\n\treturn out as WidgetScopedData\n}\n\nexport function widgetRefFromComponent(\n\tctx: ComponentContext,\n\twidget: WidgetContext[\"widget\"]\n): WidgetContextRef {\n\t// Any section the host pushes re-projects the context, as a native\n\t// host's re-projection does.\n\tlet version = $state(0)\n\tctx.subscribe(() => version++)\n\n\tconst current = $derived.by((): RemoteWidgetContext => {\n\t\tvoid version\n\t\tconst scoped = ctx.scoped ?? {}\n\t\treturn {\n\t\t\tprotocol: WIDGET_PROTOCOL,\n\t\t\twidget,\n\t\t\tlayout: { v1: (ctx.layout ?? {}) as LayoutV1 },\n\t\t\tsession: { v1: (ctx.session ?? { id: 0, name: null }) as WidgetContext[\"session\"][\"v1\"] },\n\t\t\tchannels: { v1: Object.keys(ctx.channels ?? {}) },\n\t\t\tmessages: { v1: (ctx.messages ?? []) as WidgetContext[\"messages\"][\"v1\"] },\n\t\t\tprops: { v1: ctx.props ?? {} },\n\t\t\tactions: { v1: (ctx.actions ?? {}) as WidgetContext[\"actions\"][\"v1\"] },\n\t\t\tsettings: { v1: ctx.settings ?? {} },\n\t\t\tannex: { v1: (ctx.annex ?? {}) as WidgetContext[\"annex\"][\"v1\"] },\n\t\t\tlocale: { v1: ctx.locale ?? \"en\" },\n\t\t\tviewer: { v1: ctx.viewer ?? NOBODY },\n\t\t\tturnOrder: { v1: ctx.turnOrder ?? EMPTY_TURN_ORDER },\n\t\t\t// What the host said this widget holds — absent until it has — so a\n\t\t\t// widget can tell a scope never granted apart from a section not yet posted.\n\t\t\tgrants: ctx.grants,\n\t\t\t// The scoped sections the host granted, each as its `{ v1 }` bag — by\n\t\t\t// the table, so a section the SDK adds arrives with no change here.\n\t\t\t...scopedData(scoped),\n\t\t\taction: (fn, messageId, payload, action, blockId) => ctx.action(fn, messageId, payload, action, blockId),\n\t\t\tinvoke: (key, args) => ctx.invoke(key, args),\n\t\t\trequest: ((kind, params) => ctx.request(kind, params)) as WidgetContext[\"request\"],\n\t\t\t// No host menu across the port yet: dismissed, as a native host without one answers.\n\t\t\tmenu: async () => null,\n\t\t\ton: (kind: WidgetEventKind | \"*\", cb: (e: WidgetEvent) => void) =>\n\t\t\t\tctx.onEvent((e) => {\n\t\t\t\t\tconst ev = e as WidgetEvent\n\t\t\t\t\tif (kind === \"*\" || ev.kind === kind) cb(ev)\n\t\t\t\t}),\n\t\t\tt: (source) => ctx.t(source),\n\t\t\tstate: ctx.state,\n\t\t\tsaveState: (state) => ctx.saveState(state)\n\t\t}\n\t})\n\n\treturn {\n\t\tget current() {\n\t\t\treturn current\n\t\t}\n\t}\n}\n"},"sourceHash":"5458d5b55cf30d2fac49eb52bb87a1e343084172a1cb40dc392da3710299116f","catalogVersion":"0.6.0-pr-1"}
|
|
1
|
+
{"slug":"authors-note","framework":"svelte","entry":"sessions/authors-note/authors-note.ts","files":{"sessions/authors-note/AuthorsNote.svelte":"<script lang=\"ts\">\n\t/**\n\t * Core's Author's note widget as a remote component (2026-10-02, AN1):\n\t * the component context, as the native widget context, around\n\t * `AuthorsNoteWidget`. It reads no section at all — everything is asked\n\t * of the page — so it asks as soon as it mounts.\n\t */\n\timport { setContext, untrack } from \"svelte\"\n\timport type { ComponentContext } from \"@serene-pub/sdk/component\"\n\timport { WIDGET_CONTEXT_KEY } from \"@serene-pub/core-catalog/widgets\"\n\timport AuthorsNoteWidget from \"./AuthorsNoteWidget.svelte\"\n\timport { widgetRefFromComponent } from \"../shared/widgetRef.svelte\"\n\n\tlet { ctx }: { ctx: ComponentContext } = $props()\n\n\t// The context is the mount's, handed once: its sections move, it does not.\n\tsetContext(\n\t\tWIDGET_CONTEXT_KEY,\n\t\twidgetRefFromComponent(\n\t\t\tuntrack(() => ctx),\n\t\t\t{ id: \"authors-note\", instanceId: \"authors-note\", title: \"Author's note\" }\n\t\t)\n\t)\n</script>\n\n<AuthorsNoteWidget />\n","sessions/authors-note/AuthorsNoteWidget.svelte":"<script lang=\"ts\">\n\t/**\n\t * The author's note (2026-10-02, AN1; Chat only, owner ruling): the\n\t * session's own note to the model — what is true now, where the story\n\t * should lean — placed `depth` messages before the reply on every\n\t * `interval`-th reply. Not the post-history reminder, which is the\n\t * pipeline's and the card's; this widget never shows or edits that.\n\t *\n\t * Everything is asked of the page: `authors-note` reads the note, whether\n\t * the viewer may change it (the session's owner), and what the newest\n\t * reply's prompt did with it; `set-authors-note` saves it, whole. It asks\n\t * again when a generation ends, so the last-reply line follows the\n\t * conversation, and when the session's genre fields change\n\t * (`genreFields:changed`), so a note saved in Edit Session or another tab\n\t * shows here.\n\t *\n\t * Saved explicitly (STYLE-GUIDE §6.14): edits wait for **Save**; dirty is\n\t * derived (the draft differs from what is saved, never \"touched\"); a\n\t * re-read moves the saved snapshot and keeps what is being typed.\n\t * What goes wrong is said here, in this widget (R77) — never a toast.\n\t *\n\t * The markup carries no look: its elements carry `authors-note.*` widget\n\t * parts and the default widget stylesheet draws them (STYLE-GUIDE §6.16).\n\t */\n\timport { untrack } from \"svelte\"\n\timport type { AuthorsNoteV1, AuthorsNoteValueV1 } from \"@serene-pub/sdk/component\"\n\timport {\n\t\tAUTHORS_NOTE_DEFAULTS,\n\t\tAUTHORS_NOTE_ROLES,\n\t\tauthorsNoteDirty,\n\t\tauthorsNoteLastReplyLine,\n\t\treadAuthorsNote\n\t} from \"@serene-pub/core-catalog/authors-note\"\n\timport { useWidgetContext } from \"../shared/context\"\n\n\tconst widget = useWidgetContext()\n\tconst t = (source: string): string => widget?.current?.t(source) ?? source\n\n\t/** What the page last answered. */\n\tlet answer = $state<AuthorsNoteV1 | null>(null)\n\t/** The form's own copy; Save sends it whole. */\n\tlet draft = $state<AuthorsNoteValueV1>({ ...AUTHORS_NOTE_DEFAULTS })\n\tlet readError = $state<string | null>(null)\n\tlet saveError = $state<string | null>(null)\n\tlet saving = $state(false)\n\n\tconst saved = $derived(answer ? readAuthorsNote(answer.note) : AUTHORS_NOTE_DEFAULTS)\n\tconst dirty = $derived(answer ? authorsNoteDirty(draft, saved) : false)\n\tconst canEdit = $derived(answer?.canEdit === true)\n\tconst lastLine = $derived(answer ? authorsNoteLastReplyLine(answer.lastReply, t) : null)\n\n\tconst reason = (e: unknown) => (e instanceof Error ? e.message : String(e))\n\n\t/**\n\t * Take the page's answer as the saved snapshot. A clean form follows it;\n\t * an edited one keeps the person's edits (§6.14 — a push never lies).\n\t */\n\tfunction adopt(next: AuthorsNoteV1) {\n\t\tconst wasDirty = answer ? authorsNoteDirty(draft, readAuthorsNote(answer.note)) : false\n\t\tanswer = next\n\t\tif (!wasDirty) draft = readAuthorsNote(next.note)\n\t}\n\n\tlet asked = 0\n\tfunction ask() {\n\t\tconst ctx = untrack(() => widget?.current)\n\t\tif (!ctx) return\n\t\tconst ticket = ++asked\n\t\tctx.request(\"authors-note\", {}).then(\n\t\t\t(res) => {\n\t\t\t\tif (ticket !== asked) return\n\t\t\t\treadError = null\n\t\t\t\tadopt(res)\n\t\t\t},\n\t\t\t(e) => {\n\t\t\t\tif (ticket !== asked) return\n\t\t\t\treadError = reason(e)\n\t\t\t}\n\t\t)\n\t}\n\n\t$effect(() => untrack(() => ask()))\n\n\t// A reply finished: what it did with the note is on its receipt now.\n\t$effect(() =>\n\t\tuntrack(() =>\n\t\t\twidget?.current?.on(\"generation:end\", (e) => {\n\t\t\t\tif (e.kind === \"generation:end\") ask()\n\t\t\t})\n\t\t)\n\t)\n\n\t// The note was saved somewhere else — Edit Session, or this widget in\n\t// another tab: read it again (a clean form follows it, an edited one\n\t// keeps the person's edits).\n\t$effect(() =>\n\t\tuntrack(() =>\n\t\t\twidget?.current?.on(\"genreFields:changed\", (e) => {\n\t\t\t\tif (e.kind === \"genreFields:changed\") ask()\n\t\t\t})\n\t\t)\n\t)\n\n\tasync function save() {\n\t\tconst ctx = untrack(() => widget?.current)\n\t\tif (!ctx || !canEdit || !dirty || saving) return\n\t\tsaving = true\n\t\tsaveError = null\n\t\tconst sent = readAuthorsNote(draft)\n\t\ttry {\n\t\t\tconst now = await ctx.request(\"set-authors-note\", { note: sent })\n\t\t\t// The saved row is what the page answered; the form is clean against it.\n\t\t\tanswer = now\n\t\t\tdraft = readAuthorsNote(now.note)\n\t\t} catch (e) {\n\t\t\tsaveError = t(\"Not saved: {reason}\").replace(\"{reason}\", reason(e))\n\t\t} finally {\n\t\t\tsaving = false\n\t\t}\n\t}\n\n\tfunction discard() {\n\t\tdraft = { ...saved }\n\t\tsaveError = null\n\t}\n\n\tconst setNumber = (key: \"depth\" | \"interval\", raw: string) => {\n\t\tconst n = raw.trim() === \"\" ? NaN : Number(raw)\n\t\tdraft = { ...draft, [key]: Number.isFinite(n) ? n : draft[key] }\n\t}\n</script>\n\n<div data-widget-part=\"authors-note.root\" data-widget=\"authors-note\" data-dirty={dirty ? \"\" : undefined}>\n\t{#if readError}\n\t\t<p data-widget-part=\"authors-note.alert\" role=\"alert\">\n\t\t\t{t(\"Could not read the author's note: {reason}\").replace(\"{reason}\", readError)}\n\t\t</p>\n\t{/if}\n\t{#if !answer}\n\t\t{#if !readError}\n\t\t\t<p data-widget-part=\"authors-note.note\">{t(\"Reading the author's note…\")}</p>\n\t\t{/if}\n\t{:else if !answer.offered}\n\t\t<p data-widget-part=\"authors-note.note\">\n\t\t\t{t(\"This kind of session has no author's note.\")}\n\t\t</p>\n\t{:else}\n\t\t{#if !canEdit}\n\t\t\t<p data-widget-part=\"authors-note.note\">\n\t\t\t\t{t(\"Only the session's owner can change the author's note.\")}\n\t\t\t</p>\n\t\t{/if}\n\t\t<label data-widget-part=\"authors-note.field\">\n\t\t\t<span data-widget-part=\"authors-note.label label\">{t(\"Note\")}</span>\n\t\t\t<textarea\n\t\t\t\tdata-widget-part=\"authors-note.text\"\n\t\t\t\trows=\"5\"\n\t\t\t\tplaceholder={t(\"What is true now, or where the story should go.\")}\n\t\t\t\tdisabled={!canEdit}\n\t\t\t\tvalue={draft.text}\n\t\t\t\toninput={(e) => (draft = { ...draft, text: e.currentTarget.value })}\n\t\t\t></textarea>\n\t\t</label>\n\t\t<div data-widget-part=\"authors-note.numbers\">\n\t\t\t<label data-widget-part=\"authors-note.field\">\n\t\t\t\t<span data-widget-part=\"authors-note.label label\">{t(\"Messages from the end\")}</span>\n\t\t\t\t<input\n\t\t\t\t\ttype=\"number\"\n\t\t\t\t\tdata-widget-part=\"authors-note.number\"\n\t\t\t\t\tmin=\"0\"\n\t\t\t\t\tstep=\"1\"\n\t\t\t\t\tdisabled={!canEdit}\n\t\t\t\t\tvalue={String(draft.depth)}\n\t\t\t\t\toninput={(e) => setNumber(\"depth\", e.currentTarget.value)}\n\t\t\t\t/>\n\t\t\t</label>\n\t\t\t<label data-widget-part=\"authors-note.field\">\n\t\t\t\t<span data-widget-part=\"authors-note.label label\">{t(\"Every how many replies\")}</span>\n\t\t\t\t<input\n\t\t\t\t\ttype=\"number\"\n\t\t\t\t\tdata-widget-part=\"authors-note.number\"\n\t\t\t\t\tmin=\"1\"\n\t\t\t\t\tstep=\"1\"\n\t\t\t\t\tdisabled={!canEdit}\n\t\t\t\t\tvalue={String(draft.interval)}\n\t\t\t\t\toninput={(e) => setNumber(\"interval\", e.currentTarget.value)}\n\t\t\t\t/>\n\t\t\t</label>\n\t\t</div>\n\t\t<p data-widget-part=\"authors-note.help\">\n\t\t\t{t(\"0 messages puts it right before the reply. Every 1 reply adds it each time.\")}\n\t\t</p>\n\t\t<sp-accordion data-widget-part=\"authors-note.advanced\">\n\t\t\t<sp-accordion-item value=\"advanced\" heading={t(\"Advanced\")} level=\"4\">\n\t\t\t\t<span data-widget-part=\"authors-note.role\">\n\t\t\t\t\t<sp-combobox\n\t\t\t\t\t\tdata-widget-part=\"authors-note.role-field\"\n\t\t\t\t\t\tlabel={t(\"Sent as\")}\n\t\t\t\t\t\tvalue={draft.role}\n\t\t\t\t\t\tdisabled={!canEdit}\n\t\t\t\t\t\tonchange={(e: CustomEvent<{ value: string }>) => {\n\t\t\t\t\t\t\tconst next = AUTHORS_NOTE_ROLES.find((r) => r.value === e.detail.value)\n\t\t\t\t\t\t\tif (next) draft = { ...draft, role: next.value }\n\t\t\t\t\t\t}}\n\t\t\t\t\t>\n\t\t\t\t\t\t{#each AUTHORS_NOTE_ROLES as r (r.value)}\n\t\t\t\t\t\t\t<sp-option value={r.value}>{t(r.label)}</sp-option>\n\t\t\t\t\t\t{/each}\n\t\t\t\t\t</sp-combobox>\n\t\t\t\t</span>\n\t\t\t</sp-accordion-item>\n\t\t</sp-accordion>\n\t\t{#if saveError}\n\t\t\t<p data-widget-part=\"authors-note.alert\" role=\"alert\">{saveError}</p>\n\t\t{/if}\n\t\t{#if canEdit}\n\t\t\t<div data-widget-part=\"authors-note.actions toolbar\">\n\t\t\t\t{#if dirty}\n\t\t\t\t\t<span data-widget-part=\"authors-note.unsaved\">{t(\"Unsaved changes\")}</span>\n\t\t\t\t\t<button type=\"button\" data-widget-part=\"authors-note.discard\" disabled={saving} onclick={discard}>\n\t\t\t\t\t\t{t(\"Discard\")}\n\t\t\t\t\t</button>\n\t\t\t\t{/if}\n\t\t\t\t<button\n\t\t\t\t\ttype=\"button\"\n\t\t\t\t\tdata-widget-part=\"authors-note.save\"\n\t\t\t\t\tdisabled={!dirty || saving}\n\t\t\t\t\tonclick={save}\n\t\t\t\t>\n\t\t\t\t\t{saving ? t(\"Saving…\") : t(\"Save\")}\n\t\t\t\t</button>\n\t\t\t</div>\n\t\t{/if}\n\t\t{#if lastLine}\n\t\t\t<p data-widget-part=\"authors-note.last-reply\" data-applied={answer.lastReply?.included ? \"\" : undefined}>\n\t\t\t\t{lastLine}\n\t\t\t</p>\n\t\t{/if}\n\t{/if}\n</div>\n","sessions/authors-note/authors-note.ts":"/**\n * Core's `authors-note` component (2026-10-02, AN1): the session's author's\n * note — its text, how far back it goes, how often it repeats — saved\n * explicitly, and what the newest reply did with it. `npm run build`\n * compiles it with the CLI's component bundler to\n * `dist/components/authors-note.js`, the module the app serves at\n * `/core-ui/authors-note`.\n */\nimport { svelteComponent } from '@serene-pub/component-client/svelte'\nimport AuthorsNote from './AuthorsNote.svelte'\n\nexport default svelteComponent(AuthorsNote)\n","sessions/shared/context.ts":"/**\n * Core's widgets read their widget context with their own `getContext`, so\n * the lookup resolves in whichever Svelte runtime renders them — the\n * component's, in the page's UI worker. The key and the context's shape are\n * the host's contract (`@serene-pub/core-catalog/widgets`). Shared by every\n * core widget (R21); the conversation was the first.\n */\nimport { getContext } from 'svelte'\nimport { WIDGET_CONTEXT_KEY, type WidgetContextRef } from '@serene-pub/core-catalog/widgets'\n\n/** The widget context, if a host provides one; undefined outside a host (tests, a bare mount). */\nexport function useWidgetContext(): WidgetContextRef | undefined {\n\treturn getContext<WidgetContextRef | undefined>(WIDGET_CONTEXT_KEY)\n}\n","sessions/shared/widgetRef.svelte.ts":"/**\n * A remote's widget context (C0b): the component context a UI worker hands\n * a component, as the native `WidgetContext` core's widgets read\n * (`useWidgetContext`). So a core widget — written against the native\n * context — runs in a worker with no change to its source: the same\n * sections, the same verbs, reaching the host over the component's port.\n * Shared by every core widget (R21); the conversation was the first.\n */\nimport {\n\tEMPTY_TURN_ORDER,\n\tWIDGET_PROTOCOL,\n\ttype ComponentContext,\n\ttype LayoutV1,\n\ttype ViewerV1,\n\ttype WidgetEvent,\n\ttype WidgetEventKind\n} from \"@serene-pub/sdk/component\"\nimport {\n\tWIDGET_SCOPED_SECTIONS,\n\ttype WidgetContext,\n\ttype WidgetContextRef,\n\ttype WidgetScopedData\n} from \"@serene-pub/core-catalog/widgets\"\n\n/** Every scoped section's posted name — the SDK's one table, read once. */\nconst SCOPED_NAMES = Object.values(WIDGET_SCOPED_SECTIONS)\n\nconst NOBODY: ViewerV1 = { userId: null, isAdmin: false, isGuest: false }\n\n/**\n * A remote's context carries its saved view state besides: what it saved\n * last mount (`state`) and the host's save-state channel (`saveState`) —\n * read by core's widgets off the context where a remote has them.\n */\ntype RemoteWidgetContext = WidgetContext & {\n\tstate: unknown\n\tsaveState: (state: unknown) => void\n}\n\n/** The granted scoped sections as the envelope carries them: `{ <name>: { v1 } }`, absent when not granted. */\nfunction scopedData(scoped: ComponentContext[\"scoped\"]): WidgetScopedData {\n\tconst out: Record<string, { v1: unknown }> = {}\n\tfor (const name of SCOPED_NAMES) if (scoped[name] !== undefined) out[name] = { v1: scoped[name] }\n\treturn out as WidgetScopedData\n}\n\nexport function widgetRefFromComponent(\n\tctx: ComponentContext,\n\twidget: WidgetContext[\"widget\"]\n): WidgetContextRef {\n\t// Any section the host pushes re-projects the context, as a native\n\t// host's re-projection does.\n\tlet version = $state(0)\n\tctx.subscribe(() => version++)\n\n\tconst current = $derived.by((): RemoteWidgetContext => {\n\t\tvoid version\n\t\tconst scoped = ctx.scoped ?? {}\n\t\treturn {\n\t\t\tprotocol: WIDGET_PROTOCOL,\n\t\t\twidget,\n\t\t\tlayout: { v1: (ctx.layout ?? {}) as LayoutV1 },\n\t\t\tsession: { v1: (ctx.session ?? { id: 0, name: null }) as WidgetContext[\"session\"][\"v1\"] },\n\t\t\tchannels: { v1: Object.keys(ctx.channels ?? {}) },\n\t\t\tmessages: { v1: (ctx.messages ?? []) as WidgetContext[\"messages\"][\"v1\"] },\n\t\t\tprops: { v1: ctx.props ?? {} },\n\t\t\tactions: { v1: (ctx.actions ?? {}) as WidgetContext[\"actions\"][\"v1\"] },\n\t\t\tsettings: { v1: ctx.settings ?? {} },\n\t\t\tannex: { v1: (ctx.annex ?? {}) as WidgetContext[\"annex\"][\"v1\"] },\n\t\t\tlocale: { v1: ctx.locale ?? \"en\" },\n\t\t\tviewer: { v1: ctx.viewer ?? NOBODY },\n\t\t\tturnOrder: { v1: ctx.turnOrder ?? EMPTY_TURN_ORDER },\n\t\t\t// What the host said this widget holds — absent until it has — so a\n\t\t\t// widget can tell a scope never granted apart from a section not yet posted.\n\t\t\tgrants: ctx.grants,\n\t\t\t// The scoped sections the host granted, each as its `{ v1 }` bag — by\n\t\t\t// the table, so a section the SDK adds arrives with no change here.\n\t\t\t...scopedData(scoped),\n\t\t\taction: (fn, messageId, payload, action, blockId) => ctx.action(fn, messageId, payload, action, blockId),\n\t\t\tinvoke: (key, args) => ctx.invoke(key, args),\n\t\t\trequest: ((kind, params) => ctx.request(kind, params)) as WidgetContext[\"request\"],\n\t\t\t// No host menu across the port yet: dismissed, as a native host without one answers.\n\t\t\tmenu: async () => null,\n\t\t\ton: (kind: WidgetEventKind | \"*\", cb: (e: WidgetEvent) => void) =>\n\t\t\t\tctx.onEvent((e) => {\n\t\t\t\t\tconst ev = e as WidgetEvent\n\t\t\t\t\tif (kind === \"*\" || ev.kind === kind) cb(ev)\n\t\t\t\t}),\n\t\t\tt: (source) => ctx.t(source),\n\t\t\tstate: ctx.state,\n\t\t\tsaveState: (state) => ctx.saveState(state)\n\t\t}\n\t})\n\n\treturn {\n\t\tget current() {\n\t\t\treturn current\n\t\t}\n\t}\n}\n"},"sourceHash":"5458d5b55cf30d2fac49eb52bb87a1e343084172a1cb40dc392da3710299116f","catalogVersion":"0.6.0-pr-2"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"slug":"lore-entries","framework":"svelte","entry":"sessions/lore-entries/lore-entries.ts","files":{"sessions/lore-entries/LoreEntries.svelte":"<script lang=\"ts\">\n\t/**\n\t * Core's Lore entries widget as a remote component (R21): the component\n\t * context, as the native widget context, around `LoreEntriesWidget`.\n\t *\n\t * The widget asks the page for its first page only once its settings\n\t * have arrived: the page posts a widget's settings (it reads them) right\n\t * after it says ready, and an ask made before would be spent on the\n\t * declared defaults instead of this instance's sort and page size.\n\t */\n\timport { setContext, untrack } from \"svelte\"\n\timport type { ComponentContext } from \"@serene-pub/sdk/component\"\n\timport { WIDGET_CONTEXT_KEY } from \"@serene-pub/core-catalog/widgets\"\n\timport LoreEntriesWidget from \"./LoreEntriesWidget.svelte\"\n\timport { widgetRefFromComponent } from \"../shared/widgetRef.svelte\"\n\n\tlet { ctx }: { ctx: ComponentContext } = $props()\n\n\tlet settled = $state(untrack(() => ctx.settings) !== undefined)\n\t$effect(() =>\n\t\tuntrack(() => ctx).subscribe((section) => {\n\t\t\tif (section === \"settings\") settled = true\n\t\t})\n\t)\n\n\t// The context is the mount's, handed once: its sections move, it does not.\n\tsetContext(\n\t\tWIDGET_CONTEXT_KEY,\n\t\twidgetRefFromComponent(\n\t\t\tuntrack(() => ctx),\n\t\t\t{ id: \"lore-entries\", instanceId: \"lore-entries\", title: \"Lore entries\" }\n\t\t)\n\t)\n</script>\n\n<LoreEntriesWidget ready={settled} />\n","sessions/lore-entries/LoreEntriesWidget.svelte":"<script lang=\"ts\">\n\t/**\n\t * Lore entries (PLAN-sdk-1.0 §3.9, R58; R21 port): the session's lorebook\n\t * entry by entry, with what this session's rankings made of each, and the\n\t * two marks — **Off** and **Pin** — which never force a re-embed.\n\t *\n\t * It reads its settings alone. Everything else is asked of the page: one\n\t * `session-entries` does the search, sort, filter and paging for the\n\t * page's own session (the declared `lore` scope is the grant for it), and\n\t * `set-entry-marks` sets a mark. The page answers every ask with its own\n\t * reply, so which answer to show is this widget's: its latest-ask guard.\n\t * A turn that writes the rankings tells it `lore:ranked` (R81), and it\n\t * pages again; so does a mark set anywhere else on an entry it shows, or\n\t * on any entry while it shows only Pinned or Off (`lore:marked`). The\n\t * refresh button stays.\n\t *\n\t * What goes wrong is said here, in this widget (R77) — never a toast every\n\t * lore widget shows. The book's owner and admins see the entries; anyone\n\t * else is told whose they are, because a widget declaration has no\n\t * visibility field of its own. So is a mark saved to the entry that a\n\t * dated amendment still decides in this session's story (the answer's\n\t * `heldBy`): the row reads as before, and the line says why.\n\t *\n\t * The markup carries no look (P3d): its elements carry `lore-entries.*`\n\t * widget parts and the default widget stylesheet draws them (STYLE-GUIDE\n\t * §6.16). State is the elements' own: a chosen filter is its radio's\n\t * `:checked`, a pressed mark its button's `aria-pressed`, an entry turned\n\t * off `data-off`.\n\t */\n\timport { untrack } from \"svelte\"\n\timport type { SessionEntryV1, WidgetRequests } from \"@serene-pub/sdk/component\"\n\timport {\n\t\tLORE_ENTRIES_FILTERS,\n\t\tLORE_ENTRIES_SORTS,\n\t\tcreateLatestAsk,\n\t\tloreEntriesEmptyLine,\n\t\tloreEntriesSpan,\n\t\tloreEntryName,\n\t\tloreEntryReadLine,\n\t\treadLoreEntriesSettings,\n\t\ttype LoreEntriesFilter,\n\t\ttype LoreEntriesSort\n\t} from \"@serene-pub/core-catalog/lore-entries\"\n\timport { useWidgetContext } from \"../shared/context\"\n\n\ttype Answer = WidgetRequests[\"session-entries\"][\"result\"]\n\ttype Ask = WidgetRequests[\"session-entries\"][\"params\"]\n\n\t/** Whether to ask the page yet: false until the host has posted this instance's settings. */\n\tlet { ready = true }: { ready?: boolean } = $props()\n\n\tconst widget = useWidgetContext()\n\tconst t = (source: string): string => widget?.current?.t(source) ?? source\n\n\t// Primitives, so a push that changes neither asks nothing again.\n\tconst pageSize = $derived(\n\t\treadLoreEntriesSettings(widget?.current?.settings?.v1 as Record<string, unknown> | undefined).pageSize\n\t)\n\tconst settledSort = $derived(\n\t\treadLoreEntriesSettings(widget?.current?.settings?.v1 as Record<string, unknown> | undefined).sort\n\t)\n\n\tlet query = $state(\"\")\n\tlet sort = $state<LoreEntriesSort | null>(null)\n\tconst effectiveSort = $derived<LoreEntriesSort>(sort ?? settledSort)\n\tlet filter = $state<LoreEntriesFilter>(\"all\")\n\tlet offset = $state(0)\n\n\tlet answer = $state<Answer | null>(null)\n\t/** Why the page could not be read, this widget's own. */\n\tlet readError = $state<string | null>(null)\n\t/** Why a mark did not change, this widget's own. */\n\tlet markError = $state<string | null>(null)\n\t/**\n\t * A mark saved to the entry that a dated amendment still decides here\n\t * (`heldBy`): the row reads as before, and this says why.\n\t */\n\tlet markHeld = $state<string | null>(null)\n\n\t/** The filter radios' group name: one per mount, so two copies never share a group (F8). */\n\tconst filterGroup = `sp-lore-filter-${Math.random().toString(36).slice(2, 10)}`\n\n\tconst latest = createLatestAsk()\n\tconst reason = (e: unknown) => (e instanceof Error ? e.message : String(e))\n\n\t// The search asks once typing pauses, not once per keystroke.\n\tlet searched = $state(\"\")\n\t$effect(() => {\n\t\tconst q = query.trim()\n\t\tconst timer = setTimeout(() => (searched = q), 250)\n\t\treturn () => clearTimeout(timer)\n\t})\n\n\tconst askParams = (): Ask => ({\n\t\t...(searched ? { titleOrKey: searched } : {}),\n\t\tsort: effectiveSort,\n\t\tfilter,\n\t\toffset,\n\t\tlimit: pageSize\n\t})\n\n\tfunction ask(params: Ask) {\n\t\tconst ctx = widget?.current\n\t\tif (!ctx) return\n\t\tconst ticket = latest.next()\n\t\tctx.request(\"session-entries\", params).then(\n\t\t\t(res) => {\n\t\t\t\tif (!latest.isLatest(ticket)) return\n\t\t\t\treadError = null\n\t\t\t\tanswer = res\n\t\t\t\t// The page pulls a page that ran past the end back to the last one.\n\t\t\t\tif (typeof res.offset === \"number\" && res.offset !== offset) offset = res.offset\n\t\t\t},\n\t\t\t(e) => {\n\t\t\t\tif (!latest.isLatest(ticket)) return\n\t\t\t\treadError = reason(e)\n\t\t\t}\n\t\t)\n\t}\n\n\t/** Ask again for the page on screen. */\n\tconst refresh = () => untrack(() => ready && ask(askParams()))\n\n\t// Each change of the search, sort, filter, page or page size asks again —\n\t// and a mark's line, refused or held, goes with the view it was said over.\n\t$effect(() => {\n\t\tif (!ready) return\n\t\tconst params = askParams()\n\t\tuntrack(() => {\n\t\t\tmarkError = null\n\t\t\tmarkHeld = null\n\t\t\task(params)\n\t\t})\n\t})\n\n\t// A turn wrote the rankings these entries read (R81): ask again.\n\t$effect(() => untrack(() => widget?.current?.on(\"lore:ranked\", refresh)))\n\n\t// A mark changed elsewhere — another widget, another tab, the entry\n\t// editor — on an entry shown here: ask again, so this list is never the\n\t// stale one. Showing only Pinned or Off, on any entry: the event names the\n\t// entry but not how this session reads it now, and it may have joined.\n\t$effect(() =>\n\t\tuntrack(() =>\n\t\t\twidget?.current?.on(\"lore:marked\", (e) => {\n\t\t\t\tif (e.kind !== \"lore:marked\") return\n\t\t\t\tif (filter === \"pinned\" || filter === \"off\" || answer?.rows.some((r) => r.id === e.entryId))\n\t\t\t\t\trefresh()\n\t\t\t})\n\t\t)\n\t)\n\n\tfunction setFilter(value: LoreEntriesFilter) {\n\t\tfilter = value\n\t\toffset = 0\n\t}\n\n\tasync function setMark(row: SessionEntryV1, mark: \"off\" | \"pinned\") {\n\t\tconst ctx = untrack(() => widget?.current)\n\t\tif (!ctx) return\n\t\tmarkError = null\n\t\tmarkHeld = null\n\t\ttry {\n\t\t\tconst now = await ctx.request(\"set-entry-marks\", {\n\t\t\t\tentryId: row.id,\n\t\t\t\t...(mark === \"off\" ? { off: !row.off } : { pinned: !row.pinned })\n\t\t\t})\n\t\t\tif (now.heldBy)\n\t\t\t\tmarkHeld = t(\n\t\t\t\t\tnow.heldBy.mark === \"off\"\n\t\t\t\t\t\t? \"Saved to the entry, but an amendment dated {date} still decides whether it is off here.\"\n\t\t\t\t\t\t: \"Saved to the entry, but an amendment dated {date} still decides whether it is pinned here.\"\n\t\t\t\t).replace(\"{date}\", now.heldBy.date)\n\t\t\tif (answer)\n\t\t\t\tanswer = {\n\t\t\t\t\t...answer,\n\t\t\t\t\trows: answer.rows.map((r) => (r.id === row.id ? { ...r, off: now.off, pinned: now.pinned } : r))\n\t\t\t\t}\n\t\t} catch (e) {\n\t\t\tmarkError = t(\"Not changed: {reason}\").replace(\"{reason}\", reason(e))\n\t\t}\n\t\t// What the filter shows may have moved either way.\n\t\trefresh()\n\t}\n\n\tconst span = $derived(answer ? loreEntriesSpan(offset, pageSize, answer.total) : null)\n\tconst readLine = (r: SessionEntryV1) => loreEntryReadLine(r, Date.now(), t)\n</script>\n\n<div data-widget-part=\"lore-entries.root\" data-widget=\"lore-entries\">\n\t{#if answer?.ownerOnly}\n\t\t<p data-widget-part=\"lore-entries.note\">\n\t\t\t{t(\"These entries are the lorebook owner's to manage.\")}\n\t\t</p>\n\t{:else if answer && answer.lorebookId === null}\n\t\t<p data-widget-part=\"lore-entries.note\">{t(\"This session reads no lorebook.\")}</p>\n\t{:else}\n\t\t<div data-widget-part=\"lore-entries.search-bar toolbar\">\n\t\t\t<label data-widget-part=\"lore-entries.search\">\n\t\t\t\t<span data-widget-part=\"lore-entries.search-label\">{t(\"Search entries by title or key\")}</span>\n\t\t\t\t<span data-widget-part=\"lore-entries.search-icon\">\n\t\t\t\t\t<sp-icon name=\"search\" size=\"14\"></sp-icon>\n\t\t\t\t</span>\n\t\t\t\t<input\n\t\t\t\t\ttype=\"text\"\n\t\t\t\t\tdata-widget-part=\"lore-entries.search-input\"\n\t\t\t\t\tplaceholder={answer\n\t\t\t\t\t\t? t(\"Search {total} entries\").replace(\"{total}\", String(answer.total))\n\t\t\t\t\t\t: t(\"Search entries\")}\n\t\t\t\t\tvalue={query}\n\t\t\t\t\toninput={(e) => {\n\t\t\t\t\t\tquery = e.currentTarget.value\n\t\t\t\t\t\toffset = 0\n\t\t\t\t\t}}\n\t\t\t\t/>\n\t\t\t</label>\n\t\t\t<button\n\t\t\t\ttype=\"button\"\n\t\t\t\tdata-widget-part=\"lore-entries.refresh\"\n\t\t\t\taria-label={t(\"Refresh\")}\n\t\t\t\ttitle={t(\"Refresh\")}\n\t\t\t\tonclick={refresh}\n\t\t\t>\n\t\t\t\t<sp-icon name=\"refresh-cw\" size=\"14\"></sp-icon>\n\t\t\t</button>\n\t\t</div>\n\t\t<div data-widget-part=\"lore-entries.filter-bar toolbar\">\n\t\t\t<div data-widget-part=\"lore-entries.filters\" role=\"radiogroup\" aria-label={t(\"Show\")}>\n\t\t\t\t{#each LORE_ENTRIES_FILTERS as f (f.value)}\n\t\t\t\t\t<!-- Chosen is the radio's own `:checked`: the sheet reads it, no state attribute. -->\n\t\t\t\t\t<label data-widget-part=\"lore-entries.filter chip\">\n\t\t\t\t\t\t<input\n\t\t\t\t\t\t\ttype=\"radio\"\n\t\t\t\t\t\t\tdata-widget-part=\"lore-entries.filter-input\"\n\t\t\t\t\t\t\tname={filterGroup}\n\t\t\t\t\t\t\tvalue={f.value}\n\t\t\t\t\t\t\tchecked={filter === f.value}\n\t\t\t\t\t\t\tonchange={() => setFilter(f.value)}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t{t(f.label)}\n\t\t\t\t\t</label>\n\t\t\t\t{/each}\n\t\t\t</div>\n\t\t\t<span data-widget-part=\"lore-entries.sort\">\n\t\t\t\t<!-- The combobox's own label is the one visible \"Sort\" (the host draws it). -->\n\t\t\t\t<sp-combobox\n\t\t\t\t\tdata-widget-part=\"lore-entries.sort-field\"\n\t\t\t\t\tlabel={t(\"Sort\")}\n\t\t\t\t\tvalue={effectiveSort}\n\t\t\t\t\tonchange={(e: CustomEvent<{ value: string }>) => {\n\t\t\t\t\t\tconst next = LORE_ENTRIES_SORTS.find((s) => s.value === e.detail.value)\n\t\t\t\t\t\tif (!next) return\n\t\t\t\t\t\tsort = next.value\n\t\t\t\t\t\toffset = 0\n\t\t\t\t\t}}\n\t\t\t\t>\n\t\t\t\t\t{#each LORE_ENTRIES_SORTS as o (o.value)}\n\t\t\t\t\t\t<sp-option value={o.value}>{t(o.label)}</sp-option>\n\t\t\t\t\t{/each}\n\t\t\t\t</sp-combobox>\n\t\t\t</span>\n\t\t</div>\n\n\t\t{#if readError}\n\t\t\t<p data-widget-part=\"lore-entries.alert\" role=\"alert\">{readError}</p>\n\t\t{/if}\n\t\t{#if markError}\n\t\t\t<p data-widget-part=\"lore-entries.alert\" role=\"alert\">{markError}</p>\n\t\t{/if}\n\t\t{#if markHeld}\n\t\t\t<p data-widget-part=\"lore-entries.held\" role=\"status\">{markHeld}</p>\n\t\t{/if}\n\n\t\t<ul data-widget-part=\"lore-entries.entries list\" aria-label={t(\"Lore entries\")}>\n\t\t\t{#each answer?.rows ?? [] as r (r.id)}\n\t\t\t\t<!-- Pressed marks are the buttons' own `aria-pressed`; an entry turned off is `data-off`. -->\n\t\t\t\t<li data-widget-part=\"lore-entries.entry row\" data-entry-id={r.id} data-off={r.off ? \"\" : undefined}>\n\t\t\t\t\t<span data-widget-part=\"lore-entries.entry-text\">\n\t\t\t\t\t\t<span data-widget-part=\"lore-entries.entry-title label\">\n\t\t\t\t\t\t\t{loreEntryName(r, t)}\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t{#if r.keys.length}\n\t\t\t\t\t\t\t<span data-widget-part=\"lore-entries.entry-keys\">{r.keys.join(t(\", \"))}</span>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t<span data-widget-part=\"lore-entries.entry-read\">{readLine(r)}</span>\n\t\t\t\t\t</span>\n\t\t\t\t\t<span data-widget-part=\"lore-entries.marks\">\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\tdata-widget-part=\"lore-entries.pin\"\n\t\t\t\t\t\t\taria-pressed={r.pinned}\n\t\t\t\t\t\t\taria-label={t(\"Pin {name}\").replace(\"{name}\", r.title || t(\"entry {id}\").replace(\"{id}\", String(r.id)))}\n\t\t\t\t\t\t\ttitle={r.pinned ? t(\"Pinned: always read\") : t(\"Pin: always read\")}\n\t\t\t\t\t\t\tonclick={() => setMark(r, \"pinned\")}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<sp-icon name=\"pin\" size=\"14\"></sp-icon>\n\t\t\t\t\t\t</button>\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\tdata-widget-part=\"lore-entries.off\"\n\t\t\t\t\t\t\taria-pressed={r.off}\n\t\t\t\t\t\t\taria-label={t(\"Turn {name} off\").replace(\"{name}\", r.title || t(\"entry {id}\").replace(\"{id}\", String(r.id)))}\n\t\t\t\t\t\t\ttitle={r.off ? t(\"Off: never read\") : t(\"Turn off: never read\")}\n\t\t\t\t\t\t\tonclick={() => setMark(r, \"off\")}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<sp-icon name=\"circle-off\" size=\"14\"></sp-icon>\n\t\t\t\t\t\t</button>\n\t\t\t\t\t</span>\n\t\t\t\t</li>\n\t\t\t{:else}\n\t\t\t\t{#if answer}\n\t\t\t\t\t<li data-widget-part=\"lore-entries.empty empty\">{loreEntriesEmptyLine(query, filter, t)}</li>\n\t\t\t\t{/if}\n\t\t\t{/each}\n\t\t</ul>\n\n\t\t{#if span?.paged}\n\t\t\t<div data-widget-part=\"lore-entries.pager\">\n\t\t\t\t<button\n\t\t\t\t\ttype=\"button\"\n\t\t\t\t\tdata-widget-part=\"lore-entries.previous\"\n\t\t\t\t\tdisabled={!span.hasPrevious}\n\t\t\t\t\tonclick={() => (offset = span.previousOffset)}\n\t\t\t\t>\n\t\t\t\t\t{t(\"Previous\")}\n\t\t\t\t</button>\n\t\t\t\t<span data-widget-part=\"lore-entries.page-count\">\n\t\t\t\t\t{t(\"{from}–{to} of {total}\")\n\t\t\t\t\t\t.replace(\"{from}\", String(span.from))\n\t\t\t\t\t\t.replace(\"{to}\", String(span.to))\n\t\t\t\t\t\t.replace(\"{total}\", String(span.total))}\n\t\t\t\t</span>\n\t\t\t\t<button\n\t\t\t\t\ttype=\"button\"\n\t\t\t\t\tdata-widget-part=\"lore-entries.next\"\n\t\t\t\t\tdisabled={!span.hasNext}\n\t\t\t\t\tonclick={() => (offset = span.nextOffset)}\n\t\t\t\t>\n\t\t\t\t\t{t(\"Next\")}\n\t\t\t\t</button>\n\t\t\t</div>\n\t\t{/if}\n\t{/if}\n</div>\n","sessions/lore-entries/lore-entries.ts":"/**\n * Core's `lore-entries` component (R21, R58): the session's lorebook entry\n * by entry, with what this session's rankings made of each, and the two\n * marks — **Off** and **Pin**. `npm run build` compiles it with the CLI's\n * component bundler to `dist/components/lore-entries.js`, the module the app\n * serves at `/core-ui/lore-entries`.\n */\nimport { svelteComponent } from '@serene-pub/component-client/svelte'\nimport LoreEntries from './LoreEntries.svelte'\n\nexport default svelteComponent(LoreEntries)\n","sessions/shared/context.ts":"/**\n * Core's widgets read their widget context with their own `getContext`, so\n * the lookup resolves in whichever Svelte runtime renders them — the\n * component's, in the page's UI worker. The key and the context's shape are\n * the host's contract (`@serene-pub/core-catalog/widgets`). Shared by every\n * core widget (R21); the conversation was the first.\n */\nimport { getContext } from 'svelte'\nimport { WIDGET_CONTEXT_KEY, type WidgetContextRef } from '@serene-pub/core-catalog/widgets'\n\n/** The widget context, if a host provides one; undefined outside a host (tests, a bare mount). */\nexport function useWidgetContext(): WidgetContextRef | undefined {\n\treturn getContext<WidgetContextRef | undefined>(WIDGET_CONTEXT_KEY)\n}\n","sessions/shared/widgetRef.svelte.ts":"/**\n * A remote's widget context (C0b): the component context a UI worker hands\n * a component, as the native `WidgetContext` core's widgets read\n * (`useWidgetContext`). So a core widget — written against the native\n * context — runs in a worker with no change to its source: the same\n * sections, the same verbs, reaching the host over the component's port.\n * Shared by every core widget (R21); the conversation was the first.\n */\nimport {\n\tEMPTY_TURN_ORDER,\n\tWIDGET_PROTOCOL,\n\ttype ComponentContext,\n\ttype LayoutV1,\n\ttype ViewerV1,\n\ttype WidgetEvent,\n\ttype WidgetEventKind\n} from \"@serene-pub/sdk/component\"\nimport {\n\tWIDGET_SCOPED_SECTIONS,\n\ttype WidgetContext,\n\ttype WidgetContextRef,\n\ttype WidgetScopedData\n} from \"@serene-pub/core-catalog/widgets\"\n\n/** Every scoped section's posted name — the SDK's one table, read once. */\nconst SCOPED_NAMES = Object.values(WIDGET_SCOPED_SECTIONS)\n\nconst NOBODY: ViewerV1 = { userId: null, isAdmin: false, isGuest: false }\n\n/**\n * A remote's context carries its saved view state besides: what it saved\n * last mount (`state`) and the host's save-state channel (`saveState`) —\n * read by core's widgets off the context where a remote has them.\n */\ntype RemoteWidgetContext = WidgetContext & {\n\tstate: unknown\n\tsaveState: (state: unknown) => void\n}\n\n/** The granted scoped sections as the envelope carries them: `{ <name>: { v1 } }`, absent when not granted. */\nfunction scopedData(scoped: ComponentContext[\"scoped\"]): WidgetScopedData {\n\tconst out: Record<string, { v1: unknown }> = {}\n\tfor (const name of SCOPED_NAMES) if (scoped[name] !== undefined) out[name] = { v1: scoped[name] }\n\treturn out as WidgetScopedData\n}\n\nexport function widgetRefFromComponent(\n\tctx: ComponentContext,\n\twidget: WidgetContext[\"widget\"]\n): WidgetContextRef {\n\t// Any section the host pushes re-projects the context, as a native\n\t// host's re-projection does.\n\tlet version = $state(0)\n\tctx.subscribe(() => version++)\n\n\tconst current = $derived.by((): RemoteWidgetContext => {\n\t\tvoid version\n\t\tconst scoped = ctx.scoped ?? {}\n\t\treturn {\n\t\t\tprotocol: WIDGET_PROTOCOL,\n\t\t\twidget,\n\t\t\tlayout: { v1: (ctx.layout ?? {}) as LayoutV1 },\n\t\t\tsession: { v1: (ctx.session ?? { id: 0, name: null }) as WidgetContext[\"session\"][\"v1\"] },\n\t\t\tchannels: { v1: Object.keys(ctx.channels ?? {}) },\n\t\t\tmessages: { v1: (ctx.messages ?? []) as WidgetContext[\"messages\"][\"v1\"] },\n\t\t\tprops: { v1: ctx.props ?? {} },\n\t\t\tactions: { v1: (ctx.actions ?? {}) as WidgetContext[\"actions\"][\"v1\"] },\n\t\t\tsettings: { v1: ctx.settings ?? {} },\n\t\t\tannex: { v1: (ctx.annex ?? {}) as WidgetContext[\"annex\"][\"v1\"] },\n\t\t\tlocale: { v1: ctx.locale ?? \"en\" },\n\t\t\tviewer: { v1: ctx.viewer ?? NOBODY },\n\t\t\tturnOrder: { v1: ctx.turnOrder ?? EMPTY_TURN_ORDER },\n\t\t\t// What the host said this widget holds — absent until it has — so a\n\t\t\t// widget can tell a scope never granted apart from a section not yet posted.\n\t\t\tgrants: ctx.grants,\n\t\t\t// The scoped sections the host granted, each as its `{ v1 }` bag — by\n\t\t\t// the table, so a section the SDK adds arrives with no change here.\n\t\t\t...scopedData(scoped),\n\t\t\taction: (fn, messageId, payload, action, blockId) => ctx.action(fn, messageId, payload, action, blockId),\n\t\t\tinvoke: (key, args) => ctx.invoke(key, args),\n\t\t\trequest: ((kind, params) => ctx.request(kind, params)) as WidgetContext[\"request\"],\n\t\t\t// No host menu across the port yet: dismissed, as a native host without one answers.\n\t\t\tmenu: async () => null,\n\t\t\ton: (kind: WidgetEventKind | \"*\", cb: (e: WidgetEvent) => void) =>\n\t\t\t\tctx.onEvent((e) => {\n\t\t\t\t\tconst ev = e as WidgetEvent\n\t\t\t\t\tif (kind === \"*\" || ev.kind === kind) cb(ev)\n\t\t\t\t}),\n\t\t\tt: (source) => ctx.t(source),\n\t\t\tstate: ctx.state,\n\t\t\tsaveState: (state) => ctx.saveState(state)\n\t\t}\n\t})\n\n\treturn {\n\t\tget current() {\n\t\t\treturn current\n\t\t}\n\t}\n}\n"},"sourceHash":"dc0302b4eea4eb7f1aa80aef26956a2ff614d7a4f42e288fa9ebb669c684b088","catalogVersion":"0.6.0-pr-1"}
|
|
1
|
+
{"slug":"lore-entries","framework":"svelte","entry":"sessions/lore-entries/lore-entries.ts","files":{"sessions/lore-entries/LoreEntries.svelte":"<script lang=\"ts\">\n\t/**\n\t * Core's Lore entries widget as a remote component (R21): the component\n\t * context, as the native widget context, around `LoreEntriesWidget`.\n\t *\n\t * The widget asks the page for its first page only once its settings\n\t * have arrived: the page posts a widget's settings (it reads them) right\n\t * after it says ready, and an ask made before would be spent on the\n\t * declared defaults instead of this instance's sort and page size.\n\t */\n\timport { setContext, untrack } from \"svelte\"\n\timport type { ComponentContext } from \"@serene-pub/sdk/component\"\n\timport { WIDGET_CONTEXT_KEY } from \"@serene-pub/core-catalog/widgets\"\n\timport LoreEntriesWidget from \"./LoreEntriesWidget.svelte\"\n\timport { widgetRefFromComponent } from \"../shared/widgetRef.svelte\"\n\n\tlet { ctx }: { ctx: ComponentContext } = $props()\n\n\tlet settled = $state(untrack(() => ctx.settings) !== undefined)\n\t$effect(() =>\n\t\tuntrack(() => ctx).subscribe((section) => {\n\t\t\tif (section === \"settings\") settled = true\n\t\t})\n\t)\n\n\t// The context is the mount's, handed once: its sections move, it does not.\n\tsetContext(\n\t\tWIDGET_CONTEXT_KEY,\n\t\twidgetRefFromComponent(\n\t\t\tuntrack(() => ctx),\n\t\t\t{ id: \"lore-entries\", instanceId: \"lore-entries\", title: \"Lore entries\" }\n\t\t)\n\t)\n</script>\n\n<LoreEntriesWidget ready={settled} />\n","sessions/lore-entries/LoreEntriesWidget.svelte":"<script lang=\"ts\">\n\t/**\n\t * Lore entries (PLAN-sdk-1.0 §3.9, R58; R21 port): the session's lorebook\n\t * entry by entry, with what this session's rankings made of each, and the\n\t * two marks — **Off** and **Pin** — which never force a re-embed.\n\t *\n\t * It reads its settings alone. Everything else is asked of the page: one\n\t * `session-entries` does the search, sort, filter and paging for the\n\t * page's own session (the declared `lore` scope is the grant for it), and\n\t * `set-entry-marks` sets a mark. The page answers every ask with its own\n\t * reply, so which answer to show is this widget's: its latest-ask guard.\n\t * A turn that writes the rankings tells it `lore:ranked` (R81), and it\n\t * pages again; so does a mark set anywhere else on an entry it shows, or\n\t * on any entry while it shows only Pinned or Off (`lore:marked`). The\n\t * refresh button stays.\n\t *\n\t * What goes wrong is said here, in this widget (R77) — never a toast every\n\t * lore widget shows. The book's owner and admins see the entries; anyone\n\t * else is told whose they are, because a widget declaration has no\n\t * visibility field of its own. So is a mark saved to the entry that a\n\t * dated amendment still decides in this session's story (the answer's\n\t * `heldBy`): the row reads as before, and the line says why.\n\t *\n\t * The markup carries no look (P3d): its elements carry `lore-entries.*`\n\t * widget parts and the default widget stylesheet draws them (STYLE-GUIDE\n\t * §6.16). State is the elements' own: a chosen filter is its radio's\n\t * `:checked`, a pressed mark its button's `aria-pressed`, an entry turned\n\t * off `data-off`.\n\t */\n\timport { untrack } from \"svelte\"\n\timport type { SessionEntryV1, WidgetRequests } from \"@serene-pub/sdk/component\"\n\timport {\n\t\tLORE_ENTRIES_FILTERS,\n\t\tLORE_ENTRIES_SORTS,\n\t\tcreateLatestAsk,\n\t\tloreEntriesEmptyLine,\n\t\tloreEntriesSpan,\n\t\tloreEntryName,\n\t\tloreEntryReadLine,\n\t\treadLoreEntriesSettings,\n\t\ttype LoreEntriesFilter,\n\t\ttype LoreEntriesSort\n\t} from \"@serene-pub/core-catalog/lore-entries\"\n\timport { useWidgetContext } from \"../shared/context\"\n\n\ttype Answer = WidgetRequests[\"session-entries\"][\"result\"]\n\ttype Ask = WidgetRequests[\"session-entries\"][\"params\"]\n\n\t/** Whether to ask the page yet: false until the host has posted this instance's settings. */\n\tlet { ready = true }: { ready?: boolean } = $props()\n\n\tconst widget = useWidgetContext()\n\tconst t = (source: string): string => widget?.current?.t(source) ?? source\n\n\t// Primitives, so a push that changes neither asks nothing again.\n\tconst pageSize = $derived(\n\t\treadLoreEntriesSettings(widget?.current?.settings?.v1 as Record<string, unknown> | undefined).pageSize\n\t)\n\tconst settledSort = $derived(\n\t\treadLoreEntriesSettings(widget?.current?.settings?.v1 as Record<string, unknown> | undefined).sort\n\t)\n\n\tlet query = $state(\"\")\n\tlet sort = $state<LoreEntriesSort | null>(null)\n\tconst effectiveSort = $derived<LoreEntriesSort>(sort ?? settledSort)\n\tlet filter = $state<LoreEntriesFilter>(\"all\")\n\tlet offset = $state(0)\n\n\tlet answer = $state<Answer | null>(null)\n\t/** Why the page could not be read, this widget's own. */\n\tlet readError = $state<string | null>(null)\n\t/** Why a mark did not change, this widget's own. */\n\tlet markError = $state<string | null>(null)\n\t/**\n\t * A mark saved to the entry that a dated amendment still decides here\n\t * (`heldBy`): the row reads as before, and this says why.\n\t */\n\tlet markHeld = $state<string | null>(null)\n\n\t/** The filter radios' group name: one per mount, so two copies never share a group (F8). */\n\tconst filterGroup = `sp-lore-filter-${Math.random().toString(36).slice(2, 10)}`\n\n\tconst latest = createLatestAsk()\n\tconst reason = (e: unknown) => (e instanceof Error ? e.message : String(e))\n\n\t// The search asks once typing pauses, not once per keystroke.\n\tlet searched = $state(\"\")\n\t$effect(() => {\n\t\tconst q = query.trim()\n\t\tconst timer = setTimeout(() => (searched = q), 250)\n\t\treturn () => clearTimeout(timer)\n\t})\n\n\tconst askParams = (): Ask => ({\n\t\t...(searched ? { titleOrKey: searched } : {}),\n\t\tsort: effectiveSort,\n\t\tfilter,\n\t\toffset,\n\t\tlimit: pageSize\n\t})\n\n\tfunction ask(params: Ask) {\n\t\tconst ctx = widget?.current\n\t\tif (!ctx) return\n\t\tconst ticket = latest.next()\n\t\tctx.request(\"session-entries\", params).then(\n\t\t\t(res) => {\n\t\t\t\tif (!latest.isLatest(ticket)) return\n\t\t\t\treadError = null\n\t\t\t\tanswer = res\n\t\t\t\t// The page pulls a page that ran past the end back to the last one.\n\t\t\t\tif (typeof res.offset === \"number\" && res.offset !== offset) offset = res.offset\n\t\t\t},\n\t\t\t(e) => {\n\t\t\t\tif (!latest.isLatest(ticket)) return\n\t\t\t\treadError = reason(e)\n\t\t\t}\n\t\t)\n\t}\n\n\t/** Ask again for the page on screen. */\n\tconst refresh = () => untrack(() => ready && ask(askParams()))\n\n\t// Each change of the search, sort, filter, page or page size asks again —\n\t// and a mark's line, refused or held, goes with the view it was said over.\n\t$effect(() => {\n\t\tif (!ready) return\n\t\tconst params = askParams()\n\t\tuntrack(() => {\n\t\t\tmarkError = null\n\t\t\tmarkHeld = null\n\t\t\task(params)\n\t\t})\n\t})\n\n\t// A turn wrote the rankings these entries read (R81): ask again.\n\t$effect(() => untrack(() => widget?.current?.on(\"lore:ranked\", refresh)))\n\n\t// A mark changed elsewhere — another widget, another tab, the entry\n\t// editor — on an entry shown here: ask again, so this list is never the\n\t// stale one. Showing only Pinned or Off, on any entry: the event names the\n\t// entry but not how this session reads it now, and it may have joined.\n\t$effect(() =>\n\t\tuntrack(() =>\n\t\t\twidget?.current?.on(\"lore:marked\", (e) => {\n\t\t\t\tif (e.kind !== \"lore:marked\") return\n\t\t\t\tif (filter === \"pinned\" || filter === \"off\" || answer?.rows.some((r) => r.id === e.entryId))\n\t\t\t\t\trefresh()\n\t\t\t})\n\t\t)\n\t)\n\n\tfunction setFilter(value: LoreEntriesFilter) {\n\t\tfilter = value\n\t\toffset = 0\n\t}\n\n\tasync function setMark(row: SessionEntryV1, mark: \"off\" | \"pinned\") {\n\t\tconst ctx = untrack(() => widget?.current)\n\t\tif (!ctx) return\n\t\tmarkError = null\n\t\tmarkHeld = null\n\t\ttry {\n\t\t\tconst now = await ctx.request(\"set-entry-marks\", {\n\t\t\t\tentryId: row.id,\n\t\t\t\t...(mark === \"off\" ? { off: !row.off } : { pinned: !row.pinned })\n\t\t\t})\n\t\t\tif (now.heldBy)\n\t\t\t\tmarkHeld = t(\n\t\t\t\t\tnow.heldBy.mark === \"off\"\n\t\t\t\t\t\t? \"Saved to the entry, but an amendment dated {date} still decides whether it is off here.\"\n\t\t\t\t\t\t: \"Saved to the entry, but an amendment dated {date} still decides whether it is pinned here.\"\n\t\t\t\t).replace(\"{date}\", now.heldBy.date)\n\t\t\tif (answer)\n\t\t\t\tanswer = {\n\t\t\t\t\t...answer,\n\t\t\t\t\trows: answer.rows.map((r) => (r.id === row.id ? { ...r, off: now.off, pinned: now.pinned } : r))\n\t\t\t\t}\n\t\t} catch (e) {\n\t\t\tmarkError = t(\"Not changed: {reason}\").replace(\"{reason}\", reason(e))\n\t\t}\n\t\t// What the filter shows may have moved either way.\n\t\trefresh()\n\t}\n\n\tconst span = $derived(answer ? loreEntriesSpan(offset, pageSize, answer.total) : null)\n\tconst readLine = (r: SessionEntryV1) => loreEntryReadLine(r, Date.now(), t)\n</script>\n\n<div data-widget-part=\"lore-entries.root\" data-widget=\"lore-entries\">\n\t{#if answer?.ownerOnly}\n\t\t<p data-widget-part=\"lore-entries.note\">\n\t\t\t{t(\"These entries are the lorebook owner's to manage.\")}\n\t\t</p>\n\t{:else if answer && answer.lorebookId === null}\n\t\t<p data-widget-part=\"lore-entries.note\">{t(\"This session reads no lorebook.\")}</p>\n\t{:else}\n\t\t<div data-widget-part=\"lore-entries.search-bar toolbar\">\n\t\t\t<label data-widget-part=\"lore-entries.search\">\n\t\t\t\t<span data-widget-part=\"lore-entries.search-label\">{t(\"Search entries by title or key\")}</span>\n\t\t\t\t<span data-widget-part=\"lore-entries.search-icon\">\n\t\t\t\t\t<sp-icon name=\"search\" size=\"14\"></sp-icon>\n\t\t\t\t</span>\n\t\t\t\t<input\n\t\t\t\t\ttype=\"text\"\n\t\t\t\t\tdata-widget-part=\"lore-entries.search-input\"\n\t\t\t\t\tplaceholder={answer\n\t\t\t\t\t\t? t(\"Search {total} entries\").replace(\"{total}\", String(answer.total))\n\t\t\t\t\t\t: t(\"Search entries\")}\n\t\t\t\t\tvalue={query}\n\t\t\t\t\toninput={(e) => {\n\t\t\t\t\t\tquery = e.currentTarget.value\n\t\t\t\t\t\toffset = 0\n\t\t\t\t\t}}\n\t\t\t\t/>\n\t\t\t</label>\n\t\t\t<button\n\t\t\t\ttype=\"button\"\n\t\t\t\tdata-widget-part=\"lore-entries.refresh\"\n\t\t\t\taria-label={t(\"Refresh\")}\n\t\t\t\ttitle={t(\"Refresh\")}\n\t\t\t\tonclick={refresh}\n\t\t\t>\n\t\t\t\t<sp-icon name=\"refresh-cw\" size=\"14\"></sp-icon>\n\t\t\t</button>\n\t\t</div>\n\t\t<div data-widget-part=\"lore-entries.filter-bar toolbar\">\n\t\t\t<div data-widget-part=\"lore-entries.filters\" role=\"radiogroup\" aria-label={t(\"Show\")}>\n\t\t\t\t{#each LORE_ENTRIES_FILTERS as f (f.value)}\n\t\t\t\t\t<!-- Chosen is the radio's own `:checked`: the sheet reads it, no state attribute. -->\n\t\t\t\t\t<label data-widget-part=\"lore-entries.filter chip\">\n\t\t\t\t\t\t<input\n\t\t\t\t\t\t\ttype=\"radio\"\n\t\t\t\t\t\t\tdata-widget-part=\"lore-entries.filter-input\"\n\t\t\t\t\t\t\tname={filterGroup}\n\t\t\t\t\t\t\tvalue={f.value}\n\t\t\t\t\t\t\tchecked={filter === f.value}\n\t\t\t\t\t\t\tonchange={() => setFilter(f.value)}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t{t(f.label)}\n\t\t\t\t\t</label>\n\t\t\t\t{/each}\n\t\t\t</div>\n\t\t\t<span data-widget-part=\"lore-entries.sort\">\n\t\t\t\t<!-- The combobox's own label is the one visible \"Sort\" (the host draws it). -->\n\t\t\t\t<sp-combobox\n\t\t\t\t\tdata-widget-part=\"lore-entries.sort-field\"\n\t\t\t\t\tlabel={t(\"Sort\")}\n\t\t\t\t\tvalue={effectiveSort}\n\t\t\t\t\tonchange={(e: CustomEvent<{ value: string }>) => {\n\t\t\t\t\t\tconst next = LORE_ENTRIES_SORTS.find((s) => s.value === e.detail.value)\n\t\t\t\t\t\tif (!next) return\n\t\t\t\t\t\tsort = next.value\n\t\t\t\t\t\toffset = 0\n\t\t\t\t\t}}\n\t\t\t\t>\n\t\t\t\t\t{#each LORE_ENTRIES_SORTS as o (o.value)}\n\t\t\t\t\t\t<sp-option value={o.value}>{t(o.label)}</sp-option>\n\t\t\t\t\t{/each}\n\t\t\t\t</sp-combobox>\n\t\t\t</span>\n\t\t</div>\n\n\t\t{#if readError}\n\t\t\t<p data-widget-part=\"lore-entries.alert\" role=\"alert\">{readError}</p>\n\t\t{/if}\n\t\t{#if markError}\n\t\t\t<p data-widget-part=\"lore-entries.alert\" role=\"alert\">{markError}</p>\n\t\t{/if}\n\t\t{#if markHeld}\n\t\t\t<p data-widget-part=\"lore-entries.held\" role=\"status\">{markHeld}</p>\n\t\t{/if}\n\n\t\t<ul data-widget-part=\"lore-entries.entries list\" aria-label={t(\"Lore entries\")}>\n\t\t\t{#each answer?.rows ?? [] as r (r.id)}\n\t\t\t\t<!-- Pressed marks are the buttons' own `aria-pressed`; an entry turned off is `data-off`. -->\n\t\t\t\t<li data-widget-part=\"lore-entries.entry row\" data-entry-id={r.id} data-off={r.off ? \"\" : undefined}>\n\t\t\t\t\t<span data-widget-part=\"lore-entries.entry-text\">\n\t\t\t\t\t\t<span data-widget-part=\"lore-entries.entry-title label\">\n\t\t\t\t\t\t\t{loreEntryName(r, t)}\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t{#if r.keys.length}\n\t\t\t\t\t\t\t<span data-widget-part=\"lore-entries.entry-keys\">{r.keys.join(t(\", \"))}</span>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t<span data-widget-part=\"lore-entries.entry-read\">{readLine(r)}</span>\n\t\t\t\t\t</span>\n\t\t\t\t\t<span data-widget-part=\"lore-entries.marks\">\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\tdata-widget-part=\"lore-entries.pin\"\n\t\t\t\t\t\t\taria-pressed={r.pinned}\n\t\t\t\t\t\t\taria-label={t(\"Pin {name}\").replace(\"{name}\", r.title || t(\"entry {id}\").replace(\"{id}\", String(r.id)))}\n\t\t\t\t\t\t\ttitle={r.pinned ? t(\"Pinned: always read\") : t(\"Pin: always read\")}\n\t\t\t\t\t\t\tonclick={() => setMark(r, \"pinned\")}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<sp-icon name=\"pin\" size=\"14\"></sp-icon>\n\t\t\t\t\t\t</button>\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\tdata-widget-part=\"lore-entries.off\"\n\t\t\t\t\t\t\taria-pressed={r.off}\n\t\t\t\t\t\t\taria-label={t(\"Turn {name} off\").replace(\"{name}\", r.title || t(\"entry {id}\").replace(\"{id}\", String(r.id)))}\n\t\t\t\t\t\t\ttitle={r.off ? t(\"Off: never read\") : t(\"Turn off: never read\")}\n\t\t\t\t\t\t\tonclick={() => setMark(r, \"off\")}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<sp-icon name=\"circle-off\" size=\"14\"></sp-icon>\n\t\t\t\t\t\t</button>\n\t\t\t\t\t</span>\n\t\t\t\t</li>\n\t\t\t{:else}\n\t\t\t\t{#if answer}\n\t\t\t\t\t<li data-widget-part=\"lore-entries.empty empty\">{loreEntriesEmptyLine(query, filter, t)}</li>\n\t\t\t\t{/if}\n\t\t\t{/each}\n\t\t</ul>\n\n\t\t{#if span?.paged}\n\t\t\t<div data-widget-part=\"lore-entries.pager\">\n\t\t\t\t<button\n\t\t\t\t\ttype=\"button\"\n\t\t\t\t\tdata-widget-part=\"lore-entries.previous\"\n\t\t\t\t\tdisabled={!span.hasPrevious}\n\t\t\t\t\tonclick={() => (offset = span.previousOffset)}\n\t\t\t\t>\n\t\t\t\t\t{t(\"Previous\")}\n\t\t\t\t</button>\n\t\t\t\t<span data-widget-part=\"lore-entries.page-count\">\n\t\t\t\t\t{t(\"{from}–{to} of {total}\")\n\t\t\t\t\t\t.replace(\"{from}\", String(span.from))\n\t\t\t\t\t\t.replace(\"{to}\", String(span.to))\n\t\t\t\t\t\t.replace(\"{total}\", String(span.total))}\n\t\t\t\t</span>\n\t\t\t\t<button\n\t\t\t\t\ttype=\"button\"\n\t\t\t\t\tdata-widget-part=\"lore-entries.next\"\n\t\t\t\t\tdisabled={!span.hasNext}\n\t\t\t\t\tonclick={() => (offset = span.nextOffset)}\n\t\t\t\t>\n\t\t\t\t\t{t(\"Next\")}\n\t\t\t\t</button>\n\t\t\t</div>\n\t\t{/if}\n\t{/if}\n</div>\n","sessions/lore-entries/lore-entries.ts":"/**\n * Core's `lore-entries` component (R21, R58): the session's lorebook entry\n * by entry, with what this session's rankings made of each, and the two\n * marks — **Off** and **Pin**. `npm run build` compiles it with the CLI's\n * component bundler to `dist/components/lore-entries.js`, the module the app\n * serves at `/core-ui/lore-entries`.\n */\nimport { svelteComponent } from '@serene-pub/component-client/svelte'\nimport LoreEntries from './LoreEntries.svelte'\n\nexport default svelteComponent(LoreEntries)\n","sessions/shared/context.ts":"/**\n * Core's widgets read their widget context with their own `getContext`, so\n * the lookup resolves in whichever Svelte runtime renders them — the\n * component's, in the page's UI worker. The key and the context's shape are\n * the host's contract (`@serene-pub/core-catalog/widgets`). Shared by every\n * core widget (R21); the conversation was the first.\n */\nimport { getContext } from 'svelte'\nimport { WIDGET_CONTEXT_KEY, type WidgetContextRef } from '@serene-pub/core-catalog/widgets'\n\n/** The widget context, if a host provides one; undefined outside a host (tests, a bare mount). */\nexport function useWidgetContext(): WidgetContextRef | undefined {\n\treturn getContext<WidgetContextRef | undefined>(WIDGET_CONTEXT_KEY)\n}\n","sessions/shared/widgetRef.svelte.ts":"/**\n * A remote's widget context (C0b): the component context a UI worker hands\n * a component, as the native `WidgetContext` core's widgets read\n * (`useWidgetContext`). So a core widget — written against the native\n * context — runs in a worker with no change to its source: the same\n * sections, the same verbs, reaching the host over the component's port.\n * Shared by every core widget (R21); the conversation was the first.\n */\nimport {\n\tEMPTY_TURN_ORDER,\n\tWIDGET_PROTOCOL,\n\ttype ComponentContext,\n\ttype LayoutV1,\n\ttype ViewerV1,\n\ttype WidgetEvent,\n\ttype WidgetEventKind\n} from \"@serene-pub/sdk/component\"\nimport {\n\tWIDGET_SCOPED_SECTIONS,\n\ttype WidgetContext,\n\ttype WidgetContextRef,\n\ttype WidgetScopedData\n} from \"@serene-pub/core-catalog/widgets\"\n\n/** Every scoped section's posted name — the SDK's one table, read once. */\nconst SCOPED_NAMES = Object.values(WIDGET_SCOPED_SECTIONS)\n\nconst NOBODY: ViewerV1 = { userId: null, isAdmin: false, isGuest: false }\n\n/**\n * A remote's context carries its saved view state besides: what it saved\n * last mount (`state`) and the host's save-state channel (`saveState`) —\n * read by core's widgets off the context where a remote has them.\n */\ntype RemoteWidgetContext = WidgetContext & {\n\tstate: unknown\n\tsaveState: (state: unknown) => void\n}\n\n/** The granted scoped sections as the envelope carries them: `{ <name>: { v1 } }`, absent when not granted. */\nfunction scopedData(scoped: ComponentContext[\"scoped\"]): WidgetScopedData {\n\tconst out: Record<string, { v1: unknown }> = {}\n\tfor (const name of SCOPED_NAMES) if (scoped[name] !== undefined) out[name] = { v1: scoped[name] }\n\treturn out as WidgetScopedData\n}\n\nexport function widgetRefFromComponent(\n\tctx: ComponentContext,\n\twidget: WidgetContext[\"widget\"]\n): WidgetContextRef {\n\t// Any section the host pushes re-projects the context, as a native\n\t// host's re-projection does.\n\tlet version = $state(0)\n\tctx.subscribe(() => version++)\n\n\tconst current = $derived.by((): RemoteWidgetContext => {\n\t\tvoid version\n\t\tconst scoped = ctx.scoped ?? {}\n\t\treturn {\n\t\t\tprotocol: WIDGET_PROTOCOL,\n\t\t\twidget,\n\t\t\tlayout: { v1: (ctx.layout ?? {}) as LayoutV1 },\n\t\t\tsession: { v1: (ctx.session ?? { id: 0, name: null }) as WidgetContext[\"session\"][\"v1\"] },\n\t\t\tchannels: { v1: Object.keys(ctx.channels ?? {}) },\n\t\t\tmessages: { v1: (ctx.messages ?? []) as WidgetContext[\"messages\"][\"v1\"] },\n\t\t\tprops: { v1: ctx.props ?? {} },\n\t\t\tactions: { v1: (ctx.actions ?? {}) as WidgetContext[\"actions\"][\"v1\"] },\n\t\t\tsettings: { v1: ctx.settings ?? {} },\n\t\t\tannex: { v1: (ctx.annex ?? {}) as WidgetContext[\"annex\"][\"v1\"] },\n\t\t\tlocale: { v1: ctx.locale ?? \"en\" },\n\t\t\tviewer: { v1: ctx.viewer ?? NOBODY },\n\t\t\tturnOrder: { v1: ctx.turnOrder ?? EMPTY_TURN_ORDER },\n\t\t\t// What the host said this widget holds — absent until it has — so a\n\t\t\t// widget can tell a scope never granted apart from a section not yet posted.\n\t\t\tgrants: ctx.grants,\n\t\t\t// The scoped sections the host granted, each as its `{ v1 }` bag — by\n\t\t\t// the table, so a section the SDK adds arrives with no change here.\n\t\t\t...scopedData(scoped),\n\t\t\taction: (fn, messageId, payload, action, blockId) => ctx.action(fn, messageId, payload, action, blockId),\n\t\t\tinvoke: (key, args) => ctx.invoke(key, args),\n\t\t\trequest: ((kind, params) => ctx.request(kind, params)) as WidgetContext[\"request\"],\n\t\t\t// No host menu across the port yet: dismissed, as a native host without one answers.\n\t\t\tmenu: async () => null,\n\t\t\ton: (kind: WidgetEventKind | \"*\", cb: (e: WidgetEvent) => void) =>\n\t\t\t\tctx.onEvent((e) => {\n\t\t\t\t\tconst ev = e as WidgetEvent\n\t\t\t\t\tif (kind === \"*\" || ev.kind === kind) cb(ev)\n\t\t\t\t}),\n\t\t\tt: (source) => ctx.t(source),\n\t\t\tstate: ctx.state,\n\t\t\tsaveState: (state) => ctx.saveState(state)\n\t\t}\n\t})\n\n\treturn {\n\t\tget current() {\n\t\t\treturn current\n\t\t}\n\t}\n}\n"},"sourceHash":"dc0302b4eea4eb7f1aa80aef26956a2ff614d7a4f42e288fa9ebb669c684b088","catalogVersion":"0.6.0-pr-2"}
|