@dovetail-ts/ember 0.0.0-stage → 1.0.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/CHANGELOG.md +38 -0
- package/LICENSE +21 -0
- package/README.md +180 -2
- package/addon-main.cjs +4 -0
- package/declarations/-private/status-dot.d.ts +14 -0
- package/declarations/-private/status-dot.d.ts.map +1 -0
- package/declarations/-private/visually-hidden.d.ts +6 -0
- package/declarations/-private/visually-hidden.d.ts.map +1 -0
- package/declarations/components/dovetail/avatar-stack.d.ts +31 -0
- package/declarations/components/dovetail/avatar-stack.d.ts.map +1 -0
- package/declarations/components/dovetail/connection-badge.d.ts +24 -0
- package/declarations/components/dovetail/connection-badge.d.ts.map +1 -0
- package/declarations/components/dovetail/dead-letters.d.ts +25 -0
- package/declarations/components/dovetail/dead-letters.d.ts.map +1 -0
- package/declarations/components/dovetail/editor.d.ts +58 -0
- package/declarations/components/dovetail/editor.d.ts.map +1 -0
- package/declarations/components/dovetail/live-cursors.d.ts +31 -0
- package/declarations/components/dovetail/live-cursors.d.ts.map +1 -0
- package/declarations/components/dovetail/presence.d.ts +27 -0
- package/declarations/components/dovetail/presence.d.ts.map +1 -0
- package/declarations/components/dovetail/sync-status.d.ts +25 -0
- package/declarations/components/dovetail/sync-status.d.ts.map +1 -0
- package/declarations/components/dovetail/typing.d.ts +17 -0
- package/declarations/components/dovetail/typing.d.ts.map +1 -0
- package/declarations/editor.d.ts +3 -0
- package/declarations/editor.d.ts.map +1 -0
- package/declarations/index.d.ts +25 -0
- package/declarations/index.d.ts.map +1 -0
- package/declarations/live.d.ts +46 -0
- package/declarations/live.d.ts.map +1 -0
- package/declarations/people.d.ts +51 -0
- package/declarations/people.d.ts.map +1 -0
- package/declarations/services/dovetail.d.ts +90 -0
- package/declarations/services/dovetail.d.ts.map +1 -0
- package/declarations/status.d.ts +16 -0
- package/declarations/status.d.ts.map +1 -0
- package/dist/_app_/components/dovetail/avatar-stack.js +1 -0
- package/dist/_app_/components/dovetail/connection-badge.js +1 -0
- package/dist/_app_/components/dovetail/dead-letters.js +1 -0
- package/dist/_app_/components/dovetail/editor.js +1 -0
- package/dist/_app_/components/dovetail/live-cursors.js +1 -0
- package/dist/_app_/components/dovetail/presence.js +1 -0
- package/dist/_app_/components/dovetail/sync-status.js +1 -0
- package/dist/_app_/components/dovetail/typing.js +1 -0
- package/dist/_app_/services/dovetail.js +1 -0
- package/dist/components/dovetail/avatar-stack.js +52 -0
- package/dist/components/dovetail/avatar-stack.js.map +1 -0
- package/dist/components/dovetail/connection-badge.js +43 -0
- package/dist/components/dovetail/connection-badge.js.map +1 -0
- package/dist/components/dovetail/dead-letters.js +47 -0
- package/dist/components/dovetail/dead-letters.js.map +1 -0
- package/dist/components/dovetail/editor.js +107 -0
- package/dist/components/dovetail/editor.js.map +1 -0
- package/dist/components/dovetail/live-cursors.js +46 -0
- package/dist/components/dovetail/live-cursors.js.map +1 -0
- package/dist/components/dovetail/presence.js +35 -0
- package/dist/components/dovetail/presence.js.map +1 -0
- package/dist/components/dovetail/sync-status.js +39 -0
- package/dist/components/dovetail/sync-status.js.map +1 -0
- package/dist/components/dovetail/typing.js +23 -0
- package/dist/components/dovetail/typing.js.map +1 -0
- package/dist/css.d.ts +2 -0
- package/dist/css.d.ts.map +1 -0
- package/dist/editor.js +2 -0
- package/dist/editor.js.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/live-u5cQDrwU.js +93 -0
- package/dist/live-u5cQDrwU.js.map +1 -0
- package/dist/people-GBjAG7ZI.js +105 -0
- package/dist/people-GBjAG7ZI.js.map +1 -0
- package/dist/services/dovetail.js +233 -0
- package/dist/services/dovetail.js.map +1 -0
- package/dist/status-CYJBlnG7.js +59 -0
- package/dist/status-CYJBlnG7.js.map +1 -0
- package/dist/status-dot-DSQMdQhW.js +31 -0
- package/dist/status-dot-DSQMdQhW.js.map +1 -0
- package/dist/styles/editor.css +27 -0
- package/dist/visually-hidden-BFhJXHGu.js +10 -0
- package/dist/visually-hidden-BFhJXHGu.js.map +1 -0
- package/package.json +121 -3
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
import { modifier } from 'ember-modifier';
|
|
3
|
+
import { s as safeColor, r as relativePointer } from '../../people-GBjAG7ZI.js';
|
|
4
|
+
import { precompileTemplate } from '@ember/template-compilation';
|
|
5
|
+
import { setComponentTemplate } from '@ember/component';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Puts a pointer at its place in the box. The color of a remote user is not trusted. A custom
|
|
9
|
+
* property takes any value, also `url(...)`, so `safeColor` lets only a hex color through.
|
|
10
|
+
*/
|
|
11
|
+
const place = modifier((element, [pointer, color]) => {
|
|
12
|
+
element.style.left = `${pointer.x * 100}%`;
|
|
13
|
+
element.style.top = `${pointer.y * 100}%`;
|
|
14
|
+
element.style.setProperty('--dovetail-cursor', safeColor(color));
|
|
15
|
+
});
|
|
16
|
+
/**
|
|
17
|
+
* The pointers of the peers over the content of the block, with their names and colors. It
|
|
18
|
+
* sends the local pointer, as a fraction of the size of the box, so that boxes of other sizes
|
|
19
|
+
* show it at the same place. The pointers are decoration for the screen readers.
|
|
20
|
+
*/
|
|
21
|
+
class LiveCursors extends Component {
|
|
22
|
+
track = modifier(element => {
|
|
23
|
+
const move = event => this.args.presence.setPointer?.(relativePointer(event.clientX, event.clientY, element.getBoundingClientRect()));
|
|
24
|
+
const leave = () => this.args.presence.setPointer?.(null);
|
|
25
|
+
element.addEventListener('pointermove', move);
|
|
26
|
+
element.addEventListener('pointerleave', leave);
|
|
27
|
+
return () => {
|
|
28
|
+
element.removeEventListener('pointermove', move);
|
|
29
|
+
element.removeEventListener('pointerleave', leave);
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
get cursors() {
|
|
33
|
+
return this.args.presence.state.peers.filter(peer => peer.pointer !== null);
|
|
34
|
+
}
|
|
35
|
+
static {
|
|
36
|
+
setComponentTemplate(precompileTemplate("<div data-test-dovetail-live-cursors style=\"position: relative\" {{this.track}} ...attributes>\n {{yield}}\n <div aria-hidden=\"true\" style=\"position: absolute; inset: 0; pointer-events: none; overflow: hidden\">\n {{#each this.cursors key=\"clientId\" as |peer|}}\n <div data-test-dovetail-cursor data-x={{peer.pointer.x}} data-y={{peer.pointer.y}} style=\"position: absolute; display: flex; align-items: flex-start; transition: left 80ms linear, top 80ms linear\" {{place peer.pointer peer.user.color}}>\n <svg width=\"14\" height=\"18\" viewBox=\"0 0 14 18\" style=\"fill: var(--dovetail-cursor)\">\n <path d=\"M0 0 L0 15 L4 11 L7 18 L9.5 17 L6.5 10 L12 10 Z\" stroke=\"white\" />\n </svg>\n <span style=\"margin-block-start: 0.75rem; padding: 0.125rem 0.375rem; border-radius: 0.25rem; font-size: 0.75rem; white-space: nowrap; color: white; background: var(--dovetail-cursor)\">{{peer.user.name}}</span>\n </div>\n {{/each}}\n </div>\n</div>", {
|
|
37
|
+
strictMode: true,
|
|
38
|
+
scope: () => ({
|
|
39
|
+
place
|
|
40
|
+
})
|
|
41
|
+
}), this);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { LiveCursors as default };
|
|
46
|
+
//# sourceMappingURL=live-cursors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"live-cursors.js","sources":["../../../src/components/dovetail/live-cursors.gts"],"sourcesContent":["import Component from '@glimmer/component'\nimport { modifier } from 'ember-modifier'\nimport type { PresencePeer, PresencePointer } from '@dovetail-ts/core'\nimport type { PresenceSource } from '../../live.ts'\nimport { relativePointer, safeColor } from '../../people.ts'\n\nexport interface LiveCursorsSignature {\n Args: {\n /** The presence of the room. The component sends the local pointer through it. */\n presence: PresenceSource\n }\n Blocks: { default: [] }\n Element: HTMLDivElement\n}\n\n/**\n * Puts a pointer at its place in the box. The color of a remote user is not trusted. A custom\n * property takes any value, also `url(...)`, so `safeColor` lets only a hex color through.\n */\nconst place = modifier((element: HTMLElement, [pointer, color]: [PresencePointer, string]) => {\n element.style.left = `${pointer.x * 100}%`\n element.style.top = `${pointer.y * 100}%`\n element.style.setProperty('--dovetail-cursor', safeColor(color))\n})\n\n/**\n * The pointers of the peers over the content of the block, with their names and colors. It\n * sends the local pointer, as a fraction of the size of the box, so that boxes of other sizes\n * show it at the same place. The pointers are decoration for the screen readers.\n */\nexport default class LiveCursors extends Component<LiveCursorsSignature> {\n track = modifier((element: HTMLElement) => {\n const move = (event: PointerEvent) =>\n this.args.presence.setPointer?.(\n relativePointer(event.clientX, event.clientY, element.getBoundingClientRect()),\n )\n const leave = () => this.args.presence.setPointer?.(null)\n element.addEventListener('pointermove', move)\n element.addEventListener('pointerleave', leave)\n return () => {\n element.removeEventListener('pointermove', move)\n element.removeEventListener('pointerleave', leave)\n }\n })\n\n get cursors(): (PresencePeer & { pointer: PresencePointer })[] {\n return this.args.presence.state.peers.filter(\n (peer): peer is PresencePeer & { pointer: PresencePointer } => peer.pointer !== null,\n )\n }\n\n <template>\n <div data-test-dovetail-live-cursors style='position: relative' {{this.track}} ...attributes>\n {{yield}}\n <div\n aria-hidden='true'\n style='position: absolute; inset: 0; pointer-events: none; overflow: hidden'\n >\n {{#each this.cursors key='clientId' as |peer|}}\n <div\n data-test-dovetail-cursor\n data-x={{peer.pointer.x}}\n data-y={{peer.pointer.y}}\n style='position: absolute; display: flex; align-items: flex-start; transition: left 80ms linear, top 80ms linear'\n {{place peer.pointer peer.user.color}}\n >\n <svg width='14' height='18' viewBox='0 0 14 18' style='fill: var(--dovetail-cursor)'>\n <path d='M0 0 L0 15 L4 11 L7 18 L9.5 17 L6.5 10 L12 10 Z' stroke='white' />\n </svg>\n <span\n style='margin-block-start: 0.75rem; padding: 0.125rem 0.375rem; border-radius: 0.25rem; font-size: 0.75rem; white-space: nowrap; color: white; background: var(--dovetail-cursor)'\n >{{peer.user.name}}</span>\n </div>\n {{/each}}\n </div>\n </div>\n </template>\n}\n"],"names":["place","modifier","element","pointer","color","style","left","x","top","y","setProperty","safeColor","LiveCursors","Component","track","move","event","args","presence","setPointer","relativePointer","clientX","clientY","getBoundingClientRect","leave","addEventListener","removeEventListener","cursors","state","peers","filter","peer","setComponentTemplate","precompileTemplate","strictMode","scope"],"mappings":";;;;;;AAeA;;;;AAIA,MAAMA,KAAA,GAAQC,QAAA,CAAS,CAACC,OAAS,EAAa,CAACC,OAAA,EAASC,KAAA,CAAiC,KAAA;EACvFF,OAAA,CAAQG,KAAK,CAACC,IAAI,GAAG,CAAA,EAAGH,QAAQI,CAAC,GAAG,GAAA,CAAA,CAAA,CAAM;EAC1CL,OAAA,CAAQG,KAAK,CAACG,GAAG,GAAG,CAAA,EAAGL,QAAQM,CAAC,GAAG,GAAA,CAAA,CAAA,CAAM;EACzCP,OAAA,CAAQG,KAAK,CAACK,WAAW,CAAC,qBAAqBC,SAAA,CAAUP,KAAA,CAAA,CAAA;AAC3D,CAAA,CAAA;AAEA;;;;;AAKe,MAAMQ,WAAA,SAAoBC,SAAA,CAAU;AACjDC,EAAAA,KAAA,GAAQb,QAAA,CAAUC,OAAS,IAAA;AACzB,IAAA,MAAMa,IAAA,GAAQC,KAAO,IACnB,IAAI,CAACC,IAAI,CAACC,QAAQ,CAACC,UAAU,GAC3BC,eAAA,CAAgBJ,MAAMK,OAAO,EAAEL,MAAMM,OAAO,EAAEpB,QAAQqB,qBAAqB,EAAA,CAAA,CAAA;AAE/E,IAAA,MAAMC,KAAA,GAAQA,MAAM,IAAI,CAACP,IAAI,CAACC,QAAQ,CAACC,UAAU,GAAG,IAAA,CAAA;AACpDjB,IAAAA,OAAA,CAAQuB,gBAAgB,CAAC,aAAA,EAAeV,IAAA,CAAA;AACxCb,IAAAA,OAAA,CAAQuB,gBAAgB,CAAC,cAAA,EAAgBD,KAAA,CAAA;AACzC,IAAA,OAAO,MAAA;AACLtB,MAAAA,OAAA,CAAQwB,mBAAmB,CAAC,aAAA,EAAeX,IAAA,CAAA;AAC3Cb,MAAAA,OAAA,CAAQwB,mBAAmB,CAAC,cAAA,EAAgBF,KAAA,CAAA;IAC9C,CAAA;AACF,EAAA,CAAA,CAAA;EAEA,IAAIG,OAAAA,GAA2D;AAC7D,IAAA,OAAO,IAAI,CAACV,IAAI,CAACC,QAAQ,CAACU,KAAK,CAACC,KAAK,CAACC,MAAM,CACzCC,QAA8DA,IAAA,CAAK5B,OAAO,KAAK,IAAA,CAAA;AAEpF,EAAA;AAEA,EAAA;IAAA6B,oBAAA,CAAAC,kBAAA,CAAA,u+BAAA,EAyBA;MAAAC,UAAA,EAAA,IAAA;AAAAC,MAAAA,KAAA,EAAAA,OAAA;AAAAnC,QAAAA;AAAA,OAAA;KAAU,CAAA,EAAV,IAAW,CAAA;AAAD;AACZ;;"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
import { service } from '@ember/service';
|
|
3
|
+
import { precompileTemplate } from '@ember/template-compilation';
|
|
4
|
+
import { setComponentTemplate } from '@ember/component';
|
|
5
|
+
import { g, i } from 'decorator-transforms/runtime';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Yields the presence of a room (`dovetail.presence(this, room)`), and stops it when it leaves
|
|
9
|
+
* the page. Give the yielded presence to the presence components.
|
|
10
|
+
*
|
|
11
|
+
* <Dovetail::Presence @room="board:1" as |presence|>
|
|
12
|
+
* <Dovetail::AvatarStack @presence={{presence}} />
|
|
13
|
+
* </Dovetail::Presence>
|
|
14
|
+
*/
|
|
15
|
+
class Presence extends Component {
|
|
16
|
+
static {
|
|
17
|
+
g(this.prototype, "dovetail", [service('dovetail')]);
|
|
18
|
+
}
|
|
19
|
+
#dovetail = (i(this, "dovetail"), void 0);
|
|
20
|
+
presence;
|
|
21
|
+
constructor(owner, args) {
|
|
22
|
+
super(owner, args);
|
|
23
|
+
// shortcut: the room is read once; render a new <Presence> (for example in an {{#each}}
|
|
24
|
+
// keyed on the room) to change it.
|
|
25
|
+
this.presence = this.dovetail.presence(this, args.room);
|
|
26
|
+
}
|
|
27
|
+
static {
|
|
28
|
+
setComponentTemplate(precompileTemplate("{{yield this.presence}}", {
|
|
29
|
+
strictMode: true
|
|
30
|
+
}), this);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { Presence as default };
|
|
35
|
+
//# sourceMappingURL=presence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presence.js","sources":["../../../src/components/dovetail/presence.gts"],"sourcesContent":["import Component from '@glimmer/component'\nimport { service } from '@ember/service'\nimport type Owner from '@ember/owner'\nimport type DovetailService from '../../services/dovetail.ts'\nimport type { LivePresence } from '../../live.ts'\n\nexport interface PresenceSignature {\n Args: {\n /** The room. A change of the room after the first render does nothing. */\n room: string\n }\n Blocks: { default: [LivePresence] }\n}\n\n/**\n * Yields the presence of a room (`dovetail.presence(this, room)`), and stops it when it leaves\n * the page. Give the yielded presence to the presence components.\n *\n * <Dovetail::Presence @room=\"board:1\" as |presence|>\n * <Dovetail::AvatarStack @presence={{presence}} />\n * </Dovetail::Presence>\n */\nexport default class Presence extends Component<PresenceSignature> {\n @service('dovetail') declare dovetail: DovetailService\n\n readonly presence: LivePresence\n\n constructor(owner: Owner, args: PresenceSignature['Args']) {\n super(owner, args)\n // shortcut: the room is read once; render a new <Presence> (for example in an {{#each}}\n // keyed on the room) to change it.\n this.presence = this.dovetail.presence(this, args.room)\n }\n\n <template>{{yield this.presence}}</template>\n}\n"],"names":["Presence","Component","g","prototype","service","i","presence","constructor","owner","args","dovetail","room","setComponentTemplate","precompileTemplate","strictMode"],"mappings":";;;;;;AAcA;;;;;;;;AAQe,MAAMA,QAAA,SAAiBC,SAAA,CAAU;AAAA,EAAA;AAAAC,IAAAA,CAAA,MAAAC,SAAA,EAAA,UAAA,EAAA,CAC7CC,OAAA,CAAQ,UAAA,CAAA,CAAA,CAAA;AAAA;EAAA,SAAA,IAAAC,CAAA,CAAA,IAAA,EAAA,UAAA,CAAA,EAAA,MAAA;EAEAC;AAETC,EAAAA,WAAAA,CAAYC,KAAY,EAAEC,IAA+B,EAAE;AACzD,IAAA,KAAK,CAACD,KAAA,EAAOC,IAAA,CAAA;AACb;AACA;AACA,IAAA,IAAI,CAACH,QAAQ,GAAG,IAAI,CAACI,QAAQ,CAACJ,QAAQ,CAAC,IAAI,EAAEG,IAAA,CAAKE,IAAI,CAAA;AACxD,EAAA;AAEA,EAAA;IAAAC,oBAAA,CAAAC,kBAAA,CAAA,yBAAA,EAAiC;MAAAC,UAAA,EAAA;KAAU,CAAA,EAAV,IAAW,CAAA;AAAD;AAC7C;;"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
import { service } from '@ember/service';
|
|
3
|
+
import { s as syncStatus } from '../../status-CYJBlnG7.js';
|
|
4
|
+
import { S as StatusDot } from '../../status-dot-DSQMdQhW.js';
|
|
5
|
+
import { precompileTemplate } from '@ember/template-compilation';
|
|
6
|
+
import { setComponentTemplate } from '@ember/component';
|
|
7
|
+
import { g, i } from 'decorator-transforms/runtime';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Whether the local changes reached the server: `Saved`, `Syncing 3 changes` or
|
|
11
|
+
* `Offline: 3 changes wait`. It is a live region.
|
|
12
|
+
*/
|
|
13
|
+
class SyncStatus extends Component {
|
|
14
|
+
static {
|
|
15
|
+
g(this.prototype, "dovetail", [service('dovetail')]);
|
|
16
|
+
}
|
|
17
|
+
#dovetail = (i(this, "dovetail"), void 0);
|
|
18
|
+
get view() {
|
|
19
|
+
return syncStatus(this.args.status ?? this.dovetail.status, this.args.queued ?? this.dovetail.queued);
|
|
20
|
+
}
|
|
21
|
+
get dot() {
|
|
22
|
+
return {
|
|
23
|
+
saved: 'online',
|
|
24
|
+
syncing: 'reconnecting',
|
|
25
|
+
offline: 'offline'
|
|
26
|
+
}[this.view.state];
|
|
27
|
+
}
|
|
28
|
+
static {
|
|
29
|
+
setComponentTemplate(precompileTemplate("<p role=\"status\" data-test-dovetail-sync-status data-state={{this.view.state}} style=\"display: inline-flex; align-items: center; gap: 0.5rem; margin: 0; font-size: 0.875rem; color: var(--muted-foreground)\" ...attributes>\n <StatusDot @status={{this.dot}} />\n {{this.view.text}}\n</p>", {
|
|
30
|
+
strictMode: true,
|
|
31
|
+
scope: () => ({
|
|
32
|
+
StatusDot
|
|
33
|
+
})
|
|
34
|
+
}), this);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { SyncStatus as default };
|
|
39
|
+
//# sourceMappingURL=sync-status.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync-status.js","sources":["../../../src/components/dovetail/sync-status.gts"],"sourcesContent":["import Component from '@glimmer/component'\nimport { service } from '@ember/service'\nimport type DovetailService from '../../services/dovetail.ts'\nimport { syncStatus } from '../../status.ts'\nimport type { ConnectionStatus } from '../../status.ts'\nimport StatusDot from '../../-private/status-dot.gts'\n\nexport interface SyncStatusSignature {\n Args: {\n /** The connection status. The default is the status of the `dovetail` service. */\n status?: ConnectionStatus\n /** The count of queued writes. The default is the count of the `dovetail` service. */\n queued?: number\n }\n Element: HTMLParagraphElement\n}\n\n/**\n * Whether the local changes reached the server: `Saved`, `Syncing 3 changes` or\n * `Offline: 3 changes wait`. It is a live region.\n */\nexport default class SyncStatus extends Component<SyncStatusSignature> {\n @service('dovetail') declare dovetail: DovetailService\n\n get view() {\n return syncStatus(\n this.args.status ?? this.dovetail.status,\n this.args.queued ?? this.dovetail.queued,\n )\n }\n\n get dot(): string {\n return { saved: 'online', syncing: 'reconnecting', offline: 'offline' }[this.view.state]\n }\n\n <template>\n <p\n role='status'\n data-test-dovetail-sync-status\n data-state={{this.view.state}}\n style='display: inline-flex; align-items: center; gap: 0.5rem; margin: 0; font-size: 0.875rem; color: var(--muted-foreground)'\n ...attributes\n >\n <StatusDot @status={{this.dot}} />\n {{this.view.text}}\n </p>\n </template>\n}\n"],"names":["SyncStatus","Component","g","prototype","service","i","view","syncStatus","args","status","dovetail","queued","dot","saved","syncing","offline","state","setComponentTemplate","precompileTemplate","strictMode","scope","StatusDot"],"mappings":";;;;;;;;AAiBA;;;;AAIe,MAAMA,UAAA,SAAmBC,SAAA,CAAU;AAAA,EAAA;AAAAC,IAAAA,CAAA,MAAAC,SAAA,EAAA,UAAA,EAAA,CAC/CC,OAAA,CAAQ,UAAA,CAAA,CAAA,CAAA;AAAA;EAAA,SAAA,IAAAC,CAAA,CAAA,IAAA,EAAA,UAAA,CAAA,EAAA,MAAA;EAET,IAAIC,IAAAA,GAAO;IACT,OAAOC,UAAA,CACL,IAAI,CAACC,IAAI,CAACC,MAAM,IAAI,IAAI,CAACC,QAAQ,CAACD,MAAM,EACxC,IAAI,CAACD,IAAI,CAACG,MAAM,IAAI,IAAI,CAACD,QAAQ,CAACC,MAAM,CAAA;AAE5C,EAAA;EAEA,IAAIC,GAAAA,GAAc;IAChB,OAAO;AAAEC,MAAAA,KAAA,EAAO,QAAA;AAAUC,MAAAA,OAAA,EAAS,cAAA;AAAgBC,MAAAA,OAAA,EAAS;AAAU,KAAC,CAAC,IAAI,CAACT,IAAI,CAACU,KAAK,CAAC;AAC1F,EAAA;AAEA,EAAA;IAAAC,oBAAA,CAAAC,kBAAA,CAAA,oSAAA,EAWA;MAAAC,UAAA,EAAA,IAAA;AAAAC,MAAAA,KAAA,EAAAA,OAAA;AAAAC,QAAAA;AAAA,OAAA;KAAU,CAAA,EAAV,IAAW,CAAA;AAAD;AACZ;;"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
import { t as typingNames } from '../../people-GBjAG7ZI.js';
|
|
3
|
+
import { t as typingText } from '../../status-CYJBlnG7.js';
|
|
4
|
+
import { precompileTemplate } from '@ember/template-compilation';
|
|
5
|
+
import { setComponentTemplate } from '@ember/component';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Who types in the room: `Ana is typing`, `Ana and Ben are typing`, `3 people are typing`. It
|
|
9
|
+
* is a live region, and it stays in the page when it is empty, so each change is read.
|
|
10
|
+
*/
|
|
11
|
+
class Typing extends Component {
|
|
12
|
+
get text() {
|
|
13
|
+
return typingText(typingNames(this.args.presence.state));
|
|
14
|
+
}
|
|
15
|
+
static {
|
|
16
|
+
setComponentTemplate(precompileTemplate("<p role=\"status\" data-test-dovetail-typing data-state={{if this.text \"typing\" \"idle\"}} style=\"margin: 0; min-block-size: 1.25rem; font-size: 0.875rem; color: var(--muted-foreground)\" ...attributes>{{this.text}}</p>", {
|
|
17
|
+
strictMode: true
|
|
18
|
+
}), this);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { Typing as default };
|
|
23
|
+
//# sourceMappingURL=typing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typing.js","sources":["../../../src/components/dovetail/typing.gts"],"sourcesContent":["import Component from '@glimmer/component'\nimport type { PresenceSource } from '../../live.ts'\nimport { typingNames } from '../../people.ts'\nimport { typingText } from '../../status.ts'\n\nexport interface TypingSignature {\n Args: {\n /** The presence of the room. Call `presence.typing()` at each keystroke of the local user. */\n presence: PresenceSource\n }\n Element: HTMLParagraphElement\n}\n\n/**\n * Who types in the room: `Ana is typing`, `Ana and Ben are typing`, `3 people are typing`. It\n * is a live region, and it stays in the page when it is empty, so each change is read.\n */\nexport default class Typing extends Component<TypingSignature> {\n get text(): string {\n return typingText(typingNames(this.args.presence.state))\n }\n\n <template>\n <p\n role='status'\n data-test-dovetail-typing\n data-state={{if this.text 'typing' 'idle'}}\n style='margin: 0; min-block-size: 1.25rem; font-size: 0.875rem; color: var(--muted-foreground)'\n ...attributes\n >{{this.text}}</p>\n </template>\n}\n"],"names":["Typing","Component","text","typingText","typingNames","args","presence","state","setComponentTemplate","precompileTemplate","strictMode"],"mappings":";;;;;;AAaA;;;;AAIe,MAAMA,MAAA,SAAeC,SAAA,CAAU;EAC5C,IAAIC,IAAAA,GAAe;AACjB,IAAA,OAAOC,UAAA,CAAWC,YAAY,IAAI,CAACC,IAAI,CAACC,QAAQ,CAACC,KAAK,CAAA,CAAA;AACxD,EAAA;AAEA,EAAA;IAAAC,oBAAA,CAAAC,kBAAA,CAAA,gOAAA,EAQA;MAAAC,UAAA,EAAA;KAAU,CAAA,EAAV,IAAW,CAAA;AAAD;AACZ;;"}
|
package/dist/css.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/dist/editor.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editor.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { default as DovetailService } from './services/dovetail.js';
|
|
2
|
+
export { a as LiveDoc, L as LivePresence } from './live-u5cQDrwU.js';
|
|
3
|
+
export { c as connectionLabel, a as connectionStatus, s as syncStatus, t as typingText } from './status-CYJBlnG7.js';
|
|
4
|
+
export { default as ConnectionBadge } from './components/dovetail/connection-badge.js';
|
|
5
|
+
export { default as AvatarStack } from './components/dovetail/avatar-stack.js';
|
|
6
|
+
export { default as DeadLetters } from './components/dovetail/dead-letters.js';
|
|
7
|
+
export { default as LiveCursors } from './components/dovetail/live-cursors.js';
|
|
8
|
+
export { default as Presence } from './components/dovetail/presence.js';
|
|
9
|
+
export { default as SyncStatus } from './components/dovetail/sync-status.js';
|
|
10
|
+
export { default as Typing } from './components/dovetail/typing.js';
|
|
11
|
+
export { d as describeError, a as describeWrite, i as initials, b as isSafeAvatarUrl, p as people, r as relativePointer, s as safeColor, t as typingNames } from './people-GBjAG7ZI.js';
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { tracked } from '@glimmer/tracking';
|
|
2
|
+
import { g, i } from 'decorator-transforms/runtime';
|
|
3
|
+
|
|
4
|
+
// Tracked wrappers of the core objects of a room. The core has no framework code (ADR 0011), so
|
|
5
|
+
// these copy each change of its state into a tracked field.
|
|
6
|
+
/** The presence of a room, with a tracked `state`. */
|
|
7
|
+
class LivePresence {
|
|
8
|
+
static {
|
|
9
|
+
g(this.prototype, "state", [tracked]);
|
|
10
|
+
}
|
|
11
|
+
#state = (i(this, "state"), void 0);
|
|
12
|
+
room;
|
|
13
|
+
presence;
|
|
14
|
+
#stop;
|
|
15
|
+
constructor(room, presence) {
|
|
16
|
+
this.room = room;
|
|
17
|
+
this.presence = presence;
|
|
18
|
+
this.state = presence.state;
|
|
19
|
+
this.#stop = presence.subscribe(state => this.state = state);
|
|
20
|
+
}
|
|
21
|
+
activity() {
|
|
22
|
+
this.presence.activity();
|
|
23
|
+
}
|
|
24
|
+
setPointer(pointer) {
|
|
25
|
+
this.presence.setPointer(pointer);
|
|
26
|
+
}
|
|
27
|
+
typing() {
|
|
28
|
+
this.presence.typing();
|
|
29
|
+
}
|
|
30
|
+
stopTyping() {
|
|
31
|
+
this.presence.stopTyping();
|
|
32
|
+
}
|
|
33
|
+
set(fields) {
|
|
34
|
+
this.presence.set(fields);
|
|
35
|
+
}
|
|
36
|
+
destroy() {
|
|
37
|
+
this.#stop();
|
|
38
|
+
this.presence.destroy();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** A CRDT document of a room, synced by a `DocSession`, with a tracked `synced`. */
|
|
43
|
+
class LiveDoc {
|
|
44
|
+
static {
|
|
45
|
+
g(this.prototype, "synced", [tracked], function () {
|
|
46
|
+
return false;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
#synced = (i(this, "synced"), void 0);
|
|
50
|
+
static {
|
|
51
|
+
g(this.prototype, "started", [tracked], function () {
|
|
52
|
+
return false;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
#started = (i(this, "started"), void 0);
|
|
56
|
+
/**
|
|
57
|
+
* True when the session started: the stored updates are in the document. A local update
|
|
58
|
+
* before the start is not lost: it waits in the storage, and the session sends it.
|
|
59
|
+
*/
|
|
60
|
+
/** The session, when it started. */
|
|
61
|
+
session;
|
|
62
|
+
/** Resolves when the session started. */
|
|
63
|
+
ready;
|
|
64
|
+
room;
|
|
65
|
+
handle;
|
|
66
|
+
#destroyed;
|
|
67
|
+
constructor(room, handle, makeSession) {
|
|
68
|
+
this.room = room;
|
|
69
|
+
this.handle = handle;
|
|
70
|
+
this.ready = this.#start(makeSession);
|
|
71
|
+
}
|
|
72
|
+
async #start(makeSession) {
|
|
73
|
+
const session = await makeSession();
|
|
74
|
+
if (this.#destroyed) return;
|
|
75
|
+
this.session = session;
|
|
76
|
+
session.onSyncChange(synced => this.synced = synced);
|
|
77
|
+
await session.start();
|
|
78
|
+
this.started = true;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Stops the session and destroys the document. A second call gives the same promise. */
|
|
82
|
+
destroy() {
|
|
83
|
+
this.#destroyed ??= (async () => {
|
|
84
|
+
await this.ready.catch(() => {});
|
|
85
|
+
await this.session?.destroy();
|
|
86
|
+
this.handle.destroy();
|
|
87
|
+
})();
|
|
88
|
+
return this.#destroyed;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export { LivePresence as L, LiveDoc as a };
|
|
93
|
+
//# sourceMappingURL=live-u5cQDrwU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"live-u5cQDrwU.js","sources":["../src/live.ts"],"sourcesContent":["// Tracked wrappers of the core objects of a room. The core has no framework code (ADR 0011), so\n// these copy each change of its state into a tracked field.\nimport { tracked } from '@glimmer/tracking'\nimport type { DocSession, PresencePointer, PresenceRoom, PresenceState } from '@dovetail-ts/core'\nimport type { DocHandle, JsonObject } from '@dovetail-ts/crdt'\n\n/**\n * What the presence components read: a state, and the calls for the local user. A\n * `LivePresence` has this shape. A story can give a plain object.\n */\nexport interface PresenceSource {\n readonly state: PresenceState\n activity?(): void\n setPointer?(pointer: PresencePointer | null): void\n typing?(): void\n}\n\n/** The presence of a room, with a tracked `state`. */\nexport class LivePresence implements PresenceSource {\n @tracked state: PresenceState\n readonly room: string\n readonly presence: PresenceRoom\n readonly #stop: () => void\n\n constructor(room: string, presence: PresenceRoom) {\n this.room = room\n this.presence = presence\n this.state = presence.state\n this.#stop = presence.subscribe(state => (this.state = state))\n }\n\n activity(): void {\n this.presence.activity()\n }\n\n setPointer(pointer: PresencePointer | null): void {\n this.presence.setPointer(pointer)\n }\n\n typing(): void {\n this.presence.typing()\n }\n\n stopTyping(): void {\n this.presence.stopTyping()\n }\n\n set(fields: JsonObject): void {\n this.presence.set(fields)\n }\n\n destroy(): void {\n this.#stop()\n this.presence.destroy()\n }\n}\n\n/** A CRDT document of a room, synced by a `DocSession`, with a tracked `synced`. */\nexport class LiveDoc {\n @tracked synced = false\n /**\n * True when the session started: the stored updates are in the document. A local update\n * before the start is not lost: it waits in the storage, and the session sends it.\n */\n @tracked started = false\n /** The session, when it started. */\n session: DocSession | undefined\n /** Resolves when the session started. */\n readonly ready: Promise<void>\n readonly room: string\n readonly handle: DocHandle\n #destroyed: Promise<void> | undefined\n\n constructor(room: string, handle: DocHandle, makeSession: () => Promise<DocSession>) {\n this.room = room\n this.handle = handle\n this.ready = this.#start(makeSession)\n }\n\n async #start(makeSession: () => Promise<DocSession>): Promise<void> {\n const session = await makeSession()\n if (this.#destroyed) return\n this.session = session\n session.onSyncChange(synced => (this.synced = synced))\n await session.start()\n this.started = true\n }\n\n /** Stops the session and destroys the document. A second call gives the same promise. */\n destroy(): Promise<void> {\n this.#destroyed ??= (async () => {\n await this.ready.catch(() => {})\n await this.session?.destroy()\n this.handle.destroy()\n })()\n return this.#destroyed\n }\n}\n"],"names":["LivePresence","g","prototype","tracked","i","room","presence","constructor","state","subscribe","activity","setPointer","pointer","typing","stopTyping","set","fields","destroy","LiveDoc","session","ready","handle","makeSession","#start","onSyncChange","synced","start","started","catch"],"mappings":";;;AAAA;AACA;AAgBA;AACO,MAAMA,YAAY,CAA2B;AAAA,EAAA;IAAAC,CAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,OAAA,EAAA,CACjDC,OAAO,CAAA,CAAA;AAAA;EAAA,MAAA,IAAAC,CAAA,CAAA,IAAA,EAAA,OAAA,CAAA,EAAA,MAAA;EACCC,IAAI;EACJC,QAAQ;AACR,EAAA,KAAK;AAEdC,EAAAA,WAAWA,CAACF,IAAY,EAAEC,QAAsB,EAAE;IAChD,IAAI,CAACD,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACC,QAAQ,GAAGA,QAAQ;AACxB,IAAA,IAAI,CAACE,KAAK,GAAGF,QAAQ,CAACE,KAAK;AAC3B,IAAA,IAAI,CAAC,KAAK,GAAGF,QAAQ,CAACG,SAAS,CAACD,KAAK,IAAK,IAAI,CAACA,KAAK,GAAGA,KAAM,CAAC;AAChE,EAAA;AAEAE,EAAAA,QAAQA,GAAS;AACf,IAAA,IAAI,CAACJ,QAAQ,CAACI,QAAQ,EAAE;AAC1B,EAAA;EAEAC,UAAUA,CAACC,OAA+B,EAAQ;AAChD,IAAA,IAAI,CAACN,QAAQ,CAACK,UAAU,CAACC,OAAO,CAAC;AACnC,EAAA;AAEAC,EAAAA,MAAMA,GAAS;AACb,IAAA,IAAI,CAACP,QAAQ,CAACO,MAAM,EAAE;AACxB,EAAA;AAEAC,EAAAA,UAAUA,GAAS;AACjB,IAAA,IAAI,CAACR,QAAQ,CAACQ,UAAU,EAAE;AAC5B,EAAA;EAEAC,GAAGA,CAACC,MAAkB,EAAQ;AAC5B,IAAA,IAAI,CAACV,QAAQ,CAACS,GAAG,CAACC,MAAM,CAAC;AAC3B,EAAA;AAEAC,EAAAA,OAAOA,GAAS;AACd,IAAA,IAAI,CAAC,KAAK,EAAE;AACZ,I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A,GAAkB;AACvB,IAAA,IAAI,CAAC,UAAU,KAAK,CAAC,YAAY;MAC/B,MAAM,IAAI,CAACG,KAAK,CAACQ,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;AAChC,MAAA,MAAM,IAAI,CAACT,OAAO,EAAEF,OAAO,EAAE;AAC7B,MAAA,IAAI,CAACI,MAAM,CAACJ,OAAO,EAAE;AACvB,IAAA,CAAC,GAAG;IACJ,OAAO,IAAI,CAAC,UAAU;AACxB,EAAA;AACF;;"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { isHexColor } from '@dovetail-ts/core';
|
|
2
|
+
|
|
3
|
+
// The data of the presence and dead-letter components, as plain functions. Remote states are
|
|
4
|
+
// not trusted: `readPresence` of core checked them, and the components show names as text.
|
|
5
|
+
|
|
6
|
+
/** One person in a room. A user with more than one client (tabs) is one person. */
|
|
7
|
+
|
|
8
|
+
/** The color of a pointer when the color of the peer is not a hex color. */
|
|
9
|
+
const FALLBACK_COLOR = '#6b7280';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* `color` when it is a hex color (`#rgb`, `#rgba`, `#rrggbb` or `#rrggbbaa`, the rule of
|
|
13
|
+
* `isHexColor` of core), or else the fallback. A remote color goes into a style, so a value such
|
|
14
|
+
* as `url(...)` must not pass.
|
|
15
|
+
*/
|
|
16
|
+
function safeColor(color) {
|
|
17
|
+
return isHexColor(color) ? color : FALLBACK_COLOR;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The default policy of the avatar URLs of the peers: an `https:` URL only. A relative URL
|
|
22
|
+
* (for example `/ann.png`) resolves against the page, so it passes on an `https:` page.
|
|
23
|
+
*/
|
|
24
|
+
function isSafeAvatarUrl(url) {
|
|
25
|
+
try {
|
|
26
|
+
return new URL(url, globalThis.location?.href).protocol === 'https:';
|
|
27
|
+
} catch {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The people that the avatar stack shows, and the people of the overflow count. */
|
|
33
|
+
function people(state, options) {
|
|
34
|
+
const allow = options.allowAvatarUrl ?? isSafeAvatarUrl;
|
|
35
|
+
const byId = new Map();
|
|
36
|
+
const add = (presence, self) => {
|
|
37
|
+
const {
|
|
38
|
+
id,
|
|
39
|
+
name,
|
|
40
|
+
color,
|
|
41
|
+
avatarUrl
|
|
42
|
+
} = presence.user;
|
|
43
|
+
const known = byId.get(id);
|
|
44
|
+
if (known) {
|
|
45
|
+
if (presence.status === 'online') known.status = 'online';
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
byId.set(id, {
|
|
49
|
+
id,
|
|
50
|
+
name,
|
|
51
|
+
color: safeColor(color),
|
|
52
|
+
avatarUrl: avatarUrl !== undefined && allow(avatarUrl) ? avatarUrl : undefined,
|
|
53
|
+
status: presence.status,
|
|
54
|
+
self
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
if (options.includeSelf) add(state.self, true);
|
|
58
|
+
for (const peer of state.peers) {
|
|
59
|
+
if (peer.user.id !== state.self.user.id || options.includeSelf) add(peer, false);
|
|
60
|
+
}
|
|
61
|
+
const all = [...byId.values()];
|
|
62
|
+
return {
|
|
63
|
+
visible: all.slice(0, options.max),
|
|
64
|
+
hidden: all.slice(options.max)
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** The names of the peers that type, each user once. */
|
|
69
|
+
function typingNames(state) {
|
|
70
|
+
const names = new Map();
|
|
71
|
+
for (const peer of state.peers) if (peer.typing) names.set(peer.user.id, peer.user.name);
|
|
72
|
+
return [...names.values()];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** The initials of a name: the first letter of the first two words. */
|
|
76
|
+
function initials(name) {
|
|
77
|
+
const letters = name.trim().split(/\s+/).filter(Boolean).slice(0, 2).map(word => word[0]?.toUpperCase()).join('');
|
|
78
|
+
return letters || '?';
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** A pointer position as a fraction (0 to 1) of a box, so clients with other sizes agree. */
|
|
82
|
+
function relativePointer(clientX, clientY, box) {
|
|
83
|
+
const fraction = (value, size) => size > 0 ? Math.min(1, Math.max(0, value / size)) : 0;
|
|
84
|
+
return {
|
|
85
|
+
x: fraction(clientX - box.left, box.width),
|
|
86
|
+
y: fraction(clientY - box.top, box.height)
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** A short name of a write: `Save note 1`, `Delete note 2`. */
|
|
91
|
+
function describeWrite(op) {
|
|
92
|
+
if (op.op === 'delete') return `Delete ${op.ref.type} ${op.ref.id}`;
|
|
93
|
+
const data = op.document.data;
|
|
94
|
+
if (Array.isArray(data)) return `Save ${data.length} records`;
|
|
95
|
+
return data ? `Save ${data.type} ${data.id}` : 'Save';
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Why the server refused a write: the detail or the title of the first error, or the status. */
|
|
99
|
+
function describeError(status, errors) {
|
|
100
|
+
const first = errors[0];
|
|
101
|
+
return first?.detail ?? first?.title ?? `The server refused the change (${status})`;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export { describeWrite as a, isSafeAvatarUrl as b, describeError as d, initials as i, people as p, relativePointer as r, safeColor as s, typingNames as t };
|
|
105
|
+
//# sourceMappingURL=people-GBjAG7ZI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"people-GBjAG7ZI.js","sources":["../src/people.ts"],"sourcesContent":["// The data of the presence and dead-letter components, as plain functions. Remote states are\n// not trusted: `readPresence` of core checked them, and the components show names as text.\nimport { isHexColor } from '@dovetail-ts/core'\nimport type { PresencePointer, PresenceState, PresenceStatus } from '@dovetail-ts/core'\nimport type { JsonApiError, StoreOp } from '@dovetail-ts/protocol'\n\n/** One person in a room. A user with more than one client (tabs) is one person. */\nexport interface Person {\n id: string\n name: string\n color: string\n avatarUrl: string | undefined\n status: PresenceStatus\n /** True for the local user. */\n self: boolean\n}\n\n/** The color of a pointer when the color of the peer is not a hex color. */\nexport const FALLBACK_COLOR = '#6b7280'\n\n/**\n * `color` when it is a hex color (`#rgb`, `#rgba`, `#rrggbb` or `#rrggbbaa`, the rule of\n * `isHexColor` of core), or else the fallback. A remote color goes into a style, so a value such\n * as `url(...)` must not pass.\n */\nexport function safeColor(color: unknown): string {\n return isHexColor(color) ? color : FALLBACK_COLOR\n}\n\n/**\n * The default policy of the avatar URLs of the peers: an `https:` URL only. A relative URL\n * (for example `/ann.png`) resolves against the page, so it passes on an `https:` page.\n */\nexport function isSafeAvatarUrl(url: string): boolean {\n try {\n return new URL(url, globalThis.location?.href).protocol === 'https:'\n } catch {\n return false\n }\n}\n\n/** The people that the avatar stack shows, and the people of the overflow count. */\nexport function people(\n state: PresenceState,\n options: {\n max: number\n includeSelf: boolean\n /** True for an avatar URL that the page can load. The default is `isSafeAvatarUrl`. */\n allowAvatarUrl?: (url: string) => boolean\n },\n): { visible: Person[]; hidden: Person[] } {\n const allow = options.allowAvatarUrl ?? isSafeAvatarUrl\n const byId = new Map<string, Person>()\n const add = (presence: PresenceState['self'], self: boolean) => {\n const { id, name, color, avatarUrl } = presence.user\n const known = byId.get(id)\n if (known) {\n if (presence.status === 'online') known.status = 'online'\n return\n }\n byId.set(id, {\n id,\n name,\n color: safeColor(color),\n avatarUrl: avatarUrl !== undefined && allow(avatarUrl) ? avatarUrl : undefined,\n status: presence.status,\n self,\n })\n }\n if (options.includeSelf) add(state.self, true)\n for (const peer of state.peers) {\n if (peer.user.id !== state.self.user.id || options.includeSelf) add(peer, false)\n }\n const all = [...byId.values()]\n return { visible: all.slice(0, options.max), hidden: all.slice(options.max) }\n}\n\n/** The names of the peers that type, each user once. */\nexport function typingNames(state: PresenceState): string[] {\n const names = new Map<string, string>()\n for (const peer of state.peers) if (peer.typing) names.set(peer.user.id, peer.user.name)\n return [...names.values()]\n}\n\n/** The initials of a name: the first letter of the first two words. */\nexport function initials(name: string): string {\n const letters = name\n .trim()\n .split(/\\s+/)\n .filter(Boolean)\n .slice(0, 2)\n .map(word => word[0]?.toUpperCase())\n .join('')\n return letters || '?'\n}\n\n/** A pointer position as a fraction (0 to 1) of a box, so clients with other sizes agree. */\nexport function relativePointer(\n clientX: number,\n clientY: number,\n box: { left: number; top: number; width: number; height: number },\n): PresencePointer {\n const fraction = (value: number, size: number) =>\n size > 0 ? Math.min(1, Math.max(0, value / size)) : 0\n return { x: fraction(clientX - box.left, box.width), y: fraction(clientY - box.top, box.height) }\n}\n\n/** A short name of a write: `Save note 1`, `Delete note 2`. */\nexport function describeWrite(op: StoreOp): string {\n if (op.op === 'delete') return `Delete ${op.ref.type} ${op.ref.id}`\n const data = op.document.data\n if (Array.isArray(data)) return `Save ${data.length} records`\n return data ? `Save ${data.type} ${data.id}` : 'Save'\n}\n\n/** Why the server refused a write: the detail or the title of the first error, or the status. */\nexport function describeError(status: number, errors: readonly JsonApiError[]): string {\n const first = errors[0]\n return first?.detail ?? first?.title ?? `The server refused the change (${status})`\n}\n"],"names":["FALLBACK_COLOR","safeColor","color","isHexColor","isSafeAvatarUrl","url","URL","globalThis","location","href","protocol","people","state","options","allow","allowAvatarUrl","byId","Map","add","presence","self","id","name","avatarUrl","user","known","get","status","set","undefined","includeSelf","peer","peers","all","values","visible","slice","max","hidden","typingNames","names","typing","initials","letters","trim","split","filter","Boolean","map","word","toUpperCase","join","relativePointer","clientX","clientY","box","fraction","value","size","Math","min","x","left","width","y","top","height","describeWrite","op","ref","type","data","document","Array","isArray","length","describeError","errors","first","detail","title"],"mappings":";;AAAA;AACA;;AAKA;;AAWA;AACO,MAAMA,cAAc,GAAG,SAAS;;AAEvC;AACA;AACA;AACA;AACA;AACO,SAASC,SAASA,CAACC,KAAc,EAAU;AAChD,EAAA,OAAOC,UAAU,CAACD,KAAK,CAAC,GAAGA,KAAK,GAAGF,cAAc;AACnD;;AAEA;AACA;AACA;AACA;AACO,SAASI,eAAeA,CAACC,GAAW,EAAW;EACpD,IAAI;AACF,IAAA,OAAO,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