@internetarchive/ia-book-actions 0.0.17 → 0.0.19-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -7
- package/src/assets/data/archive-logo.js +1 -1
- package/src/assets/data/dropdown-arrow.js +1 -1
- package/src/assets/data/purchase.js +1 -1
- package/src/assets/styles/collapsible-action-group.js +9 -9
- package/src/assets/styles/ia-button.js +53 -28
- package/src/components/book-title-bar.js +1 -1
- package/src/components/collapsible-action-group.js +25 -5
- package/src/components/info-icon.js +2 -2
- package/src/components/text-group.js +1 -1
- package/src/core/config/url-helper.js +1 -1
- package/src/core/services/actions-handler/actions-handler-service.js +39 -39
- package/src/core/services/actions-handler/actions-handler.js +4 -1
- package/src/ia-book-actions.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@internetarchive/ia-book-actions",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.19-2",
|
|
4
4
|
"description": "Bookreader actions for borrowable book",
|
|
5
5
|
"author": "Internet Archive",
|
|
6
6
|
"license": "AGPL-3.0-only",
|
|
@@ -18,15 +18,11 @@
|
|
|
18
18
|
"test:watch": "web-test-runner --watch --playwright --browsers chromium firefox webkit"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@internetarchive/ia-icons": "^1.2.2",
|
|
22
|
-
"@internetarchive/icon-bookmark": "^1.1.3",
|
|
23
|
-
"@internetarchive/icon-close": "^1.1.3",
|
|
24
21
|
"@internetarchive/icon-info": "^1.2.6",
|
|
25
22
|
"@internetarchive/local-cache": "^0.2.0",
|
|
26
23
|
"@internetarchive/modal-manager": "^0.1.0",
|
|
27
|
-
"@internetarchive/shared-resize-observer": "^0.0
|
|
28
|
-
"lit
|
|
29
|
-
"lit-html": "^1.3.0"
|
|
24
|
+
"@internetarchive/shared-resize-observer": "^0.2.0",
|
|
25
|
+
"lit": "^2.2.1"
|
|
30
26
|
},
|
|
31
27
|
"devDependencies": {
|
|
32
28
|
"@open-wc/eslint-config": "^4.2.0",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { css } from 'lit
|
|
1
|
+
import { css } from 'lit';
|
|
2
2
|
|
|
3
3
|
export default css`
|
|
4
4
|
:host {
|
|
@@ -14,18 +14,15 @@ export default css`
|
|
|
14
14
|
align-items: center;
|
|
15
15
|
}
|
|
16
16
|
.action-buttons .ia-button {
|
|
17
|
-
|
|
18
|
-
align-items: center;
|
|
19
|
-
vertical-align: middle;
|
|
17
|
+
margin: 0;
|
|
20
18
|
height: 3.5rem;
|
|
21
|
-
transition: all 0.1s ease 0s;
|
|
22
|
-
vertical-align: middle;
|
|
23
|
-
padding: 0 1rem;
|
|
24
|
-
margin: 0 3px;
|
|
25
19
|
}
|
|
26
20
|
.primary,
|
|
27
21
|
.secondary {
|
|
28
22
|
position: relative;
|
|
23
|
+
background: var(--white);
|
|
24
|
+
border-radius: 5px;
|
|
25
|
+
margin: 0 3px;
|
|
29
26
|
}
|
|
30
27
|
.primary .initial {
|
|
31
28
|
border-radius: 0.4rem 0 0 0.4rem;
|
|
@@ -51,9 +48,9 @@ export default css`
|
|
|
51
48
|
}
|
|
52
49
|
.dropdown-content .ia-button {
|
|
53
50
|
background: none;
|
|
51
|
+
color: var(--primaryTextColor, #fff);
|
|
54
52
|
border: none;
|
|
55
53
|
box-sizing: border-box;
|
|
56
|
-
display: block;
|
|
57
54
|
width: 100%;
|
|
58
55
|
text-align: left;
|
|
59
56
|
height: 3rem;
|
|
@@ -61,6 +58,9 @@ export default css`
|
|
|
61
58
|
padding: 0.6rem 1.2rem;
|
|
62
59
|
margin: 0;
|
|
63
60
|
}
|
|
61
|
+
.dropdown-content .ia-button:is(:focus-visible, :hover) {
|
|
62
|
+
background: unset;
|
|
63
|
+
}
|
|
64
64
|
.dropdown-content li .ia-button {
|
|
65
65
|
border-radius: 0;
|
|
66
66
|
}
|
|
@@ -1,65 +1,90 @@
|
|
|
1
|
-
import { css } from 'lit
|
|
1
|
+
import { css } from 'lit';
|
|
2
2
|
|
|
3
3
|
export default css`
|
|
4
4
|
.ia-button {
|
|
5
5
|
min-height: 3rem;
|
|
6
|
-
border: none;
|
|
7
|
-
outline: none;
|
|
8
6
|
cursor: pointer;
|
|
9
|
-
color: #fff;
|
|
7
|
+
color: var(--primaryTextColor, #fff);
|
|
10
8
|
line-height: normal;
|
|
11
9
|
border-radius: 0.4rem;
|
|
12
|
-
text-align: center;
|
|
13
|
-
vertical-align: middle;
|
|
14
10
|
font-size: 1.4rem;
|
|
15
11
|
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
|
|
16
|
-
display: inline-block;
|
|
17
|
-
padding: 0.85rem 1.2rem;
|
|
18
12
|
border: 1px solid transparent;
|
|
19
13
|
white-space: nowrap;
|
|
20
14
|
appearance: auto;
|
|
21
15
|
box-sizing: border-box;
|
|
16
|
+
display: flex;
|
|
17
|
+
align-items: center;
|
|
18
|
+
transition: all 0.1s ease 0s;
|
|
19
|
+
vertical-align: middle;
|
|
20
|
+
padding: 0 1rem;
|
|
21
|
+
outline-color: var(--primaryTextColor, #fff);
|
|
22
|
+
outline-offset: -4px;
|
|
23
|
+
user-select: none;
|
|
24
|
+
text-decoration: none;
|
|
25
|
+
width: fit-content;
|
|
22
26
|
-webkit-user-select: none;
|
|
23
27
|
-moz-user-select: none;
|
|
24
28
|
-ms-user-select: none;
|
|
25
29
|
-o-user-select: none;
|
|
26
|
-
user-select: none;
|
|
27
30
|
}
|
|
28
|
-
.ia-button:
|
|
29
|
-
|
|
31
|
+
.ia-button:is(:focus-visible) {
|
|
32
|
+
outline-style: double;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.ia-button:disabled {
|
|
30
36
|
cursor: not-allowed;
|
|
31
37
|
background-color: var(--primaryDisableCTAFill, #767676);
|
|
32
38
|
border: 1px solid var(--secondaryCTABorder, #999);
|
|
33
|
-
color: var(--primaryTextColor, #fff);
|
|
34
39
|
}
|
|
35
40
|
.ia-button.transparent {
|
|
36
41
|
background-color: transparent;
|
|
37
42
|
}
|
|
38
43
|
|
|
39
|
-
.ia-button.
|
|
40
|
-
|
|
44
|
+
.ia-button.warning {
|
|
45
|
+
background-color: #ee8950;
|
|
46
|
+
border-color: #ec7939;
|
|
41
47
|
}
|
|
48
|
+
|
|
42
49
|
.ia-button.primary {
|
|
43
|
-
background-color: #194880;
|
|
50
|
+
background-color: var(--primaryCTAFill, #194880);
|
|
44
51
|
border-color: #c5d1df;
|
|
45
52
|
}
|
|
46
|
-
.ia-button.
|
|
47
|
-
color:
|
|
48
|
-
background-color: #333;
|
|
49
|
-
border-color: #979797;
|
|
53
|
+
.ia-button.primary:is(:hover) {
|
|
54
|
+
background-color: rgba(27, 72, 128, 0.9);
|
|
50
55
|
}
|
|
56
|
+
.ia-button.primary:is(:focus-visible) {
|
|
57
|
+
background-color: rgba(27, 72, 128, 0.8);
|
|
58
|
+
}
|
|
59
|
+
.ia-button.primary:is(:active) {
|
|
60
|
+
background-color: rgba(27, 72, 128, 0.7);
|
|
61
|
+
}
|
|
62
|
+
|
|
51
63
|
.ia-button.danger {
|
|
52
|
-
color: #
|
|
53
|
-
background-color: #d9534f;
|
|
64
|
+
background-color: var(--primaryErrorCTAFill, #e51c26);
|
|
54
65
|
border-color: #d43f3a;
|
|
55
66
|
}
|
|
56
|
-
.ia-button.
|
|
57
|
-
color:
|
|
58
|
-
|
|
59
|
-
|
|
67
|
+
.ia-button.danger:is(:hover) {
|
|
68
|
+
background-color: rgba(229, 28, 38, 0.9);
|
|
69
|
+
}
|
|
70
|
+
.ia-button.danger:is(:focus-visible) {
|
|
71
|
+
background-color: rgba(229, 28, 38, 0.8);
|
|
72
|
+
}
|
|
73
|
+
.ia-button.danger:is(:active) {
|
|
74
|
+
background-color: rgba(229, 28, 38, 0.7);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.ia-button.dark {
|
|
78
|
+
background-color: var(--secondaryCTAFill, #333);
|
|
79
|
+
border-color: #979797;
|
|
80
|
+
}
|
|
81
|
+
.ia-button.dark:is(:hover) {
|
|
82
|
+
background-color: rgba(51, 51, 51, 0.9);
|
|
83
|
+
}
|
|
84
|
+
.ia-button.dark:is(:focus-visible) {
|
|
85
|
+
background-color: rgba(51, 51, 51, 0.8);
|
|
60
86
|
}
|
|
61
|
-
.ia-button.
|
|
62
|
-
background-color:
|
|
63
|
-
border-color: #f8c6c8;
|
|
87
|
+
.ia-button.dark:is(:active) {
|
|
88
|
+
background-color: rgba(51, 51, 51, 0.7);
|
|
64
89
|
}
|
|
65
90
|
`;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { html } from 'lit
|
|
2
|
-
import { nothing } from 'lit
|
|
3
|
-
import { classMap } from 'lit
|
|
1
|
+
import { html } from 'lit';
|
|
2
|
+
import { nothing } from 'lit/html.js';
|
|
3
|
+
import { classMap } from 'lit/directives/class-map.js';
|
|
4
4
|
|
|
5
5
|
import ActionsHandler from '../core/services/actions-handler/actions-handler.js';
|
|
6
6
|
|
|
@@ -50,7 +50,10 @@ export class CollapsibleActionGroup extends ActionsHandler {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
updated(changed) {
|
|
53
|
-
if (
|
|
53
|
+
if (
|
|
54
|
+
(changed.has('width') && this.isBelowTabletContainer) ||
|
|
55
|
+
changed.has('disabled')
|
|
56
|
+
) {
|
|
54
57
|
this.resetActions();
|
|
55
58
|
}
|
|
56
59
|
}
|
|
@@ -110,6 +113,9 @@ export class CollapsibleActionGroup extends ActionsHandler {
|
|
|
110
113
|
<section class="action-buttons secondary">
|
|
111
114
|
${this.renderSecondaryActions}
|
|
112
115
|
</section>
|
|
116
|
+
<section class="action-buttons secondary purchase">
|
|
117
|
+
${this.renderPurchaseAction}
|
|
118
|
+
</section>
|
|
113
119
|
</div>
|
|
114
120
|
`;
|
|
115
121
|
}
|
|
@@ -147,13 +153,27 @@ export class CollapsibleActionGroup extends ActionsHandler {
|
|
|
147
153
|
return this.secondaryActions.map(action => this.renderActionLink(action));
|
|
148
154
|
}
|
|
149
155
|
|
|
156
|
+
get renderPurchaseAction() {
|
|
157
|
+
if (!this.secondaryActions.length) return nothing;
|
|
158
|
+
|
|
159
|
+
if (this.secondaryActions.length === 2) {
|
|
160
|
+
return this.renderActionLink(this.secondaryActions[1], true);
|
|
161
|
+
}
|
|
162
|
+
if (this.secondaryActions[0].id === 'purchaseBook') {
|
|
163
|
+
return this.renderActionLink(this.secondaryActions[0], true);
|
|
164
|
+
}
|
|
165
|
+
return nothing;
|
|
166
|
+
}
|
|
167
|
+
|
|
150
168
|
/**
|
|
151
|
-
* Render action as a link for secondary actions like admin,
|
|
169
|
+
* Render action as a link for secondary actions like admin, printdisability links.
|
|
152
170
|
* @param { Object } action
|
|
153
171
|
* @param { Boolean } initialButton
|
|
154
172
|
* @returns { HTMLElement }
|
|
155
173
|
*/
|
|
156
174
|
renderActionLink(action, initialButton = false) {
|
|
175
|
+
if (!initialButton && action?.id === 'purchaseBook') return nothing; // handle purchase action differerntly
|
|
176
|
+
|
|
157
177
|
return html`<a
|
|
158
178
|
class="ia-button ${action.className} ${initialButton ? 'initial' : ''}"
|
|
159
179
|
href="${action.url}"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { html, css, LitElement, svg } from 'lit
|
|
2
|
-
import { unsafeHTML } from 'lit
|
|
1
|
+
import { html, css, LitElement, svg } from 'lit';
|
|
2
|
+
import { unsafeHTML } from 'lit/directives/unsafe-html.js';
|
|
3
3
|
import '@internetarchive/icon-info/icon-info.js';
|
|
4
4
|
|
|
5
5
|
export class InfoIcon extends LitElement {
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Helper to call loan service
|
|
5
5
|
* @param {Object} options
|
|
6
6
|
*/
|
|
7
|
-
export default function ActionsHandlerService(options) {
|
|
7
|
+
export default async function ActionsHandlerService(options) {
|
|
8
8
|
const option = {
|
|
9
9
|
action: null,
|
|
10
10
|
identifier: '',
|
|
@@ -16,7 +16,11 @@ export default function ActionsHandlerService(options) {
|
|
|
16
16
|
let baseHost = '/services/loans/loan';
|
|
17
17
|
const location = window?.location;
|
|
18
18
|
|
|
19
|
-
// return
|
|
19
|
+
// return error reponse when not production and has ?error=true param...
|
|
20
|
+
const tokenError = 'loan token not found. please try again later.';
|
|
21
|
+
const borrowError =
|
|
22
|
+
'This book is not available to borrow at this time. Please try again later.';
|
|
23
|
+
const erroneousActions = ['browse_book', 'borrow_book', 'create_token'];
|
|
20
24
|
const shouldReturnError =
|
|
21
25
|
location?.href?.indexOf('?error=true') !== -1 &&
|
|
22
26
|
location?.hostname !== 'archive.org';
|
|
@@ -26,43 +30,39 @@ export default function ActionsHandlerService(options) {
|
|
|
26
30
|
let formData = new FormData();
|
|
27
31
|
formData.append('action', option.action);
|
|
28
32
|
formData.append('identifier', option.identifier);
|
|
33
|
+
try {
|
|
34
|
+
await fetch(baseHost, {
|
|
35
|
+
method: 'POST',
|
|
36
|
+
body: formData,
|
|
37
|
+
})
|
|
38
|
+
.then(response => {
|
|
39
|
+
// intentional error on localhost
|
|
40
|
+
if (shouldReturnError && erroneousActions.includes(option?.action)) {
|
|
41
|
+
return {
|
|
42
|
+
success: false,
|
|
43
|
+
error: option?.action === 'create_token' ? tokenError : borrowError,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
29
46
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
'This book is not available to borrow at this time. Please try again later.';
|
|
38
|
-
|
|
39
|
-
// return error reponse when not production and has ?error=true param...
|
|
40
|
-
const erroneousActions = ['browse_book', 'borrow_book', 'create_token'];
|
|
41
|
-
if (shouldReturnError && erroneousActions.includes(option?.action)) {
|
|
42
|
-
return {
|
|
43
|
-
success: false,
|
|
44
|
-
error: option?.action === 'create_token' ? tokenError : borrowError,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// return success response for /demo/ server...
|
|
49
|
-
if (baseHost == '/demo/1' || baseHost == '/demo/') {
|
|
50
|
-
return {
|
|
51
|
-
success: true,
|
|
52
|
-
message: 'operation executed successfully!',
|
|
53
|
-
};
|
|
54
|
-
}
|
|
47
|
+
// return success response for /demo/ server...
|
|
48
|
+
if (baseHost == '/demo/1' || baseHost == '/demo/') {
|
|
49
|
+
return {
|
|
50
|
+
success: true,
|
|
51
|
+
message: 'operation executed successfully!',
|
|
52
|
+
};
|
|
53
|
+
}
|
|
55
54
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
55
|
+
// The response is a Response instance.
|
|
56
|
+
// You parse the data into a useable format using `.json()`
|
|
57
|
+
return response.json();
|
|
58
|
+
})
|
|
59
|
+
.then(data => {
|
|
60
|
+
// `data` is the parsed version of the JSON returned from the above endpoint.
|
|
61
|
+
if (!data?.error) {
|
|
62
|
+
option?.success(data);
|
|
63
|
+
} else {
|
|
64
|
+
option?.error(data);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
} catch (err) {}
|
|
68
68
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LitElement } from 'lit
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
2
|
|
|
3
3
|
import { URLHelper } from '../../config/url-helper.js';
|
|
4
4
|
import ActionsHandlerService from './actions-handler-service.js';
|
|
@@ -188,6 +188,9 @@ export default class ActionsHandler extends LitElement {
|
|
|
188
188
|
* @fires ActionsHandler#lendingActionError
|
|
189
189
|
*/
|
|
190
190
|
dispatchActionError(action, data = {}) {
|
|
191
|
+
// send LendingServiceError to GA
|
|
192
|
+
this.sendEvent('LendingServiceError', action);
|
|
193
|
+
|
|
191
194
|
this.dispatchEvent(
|
|
192
195
|
new CustomEvent('lendingActionError', {
|
|
193
196
|
detail: { action, data },
|
package/src/ia-book-actions.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable camelcase */
|
|
2
|
-
import { html, css, LitElement } from 'lit
|
|
2
|
+
import { html, css, LitElement } from 'lit';
|
|
3
3
|
|
|
4
4
|
import { SharedResizeObserver } from '@internetarchive/shared-resize-observer';
|
|
5
5
|
import { ModalConfig } from '@internetarchive/modal-manager';
|