@blogmcp/community 0.4.1 → 0.5.1
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/blogmcp-community-private.global.js +8 -0
- package/dist/blogmcp-community.global.js +3 -3
- package/dist/chunks/{mount-Ts_r2fwt.js → mount-SKmc4NgD.js} +39 -9
- package/dist/chunks/private-mount-BgfUSd3g.js +5548 -0
- package/dist/core/attrs.d.ts +15 -0
- package/dist/core/settings.d.ts +5 -0
- package/dist/index.js +2 -2
- package/dist/private/core/dock.d.ts +38 -0
- package/dist/private/core/push.d.ts +49 -0
- package/dist/private/core/realtime.d.ts +57 -0
- package/dist/private/core/setup.d.ts +43 -0
- package/dist/private/core/view.d.ts +179 -0
- package/dist/private/dm/composer.d.ts +34 -0
- package/dist/private/dm/controller.d.ts +162 -0
- package/dist/private/dm/index.d.ts +14 -0
- package/dist/private/dm/links.d.ts +33 -0
- package/dist/private/dm/muted.d.ts +37 -0
- package/dist/private/dm/search.d.ts +7 -0
- package/dist/private/dm/text.d.ts +27 -0
- package/dist/private/dm/ui/DmBlocks.vue.d.ts +8 -0
- package/dist/private/dm/ui/DmCases.vue.d.ts +8 -0
- package/dist/private/dm/ui/DmComposer.vue.d.ts +20 -0
- package/dist/private/dm/ui/DmInbox.vue.d.ts +12 -0
- package/dist/private/dm/ui/DmLinkWarning.vue.d.ts +8 -0
- package/dist/private/dm/ui/DmLocalAids.vue.d.ts +8 -0
- package/dist/private/dm/ui/DmMessageText.vue.d.ts +8 -0
- package/dist/private/dm/ui/DmNew.vue.d.ts +12 -0
- package/dist/private/dm/ui/DmReport.vue.d.ts +8 -0
- package/dist/private/dm/ui/DmRequests.vue.d.ts +12 -0
- package/dist/private/dm/ui/DmScreens.vue.d.ts +9 -0
- package/dist/private/dm/ui/DmThread.vue.d.ts +9 -0
- package/dist/private/element.d.ts +23 -0
- package/dist/private/global.d.ts +10 -0
- package/dist/private/i18n.d.ts +41 -0
- package/dist/private/index.d.ts +32 -0
- package/dist/private/index.js +57 -0
- package/dist/private/mount.d.ts +55 -0
- package/dist/private/pages/api.d.ts +44 -0
- package/dist/private/pages/element.d.ts +6 -0
- package/dist/private/pages/fragment.d.ts +43 -0
- package/dist/private/pages/i18n.d.ts +25 -0
- package/dist/private/pages/index.d.ts +1 -0
- package/dist/private/pages/pages.d.ts +276 -0
- package/dist/private/pages/proof.d.ts +36 -0
- package/dist/private/pages/provider-view.d.ts +33 -0
- package/dist/private/pages/setup.d.ts +42 -0
- package/dist/private/pages/ui/AccountPageRoot.vue.d.ts +9 -0
- package/dist/private/pages/ui/PageActivation.vue.d.ts +9 -0
- package/dist/private/pages/ui/PageAddress.vue.d.ts +8 -0
- package/dist/private/pages/ui/PageDeviceApprove.vue.d.ts +8 -0
- package/dist/private/pages/ui/PageDevices.vue.d.ts +8 -0
- package/dist/private/pages/ui/PageExport.vue.d.ts +8 -0
- package/dist/private/pages/ui/PageMessages.vue.d.ts +9 -0
- package/dist/private/react.d.ts +12 -0
- package/dist/private/react.js +36 -0
- package/dist/private/ui/ChatDockRoot.vue.d.ts +20 -0
- package/dist/private/ui/LegalBlocks.vue.d.ts +10 -0
- package/dist/private/ui/LegalRun.vue.d.ts +7 -0
- package/dist/private/ui/LegalRuns.vue.d.ts +6 -0
- package/dist/private/ui/LegalText.vue.d.ts +13 -0
- package/dist/private/ui/PrivateScreens.vue.d.ts +14 -0
- package/dist/private/ui/PrivateViewRoot.vue.d.ts +23 -0
- package/dist/private/ui/PromiseBlock.vue.d.ts +9 -0
- package/dist/private/ui/ProviderLine.vue.d.ts +8 -0
- package/dist/private/ui/ScreenActivation.vue.d.ts +8 -0
- package/dist/private/ui/ScreenAddress.vue.d.ts +8 -0
- package/dist/private/ui/ScreenApproval.vue.d.ts +8 -0
- package/dist/private/ui/ScreenDevices.vue.d.ts +8 -0
- package/dist/private/ui/ScreenHome.vue.d.ts +12 -0
- package/dist/private/ui/ScreenNotifications.vue.d.ts +8 -0
- package/dist/private/ui/ScreenReads.vue.d.ts +8 -0
- package/dist/private/ui/ScreenSettings.vue.d.ts +8 -0
- package/dist/private/ui/legal.d.ts +15 -0
- package/dist/private/ui/root.d.ts +35 -0
- package/dist/private/ui/text.d.ts +22 -0
- package/dist/private/vue.d.ts +88 -0
- package/dist/private/vue.js +72 -0
- package/dist/react.js +14 -14
- package/dist/vue.js +14 -14
- package/package.json +23 -6
- package/src/core/attrs.ts +19 -0
- package/src/core/settings.ts +55 -12
- package/src/private/core/dock.ts +105 -0
- package/src/private/core/push.ts +166 -0
- package/src/private/core/realtime.ts +109 -0
- package/src/private/core/setup.ts +75 -0
- package/src/private/core/view.ts +920 -0
- package/src/private/dm/composer.ts +74 -0
- package/src/private/dm/controller.ts +636 -0
- package/src/private/dm/index.ts +14 -0
- package/src/private/dm/links.ts +55 -0
- package/src/private/dm/muted.ts +160 -0
- package/src/private/dm/search.ts +18 -0
- package/src/private/dm/text.ts +60 -0
- package/src/private/dm/ui/DmBlocks.vue +27 -0
- package/src/private/dm/ui/DmCases.vue +58 -0
- package/src/private/dm/ui/DmComposer.vue +68 -0
- package/src/private/dm/ui/DmInbox.vue +34 -0
- package/src/private/dm/ui/DmLinkWarning.vue +27 -0
- package/src/private/dm/ui/DmLocalAids.vue +43 -0
- package/src/private/dm/ui/DmMessageText.vue +16 -0
- package/src/private/dm/ui/DmNew.vue +46 -0
- package/src/private/dm/ui/DmReport.vue +93 -0
- package/src/private/dm/ui/DmRequests.vue +50 -0
- package/src/private/dm/ui/DmScreens.vue +66 -0
- package/src/private/dm/ui/DmThread.vue +235 -0
- package/src/private/element.ts +90 -0
- package/src/private/global.ts +14 -0
- package/src/private/i18n.ts +127 -0
- package/src/private/index.ts +68 -0
- package/src/private/messages/cs.json +311 -0
- package/src/private/messages/en.json +319 -0
- package/src/private/mount.ts +103 -0
- package/src/private/pages/api.ts +96 -0
- package/src/private/pages/build.d.mts +2 -0
- package/src/private/pages/build.mjs +72 -0
- package/src/private/pages/element.ts +49 -0
- package/src/private/pages/fragment.ts +63 -0
- package/src/private/pages/i18n.ts +82 -0
- package/src/private/pages/index.ts +10 -0
- package/src/private/pages/messages/cs.json +97 -0
- package/src/private/pages/messages/en.json +97 -0
- package/src/private/pages/pages.ts +410 -0
- package/src/private/pages/proof.ts +110 -0
- package/src/private/pages/provider-view.ts +121 -0
- package/src/private/pages/setup.ts +79 -0
- package/src/private/pages/ui/AccountPageRoot.vue +45 -0
- package/src/private/pages/ui/PageActivation.vue +42 -0
- package/src/private/pages/ui/PageAddress.vue +39 -0
- package/src/private/pages/ui/PageDeviceApprove.vue +62 -0
- package/src/private/pages/ui/PageDevices.vue +84 -0
- package/src/private/pages/ui/PageExport.vue +35 -0
- package/src/private/pages/ui/PageMessages.vue +39 -0
- package/src/private/pages/ui/account.css +6 -0
- package/src/private/react.ts +49 -0
- package/src/private/shims.d.ts +6 -0
- package/src/private/ui/ChatDockRoot.vue +119 -0
- package/src/private/ui/LegalBlocks.vue +30 -0
- package/src/private/ui/LegalRun.vue +13 -0
- package/src/private/ui/LegalRuns.vue +20 -0
- package/src/private/ui/LegalText.vue +25 -0
- package/src/private/ui/PrivateScreens.vue +61 -0
- package/src/private/ui/PrivateViewRoot.vue +70 -0
- package/src/private/ui/PromiseBlock.vue +18 -0
- package/src/private/ui/ProviderLine.vue +20 -0
- package/src/private/ui/ScreenActivation.vue +82 -0
- package/src/private/ui/ScreenAddress.vue +37 -0
- package/src/private/ui/ScreenApproval.vue +71 -0
- package/src/private/ui/ScreenDevices.vue +42 -0
- package/src/private/ui/ScreenHome.vue +29 -0
- package/src/private/ui/ScreenNotifications.vue +44 -0
- package/src/private/ui/ScreenReads.vue +23 -0
- package/src/private/ui/ScreenSettings.vue +44 -0
- package/src/private/ui/legal.ts +29 -0
- package/src/private/ui/private.css +90 -0
- package/src/private/ui/root.ts +89 -0
- package/src/private/ui/text.ts +40 -0
- package/src/private/vue.ts +87 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* The private settings (DM3's `settings/get|set`): who may write to the member, within the preset's ceiling (B-52),
|
|
4
|
+
* read receipts and typing. Until DM3 serves them the screen says they come with private messages.
|
|
5
|
+
*/
|
|
6
|
+
import { computed } from 'vue'
|
|
7
|
+
import { DM_AUDIENCES, type PrivateViewController } from '../core/view'
|
|
8
|
+
import type { Lang } from '../i18n'
|
|
9
|
+
import DmLocalAids from '../dm/ui/DmLocalAids.vue'
|
|
10
|
+
import { screenText } from './text'
|
|
11
|
+
|
|
12
|
+
const props = defineProps<{ controller: PrivateViewController; lang: Lang }>()
|
|
13
|
+
const tx = computed(() => screenText(props.lang))
|
|
14
|
+
const s = computed(() => props.controller.state)
|
|
15
|
+
const audiences = computed(() => {
|
|
16
|
+
const ceiling = s.value.settings?.ceiling
|
|
17
|
+
return ceiling ? DM_AUDIENCES.slice(0, DM_AUDIENCES.indexOf(ceiling) + 1) : []
|
|
18
|
+
})
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<template>
|
|
22
|
+
<section class="bcm-p-screen" data-screen="settings">
|
|
23
|
+
<h2>{{ tx.pt('private.settings.title') }}</h2>
|
|
24
|
+
<p v-if="s.settingsUnavailable" data-settings-unavailable>{{ tx.pt('private.settings.unavailable') }}</p>
|
|
25
|
+
<form v-else-if="s.settings" class="bcm-p-form" @submit.prevent>
|
|
26
|
+
<fieldset>
|
|
27
|
+
<legend>{{ tx.pt('private.settings.audience') }}</legend>
|
|
28
|
+
<label v-for="a in audiences" :key="a" class="bcm-p-check">
|
|
29
|
+
<input type="radio" name="dmAudience" :value="a" :checked="s.settings.values.dmAudience === a" :data-audience="a" @change="controller.setSetting('dmAudience', a)" />
|
|
30
|
+
{{ tx.pt(`private.settings.audience.${a}`) }}
|
|
31
|
+
</label>
|
|
32
|
+
</fieldset>
|
|
33
|
+
<label class="bcm-p-check">
|
|
34
|
+
<input type="checkbox" :checked="s.settings.values.dmReadReceipts" data-setting="dmReadReceipts" @change="controller.setSetting('dmReadReceipts', ($event.target as HTMLInputElement).checked)" />
|
|
35
|
+
{{ tx.pt('private.settings.readReceipts') }}
|
|
36
|
+
</label>
|
|
37
|
+
<label class="bcm-p-check">
|
|
38
|
+
<input type="checkbox" :checked="s.settings.values.dmTyping" data-setting="dmTyping" @change="controller.setSetting('dmTyping', ($event.target as HTMLInputElement).checked)" />
|
|
39
|
+
{{ tx.pt('private.settings.typing') }}
|
|
40
|
+
</label>
|
|
41
|
+
</form>
|
|
42
|
+
<DmLocalAids v-if="s.dm" :dm="s.dm" :lang="lang" />
|
|
43
|
+
</section>
|
|
44
|
+
</template>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A legal text's blocks on a private screen (m4-contracts.md §5.11 "Formatting"): `legalTextBlocks` of the SDK parses
|
|
3
|
+
* the body's Markdown subset, and the components render the blocks as elements with text in them — never as markup.
|
|
4
|
+
* The session's placeholders are filled in the runs, after parsing, so a filled value is never read as Markdown.
|
|
5
|
+
*/
|
|
6
|
+
import type { LegalTextBlock, LegalTextRun } from '@blogmcp/sdk/community'
|
|
7
|
+
|
|
8
|
+
/** The blocks with every run's text passed through `fill`. */
|
|
9
|
+
export function fillBlocks(blocks: readonly LegalTextBlock[], fill: (text: string) => string): LegalTextBlock[] {
|
|
10
|
+
return blocks.map((b): LegalTextBlock => {
|
|
11
|
+
if (b.type === 'list') return { ...b, items: b.items.map((item) => ({ blocks: fillBlocks(item.blocks, fill) })) }
|
|
12
|
+
return { ...b, runs: b.runs.map((r) => ({ ...r, text: fill(r.text) })) }
|
|
13
|
+
})
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Consecutive runs of one link together (one `<a>`), the rest one by one with no href. */
|
|
17
|
+
export function linkGroups(runs: readonly LegalTextRun[]): Array<{ href: string | null; runs: LegalTextRun[] }> {
|
|
18
|
+
const out: Array<{ href: string | null; runs: LegalTextRun[] }> = []
|
|
19
|
+
for (const run of runs) {
|
|
20
|
+
const href = run.href ?? null
|
|
21
|
+
const last = out[out.length - 1]
|
|
22
|
+
if (href !== null && last && last.href === href) last.runs.push(run)
|
|
23
|
+
else out.push({ href, runs: [run] })
|
|
24
|
+
}
|
|
25
|
+
return out
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** A text's heading level on a screen: two below the screen's own `<h2>`, at most `<h6>`. */
|
|
29
|
+
export const headingLevel = (level: number): 3 | 4 | 5 | 6 => Math.min(6, Math.max(3, level + 2)) as 3 | 4 | 5 | 6
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/* The private elements' one stylesheet (each shadow root carries it, with the CSP nonce). Colours follow the host's
|
|
2
|
+
`color-scheme`; a host themes them through the custom properties below. */
|
|
3
|
+
:host {
|
|
4
|
+
--bcm-p-fg: CanvasText;
|
|
5
|
+
--bcm-p-bg: Canvas;
|
|
6
|
+
--bcm-p-muted: GrayText;
|
|
7
|
+
--bcm-p-accent: #2f6f4f;
|
|
8
|
+
--bcm-p-danger: #a3261f;
|
|
9
|
+
--bcm-p-radius: 10px;
|
|
10
|
+
display: block;
|
|
11
|
+
font: inherit;
|
|
12
|
+
color: var(--bcm-p-fg);
|
|
13
|
+
}
|
|
14
|
+
/* The host hides the dock on a page without unmounting it (§6.2): its session and windows stay. */
|
|
15
|
+
:host([hidden-by-host]) {
|
|
16
|
+
display: none !important;
|
|
17
|
+
}
|
|
18
|
+
:host([hidden]) {
|
|
19
|
+
display: none;
|
|
20
|
+
}
|
|
21
|
+
.bcm-p-root { box-sizing: border-box; }
|
|
22
|
+
.bcm-p-root *, .bcm-p-root *::before, .bcm-p-root *::after { box-sizing: inherit; }
|
|
23
|
+
.bcm-p-screen h2 { font-size: 1.15em; margin: 0 0 0.5em; }
|
|
24
|
+
.bcm-p-screen h3 { font-size: 1em; margin: 0.75em 0 0.25em; }
|
|
25
|
+
.bcm-p-muted { color: var(--bcm-p-muted); font-size: 0.9em; }
|
|
26
|
+
.bcm-p-note { border-left: 3px solid var(--bcm-p-accent); padding-left: 0.6em; }
|
|
27
|
+
.bcm-p-warning { border-left: 3px solid var(--bcm-p-danger); padding-left: 0.6em; }
|
|
28
|
+
.bcm-p-error { color: var(--bcm-p-danger); }
|
|
29
|
+
.bcm-p-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
|
|
30
|
+
.bcm-p-btn {
|
|
31
|
+
font: inherit; cursor: pointer; border: 1px solid currentColor; background: transparent; color: inherit;
|
|
32
|
+
border-radius: var(--bcm-p-radius); padding: 0.45em 0.9em; margin: 0.2em 0.4em 0.2em 0;
|
|
33
|
+
}
|
|
34
|
+
.bcm-p-btn:disabled { opacity: 0.55; cursor: default; }
|
|
35
|
+
.bcm-p-primary { background: var(--bcm-p-accent); border-color: var(--bcm-p-accent); color: #fff; }
|
|
36
|
+
.bcm-p-danger { border-color: var(--bcm-p-danger); color: var(--bcm-p-danger); }
|
|
37
|
+
.bcm-p-link { font: inherit; background: none; border: 0; padding: 0.2em 0; color: var(--bcm-p-accent); cursor: pointer; text-decoration: underline; }
|
|
38
|
+
.bcm-p-icon { font: inherit; background: none; border: 0; cursor: pointer; font-size: 1.3em; line-height: 1; color: inherit; }
|
|
39
|
+
.bcm-p-input { font: inherit; padding: 0.45em; border: 1px solid var(--bcm-p-muted); border-radius: var(--bcm-p-radius); min-width: 10ch; }
|
|
40
|
+
.bcm-p-row { display: flex; gap: 0.5em; align-items: center; flex-wrap: wrap; }
|
|
41
|
+
.bcm-p-actions { display: flex; flex-wrap: wrap; gap: 0.25em; margin: 0.5em 0; }
|
|
42
|
+
.bcm-p-list, .bcm-p-menu { list-style: none; padding: 0; margin: 0.5em 0; }
|
|
43
|
+
.bcm-p-list > li { border-top: 1px solid color-mix(in srgb, var(--bcm-p-muted) 35%, transparent); padding: 0.5em 0; }
|
|
44
|
+
.bcm-p-unread { font-weight: 600; }
|
|
45
|
+
.bcm-p-badge { display: inline-block; font-size: 0.8em; border: 1px solid var(--bcm-p-muted); border-radius: 999px; padding: 0 0.5em; margin-left: 0.4em; }
|
|
46
|
+
.bcm-p-code { font-family: ui-monospace, monospace; font-size: 1.4em; letter-spacing: 0.15em; }
|
|
47
|
+
.bcm-p-check { display: flex; gap: 0.5em; align-items: flex-start; margin: 0.4em 0; }
|
|
48
|
+
.bcm-p-legal { margin: 0.75em 0; }
|
|
49
|
+
.bcm-p-legal-body { white-space: pre-wrap; max-height: 18em; overflow: auto; border: 1px solid color-mix(in srgb, var(--bcm-p-muted) 35%, transparent); border-radius: var(--bcm-p-radius); padding: 0.6em; }
|
|
50
|
+
/* A legal text's blocks (LegalBlocks): the same scroll box; a run's `\n` is a hard line break. */
|
|
51
|
+
.bcm-p-legal-doc { max-height: 18em; overflow: auto; overflow-wrap: anywhere; white-space: pre-line; border: 1px solid color-mix(in srgb, var(--bcm-p-muted) 35%, transparent); border-radius: var(--bcm-p-radius); padding: 0 0.6em; }
|
|
52
|
+
.bcm-p-legal-doc h3, .bcm-p-legal-doc h4, .bcm-p-legal-doc h5, .bcm-p-legal-doc h6 { font-size: 1em; margin: 0.9em 0 0.3em; }
|
|
53
|
+
.bcm-p-legal-doc h3 { font-size: 1.08em; }
|
|
54
|
+
.bcm-p-legal-doc p { margin: 0.5em 0; }
|
|
55
|
+
.bcm-p-legal-doc ul, .bcm-p-legal-doc ol { margin: 0.5em 0; padding-left: 1.4em; }
|
|
56
|
+
.bcm-p-legal-doc li > p { margin: 0.2em 0; }
|
|
57
|
+
.bcm-p-legal-doc code { font-family: ui-monospace, monospace; font-size: 0.92em; }
|
|
58
|
+
.bcm-p-legal-doc a { color: inherit; }
|
|
59
|
+
.bcm-p-provider { margin-top: 1em; font-size: 0.85em; color: var(--bcm-p-muted); }
|
|
60
|
+
.bcm-p-provider-links a { margin-right: 0.8em; color: inherit; }
|
|
61
|
+
.bcm-p-dot { display: inline-block; width: 0.6em; height: 0.6em; border-radius: 50%; background: var(--bcm-p-danger); margin-left: 0.35em; vertical-align: middle; }
|
|
62
|
+
/* The dock: fixed to the bottom corner, windows beside the launcher. */
|
|
63
|
+
.bcm-p-dock { position: fixed; right: 16px; bottom: 16px; z-index: 2147483000; display: flex; align-items: flex-end; gap: 12px; }
|
|
64
|
+
.bcm-p-launcher {
|
|
65
|
+
font: inherit; cursor: pointer; border: 0; border-radius: 999px; padding: 0.7em 1.1em; background: var(--bcm-p-accent); color: #fff;
|
|
66
|
+
box-shadow: 0 4px 16px rgb(0 0 0 / 0.2); text-decoration: none;
|
|
67
|
+
}
|
|
68
|
+
.bcm-p-panel, .bcm-p-window {
|
|
69
|
+
background: var(--bcm-p-bg); border-radius: var(--bcm-p-radius); box-shadow: 0 8px 28px rgb(0 0 0 / 0.25);
|
|
70
|
+
width: 320px; max-height: 70vh; overflow: auto; padding: 0.8em;
|
|
71
|
+
}
|
|
72
|
+
.bcm-p-windows { display: flex; gap: 12px; align-items: flex-end; }
|
|
73
|
+
.bcm-p-window-head { display: flex; justify-content: space-between; align-items: center; gap: 0.5em; }
|
|
74
|
+
.bcm-p-window-head h2 { font-size: 1em; margin: 0; }
|
|
75
|
+
/* A phone: a window takes the whole screen. */
|
|
76
|
+
.bcm-p-mobile .bcm-p-window { position: fixed; inset: 0; width: auto; max-height: none; border-radius: 0; }
|
|
77
|
+
.bcm-p-mobile .bcm-p-panel { position: fixed; left: 8px; right: 8px; bottom: 72px; width: auto; }
|
|
78
|
+
/* The conversations (DM8b): the member's own messages to the right, search hits marked, the composer full width. */
|
|
79
|
+
.bcm-p-dm-messages > li { position: relative; padding-right: 2em; }
|
|
80
|
+
.bcm-p-dm-messages > li > .bcm-p-icon { position: absolute; top: 0.4em; right: 0; }
|
|
81
|
+
.bcm-p-dm-mine { text-align: right; }
|
|
82
|
+
.bcm-p-dm-mine .bcm-p-actions { justify-content: flex-end; }
|
|
83
|
+
.bcm-p-dm-hit { background: color-mix(in srgb, var(--bcm-p-accent) 14%, transparent); }
|
|
84
|
+
.bcm-p-dm-body { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0.2em 0; }
|
|
85
|
+
.bcm-p-dm-meta { margin: 0; }
|
|
86
|
+
.bcm-p-dm-box { width: 100%; resize: vertical; }
|
|
87
|
+
.bcm-p-dm-sentence p { margin: 0.15em 0; }
|
|
88
|
+
.bcm-p-dm-href { overflow-wrap: anywhere; }
|
|
89
|
+
.bcm-p-dm-tabs { margin: 0.25em 0 0.75em; }
|
|
90
|
+
.bcm-p-dm-tabs [aria-current='page'] { font-weight: 600; text-decoration: none; }
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What both private roots share: their props (attributes, and the `transport`, `client` and `push` properties), the
|
|
3
|
+
* setup from them, and the private-root mark on the host element (`markPrivateRoot`, §6.1, §7.1). The mark makes the
|
|
4
|
+
* host pause its analytics and RUM, so it is on only while the root may show something private: from the moment the
|
|
5
|
+
* host's `me/get` names a private block that is live or read_only and rendered here — before the private client is
|
|
6
|
+
* asked anything — through the private screens, a reload of them and a refusal said in their place. It is off for a
|
|
7
|
+
* visitor, on a dark instance, under `provider_page` (only a link to the account host), when the setup is refused and
|
|
8
|
+
* after a refusal no retry cures (FINAL_REFUSALS), and it goes with the element. A dock in the root layout is therefore unmarked on every page of a signed-out visitor.
|
|
9
|
+
*/
|
|
10
|
+
import { computed, onBeforeUnmount, onMounted, shallowRef, useHost, watch, type ComputedRef, type ShallowRef } from 'vue'
|
|
11
|
+
import { markPrivateRoot, type PrivateClient } from '@blogmcp/sdk/community/private'
|
|
12
|
+
import type { CommunityTransport } from '@blogmcp/sdk/community'
|
|
13
|
+
import { documentLang, pickLang, type Lang } from '../i18n'
|
|
14
|
+
import { privateSetupFor, type PrivateSetup } from '../core/setup'
|
|
15
|
+
import type { PrivatePushPort } from '../core/push'
|
|
16
|
+
import type { PrivateRealtimeInput } from '../core/realtime'
|
|
17
|
+
import { isFinalFailure } from '../core/view'
|
|
18
|
+
|
|
19
|
+
export interface PrivateRootProps {
|
|
20
|
+
kbOrigin?: string
|
|
21
|
+
apiBase?: string
|
|
22
|
+
siteBase?: string
|
|
23
|
+
routes?: string
|
|
24
|
+
lang?: string
|
|
25
|
+
siteName?: string
|
|
26
|
+
swPath?: string
|
|
27
|
+
accountOrigin?: string
|
|
28
|
+
transport?: CommunityTransport
|
|
29
|
+
client?: PrivateClient
|
|
30
|
+
push?: PrivatePushPort | null
|
|
31
|
+
realtime?: PrivateRealtimeInput
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface PrivateRoot {
|
|
35
|
+
setup: ShallowRef<PrivateSetup | null>
|
|
36
|
+
lang: ComputedRef<Lang>
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function usePrivateRoot(props: PrivateRootProps): PrivateRoot {
|
|
40
|
+
const host = useHost()
|
|
41
|
+
const setup = shallowRef<PrivateSetup | null>(null)
|
|
42
|
+
const lang = computed(() => pickLang(props.lang, documentLang()))
|
|
43
|
+
let unmark: (() => void) | null = null
|
|
44
|
+
|
|
45
|
+
function start(): void {
|
|
46
|
+
setup.value?.controller.dispose()
|
|
47
|
+
setup.value = privateSetupFor({
|
|
48
|
+
kbOrigin: props.kbOrigin,
|
|
49
|
+
apiBase: props.apiBase,
|
|
50
|
+
siteBase: props.siteBase,
|
|
51
|
+
routes: props.routes,
|
|
52
|
+
siteName: props.siteName,
|
|
53
|
+
swPath: props.swPath,
|
|
54
|
+
accountOrigin: props.accountOrigin,
|
|
55
|
+
transport: props.transport,
|
|
56
|
+
client: props.client,
|
|
57
|
+
...(props.push !== undefined ? { push: props.push } : {}),
|
|
58
|
+
realtime: props.realtime ?? null,
|
|
59
|
+
})
|
|
60
|
+
void setup.value?.controller.load()
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Whether something private may be on screen (see the module doc). */
|
|
64
|
+
const privateOnPage = computed(() => {
|
|
65
|
+
const s = setup.value?.controller.state
|
|
66
|
+
if (!s) return false
|
|
67
|
+
const b = s.block
|
|
68
|
+
const admitted = b !== null && (b.state === 'live' || b.state === 'read_only') && b.rendering !== 'provider_page'
|
|
69
|
+
// A refusal no retry cures (FINAL_REFUSALS) ends the private part of the page: the mark goes with it.
|
|
70
|
+
return admitted && (s.phase === 'ready' || s.phase === 'loading' || (s.phase === 'failed' && !isFinalFailure(s)))
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
onMounted(() => start())
|
|
74
|
+
watch(privateOnPage, (on) => {
|
|
75
|
+
if (on && !unmark && host) unmark = markPrivateRoot(host)
|
|
76
|
+
else if (!on && unmark) {
|
|
77
|
+
unmark()
|
|
78
|
+
unmark = null
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
// The attributes that change who or where the session is make a new controller; the language does not.
|
|
82
|
+
watch(() => [props.kbOrigin, props.apiBase, props.siteBase, props.routes, props.transport, props.client, props.realtime] as const, () => start())
|
|
83
|
+
onBeforeUnmount(() => {
|
|
84
|
+
setup.value?.controller.dispose()
|
|
85
|
+
unmark?.()
|
|
86
|
+
unmark = null
|
|
87
|
+
})
|
|
88
|
+
return { setup, lang }
|
|
89
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The screens' words: catalogue keys turned into text in the element's language (i18n.ts), a controller's text
|
|
3
|
+
* reference (an `error:<CODE>` one is its refusal's sentence), and a date.
|
|
4
|
+
*/
|
|
5
|
+
import { formatWhen, errorKey, privateMessage, type Lang, type PrivateParams } from '../i18n'
|
|
6
|
+
import type { PrivateTextRef } from '../core/view'
|
|
7
|
+
|
|
8
|
+
export interface ScreenText {
|
|
9
|
+
pt(key: string, params?: PrivateParams): string
|
|
10
|
+
refText(ref: PrivateTextRef | null): string
|
|
11
|
+
when(iso: string | null | undefined, withTime?: boolean): string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function screenText(lang: Lang): ScreenText {
|
|
15
|
+
return {
|
|
16
|
+
pt: (key, params) => privateMessage(lang, key, params),
|
|
17
|
+
refText(ref) {
|
|
18
|
+
if (!ref) return ''
|
|
19
|
+
if (ref.msg.startsWith('error:')) return privateMessage(lang, errorKey(ref.msg.slice('error:'.length)))
|
|
20
|
+
return privateMessage(lang, ref.msg, ref.params)
|
|
21
|
+
},
|
|
22
|
+
when: (iso, withTime = true) => formatWhen(lang, iso, withTime),
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** An https address kb-api handed over (the address link, the provider's links), or null: nothing else is a link. */
|
|
27
|
+
export function httpsHref(value: string | null | undefined): string | null {
|
|
28
|
+
return typeof value === 'string' && /^https:\/\/[^\s/?#]+(?:[/?#][^\s]*)?$/i.test(value) ? value : null
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A served text with the session's placeholders filled from `display` (§5.11: `{{device_label}}`, `{{approval_email}}`
|
|
33
|
+
* — masked on this screen, B-63 —, `{{accepted_at}}`); the text stays text.
|
|
34
|
+
*/
|
|
35
|
+
export function fillDisplay(body: string, display: { approvalEmail: string | null; deviceLabel: string } | null | undefined, acceptedAt: string): string {
|
|
36
|
+
return body
|
|
37
|
+
.replace(/\{\{device_label\}\}/g, display?.deviceLabel ?? '')
|
|
38
|
+
.replace(/\{\{approval_email\}\}/g, display?.approvalEmail ?? '')
|
|
39
|
+
.replace(/\{\{accepted_at\}\}/g, acceptedAt)
|
|
40
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `<KbChatDock>` and `<KbPrivateView>` for Vue / Nuxt (m4-contracts.md §6.2): each mounts its element on the client,
|
|
3
|
+
* after hydration, and removes it on unmount; each renders one empty `<div>` as the mount point. The element's module
|
|
4
|
+
* (which imports the browser-only `@blogmcp/sdk/community/private`) is imported lazily, so a server render never
|
|
5
|
+
* loads it. `<KbChatDock>` belongs in the root layout: a client-side navigation then keeps its session and windows,
|
|
6
|
+
* and `hidden-by-host` hides it on a page without unmounting it.
|
|
7
|
+
*/
|
|
8
|
+
import { defineComponent, h, onBeforeUnmount, onMounted, ref, watch, type PropType } from 'vue'
|
|
9
|
+
import type { CommunityTransport } from '@blogmcp/sdk/community'
|
|
10
|
+
import type { PrivateClient } from '@blogmcp/sdk/community/private'
|
|
11
|
+
import type { CommunityRoutes } from '../core/attrs'
|
|
12
|
+
import type { PrivateDockRealtime } from './core/dock'
|
|
13
|
+
import type { MountChatDockOptions, MountPrivateViewOptions } from './mount'
|
|
14
|
+
|
|
15
|
+
const HIDDEN_BY_HOST = 'hidden-by-host'
|
|
16
|
+
|
|
17
|
+
function defined<T extends object>(o: T): T {
|
|
18
|
+
const out = {} as T
|
|
19
|
+
for (const [k, v] of Object.entries(o)) if (v !== undefined && v !== null) (out as Record<string, unknown>)[k] = v
|
|
20
|
+
return out
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const commonProps = {
|
|
24
|
+
kbOrigin: { type: String, required: true },
|
|
25
|
+
apiBase: String,
|
|
26
|
+
siteBase: String,
|
|
27
|
+
lang: String,
|
|
28
|
+
routes: Object as PropType<CommunityRoutes>,
|
|
29
|
+
siteName: String,
|
|
30
|
+
swPath: String,
|
|
31
|
+
accountOrigin: String,
|
|
32
|
+
nonce: String,
|
|
33
|
+
transport: Function as PropType<CommunityTransport>,
|
|
34
|
+
client: Object as PropType<PrivateClient>,
|
|
35
|
+
/** The live inbox: the SDK's `createPrivateRealtime`, or a source of the host's own (`{ subscribe }`). */
|
|
36
|
+
realtime: [Function, Object] as PropType<PrivateDockRealtime>,
|
|
37
|
+
} as const
|
|
38
|
+
|
|
39
|
+
function useMount<O extends object>(kind: string, options: () => O, load: () => Promise<(o: O & { container: Element }) => () => void>, after?: (el: Element | null) => void) {
|
|
40
|
+
const host = ref<HTMLElement | null>(null)
|
|
41
|
+
let unmount: (() => void) | null = null
|
|
42
|
+
let gone = false
|
|
43
|
+
let ticket = 0
|
|
44
|
+
async function mount(): Promise<void> {
|
|
45
|
+
const mine = ++ticket
|
|
46
|
+
const mountFn = await load()
|
|
47
|
+
if (gone || mine !== ticket || !host.value) return
|
|
48
|
+
unmount?.()
|
|
49
|
+
unmount = mountFn({ ...options(), container: host.value })
|
|
50
|
+
after?.(host.value.firstElementChild)
|
|
51
|
+
}
|
|
52
|
+
onMounted(() => void mount())
|
|
53
|
+
watch(
|
|
54
|
+
() => JSON.stringify(options(), (_k, v: unknown) => (typeof v === 'function' ? '[fn]' : v)),
|
|
55
|
+
() => void mount(),
|
|
56
|
+
)
|
|
57
|
+
onBeforeUnmount(() => {
|
|
58
|
+
gone = true
|
|
59
|
+
unmount?.()
|
|
60
|
+
unmount = null
|
|
61
|
+
})
|
|
62
|
+
return host
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export const KbChatDock = defineComponent({
|
|
66
|
+
name: 'KbChatDock',
|
|
67
|
+
props: { ...commonProps, hiddenByHost: Boolean },
|
|
68
|
+
setup(props) {
|
|
69
|
+
// `hiddenByHost` is applied to the element in place (never by mounting it anew): that is the point of the attribute.
|
|
70
|
+
const opts = (): MountChatDockOptions => defined({ ...props, hiddenByHost: undefined }) as MountChatDockOptions
|
|
71
|
+
const host = useMount('chat-dock', opts, async () => (await import('./mount')).mountChatDock, (el) => el?.toggleAttribute(HIDDEN_BY_HOST, props.hiddenByHost))
|
|
72
|
+
watch(
|
|
73
|
+
() => props.hiddenByHost,
|
|
74
|
+
(hidden) => host.value?.firstElementChild?.toggleAttribute(HIDDEN_BY_HOST, hidden),
|
|
75
|
+
)
|
|
76
|
+
return () => h('div', { ref: host, 'data-blogmcp-community': 'chat-dock' })
|
|
77
|
+
},
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
export const KbPrivateView = defineComponent({
|
|
81
|
+
name: 'KbPrivateView',
|
|
82
|
+
props: { ...commonProps, screen: String },
|
|
83
|
+
setup(props) {
|
|
84
|
+
const host = useMount('private-view', () => defined({ ...props }) as MountPrivateViewOptions, async () => (await import('./mount')).mountPrivateView)
|
|
85
|
+
return () => h('div', { ref: host, 'data-blogmcp-community': 'private-view' })
|
|
86
|
+
},
|
|
87
|
+
})
|