@uvalib/web-components 1.8.5 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +48 -0
- package/README.md +719 -72
- package/bin/install-skill.mjs +174 -54
- package/dist/base/clipboard.d.ts +9 -0
- package/dist/base/clipboard.js +30 -0
- package/dist/base/clipboard.js.map +1 -0
- package/dist/base.css +301 -3
- package/dist/components/uvalib-citation/UvalibCitation.d.ts +124 -0
- package/dist/components/uvalib-citation/UvalibCitation.js +545 -0
- package/dist/components/uvalib-citation/UvalibCitation.js.map +1 -0
- package/dist/components/uvalib-citation/uvalib-citation.d.ts +1 -0
- package/dist/components/uvalib-citation/uvalib-citation.js +4 -0
- package/dist/components/uvalib-citation/uvalib-citation.js.map +1 -0
- package/dist/components/uvalib-dialog/UvalibDialog.d.ts +167 -0
- package/dist/components/uvalib-dialog/UvalibDialog.js +688 -0
- package/dist/components/uvalib-dialog/UvalibDialog.js.map +1 -0
- package/dist/components/uvalib-dialog/uvalib-dialog.d.ts +1 -0
- package/dist/components/uvalib-dialog/uvalib-dialog.js +4 -0
- package/dist/components/uvalib-dialog/uvalib-dialog.js.map +1 -0
- package/dist/components/uvalib-filter/UvalibFilter.d.ts +92 -9
- package/dist/components/uvalib-filter/UvalibFilter.js +748 -60
- package/dist/components/uvalib-filter/UvalibFilter.js.map +1 -1
- package/dist/components/uvalib-list-filter/UvalibListFilter.d.ts +162 -0
- package/dist/components/uvalib-list-filter/UvalibListFilter.js +685 -0
- package/dist/components/uvalib-list-filter/UvalibListFilter.js.map +1 -0
- package/dist/components/uvalib-list-filter/uvalib-list-filter.d.ts +1 -0
- package/dist/components/uvalib-list-filter/uvalib-list-filter.js +4 -0
- package/dist/components/uvalib-list-filter/uvalib-list-filter.js.map +1 -0
- package/dist/components/uvalib-metadata/UvalibMetadata.js +3 -4
- package/dist/components/uvalib-metadata/UvalibMetadata.js.map +1 -1
- package/dist/components/uvalib-pagefind-search/UvalibPagefindSearch.d.ts +28 -1
- package/dist/components/uvalib-pagefind-search/UvalibPagefindSearch.js +139 -3
- package/dist/components/uvalib-pagefind-search/UvalibPagefindSearch.js.map +1 -1
- package/dist/custom-elements.json +9503 -6086
- package/dist/edition.css +758 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/styles/base.js +112 -1
- package/dist/styles/base.js.map +1 -1
- package/dist/styles/color-scheme.js +4 -0
- package/dist/styles/color-scheme.js.map +1 -1
- package/dist/styles/controls.js +6 -0
- package/dist/styles/controls.js.map +1 -1
- package/dist/styles/edition.d.ts +1 -0
- package/dist/styles/edition.js +747 -0
- package/dist/styles/edition.js.map +1 -0
- package/dist/styles/field-text.d.ts +1 -0
- package/dist/styles/field-text.js +21 -0
- package/dist/styles/field-text.js.map +1 -0
- package/dist/styles/hidden.js +15 -1
- package/dist/styles/hidden.js.map +1 -1
- package/dist/styles/layout.d.ts +1 -0
- package/dist/styles/layout.js +92 -0
- package/dist/styles/layout.js.map +1 -0
- package/dist/styles/table.d.ts +1 -0
- package/dist/styles/table.js +164 -0
- package/dist/styles/table.js.map +1 -0
- package/dist/tokens.css +4 -0
- package/dist-cdn/base.css +301 -3
- package/dist-cdn/chunks/{base-B3tNX103.js → base-DXkGlSgH.js} +113 -2
- package/dist-cdn/chunks/base-DXkGlSgH.js.map +1 -0
- package/dist-cdn/chunks/clipboard-CNG7Y_5X.js +18 -0
- package/dist-cdn/chunks/clipboard-CNG7Y_5X.js.map +1 -0
- package/dist-cdn/chunks/if-defined-COiQb-gl.js +6 -0
- package/dist-cdn/chunks/if-defined-COiQb-gl.js.map +1 -0
- package/dist-cdn/chunks/{site-header-CEmNtmk5.js → site-header-B78a_ldi.js} +27 -22
- package/dist-cdn/chunks/site-header-B78a_ldi.js.map +1 -0
- package/dist-cdn/chunks/{site-main-nav-CAwKq_x5.js → site-main-nav-CmMq2t8t.js} +52 -51
- package/dist-cdn/chunks/site-main-nav-CmMq2t8t.js.map +1 -0
- package/dist-cdn/custom-elements.json +9503 -6086
- package/dist-cdn/edition.css +758 -0
- package/dist-cdn/manifest.json +7 -3
- package/dist-cdn/site-header.js +1 -1
- package/dist-cdn/site-main-nav.js +1 -1
- package/dist-cdn/site-page.js +3 -3
- package/dist-cdn/site-style.js +1 -1
- package/dist-cdn/skills/uvalib-web-components/SKILL.md +34 -10
- package/dist-cdn/skills/uvalib-web-components/reference/components.md +188 -9
- package/dist-cdn/tokens.css +4 -0
- package/dist-cdn/uvalib-citation.js +382 -0
- package/dist-cdn/uvalib-citation.js.map +1 -0
- package/dist-cdn/uvalib-dialog.js +419 -0
- package/dist-cdn/uvalib-dialog.js.map +1 -0
- package/dist-cdn/uvalib-filter.js +603 -69
- package/dist-cdn/uvalib-filter.js.map +1 -1
- package/dist-cdn/uvalib-list-filter.js +451 -0
- package/dist-cdn/uvalib-list-filter.js.map +1 -0
- package/dist-cdn/uvalib-metadata.js +49 -49
- package/dist-cdn/uvalib-metadata.js.map +1 -1
- package/dist-cdn/uvalib-pagefind-search.js +118 -48
- package/dist-cdn/uvalib-pagefind-search.js.map +1 -1
- package/package.json +14 -1
- package/skills/uvalib-web-components/SKILL.md +34 -10
- package/skills/uvalib-web-components/reference/components.md +188 -9
- package/dist-cdn/chunks/base-B3tNX103.js.map +0 -1
- package/dist-cdn/chunks/site-header-CEmNtmk5.js.map +0 -1
- package/dist-cdn/chunks/site-main-nav-CAwKq_x5.js.map +0 -1
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { nothing, type PropertyValues } from 'lit';
|
|
2
|
+
import { UvalibElement } from '../../base/UvalibElement.js';
|
|
3
|
+
/** One format's citation, for apps: plain `text`, or `html` with inline emphasis only. */
|
|
4
|
+
export interface CitationItem {
|
|
5
|
+
/** The format's name, shown on its radio and in the status: `MLA`, `APA`, `Chicago`… */
|
|
6
|
+
format: string;
|
|
7
|
+
/** The citation as plain text (never parsed as HTML). */
|
|
8
|
+
text?: string;
|
|
9
|
+
/**
|
|
10
|
+
* The citation with inline markup such as `<i>` for a title. Only inline elements (`i`,
|
|
11
|
+
* `em`, `b`, `strong`, `span`, `cite`…) are kept, without attributes other than `lang` and
|
|
12
|
+
* `dir`; anything else is reduced to its text. Wins over `text`.
|
|
13
|
+
*/
|
|
14
|
+
html?: string;
|
|
15
|
+
}
|
|
16
|
+
/** The visitor's last format with `remember` (localStorage is per origin: per site). */
|
|
17
|
+
export declare const STORAGE_KEY = "uvalib-citation-format";
|
|
18
|
+
/**
|
|
19
|
+
* Format changes within `settle` ms count as one for analytics (arrowing through the radios
|
|
20
|
+
* reports once, for the format the visitor ends on; nothing when it is where they started).
|
|
21
|
+
* Tests may shorten it.
|
|
22
|
+
*/
|
|
23
|
+
export declare const citationTiming: {
|
|
24
|
+
settle: number;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* One record's citation in several formats (MLA, APA, Chicago, Bluebook…), a radio group to
|
|
28
|
+
* choose one, and a Copy citation button, as in Virgo's Cite dialog. Inline on a record page
|
|
29
|
+
* or inside a dialog: it assumes nothing about where it sits.
|
|
30
|
+
*
|
|
31
|
+
* Give each format as a child, `<blockquote data-format="MLA">…</blockquote>` (any element
|
|
32
|
+
* with `data-format`), so the page reads the same before the script loads (with `base.css`,
|
|
33
|
+
* only the first shows then, and the chooser's and button's space is held). Inline markup in
|
|
34
|
+
* a citation (`<i>` or `<em>` for a title) is kept; other elements are reduced to their text
|
|
35
|
+
* and nothing is parsed as HTML. Apps set the `citations` property instead (`[{ format, text,
|
|
36
|
+
* html? }]`, winning over the children while set); `html` keeps only inline elements, too.
|
|
37
|
+
*
|
|
38
|
+
* The formats are native radios drawn as one segmented bar (`role="radiogroup"`, "Citation
|
|
39
|
+
* format"): one tab stop, the arrow keys move and select, and the selected one is filled and
|
|
40
|
+
* ticked. `format` names the selected one (default the first). With `remember`, the visitor's
|
|
41
|
+
* last choice is kept in localStorage (per site) and wins over `format` on their next record.
|
|
42
|
+
*
|
|
43
|
+
* The selected citation is shown as selectable text in a region named "<format> citation".
|
|
44
|
+
* Copy citation copies it as plain text and as HTML where the browser allows (so an italic
|
|
45
|
+
* title stays italic when pasted into a word processor) and says "MLA citation copied" in a
|
|
46
|
+
* polite status next to the button, in the text colour (AAA), not in a toast. If the clipboard
|
|
47
|
+
* is unavailable, the citation is selected and the status says to copy it with the keyboard.
|
|
48
|
+
*
|
|
49
|
+
* `ris-href` adds a "Download RIS" link (`ris-label`) with a `download` attribute. Other export
|
|
50
|
+
* links go in the `actions` slot (`<a slot="actions" href="…" download>EndNote</a>`), after it.
|
|
51
|
+
*
|
|
52
|
+
* @tagname uvalib-citation
|
|
53
|
+
* @slot actions - More export links or buttons, after Copy citation and Download RIS.
|
|
54
|
+
* @fires uvalib-citation-format - The visitor chose another format: `detail` is `{ format }`. Not fired when the app sets `format`. Bubbles and is composed.
|
|
55
|
+
* @fires uvalib-analytics-event - For `<site-analytics>`, on the visitor's actions only: `['uvalib-citation', 'format', '<format>']` (once the visitor settles on one, a second after the last change), `['uvalib-citation', 'copy', '<format>']` and `['uvalib-citation', 'download', 'ris']`. Never the citation. Bubbles and is composed.
|
|
56
|
+
* @cssprop --uva-color-text - Dark-mode role token: label, citation and status colour (else `--uva-grey-darkest`).
|
|
57
|
+
* @cssprop --uva-color-border - Dark-mode role token: the citation's border (else #dadada).
|
|
58
|
+
* @cssprop --uva-color-surface-raised - Dark-mode role token: the citation's, segments' and buttons' background (else #fff).
|
|
59
|
+
* @cssprop --uva-color-control-border - Dark-mode role token: segment border (else `--uva-grey`, #808080).
|
|
60
|
+
* @cssprop --uva-color-link - Dark-mode role token: segment and button text, button border (else `--uva-brand-blue`).
|
|
61
|
+
* @cssprop --uva-color-accent-bg - Dark-mode role token: the selected segment (else `--uva-brand-blue`).
|
|
62
|
+
* @cssprop --uva-color-on-accent - Dark-mode role token: the selected segment's text (else #fff).
|
|
63
|
+
* @cssprop --uva-color-focus - Dark-mode role token: focus ring (else `--uva-brand-orange`).
|
|
64
|
+
*/
|
|
65
|
+
export declare class UvalibCitation extends UvalibElement {
|
|
66
|
+
static styles: import("lit").CSSResult[];
|
|
67
|
+
/** The group's visible label and accessible name. */
|
|
68
|
+
label: string;
|
|
69
|
+
/** Hide the label visually (it still names the group), for a dialog whose heading says it. */
|
|
70
|
+
hideLabel: boolean;
|
|
71
|
+
/** The selected format's name (default the first). Reflected when the visitor chooses one. */
|
|
72
|
+
format: string;
|
|
73
|
+
/** Keep the visitor's last format in localStorage (per site), winning over `format`. */
|
|
74
|
+
remember: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* The citations as data, for apps: `{ format, text?, html? }`. Wins over the children while
|
|
77
|
+
* set; `undefined` goes back to them.
|
|
78
|
+
*/
|
|
79
|
+
citations?: CitationItem[];
|
|
80
|
+
/** A RIS file for the record: adds a download link. */
|
|
81
|
+
risHref: string;
|
|
82
|
+
/** The RIS link's text. */
|
|
83
|
+
risLabel: string;
|
|
84
|
+
private childFormats;
|
|
85
|
+
private status;
|
|
86
|
+
private readonly uid;
|
|
87
|
+
private readonly source;
|
|
88
|
+
private sourceKey;
|
|
89
|
+
private restored;
|
|
90
|
+
private warned;
|
|
91
|
+
private timer?;
|
|
92
|
+
/** The format change waiting to settle: where the burst started. */
|
|
93
|
+
private pending?;
|
|
94
|
+
private settleTimer?;
|
|
95
|
+
/** The `citations` array the formats below were made from. */
|
|
96
|
+
private madeFrom?;
|
|
97
|
+
private made;
|
|
98
|
+
constructor();
|
|
99
|
+
protected createRenderRoot(): HTMLElement | DocumentFragment;
|
|
100
|
+
connectedCallback(): void;
|
|
101
|
+
disconnectedCallback(): void;
|
|
102
|
+
private warnOnce;
|
|
103
|
+
/** Read the formats from the children with `data-format` (not the `actions` slot). */
|
|
104
|
+
private read;
|
|
105
|
+
/** The first of each name, with one warning for the others. */
|
|
106
|
+
private unique;
|
|
107
|
+
/** The formats from `citations`, made once per array. */
|
|
108
|
+
private fromItems;
|
|
109
|
+
private get formats();
|
|
110
|
+
/** The selected format: `format` (case-insensitive), else the first. */
|
|
111
|
+
private get selected();
|
|
112
|
+
protected willUpdate(changed: PropertyValues): void;
|
|
113
|
+
protected updated(changed: PropertyValues): void;
|
|
114
|
+
/** Light DOM has no slots: move `slot="actions"` children into the actions row. */
|
|
115
|
+
private placeActions;
|
|
116
|
+
private choose;
|
|
117
|
+
/** Report the format the visitor settled on, unless it is where they started. */
|
|
118
|
+
private flushFormat;
|
|
119
|
+
private get citationEl();
|
|
120
|
+
private copy;
|
|
121
|
+
private download;
|
|
122
|
+
private renderRis;
|
|
123
|
+
protected render(): typeof nothing | import("lit").TemplateResult<1>;
|
|
124
|
+
}
|
|
@@ -0,0 +1,545 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { css, html, nothing, svg, unsafeCSS } from 'lit';
|
|
8
|
+
import { property, state } from 'lit/decorators.js';
|
|
9
|
+
import { trackEvent } from '../../base/analytics.js';
|
|
10
|
+
import { copyText, selectContents } from '../../base/clipboard.js';
|
|
11
|
+
import { UvalibElement } from '../../base/UvalibElement.js';
|
|
12
|
+
import { installLightDomStyles } from '../../base/light-dom-styles.js';
|
|
13
|
+
import { inlineCopy } from '../../base/inline-copy.js';
|
|
14
|
+
import { normalize, safeHref, SourceChildren } from '../../base/source-children.js';
|
|
15
|
+
import { accessible } from '../../styles/accessible.js';
|
|
16
|
+
const TAG = 'uvalib-citation';
|
|
17
|
+
/** The visitor's last format with `remember` (localStorage is per origin: per site). */
|
|
18
|
+
export const STORAGE_KEY = 'uvalib-citation-format';
|
|
19
|
+
const STATUS_MS = 5000;
|
|
20
|
+
/**
|
|
21
|
+
* Format changes within `settle` ms count as one for analytics (arrowing through the radios
|
|
22
|
+
* reports once, for the format the visitor ends on; nothing when it is where they started).
|
|
23
|
+
* Tests may shorten it.
|
|
24
|
+
*/
|
|
25
|
+
export const citationTiming = { settle: 1000 };
|
|
26
|
+
let uid = 0;
|
|
27
|
+
/** The tick on the selected format, so the state never rests on colour alone. */
|
|
28
|
+
const CHECK = svg `<svg class="check" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><path d="M3 8.5l3.2 3.2L13 4.8" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"/></svg>`;
|
|
29
|
+
/**
|
|
30
|
+
* Kept with `no-style`: the stacking, each radio laid over its 44px segment, the visually
|
|
31
|
+
* hidden text, and `[hidden]`. `host` is `:host` or the tag.
|
|
32
|
+
*/
|
|
33
|
+
const structuralRules = (host) => `
|
|
34
|
+
${host} { display: block; min-width: 0; }
|
|
35
|
+
/* Its own formatting context: the format bar's negative margin (focus-ring room) stays in. */
|
|
36
|
+
${host} .wrap { display: flow-root; }
|
|
37
|
+
${host} .formats {
|
|
38
|
+
display: flex;
|
|
39
|
+
flex-wrap: nowrap;
|
|
40
|
+
overflow-x: auto;
|
|
41
|
+
min-width: 0;
|
|
42
|
+
}
|
|
43
|
+
${host} .format {
|
|
44
|
+
position: relative;
|
|
45
|
+
display: inline-flex;
|
|
46
|
+
flex: none;
|
|
47
|
+
box-sizing: border-box;
|
|
48
|
+
min-width: 44px;
|
|
49
|
+
min-height: 44px;
|
|
50
|
+
margin: 0;
|
|
51
|
+
cursor: pointer;
|
|
52
|
+
}
|
|
53
|
+
${host} .format input {
|
|
54
|
+
position: absolute;
|
|
55
|
+
inset: 0;
|
|
56
|
+
width: 100%;
|
|
57
|
+
height: 100%;
|
|
58
|
+
margin: 0;
|
|
59
|
+
opacity: 0;
|
|
60
|
+
cursor: inherit;
|
|
61
|
+
}
|
|
62
|
+
${host} .face {
|
|
63
|
+
display: inline-flex;
|
|
64
|
+
flex: 1;
|
|
65
|
+
align-items: center;
|
|
66
|
+
justify-content: center;
|
|
67
|
+
gap: 0.375rem;
|
|
68
|
+
white-space: nowrap;
|
|
69
|
+
}
|
|
70
|
+
${host} .check { flex: none; width: 1em; height: 1em; }
|
|
71
|
+
${host} .format input:not(:checked) + .face .check { display: none; }
|
|
72
|
+
${host} .format input:focus-visible + .face {
|
|
73
|
+
outline: 3px solid var(--uva-color-focus, var(--uva-brand-orange, #e57200));
|
|
74
|
+
outline-offset: 2px;
|
|
75
|
+
}
|
|
76
|
+
${host} .actions { display: flex; flex-wrap: wrap; align-items: center; }
|
|
77
|
+
${host} .extra { display: contents; }
|
|
78
|
+
${host} .uvalib-button { box-sizing: border-box; min-height: 44px; }
|
|
79
|
+
${host} .visually-hidden {
|
|
80
|
+
position: absolute;
|
|
81
|
+
width: 1px;
|
|
82
|
+
height: 1px;
|
|
83
|
+
margin: -1px;
|
|
84
|
+
padding: 0;
|
|
85
|
+
overflow: hidden;
|
|
86
|
+
clip: rect(0, 0, 0, 0);
|
|
87
|
+
white-space: nowrap;
|
|
88
|
+
border: 0;
|
|
89
|
+
}
|
|
90
|
+
${host}[hidden], ${host} [hidden] { display: none !important; }
|
|
91
|
+
`;
|
|
92
|
+
const shadowStructure = unsafeCSS(structuralRules(':host'));
|
|
93
|
+
const BORDER = unsafeCSS('var(--uva-color-control-border, var(--uva-grey, #808080))');
|
|
94
|
+
const LINK = unsafeCSS('var(--uva-color-link, var(--uva-brand-blue, #232d4b))');
|
|
95
|
+
const ACCENT = unsafeCSS('var(--uva-color-accent-bg, var(--uva-brand-blue, #232d4b))');
|
|
96
|
+
/**
|
|
97
|
+
* One record's citation in several formats (MLA, APA, Chicago, Bluebook…), a radio group to
|
|
98
|
+
* choose one, and a Copy citation button, as in Virgo's Cite dialog. Inline on a record page
|
|
99
|
+
* or inside a dialog: it assumes nothing about where it sits.
|
|
100
|
+
*
|
|
101
|
+
* Give each format as a child, `<blockquote data-format="MLA">…</blockquote>` (any element
|
|
102
|
+
* with `data-format`), so the page reads the same before the script loads (with `base.css`,
|
|
103
|
+
* only the first shows then, and the chooser's and button's space is held). Inline markup in
|
|
104
|
+
* a citation (`<i>` or `<em>` for a title) is kept; other elements are reduced to their text
|
|
105
|
+
* and nothing is parsed as HTML. Apps set the `citations` property instead (`[{ format, text,
|
|
106
|
+
* html? }]`, winning over the children while set); `html` keeps only inline elements, too.
|
|
107
|
+
*
|
|
108
|
+
* The formats are native radios drawn as one segmented bar (`role="radiogroup"`, "Citation
|
|
109
|
+
* format"): one tab stop, the arrow keys move and select, and the selected one is filled and
|
|
110
|
+
* ticked. `format` names the selected one (default the first). With `remember`, the visitor's
|
|
111
|
+
* last choice is kept in localStorage (per site) and wins over `format` on their next record.
|
|
112
|
+
*
|
|
113
|
+
* The selected citation is shown as selectable text in a region named "<format> citation".
|
|
114
|
+
* Copy citation copies it as plain text and as HTML where the browser allows (so an italic
|
|
115
|
+
* title stays italic when pasted into a word processor) and says "MLA citation copied" in a
|
|
116
|
+
* polite status next to the button, in the text colour (AAA), not in a toast. If the clipboard
|
|
117
|
+
* is unavailable, the citation is selected and the status says to copy it with the keyboard.
|
|
118
|
+
*
|
|
119
|
+
* `ris-href` adds a "Download RIS" link (`ris-label`) with a `download` attribute. Other export
|
|
120
|
+
* links go in the `actions` slot (`<a slot="actions" href="…" download>EndNote</a>`), after it.
|
|
121
|
+
*
|
|
122
|
+
* @tagname uvalib-citation
|
|
123
|
+
* @slot actions - More export links or buttons, after Copy citation and Download RIS.
|
|
124
|
+
* @fires uvalib-citation-format - The visitor chose another format: `detail` is `{ format }`. Not fired when the app sets `format`. Bubbles and is composed.
|
|
125
|
+
* @fires uvalib-analytics-event - For `<site-analytics>`, on the visitor's actions only: `['uvalib-citation', 'format', '<format>']` (once the visitor settles on one, a second after the last change), `['uvalib-citation', 'copy', '<format>']` and `['uvalib-citation', 'download', 'ris']`. Never the citation. Bubbles and is composed.
|
|
126
|
+
* @cssprop --uva-color-text - Dark-mode role token: label, citation and status colour (else `--uva-grey-darkest`).
|
|
127
|
+
* @cssprop --uva-color-border - Dark-mode role token: the citation's border (else #dadada).
|
|
128
|
+
* @cssprop --uva-color-surface-raised - Dark-mode role token: the citation's, segments' and buttons' background (else #fff).
|
|
129
|
+
* @cssprop --uva-color-control-border - Dark-mode role token: segment border (else `--uva-grey`, #808080).
|
|
130
|
+
* @cssprop --uva-color-link - Dark-mode role token: segment and button text, button border (else `--uva-brand-blue`).
|
|
131
|
+
* @cssprop --uva-color-accent-bg - Dark-mode role token: the selected segment (else `--uva-brand-blue`).
|
|
132
|
+
* @cssprop --uva-color-on-accent - Dark-mode role token: the selected segment's text (else #fff).
|
|
133
|
+
* @cssprop --uva-color-focus - Dark-mode role token: focus ring (else `--uva-brand-orange`).
|
|
134
|
+
*/
|
|
135
|
+
export class UvalibCitation extends UvalibElement {
|
|
136
|
+
static { this.styles = [
|
|
137
|
+
accessible,
|
|
138
|
+
shadowStructure,
|
|
139
|
+
css `
|
|
140
|
+
:host {
|
|
141
|
+
font-size: 1rem;
|
|
142
|
+
line-height: 1.5;
|
|
143
|
+
color: var(--uva-color-text, var(--uva-grey-darkest, #2b2b2b));
|
|
144
|
+
}
|
|
145
|
+
.label {
|
|
146
|
+
margin: 0 0 0.5rem;
|
|
147
|
+
font-weight: 700;
|
|
148
|
+
}
|
|
149
|
+
/* The padding keeps the focus ring inside the scroll box; the bar itself is 44px. */
|
|
150
|
+
.formats {
|
|
151
|
+
padding: 0.375rem;
|
|
152
|
+
margin: -0.375rem -0.375rem 0.375rem;
|
|
153
|
+
}
|
|
154
|
+
.face {
|
|
155
|
+
padding: 0.25rem 0.75rem;
|
|
156
|
+
border: 1px solid ${BORDER};
|
|
157
|
+
background: var(--uva-color-surface-raised, #fff);
|
|
158
|
+
color: ${LINK};
|
|
159
|
+
font-size: 0.875rem;
|
|
160
|
+
font-weight: 600;
|
|
161
|
+
line-height: 1.3;
|
|
162
|
+
}
|
|
163
|
+
.format + .format {
|
|
164
|
+
margin-inline-start: -1px;
|
|
165
|
+
}
|
|
166
|
+
.format:first-child .face {
|
|
167
|
+
border-start-start-radius: 0.3rem;
|
|
168
|
+
border-end-start-radius: 0.3rem;
|
|
169
|
+
}
|
|
170
|
+
.format:last-child .face {
|
|
171
|
+
border-start-end-radius: 0.3rem;
|
|
172
|
+
border-end-end-radius: 0.3rem;
|
|
173
|
+
}
|
|
174
|
+
.format:hover input:not(:checked) + .face {
|
|
175
|
+
position: relative;
|
|
176
|
+
border-color: ${LINK};
|
|
177
|
+
}
|
|
178
|
+
.format input:checked + .face {
|
|
179
|
+
position: relative;
|
|
180
|
+
border-color: ${ACCENT};
|
|
181
|
+
background: ${ACCENT};
|
|
182
|
+
color: var(--uva-color-on-accent, #fff);
|
|
183
|
+
}
|
|
184
|
+
.format input:focus-visible + .face {
|
|
185
|
+
position: relative;
|
|
186
|
+
z-index: 1;
|
|
187
|
+
}
|
|
188
|
+
.citation {
|
|
189
|
+
margin: 0;
|
|
190
|
+
padding: 0.75rem 1rem;
|
|
191
|
+
border: 1px solid var(--uva-color-border, var(--uva-grey-100, #dadada));
|
|
192
|
+
border-radius: 0.3rem;
|
|
193
|
+
background: var(--uva-color-surface-raised, #fff);
|
|
194
|
+
overflow-wrap: anywhere;
|
|
195
|
+
text-wrap: pretty;
|
|
196
|
+
}
|
|
197
|
+
.actions {
|
|
198
|
+
gap: 0.5rem 0.75rem;
|
|
199
|
+
margin-top: 0.75rem;
|
|
200
|
+
}
|
|
201
|
+
.uvalib-button {
|
|
202
|
+
display: inline-flex;
|
|
203
|
+
align-items: center;
|
|
204
|
+
padding: 0.25rem 0.75rem;
|
|
205
|
+
border: 1px solid ${LINK};
|
|
206
|
+
border-radius: 0.3rem;
|
|
207
|
+
background: var(--uva-color-surface-raised, #fff);
|
|
208
|
+
color: ${LINK};
|
|
209
|
+
font: inherit;
|
|
210
|
+
text-decoration: none;
|
|
211
|
+
cursor: pointer;
|
|
212
|
+
}
|
|
213
|
+
a.uvalib-button {
|
|
214
|
+
text-decoration: underline;
|
|
215
|
+
}
|
|
216
|
+
.uvalib-button:hover {
|
|
217
|
+
text-decoration: underline;
|
|
218
|
+
}
|
|
219
|
+
slot[name='actions']::slotted(*) {
|
|
220
|
+
min-height: 44px;
|
|
221
|
+
}
|
|
222
|
+
.status {
|
|
223
|
+
color: var(--uva-color-text, var(--uva-grey-darkest, #2b2b2b));
|
|
224
|
+
font-weight: 600;
|
|
225
|
+
}
|
|
226
|
+
@media (forced-colors: active) {
|
|
227
|
+
.face,
|
|
228
|
+
.citation,
|
|
229
|
+
.uvalib-button {
|
|
230
|
+
border-color: ButtonText;
|
|
231
|
+
}
|
|
232
|
+
.face,
|
|
233
|
+
button.uvalib-button {
|
|
234
|
+
color: ButtonText;
|
|
235
|
+
}
|
|
236
|
+
a.uvalib-button {
|
|
237
|
+
color: LinkText;
|
|
238
|
+
}
|
|
239
|
+
.format input:checked + .face {
|
|
240
|
+
forced-color-adjust: none;
|
|
241
|
+
border-color: Highlight;
|
|
242
|
+
background: Highlight;
|
|
243
|
+
color: HighlightText;
|
|
244
|
+
}
|
|
245
|
+
.format input:focus-visible + .face {
|
|
246
|
+
outline-color: Highlight;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
`,
|
|
250
|
+
]; }
|
|
251
|
+
constructor() {
|
|
252
|
+
super();
|
|
253
|
+
/** The group's visible label and accessible name. */
|
|
254
|
+
this.label = 'Cite this item';
|
|
255
|
+
/** Hide the label visually (it still names the group), for a dialog whose heading says it. */
|
|
256
|
+
this.hideLabel = false;
|
|
257
|
+
/** The selected format's name (default the first). Reflected when the visitor chooses one. */
|
|
258
|
+
this.format = '';
|
|
259
|
+
/** Keep the visitor's last format in localStorage (per site), winning over `format`. */
|
|
260
|
+
this.remember = false;
|
|
261
|
+
/** A RIS file for the record: adds a download link. */
|
|
262
|
+
this.risHref = '';
|
|
263
|
+
/** The RIS link's text. */
|
|
264
|
+
this.risLabel = 'Download RIS';
|
|
265
|
+
this.childFormats = [];
|
|
266
|
+
this.status = '';
|
|
267
|
+
this.uid = `${TAG}-${++uid}`;
|
|
268
|
+
this.sourceKey = '';
|
|
269
|
+
this.restored = false;
|
|
270
|
+
this.warned = new Set();
|
|
271
|
+
this.made = [];
|
|
272
|
+
this.source = new SourceChildren(this, () => this.lightDom, (nodes) => this.read(nodes));
|
|
273
|
+
}
|
|
274
|
+
createRenderRoot() {
|
|
275
|
+
const root = super.createRenderRoot();
|
|
276
|
+
if (root instanceof ShadowRoot && this.noStyle) {
|
|
277
|
+
const sheet = shadowStructure.styleSheet;
|
|
278
|
+
if (sheet)
|
|
279
|
+
root.adoptedStyleSheets = [sheet];
|
|
280
|
+
}
|
|
281
|
+
return root;
|
|
282
|
+
}
|
|
283
|
+
connectedCallback() {
|
|
284
|
+
super.connectedCallback();
|
|
285
|
+
if (this.lightDom && this.noStyle) {
|
|
286
|
+
const node = this.getRootNode();
|
|
287
|
+
installLightDomStyles(`${TAG}::structure`, unsafeCSS(structuralRules(TAG)), {
|
|
288
|
+
root: node instanceof ShadowRoot || node instanceof Document ? node : undefined,
|
|
289
|
+
scope: false,
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
disconnectedCallback() {
|
|
294
|
+
super.disconnectedCallback();
|
|
295
|
+
clearTimeout(this.timer);
|
|
296
|
+
this.flushFormat();
|
|
297
|
+
this.status = '';
|
|
298
|
+
}
|
|
299
|
+
warnOnce(kind, message) {
|
|
300
|
+
if (this.warned.has(kind))
|
|
301
|
+
return;
|
|
302
|
+
this.warned.add(kind);
|
|
303
|
+
console.warn(`${TAG}: ${message}`);
|
|
304
|
+
}
|
|
305
|
+
/** Read the formats from the children with `data-format` (not the `actions` slot). */
|
|
306
|
+
read(nodes) {
|
|
307
|
+
const formats = [];
|
|
308
|
+
for (const n of nodes) {
|
|
309
|
+
if (!(n instanceof Element) || !n.hasAttribute('data-format'))
|
|
310
|
+
continue;
|
|
311
|
+
const name = normalize(n.getAttribute('data-format'));
|
|
312
|
+
if (!name) {
|
|
313
|
+
this.warnOnce('format', 'ignoring a citation with an empty data-format.');
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
formats.push({ name, ...inlineCopy(n.childNodes, this.ownerDocument) });
|
|
317
|
+
}
|
|
318
|
+
const unique = this.unique(formats);
|
|
319
|
+
const key = unique.map((f) => `${f.name}\u0000${f.key}`).join('\u0001');
|
|
320
|
+
if (key === this.sourceKey)
|
|
321
|
+
return;
|
|
322
|
+
this.sourceKey = key;
|
|
323
|
+
this.childFormats = unique;
|
|
324
|
+
}
|
|
325
|
+
/** The first of each name, with one warning for the others. */
|
|
326
|
+
unique(formats) {
|
|
327
|
+
const seen = new Set();
|
|
328
|
+
return formats.filter((f) => {
|
|
329
|
+
const k = f.name.toLowerCase();
|
|
330
|
+
if (seen.has(k)) {
|
|
331
|
+
this.warnOnce('duplicate', `ignoring a second citation named "${f.name}".`);
|
|
332
|
+
return false;
|
|
333
|
+
}
|
|
334
|
+
seen.add(k);
|
|
335
|
+
return true;
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
/** The formats from `citations`, made once per array. */
|
|
339
|
+
fromItems(items) {
|
|
340
|
+
if (items === this.madeFrom)
|
|
341
|
+
return this.made;
|
|
342
|
+
const doc = this.ownerDocument;
|
|
343
|
+
const formats = [];
|
|
344
|
+
for (const i of items) {
|
|
345
|
+
const name = normalize(i?.format);
|
|
346
|
+
if (!name) {
|
|
347
|
+
this.warnOnce('format', 'ignoring a citation with no format.');
|
|
348
|
+
continue;
|
|
349
|
+
}
|
|
350
|
+
let source;
|
|
351
|
+
if (typeof i.html === 'string') {
|
|
352
|
+
// A template's content is inert: nothing in it runs or loads.
|
|
353
|
+
const t = doc.createElement('template');
|
|
354
|
+
t.innerHTML = i.html;
|
|
355
|
+
source = [...t.content.childNodes];
|
|
356
|
+
}
|
|
357
|
+
else
|
|
358
|
+
source = [doc.createTextNode(i.text == null ? '' : String(i.text))];
|
|
359
|
+
formats.push({ name, ...inlineCopy(source, doc) });
|
|
360
|
+
}
|
|
361
|
+
this.madeFrom = items;
|
|
362
|
+
this.made = this.unique(formats);
|
|
363
|
+
return this.made;
|
|
364
|
+
}
|
|
365
|
+
get formats() {
|
|
366
|
+
return this.citations ? this.fromItems(this.citations) : this.childFormats;
|
|
367
|
+
}
|
|
368
|
+
/** The selected format: `format` (case-insensitive), else the first. */
|
|
369
|
+
get selected() {
|
|
370
|
+
const all = this.formats;
|
|
371
|
+
const want = normalize(this.format);
|
|
372
|
+
return (all.find((f) => f.name === want) ??
|
|
373
|
+
all.find((f) => f.name.toLowerCase() === want.toLowerCase()) ??
|
|
374
|
+
all[0]);
|
|
375
|
+
}
|
|
376
|
+
willUpdate(changed) {
|
|
377
|
+
super.willUpdate(changed);
|
|
378
|
+
// With `remember`, the visitor's last format wins once, when this record has it.
|
|
379
|
+
if (this.remember && !this.restored && this.formats.length) {
|
|
380
|
+
this.restored = true;
|
|
381
|
+
const stored = readStored();
|
|
382
|
+
const match = stored && this.formats.find((f) => f.name.toLowerCase() === stored);
|
|
383
|
+
if (match)
|
|
384
|
+
this.format = match.name;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
updated(changed) {
|
|
388
|
+
super.updated(changed);
|
|
389
|
+
this.toggleAttribute('data-empty', !this.formats.length);
|
|
390
|
+
if (this.lightDom)
|
|
391
|
+
this.placeActions();
|
|
392
|
+
}
|
|
393
|
+
/** Light DOM has no slots: move `slot="actions"` children into the actions row. */
|
|
394
|
+
placeActions() {
|
|
395
|
+
const row = this.querySelector(':scope > .wrap .extra');
|
|
396
|
+
if (!row)
|
|
397
|
+
return;
|
|
398
|
+
for (const n of this.source.nodes())
|
|
399
|
+
if (n instanceof Element && n.getAttribute('slot') === 'actions')
|
|
400
|
+
row.append(n);
|
|
401
|
+
}
|
|
402
|
+
choose(name) {
|
|
403
|
+
const before = this.selected?.name ?? '';
|
|
404
|
+
if (name === before)
|
|
405
|
+
return;
|
|
406
|
+
this.format = name;
|
|
407
|
+
clearTimeout(this.timer);
|
|
408
|
+
this.status = '';
|
|
409
|
+
if (this.remember)
|
|
410
|
+
writeStored(name.toLowerCase());
|
|
411
|
+
this.dispatchEvent(new CustomEvent('uvalib-citation-format', {
|
|
412
|
+
detail: { format: name },
|
|
413
|
+
bubbles: true,
|
|
414
|
+
composed: true,
|
|
415
|
+
}));
|
|
416
|
+
this.pending ??= before;
|
|
417
|
+
clearTimeout(this.settleTimer);
|
|
418
|
+
this.settleTimer = setTimeout(() => this.flushFormat(), citationTiming.settle);
|
|
419
|
+
}
|
|
420
|
+
/** Report the format the visitor settled on, unless it is where they started. */
|
|
421
|
+
flushFormat() {
|
|
422
|
+
clearTimeout(this.settleTimer);
|
|
423
|
+
const from = this.pending;
|
|
424
|
+
this.pending = undefined;
|
|
425
|
+
const now = this.selected?.name;
|
|
426
|
+
if (from === undefined || !now || now === from)
|
|
427
|
+
return;
|
|
428
|
+
trackEvent(this, [TAG, 'format', now]);
|
|
429
|
+
}
|
|
430
|
+
get citationEl() {
|
|
431
|
+
return this.renderRoot.querySelector('.citation');
|
|
432
|
+
}
|
|
433
|
+
async copy() {
|
|
434
|
+
const f = this.selected;
|
|
435
|
+
if (!f)
|
|
436
|
+
return;
|
|
437
|
+
trackEvent(this, [TAG, 'copy', f.name]);
|
|
438
|
+
clearTimeout(this.timer);
|
|
439
|
+
// Cleared first, so a second copy is announced again.
|
|
440
|
+
this.status = '';
|
|
441
|
+
await this.updateComplete;
|
|
442
|
+
// The safe copy itself, not the rendered region (which holds Lit's markers).
|
|
443
|
+
const box = this.ownerDocument.createElement('div');
|
|
444
|
+
box.append(...f.nodes.map((n) => n.cloneNode(true)));
|
|
445
|
+
const text = normalize(box.textContent);
|
|
446
|
+
let message = `${f.name} citation copied`;
|
|
447
|
+
try {
|
|
448
|
+
await copyText(text, f.rich ? box.innerHTML.trim() : undefined);
|
|
449
|
+
this.timer = setTimeout(() => (this.status = ''), STATUS_MS);
|
|
450
|
+
}
|
|
451
|
+
catch {
|
|
452
|
+
selectContents(this.citationEl);
|
|
453
|
+
message = `Could not copy: the ${f.name} citation is selected, copy it with your keyboard`;
|
|
454
|
+
}
|
|
455
|
+
this.status = message;
|
|
456
|
+
}
|
|
457
|
+
download() {
|
|
458
|
+
trackEvent(this, [TAG, 'download', 'ris']);
|
|
459
|
+
}
|
|
460
|
+
renderRis() {
|
|
461
|
+
const href = normalize(this.risHref);
|
|
462
|
+
if (!href)
|
|
463
|
+
return nothing;
|
|
464
|
+
if (!safeHref(href, this.ownerDocument.baseURI)) {
|
|
465
|
+
this.warnOnce('href', 'ignoring ris-href: it is not http(s) or relative.');
|
|
466
|
+
return nothing;
|
|
467
|
+
}
|
|
468
|
+
return html `<a class="uvalib-button" href=${href} download @click=${this.download}
|
|
469
|
+
>${normalize(this.risLabel) || 'Download RIS'}</a
|
|
470
|
+
>`;
|
|
471
|
+
}
|
|
472
|
+
render() {
|
|
473
|
+
const formats = this.formats;
|
|
474
|
+
const f = this.selected;
|
|
475
|
+
if (!f)
|
|
476
|
+
return nothing;
|
|
477
|
+
const labelId = `${this.uid}-label`;
|
|
478
|
+
return html `<div class="wrap" role="group" aria-labelledby=${labelId}>
|
|
479
|
+
<p class="label ${this.hideLabel ? 'visually-hidden' : ''}" id=${labelId}>
|
|
480
|
+
${normalize(this.label) || 'Cite this item'}
|
|
481
|
+
</p>
|
|
482
|
+
<div class="formats" role="radiogroup" aria-label="Citation format">
|
|
483
|
+
${formats.map((x) => html `<label class="format"
|
|
484
|
+
><input
|
|
485
|
+
type="radio"
|
|
486
|
+
name="${this.uid}-format"
|
|
487
|
+
.checked=${x === f}
|
|
488
|
+
@change=${() => this.choose(x.name)}
|
|
489
|
+
/><span class="face">${CHECK}<span>${x.name}</span></span></label
|
|
490
|
+
>`)}
|
|
491
|
+
</div>
|
|
492
|
+
<div class="citation" role="region" aria-label="${f.name} citation">${f.nodes}</div>
|
|
493
|
+
<div class="actions">
|
|
494
|
+
<button type="button" class="uvalib-button" @click=${this.copy}>Copy citation</button>
|
|
495
|
+
${this.renderRis()}
|
|
496
|
+
<span class="extra">${this.lightDom ? nothing : html `<slot name="actions"></slot>`}</span>
|
|
497
|
+
<span class="status" role="status">${this.status}</span>
|
|
498
|
+
</div>
|
|
499
|
+
</div>`;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
__decorate([
|
|
503
|
+
property({ type: String })
|
|
504
|
+
], UvalibCitation.prototype, "label", void 0);
|
|
505
|
+
__decorate([
|
|
506
|
+
property({ type: Boolean, reflect: true, attribute: 'hide-label' })
|
|
507
|
+
], UvalibCitation.prototype, "hideLabel", void 0);
|
|
508
|
+
__decorate([
|
|
509
|
+
property({ type: String, reflect: true })
|
|
510
|
+
], UvalibCitation.prototype, "format", void 0);
|
|
511
|
+
__decorate([
|
|
512
|
+
property({ type: Boolean })
|
|
513
|
+
], UvalibCitation.prototype, "remember", void 0);
|
|
514
|
+
__decorate([
|
|
515
|
+
property({ attribute: false })
|
|
516
|
+
], UvalibCitation.prototype, "citations", void 0);
|
|
517
|
+
__decorate([
|
|
518
|
+
property({ type: String, attribute: 'ris-href' })
|
|
519
|
+
], UvalibCitation.prototype, "risHref", void 0);
|
|
520
|
+
__decorate([
|
|
521
|
+
property({ type: String, attribute: 'ris-label' })
|
|
522
|
+
], UvalibCitation.prototype, "risLabel", void 0);
|
|
523
|
+
__decorate([
|
|
524
|
+
state()
|
|
525
|
+
], UvalibCitation.prototype, "childFormats", void 0);
|
|
526
|
+
__decorate([
|
|
527
|
+
state()
|
|
528
|
+
], UvalibCitation.prototype, "status", void 0);
|
|
529
|
+
function readStored() {
|
|
530
|
+
try {
|
|
531
|
+
return localStorage.getItem(STORAGE_KEY)?.toLowerCase() || undefined;
|
|
532
|
+
}
|
|
533
|
+
catch {
|
|
534
|
+
return undefined;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
function writeStored(name) {
|
|
538
|
+
try {
|
|
539
|
+
localStorage.setItem(STORAGE_KEY, name);
|
|
540
|
+
}
|
|
541
|
+
catch {
|
|
542
|
+
// Storage blocked (private mode, a sandbox): the choice lasts for this page only.
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
//# sourceMappingURL=UvalibCitation.js.map
|