@ezeep/ezeep-js 1.0.302 → 1.0.314
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/ezeep.cjs.js +1 -1
- package/dist/cjs/ezp-auth_16.cjs.entry.js +174 -11
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/collection/components/ezp-file-name/ezp-file-name.js +134 -3
- package/dist/collection/components/ezp-printer-selection/ezp-printer-selection.css +29 -3
- package/dist/collection/components/ezp-printer-selection/ezp-printer-selection.js +28 -3
- package/dist/collection/components/ezp-printing/ezp-printing.js +20 -2
- package/dist/collection/components/ezp-stepper/ezp-stepper.css +1 -2
- package/dist/collection/components/ezp-upload/ezp-upload.css +24 -3
- package/dist/collection/components/ezp-upload/ezp-upload.js +14 -3
- package/dist/collection/components/ezp-user-menu/ezp-user-menu.js +1 -1
- package/dist/collection/types/shared/types.d.ts +1 -0
- package/dist/collection/utils/utils.js +29 -0
- package/dist/components/auth.js +1 -1
- package/dist/components/ezp-file-name2.js +1 -1
- package/dist/components/ezp-printer-selection2.js +1 -1
- package/dist/components/ezp-printing.js +1 -1
- package/dist/components/ezp-stepper2.js +1 -1
- package/dist/components/ezp-upload2.js +1 -1
- package/dist/components/ezp-user-menu2.js +1 -1
- package/dist/components/utils.js +1 -1
- package/dist/directives/proxies.ts +14 -5
- package/dist/esm/ezeep.js +1 -1
- package/dist/esm/ezp-auth_16.entry.js +174 -11
- package/dist/esm/loader.js +1 -1
- package/dist/esm-es5/ezeep.js +1 -1
- package/dist/esm-es5/ezp-auth_16.entry.js +2 -2
- package/dist/esm-es5/loader.js +1 -1
- package/dist/ezeep/ezeep.esm.js +1 -1
- package/dist/ezeep/p-7b8ac37f.entry.js +1 -0
- package/dist/ezeep/p-82546765.system.entry.js +7 -0
- package/dist/ezeep/p-DCznw2Ee.system.js +1 -1
- package/dist/ezeep/types/shared/types.d.ts +1 -0
- package/dist/types/components/ezp-file-name/ezp-file-name.d.ts +43 -1
- package/dist/types/components/ezp-printer-selection/ezp-printer-selection.d.ts +8 -0
- package/dist/types/components/ezp-printing/ezp-printing.d.ts +9 -2
- package/dist/types/components/ezp-upload/ezp-upload.d.ts +4 -0
- package/dist/types/components.d.ts +19 -3
- package/dist/types/shared/types.d.ts +1 -0
- package/dist/types/utils/utils.d.ts +20 -1
- package/package.json +1 -1
- package/www/build/ezeep.esm.js +1 -1
- package/www/build/p-222b1c4b.js +1 -0
- package/www/build/p-7b8ac37f.entry.js +1 -0
- package/www/build/p-82546765.system.entry.js +7 -0
- package/www/build/p-DCznw2Ee.system.js +1 -1
- package/www/index.html +1 -1
- package/dist/ezeep/p-636e190f.system.entry.js +0 -7
- package/dist/ezeep/p-ff075048.entry.js +0 -1
- package/www/build/p-636e190f.system.entry.js +0 -7
- package/www/build/p-a2a4f55b.js +0 -1
- package/www/build/p-ff075048.entry.js +0 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Host, h } from "@stencil/core";
|
|
2
|
+
import { pickTooltipSide } from "../../utils/utils";
|
|
2
3
|
/**
|
|
3
4
|
* Characters kept at the end of a truncated name. Uploads often differ only in
|
|
4
5
|
* a suffix like `_DE.pdf`, which a plain end-ellipsis would be the first thing
|
|
@@ -14,6 +15,8 @@ export class EzpFileName {
|
|
|
14
15
|
constructor() {
|
|
15
16
|
/** Invalidates an in-flight open when the pointer leaves. */
|
|
16
17
|
this.openGeneration = 0;
|
|
18
|
+
/** Everything the open tooltip listens to for scrolling, to detach on close. */
|
|
19
|
+
this.scrollTargets = [];
|
|
17
20
|
/**
|
|
18
21
|
*
|
|
19
22
|
* Properties
|
|
@@ -29,6 +32,18 @@ export class EzpFileName {
|
|
|
29
32
|
/** Side the tooltip opens on. Consumers point it away from the edge their
|
|
30
33
|
* row sits against — `bottom` for the first row of a list, `top` below it. */
|
|
31
34
|
this.placement = 'top';
|
|
35
|
+
/** What the tooltip is placed against.
|
|
36
|
+
*
|
|
37
|
+
* `container`: the nearest positioned ancestor, by CSS alone. The consumer
|
|
38
|
+
* makes the row that ancestor, and the bubble opens at the row's edge.
|
|
39
|
+
*
|
|
40
|
+
* `parent`: the row the name sits in, measured when the tooltip opens — the
|
|
41
|
+
* closest ancestor marked `data-tooltip-row`, or else the name's parent
|
|
42
|
+
* element. For rows inside a scroll container, which would clip a bubble
|
|
43
|
+
* anchored to the row. The consumer puts the positioned ancestor outside the
|
|
44
|
+
* scroller instead, and the bubble spans that ancestor but lines up with
|
|
45
|
+
* the row. */
|
|
46
|
+
this.anchor = 'container';
|
|
32
47
|
/**
|
|
33
48
|
*
|
|
34
49
|
* States
|
|
@@ -79,8 +94,27 @@ export class EzpFileName {
|
|
|
79
94
|
*
|
|
80
95
|
*/
|
|
81
96
|
disconnectedCallback() {
|
|
82
|
-
|
|
83
|
-
|
|
97
|
+
// Closing also drops the listeners. A node that is moved comes back with
|
|
98
|
+
// its tooltip shut, rather than open with nothing left to close it.
|
|
99
|
+
this.closeTooltip();
|
|
100
|
+
this.stopWatchingScroll();
|
|
101
|
+
}
|
|
102
|
+
componentDidRender() {
|
|
103
|
+
if (this.tooltipOpen && this.anchor === 'parent')
|
|
104
|
+
this.placeTooltip();
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
*
|
|
108
|
+
* Watchers
|
|
109
|
+
*
|
|
110
|
+
*/
|
|
111
|
+
/** A measured bubble stays where it was put, so once the row scrolls away
|
|
112
|
+
* under it, it would point at the wrong name. Closing it is the honest fix. */
|
|
113
|
+
watchTooltipOpen(open) {
|
|
114
|
+
if (open && this.anchor === 'parent')
|
|
115
|
+
this.watchScroll();
|
|
116
|
+
else
|
|
117
|
+
this.stopWatchingScroll();
|
|
84
118
|
}
|
|
85
119
|
/**
|
|
86
120
|
*
|
|
@@ -130,6 +164,70 @@ export class EzpFileName {
|
|
|
130
164
|
await ((_b = head.componentOnReady) === null || _b === void 0 ? void 0 : _b.call(head));
|
|
131
165
|
return head.isTruncated();
|
|
132
166
|
}
|
|
167
|
+
/** Lines the bubble up with the row the name sits in. Its containing block
|
|
168
|
+
* is somewhere further out, so `top: 0` shows where that block starts, and
|
|
169
|
+
* the offset is taken from there. Measurements are in screen pixels, which
|
|
170
|
+
* differ from CSS pixels when a host scales the dialog with a transform, so
|
|
171
|
+
* the offset is converted back before it is applied.
|
|
172
|
+
*
|
|
173
|
+
* `placement` is a preference here: a row near the edge of whatever clips
|
|
174
|
+
* the bubble may not have room on that side, so it opens on the other. */
|
|
175
|
+
placeTooltip() {
|
|
176
|
+
var _a, _b;
|
|
177
|
+
const tooltip = (_a = this.host.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('#tooltip');
|
|
178
|
+
const row = (_b = this.host.closest('[data-tooltip-row]')) !== null && _b !== void 0 ? _b : this.host.parentElement;
|
|
179
|
+
if (!tooltip || !row)
|
|
180
|
+
return;
|
|
181
|
+
tooltip.style.bottom = 'auto';
|
|
182
|
+
tooltip.style.top = '0px';
|
|
183
|
+
const bubble = tooltip.getBoundingClientRect();
|
|
184
|
+
const scale = tooltip.offsetHeight > 0 ? bubble.height / tooltip.offsetHeight : 1;
|
|
185
|
+
const rowRect = row.getBoundingClientRect();
|
|
186
|
+
const gap = (parseFloat(getComputedStyle(tooltip).getPropertyValue('--ezp-spacing-2')) || 6) * scale;
|
|
187
|
+
const side = pickTooltipSide(this.placement, rowRect, bubble.height + gap, this.visibleArea(tooltip));
|
|
188
|
+
const top = side === 'top' ? rowRect.top - gap - bubble.height : rowRect.bottom + gap;
|
|
189
|
+
tooltip.style.top = `${(top - bubble.top) / (scale || 1)}px`;
|
|
190
|
+
}
|
|
191
|
+
/** The part of the screen the bubble can show in: the viewport, narrowed by
|
|
192
|
+
* every ancestor of its containing block that clips overflow — the host's
|
|
193
|
+
* scrolling body, say. The scroller the rows sit in isn't among them, as the
|
|
194
|
+
* bubble is anchored beyond it. */
|
|
195
|
+
visibleArea(tooltip) {
|
|
196
|
+
var _a;
|
|
197
|
+
let top = 0;
|
|
198
|
+
let bottom = window.innerHeight;
|
|
199
|
+
let node = tooltip.offsetParent;
|
|
200
|
+
while (node) {
|
|
201
|
+
if (getComputedStyle(node).overflowY !== 'visible') {
|
|
202
|
+
const rect = node.getBoundingClientRect();
|
|
203
|
+
top = Math.max(top, rect.top);
|
|
204
|
+
bottom = Math.min(bottom, rect.bottom);
|
|
205
|
+
}
|
|
206
|
+
node = (_a = node.parentElement) !== null && _a !== void 0 ? _a : (node.getRootNode().host || null);
|
|
207
|
+
}
|
|
208
|
+
return { top, bottom };
|
|
209
|
+
}
|
|
210
|
+
/** Scroll events don't bubble, so every ancestor is listened to directly —
|
|
211
|
+
* across shadow roots, since the scroll container is usually the consumer's.
|
|
212
|
+
* A window resize re-wraps the bubble just the same, so it closes it too. */
|
|
213
|
+
watchScroll() {
|
|
214
|
+
this.stopWatchingScroll();
|
|
215
|
+
const targets = [window];
|
|
216
|
+
let node = this.host.parentNode;
|
|
217
|
+
while (node) {
|
|
218
|
+
if (node.nodeType === Node.ELEMENT_NODE)
|
|
219
|
+
targets.push(node);
|
|
220
|
+
node = node instanceof ShadowRoot ? node.host : node.parentNode;
|
|
221
|
+
}
|
|
222
|
+
targets.forEach((target) => target.addEventListener('scroll', this.closeTooltip, { passive: true }));
|
|
223
|
+
window.addEventListener('resize', this.closeTooltip, { passive: true });
|
|
224
|
+
this.scrollTargets = targets;
|
|
225
|
+
}
|
|
226
|
+
stopWatchingScroll() {
|
|
227
|
+
this.scrollTargets.forEach((target) => target.removeEventListener('scroll', this.closeTooltip));
|
|
228
|
+
this.scrollTargets = [];
|
|
229
|
+
window.removeEventListener('resize', this.closeTooltip);
|
|
230
|
+
}
|
|
133
231
|
/**
|
|
134
232
|
*
|
|
135
233
|
* Render method
|
|
@@ -142,7 +240,7 @@ export class EzpFileName {
|
|
|
142
240
|
const split = !this.expanded && this.name.length > TAIL_LENGTH;
|
|
143
241
|
const head = split ? this.name.slice(0, -TAIL_LENGTH) : this.name;
|
|
144
242
|
const tail = split ? this.name.slice(-TAIL_LENGTH) : '';
|
|
145
|
-
return (h(Host, { key: '
|
|
243
|
+
return (h(Host, { key: '6fa83e22c07a31d2a56df34f2f12edf20e1eba15', class: { expanded: this.expanded, [`place-${this.placement}`]: true } }, h("button", { key: '07c2f0afc897be0ef1bd1622a486d7ff7ec73953', type: "button", id: "trigger", "aria-label": this.name, "aria-expanded": this.expanded ? 'true' : 'false', onClick: this.toggleExpanded, onMouseEnter: this.openTooltip, onMouseLeave: this.scheduleClose, onFocus: this.openTooltip, onBlur: this.closeTooltip }, h("ezp-label", { key: '7a8711a0ac21e2b7bf84a40492b0b193dd3dd29f', class: "head", ellipsis: split, level: this.level, weight: this.weight, text: head }), split && h("ezp-label", { key: 'be08c7a34cff7db6e5328627de26ff272415e27d', class: "tail", level: this.level, weight: this.weight, text: tail })), this.tooltipOpen && (h("div", { key: 'fe79f1aeced27b5ebf68e8a6cd3fcdd26e19c5eb', id: "tooltip", "aria-hidden": "true", onMouseEnter: this.cancelScheduledClose, onMouseLeave: this.closeTooltip }, this.name))));
|
|
146
244
|
}
|
|
147
245
|
static get is() { return "ezp-file-name"; }
|
|
148
246
|
static get encapsulation() { return "shadow"; }
|
|
@@ -258,6 +356,33 @@ export class EzpFileName {
|
|
|
258
356
|
"reflect": false,
|
|
259
357
|
"attribute": "placement",
|
|
260
358
|
"defaultValue": "'top'"
|
|
359
|
+
},
|
|
360
|
+
"anchor": {
|
|
361
|
+
"type": "string",
|
|
362
|
+
"mutable": false,
|
|
363
|
+
"complexType": {
|
|
364
|
+
"original": "TooltipAnchorTypes",
|
|
365
|
+
"resolved": "\"container\" | \"parent\"",
|
|
366
|
+
"references": {
|
|
367
|
+
"TooltipAnchorTypes": {
|
|
368
|
+
"location": "import",
|
|
369
|
+
"path": "../../shared/types",
|
|
370
|
+
"id": "src/shared/types.d.ts::TooltipAnchorTypes",
|
|
371
|
+
"referenceLocation": "TooltipAnchorTypes"
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
},
|
|
375
|
+
"required": false,
|
|
376
|
+
"optional": false,
|
|
377
|
+
"docs": {
|
|
378
|
+
"tags": [],
|
|
379
|
+
"text": "What the tooltip is placed against.\n\n`container`: the nearest positioned ancestor, by CSS alone. The consumer\nmakes the row that ancestor, and the bubble opens at the row's edge.\n\n`parent`: the row the name sits in, measured when the tooltip opens \u2014 the\nclosest ancestor marked `data-tooltip-row`, or else the name's parent\nelement. For rows inside a scroll container, which would clip a bubble\nanchored to the row. The consumer puts the positioned ancestor outside the\nscroller instead, and the bubble spans that ancestor but lines up with\nthe row."
|
|
380
|
+
},
|
|
381
|
+
"getter": false,
|
|
382
|
+
"setter": false,
|
|
383
|
+
"reflect": false,
|
|
384
|
+
"attribute": "anchor",
|
|
385
|
+
"defaultValue": "'container'"
|
|
261
386
|
}
|
|
262
387
|
};
|
|
263
388
|
}
|
|
@@ -268,6 +393,12 @@ export class EzpFileName {
|
|
|
268
393
|
};
|
|
269
394
|
}
|
|
270
395
|
static get elementRef() { return "host"; }
|
|
396
|
+
static get watchers() {
|
|
397
|
+
return [{
|
|
398
|
+
"propName": "tooltipOpen",
|
|
399
|
+
"methodName": "watchTooltipOpen"
|
|
400
|
+
}];
|
|
401
|
+
}
|
|
271
402
|
static get listeners() {
|
|
272
403
|
return [{
|
|
273
404
|
"name": "keydown",
|
|
@@ -132,22 +132,48 @@
|
|
|
132
132
|
* Files card
|
|
133
133
|
*
|
|
134
134
|
*/
|
|
135
|
+
/* One row is as tall as the file name in it: `ezp-label`'s secondary line height. */
|
|
136
|
+
/* Room inside the scroller for a focused name's outline (2px offset + the ring),
|
|
137
|
+
which it would otherwise clip. Taken back out of the card's padding. */
|
|
135
138
|
#files-card {
|
|
136
139
|
background: var(--ezp-core-surface-secondary);
|
|
137
140
|
border-radius: 12px;
|
|
141
|
+
padding: var(--ezp-spacing-3) var(--ezp-spacing-4);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/* Anchors the file names' tooltips, so they can span the row. It sits outside
|
|
145
|
+
the scrolling list on purpose: a scroll container clips the absolutely
|
|
146
|
+
positioned boxes anchored inside it, but not those anchored beyond it. The
|
|
147
|
+
names measure where their row is when the tooltip opens (`anchor="parent"`). */
|
|
148
|
+
#files {
|
|
149
|
+
position: relative;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/* Scrolls on its own, so a long selection doesn't make the dialog taller.
|
|
153
|
+
The card's padding stays outside it, and so do its corners. Half of a fifth
|
|
154
|
+
row shows at the bottom, which tells the list goes on. `max-height` rather
|
|
155
|
+
than `height`, so a short list looks the same as before. The inset padding
|
|
156
|
+
comes on top of `max-height` (content box), so it isn't counted in it. */
|
|
157
|
+
#files-list {
|
|
138
158
|
display: flex;
|
|
139
159
|
flex-direction: column;
|
|
140
160
|
gap: var(--ezp-spacing-2);
|
|
141
|
-
|
|
161
|
+
margin: calc(-1 * 4px);
|
|
162
|
+
max-height: var(--ezp-printerSelection-filesList-maxHeight, calc(4.5 * 20px + 4 * var(--ezp-spacing-2)));
|
|
163
|
+
/* Long names are truncated by `ezp-file-name`; nothing scrolls sideways. */
|
|
164
|
+
overflow-x: hidden;
|
|
165
|
+
overflow-y: auto;
|
|
166
|
+
padding: 4px;
|
|
167
|
+
scrollbar-width: thin;
|
|
142
168
|
}
|
|
143
169
|
|
|
144
170
|
.file-row {
|
|
145
171
|
align-items: center;
|
|
146
172
|
display: flex;
|
|
173
|
+
flex-shrink: 0;
|
|
147
174
|
gap: var(--ezp-spacing-3);
|
|
175
|
+
min-height: 20px;
|
|
148
176
|
min-width: 0;
|
|
149
|
-
/* Anchors the file name's tooltip, so it can span the row. */
|
|
150
|
-
position: relative;
|
|
151
177
|
}
|
|
152
178
|
.file-row ezp-file-name {
|
|
153
179
|
flex: 0 1 auto;
|
|
@@ -4,7 +4,7 @@ import authStore from "../../services/auth";
|
|
|
4
4
|
import printStore, { EzpPrintService } from "../../services/print";
|
|
5
5
|
import userStore, { EzpUserService } from "../../services/user";
|
|
6
6
|
import { managePaperDimensions, poll, removeEmptyStrings, subscribeToLanguageChange, } from "../../utils/utils";
|
|
7
|
-
import { PAPER_ID, validatePageRange, formatPageRange } from "../../utils/utils";
|
|
7
|
+
import { PAPER_ID, firstVisibleChild, validatePageRange, formatPageRange, } from "../../utils/utils";
|
|
8
8
|
import { applySavedProperties, classifyJobStatus, hasTrays, hasNoTrays, pickRememberedProperties, } from "../../utils/printer";
|
|
9
9
|
import { uploadAndPrintFile } from "../../services/print-job";
|
|
10
10
|
import { storage } from "../../shared/storage";
|
|
@@ -56,6 +56,9 @@ export class EzpPrinterSelection {
|
|
|
56
56
|
this.hubDriverError = false;
|
|
57
57
|
this.userMenuOpen = false;
|
|
58
58
|
this.printStopped = false;
|
|
59
|
+
/** First row of the file list that is at least partly in view. Its tooltip
|
|
60
|
+
* opens downwards, as there is no list left above it to cover. */
|
|
61
|
+
this.firstVisibleFile = 0;
|
|
59
62
|
/** Starts empty so the dialog can still render if the list never arrives. */
|
|
60
63
|
this.printers = [];
|
|
61
64
|
/** Starts empty so the dialog renders even if the list never loads. */
|
|
@@ -110,7 +113,7 @@ export class EzpPrinterSelection {
|
|
|
110
113
|
this.successfulFiles = [];
|
|
111
114
|
this.partialSuccess = false;
|
|
112
115
|
this.hubDriverError = false;
|
|
113
|
-
this.
|
|
116
|
+
this.printDismiss.emit();
|
|
114
117
|
};
|
|
115
118
|
/** Poll `validate` callback: maps a job status to component state, returns `true` to stop polling. */
|
|
116
119
|
this.validateData = (data) => {
|
|
@@ -290,6 +293,12 @@ export class EzpPrinterSelection {
|
|
|
290
293
|
this.handleUserMenu = () => {
|
|
291
294
|
this.userMenuOpen = true;
|
|
292
295
|
};
|
|
296
|
+
this.handleFilesScroll = (event) => {
|
|
297
|
+
const first = firstVisibleChild(event.currentTarget);
|
|
298
|
+
// Scroll fires every frame; only a change of row is worth a render.
|
|
299
|
+
if (first >= 0 && first !== this.firstVisibleFile)
|
|
300
|
+
this.firstVisibleFile = first;
|
|
301
|
+
};
|
|
293
302
|
this.validateFileType = async (name) => {
|
|
294
303
|
var _a;
|
|
295
304
|
const extension = (_a = name.split('.').pop()) !== null && _a !== void 0 ? _a : '';
|
|
@@ -824,7 +833,7 @@ export class EzpPrinterSelection {
|
|
|
824
833
|
? [this.filename]
|
|
825
834
|
: [];
|
|
826
835
|
const fileCount = fileNames.length;
|
|
827
|
-
return this.loading ? (h("ezp-status", { processing: true, description: i18next.t('printer_selection.loading'), instance: "loading" })) : (h(Host, { class: { seamless: this.seamless } }, h("div", { id: "box", "data-backdrop-surface": true }, !this.printStopped && this.renderStatus(), !this.hideheader && (h("div", { id: "header" }, h("div", { id: "title" }, h("ezp-label", { weight: "heavy", text: i18next.t('printer_selection.print') }), !this.notSupported && fileCount > 0 && (h("span", { id: "files-badge" }, i18next.t('printer_selection.file_count', { count: fileCount })))), h("div", { id: "header-actions" }, !this.hidemenu && (h("ezp-icon-button", { level: "tertiary", icon: "menu", id: "toggle-menu", type: "button", onClick: this.handleUserMenu })), h("ezp-icon-button", { level: "tertiary", icon: "close", id: "close", type: "button", onClick: this.handleCancel })))), h("div", { id: "body" }, !this.notSupported && fileNames.length > 0 && (h("div", { id: "files-card" }, fileNames.map((name, index) => (h("div", { class: "file-row", key: index }, h("ezp-icon", { name: "file", class: "file-row-icon" }), h("ezp-file-name", { name: name, placement: index ===
|
|
836
|
+
return this.loading ? (h("ezp-status", { processing: true, description: i18next.t('printer_selection.loading'), instance: "loading" })) : (h(Host, { class: { seamless: this.seamless } }, h("div", { id: "box", "data-backdrop-surface": true }, !this.printStopped && this.renderStatus(), !this.hideheader && (h("div", { id: "header" }, h("div", { id: "title" }, h("ezp-label", { weight: "heavy", text: i18next.t('printer_selection.print') }), !this.notSupported && fileCount > 0 && (h("span", { id: "files-badge" }, i18next.t('printer_selection.file_count', { count: fileCount })))), h("div", { id: "header-actions" }, !this.hidemenu && (h("ezp-icon-button", { level: "tertiary", icon: "menu", id: "toggle-menu", type: "button", onClick: this.handleUserMenu })), h("ezp-icon-button", { level: "tertiary", icon: "close", id: "close", type: "button", onClick: this.handleCancel })))), h("div", { id: "body" }, !this.notSupported && fileNames.length > 0 && (h("div", { id: "files-card" }, h("div", { id: "files" }, h("div", { id: "files-list", onScroll: this.handleFilesScroll }, fileNames.map((name, index) => (h("div", { class: "file-row", key: index }, h("ezp-icon", { name: "file", class: "file-row-icon" }), h("ezp-file-name", { name: name, anchor: "parent", placement: index === this.firstVisibleFile ? 'bottom' : 'top' })))))))), h("ezp-label", { id: "printer-caption", level: "tertiary", weight: "heavy", text: i18next.t('printer_selection.printer') }), h("div", { id: "printer-card" }, h("ezp-select", { id: "printer", label: i18next.t('printer_selection.printer'), icon: "printer", placeholder: this.printers.length > 0
|
|
828
837
|
? i18next.t('printer_selection.select_printer')
|
|
829
838
|
: i18next.t('printer_selection.no_printers'), toggleFlow: "vertical", optionFlow: "vertical", options: this.printers.map((printer) => ({
|
|
830
839
|
id: printer.id,
|
|
@@ -1101,6 +1110,7 @@ export class EzpPrinterSelection {
|
|
|
1101
1110
|
"hubDriverError": {},
|
|
1102
1111
|
"userMenuOpen": {},
|
|
1103
1112
|
"printStopped": {},
|
|
1113
|
+
"firstVisibleFile": {},
|
|
1104
1114
|
"userName": {},
|
|
1105
1115
|
"printers": {},
|
|
1106
1116
|
"selectedPrinter": {},
|
|
@@ -1137,6 +1147,21 @@ export class EzpPrinterSelection {
|
|
|
1137
1147
|
}
|
|
1138
1148
|
}
|
|
1139
1149
|
}
|
|
1150
|
+
}, {
|
|
1151
|
+
"method": "printDismiss",
|
|
1152
|
+
"name": "printDismiss",
|
|
1153
|
+
"bubbles": true,
|
|
1154
|
+
"cancelable": true,
|
|
1155
|
+
"composed": true,
|
|
1156
|
+
"docs": {
|
|
1157
|
+
"tags": [],
|
|
1158
|
+
"text": "Cancel or close on this dialog: the user backs out of the print options\nonly. Unlike `printCancel`, it leaves the selected files alone, so the\nhost can return to the step they were chosen on."
|
|
1159
|
+
},
|
|
1160
|
+
"complexType": {
|
|
1161
|
+
"original": "void",
|
|
1162
|
+
"resolved": "void",
|
|
1163
|
+
"references": {}
|
|
1164
|
+
}
|
|
1140
1165
|
}, {
|
|
1141
1166
|
"method": "printSubmit",
|
|
1142
1167
|
"name": "printSubmit",
|
|
@@ -74,6 +74,18 @@ export class EzpPrinting {
|
|
|
74
74
|
document.dispatchEvent(printCancelEvent);
|
|
75
75
|
this.printFinished.emit();
|
|
76
76
|
}
|
|
77
|
+
/** Cancel or close on the print options card. With an upload step to go
|
|
78
|
+
* back to, only the card closes: the files picked there stay picked, and
|
|
79
|
+
* removing them is the upload card's "Clear files". Without one there is
|
|
80
|
+
* nothing left to show, so it ends the flow like `printCancel`. */
|
|
81
|
+
listenPrintDismiss() {
|
|
82
|
+
if (this.trigger === 'file') {
|
|
83
|
+
this.printOpen = false;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
this.listenPrintCancel();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
77
89
|
/** Description... */
|
|
78
90
|
listenPrintSubmit() {
|
|
79
91
|
this.printOpen = false;
|
|
@@ -341,7 +353,7 @@ export class EzpPrinting {
|
|
|
341
353
|
*
|
|
342
354
|
*/
|
|
343
355
|
render() {
|
|
344
|
-
return (h(Host, { key: '
|
|
356
|
+
return (h(Host, { key: '1b33fdafac04c08cdd11412202a537f66131caef', class: `${userStore.state.theme} ${userStore.state.appearance === 'system'
|
|
345
357
|
? this.systemAppearance
|
|
346
358
|
: userStore.state.appearance} ${this.seamless ? 'seamless' : ''}` }, this.trigger === 'custom' ? (h("slot", null)) : this.trigger === 'file' ? (h("ezp-upload", null)) : (this.trigger === 'button' && (h("ezp-icon-button", { id: "print-trigger", icon: "printer", slot: "trigger", type: "button", onClick: () => this.open() }))), this.authOpen ? (h("ezp-auth", { clientID: this.clientid, redirectURI: this.redirecturi, hidelogin: this.hidelogin, trigger: this.trigger, code: this.code })) : this.printOpen ? (h("ezp-printer-selection", { clientID: this.clientid, redirectURI: this.redirecturi, filename: this.filename, fileurl: this.fileurl, filetype: this.filetype, fileid: this.fileid, files: this.files, hidemenu: this.hidemenu, hideheader: this.hideheader, seamless: this.seamless })) : this.noDocumentOpen ? (h("ezp-dialog", { heading: i18next.t('no_document_dialog.heading'), description: i18next.t('no_document_dialog.description'), action: i18next.t('no_document_dialog.action'), iconName: "question-mark", instance: "no-document-selected" })) : null));
|
|
347
359
|
}
|
|
@@ -769,7 +781,7 @@ export class EzpPrinting {
|
|
|
769
781
|
"composed": true,
|
|
770
782
|
"docs": {
|
|
771
783
|
"tags": [],
|
|
772
|
-
"text": "Fired when the print flow reaches an end state and the host may dismiss the\ncomponent: a print job was submitted, or the user cancelled on the upload\ncard, the sign-in dialog (with files pending) or the print options card.
|
|
784
|
+
"text": "Fired when the print flow reaches an end state and the host may dismiss the\ncomponent: a print job was submitted, or the user cancelled on the upload\ncard, the sign-in dialog (with files pending) or the print options card. A\ncancel on the print options card returns to the upload card when there is\none (`trigger=\"file\"`), so it doesn't end the flow there. It does not mean\na job was printed \u2014 check for that on the print API side."
|
|
773
785
|
},
|
|
774
786
|
"complexType": {
|
|
775
787
|
"original": "void",
|
|
@@ -910,6 +922,12 @@ export class EzpPrinting {
|
|
|
910
922
|
"target": undefined,
|
|
911
923
|
"capture": false,
|
|
912
924
|
"passive": false
|
|
925
|
+
}, {
|
|
926
|
+
"name": "printDismiss",
|
|
927
|
+
"method": "listenPrintDismiss",
|
|
928
|
+
"target": undefined,
|
|
929
|
+
"capture": false,
|
|
930
|
+
"passive": false
|
|
913
931
|
}, {
|
|
914
932
|
"name": "printSubmit",
|
|
915
933
|
"method": "listenPrintSubmit",
|
|
@@ -177,11 +177,33 @@
|
|
|
177
177
|
* File list
|
|
178
178
|
*
|
|
179
179
|
*/
|
|
180
|
+
/* The tallest thing in a row is its remove button (`.file-remove`). */
|
|
180
181
|
/* Deliberately not `overflow: hidden` — that would clip a row's tooltip. Only
|
|
181
|
-
`#add-more` paints to the edge, so it rounds its own corners instead.
|
|
182
|
+
`#add-more` paints to the edge, so it rounds its own corners instead.
|
|
183
|
+
|
|
184
|
+
Anchors the file names' tooltips, so they can span the row. It sits outside
|
|
185
|
+
the scrolling list on purpose: a scroll container clips the absolutely
|
|
186
|
+
positioned boxes anchored inside it, but not those anchored beyond it. The
|
|
187
|
+
names measure where their row is when the tooltip opens (`anchor="parent"`). */
|
|
182
188
|
#files {
|
|
183
189
|
border: 1px solid var(--ezp-core-outline);
|
|
184
190
|
border-radius: 12px;
|
|
191
|
+
position: relative;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/* Scrolls on its own, so loading more files never makes the card — or the
|
|
195
|
+
window around it — taller. "Add more files" stays below it, in reach. Half
|
|
196
|
+
of a fifth row shows at the bottom, which tells the list goes on, and each
|
|
197
|
+
row after the first adds its 1px divider. `max-height` rather than
|
|
198
|
+
`height`, so a short list looks the same as before. */
|
|
199
|
+
#file-list {
|
|
200
|
+
/* Rounds its own top corners, which the scrollbar would otherwise cover. */
|
|
201
|
+
border-radius: 11px 11px 0 0;
|
|
202
|
+
max-height: var(--ezp-upload-fileList-maxHeight, calc(4.5 * calc(28px + 2 * var(--ezp-spacing-3)) + 4px));
|
|
203
|
+
/* Long names are truncated by `ezp-file-name`; nothing scrolls sideways. */
|
|
204
|
+
overflow-x: hidden;
|
|
205
|
+
overflow-y: auto;
|
|
206
|
+
scrollbar-width: thin;
|
|
185
207
|
}
|
|
186
208
|
|
|
187
209
|
.file {
|
|
@@ -189,9 +211,8 @@
|
|
|
189
211
|
display: grid;
|
|
190
212
|
gap: var(--ezp-spacing-3);
|
|
191
213
|
grid-template-columns: auto minmax(0, 1fr) auto;
|
|
214
|
+
min-height: calc(28px + 2 * var(--ezp-spacing-3));
|
|
192
215
|
padding: var(--ezp-spacing-3) var(--ezp-spacing-4);
|
|
193
|
-
/* Anchors the file name's tooltip, so it can span the row. */
|
|
194
|
-
position: relative;
|
|
195
216
|
}
|
|
196
217
|
|
|
197
218
|
.file + .file {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Host, h } from "@stencil/core";
|
|
2
|
-
import { subscribeToLanguageChange } from "../../utils/utils";
|
|
2
|
+
import { firstVisibleChild, subscribeToLanguageChange } from "../../utils/utils";
|
|
3
3
|
import i18next from "i18next";
|
|
4
4
|
/** File formats advertised to the user as supported for printing. */
|
|
5
5
|
const SUPPORTED_FORMATS = ['PDF', 'DOCX', 'PNG', 'JPG', 'XLSX'];
|
|
@@ -12,6 +12,9 @@ export class EzpUpload {
|
|
|
12
12
|
*/
|
|
13
13
|
this.selectedFiles = [];
|
|
14
14
|
this.dragging = false;
|
|
15
|
+
/** First row of the file list that is at least partly in view. Its tooltip
|
|
16
|
+
* opens downwards, as there is no list left above it to cover. */
|
|
17
|
+
this.firstVisibleFile = 0;
|
|
15
18
|
/**
|
|
16
19
|
*
|
|
17
20
|
* Listeners
|
|
@@ -67,6 +70,12 @@ export class EzpUpload {
|
|
|
67
70
|
// `printCancel` listener resets the form and the selection.
|
|
68
71
|
this.printCancel.emit();
|
|
69
72
|
};
|
|
73
|
+
this.handleFilesScroll = (event) => {
|
|
74
|
+
const first = firstVisibleChild(event.currentTarget);
|
|
75
|
+
// Scroll fires every frame; only a change of row is worth a render.
|
|
76
|
+
if (first >= 0 && first !== this.firstVisibleFile)
|
|
77
|
+
this.firstVisibleFile = first;
|
|
78
|
+
};
|
|
70
79
|
this.handleContinue = () => {
|
|
71
80
|
if (this.selectedFiles.length === 0)
|
|
72
81
|
return;
|
|
@@ -119,6 +128,7 @@ export class EzpUpload {
|
|
|
119
128
|
var _a;
|
|
120
129
|
(_a = this.form) === null || _a === void 0 ? void 0 : _a.reset();
|
|
121
130
|
this.selectedFiles = [];
|
|
131
|
+
this.firstVisibleFile = 0;
|
|
122
132
|
this.resetDrag();
|
|
123
133
|
}
|
|
124
134
|
fileKey(file) {
|
|
@@ -152,7 +162,7 @@ export class EzpUpload {
|
|
|
152
162
|
*/
|
|
153
163
|
render() {
|
|
154
164
|
const hasFiles = this.selectedFiles.length > 0;
|
|
155
|
-
return (h(Host, { key: '
|
|
165
|
+
return (h(Host, { key: '647c38e3dd42274be594a2fd5eb668943cd37256', class: { dragging: this.dragging } }, h("form", { key: 'a0af9e0bb32e8460b0b86bd897913a1c434747a8', id: "form", ref: (form) => (this.form = form) }, h("input", { key: 'd687034216a6e03a484fdd4462a7e2817675237c', type: "file", name: "input", id: "input", multiple: true, "aria-label": i18next.t('upload.choose_files'), ref: (input) => (this.input = input), onInput: this.handleInput }), h("div", { key: '82a76ba0258746bc552afc03c500a563c698e821', id: "modal" }, h("div", { key: 'a6113ba410cf3985ad64fa9300cf4e9ef2182e4f', id: "body-frame" }, h("div", { key: 'd9af36800ce744146c43a7e99f289413e13b9ae3', id: "body" }, !hasFiles && (h("div", { key: 'df98d670f9c0498597f414158108c38265b59b90', id: "dropzone" }, h("ezp-icon", { key: '0202221de58ae709f5823501cfce1bc9d1087136', id: "dropzone-icon", name: "cloud-upload" }), h("ezp-label", { key: '9cbb60bc48f9e74af2c613d8c83a973e984ce824', id: "dropzone-title", level: "primary", weight: "heavy", text: i18next.t('upload.dropzone_title') }), h("div", { key: 'ccaef599519bf24af543f4727fb4c1a62338b9df', id: "dropzone-prompt" }, h("ezp-text-button", { key: 'f084bb66ff63e9448cb6e7aea1782d8d2c9914b3', id: "choose", type: "button", onClick: this.openPicker, label: i18next.t('upload.choose_files') }), h("ezp-label", { key: 'f5e7bd5219637c13cc0f9ad97ab42a14d35aa601', id: "drag-hint", level: "secondary", weight: "strong", text: i18next.t('upload.drag_hint') }), h("ezp-label", { key: 'd5334e1e3aaaaaf9a7abb4be38a27226f73a162a', id: "formats", level: "tertiary", text: SUPPORTED_FORMATS.join(', ') })))), hasFiles && (h("div", { key: '9eaec0f2ddb0f2ca4679e4a314afb2b42c211a17', id: "files" }, h("div", { key: 'bc990a270c2432c8237b75eebc9d4881a6bb856e', id: "file-list", onScroll: this.handleFilesScroll }, this.selectedFiles.map((file, index) => (h("div", { key: this.fileKey(file), class: "file", "data-tooltip-row": true }, h("span", { class: "file-type", "aria-hidden": "true" }, this.fileType(file.name)), h("div", { class: "file-details" }, h("ezp-file-name", { class: "file-name", weight: "heavy", name: file.name, anchor: "parent", placement: index === this.firstVisibleFile ? 'bottom' : 'top' }), h("ezp-label", { class: "file-size", level: "tertiary", text: this.formatSize(file.size) })), h("button", { type: "button", class: "file-remove", "aria-label": i18next.t('upload.remove_file'), onClick: (event) => this.removeFile(event, index) }, h("ezp-icon", { name: "close" })))))), h("button", { key: 'd22584a56b417545260c5b8c2210a6c62b59426e', type: "button", id: "add-more", onClick: this.openPicker }, h("ezp-icon", { key: '1313f4255c6a58e58d04b0188153ec815ce6b938', name: "plus" }), h("ezp-label", { key: 'deadcecb7b733c33a3990802a4ebf6b84726b48e', level: "secondary", weight: "heavy", text: i18next.t('upload.add_more') }))))), hasFiles && this.dragging && (h("div", { key: '20bf6c68fd28c8de0b63b88aad24f1ab63d25ac3', id: "drop-overlay", "aria-hidden": "true" }, h("ezp-icon", { key: '135896652629a8eba574c21af1af20ba6722ad5d', id: "dropzone-icon", name: "cloud-upload" }), h("ezp-label", { key: '03921a166561ce06af4fce3abcd1f812738844f5', level: "primary", weight: "heavy", text: i18next.t('upload.dropzone_title') })))), h("div", { key: '2d1e16e9e8ca950e1e968ca12939a245f7618adc', id: "footer" }, h("ezp-text-button", { key: '6a776b09c068982932225a4903df003e8a89b20a', id: "clear", type: "button", level: "secondary", disabled: !hasFiles, onClick: this.handleCancel, label: i18next.t('upload.remove_files'), class: "action" }), h("ezp-text-button", { key: 'ca872a7d7834191001faef1140dbd344566ed79d', id: "continue", type: "button", disabled: !hasFiles, onClick: this.handleContinue, label: i18next.t('upload.continue'), class: "action" }))))));
|
|
156
166
|
}
|
|
157
167
|
static get is() { return "ezp-upload"; }
|
|
158
168
|
static get encapsulation() { return "shadow"; }
|
|
@@ -169,7 +179,8 @@ export class EzpUpload {
|
|
|
169
179
|
static get states() {
|
|
170
180
|
return {
|
|
171
181
|
"selectedFiles": {},
|
|
172
|
-
"dragging": {}
|
|
182
|
+
"dragging": {},
|
|
183
|
+
"firstVisibleFile": {}
|
|
173
184
|
};
|
|
174
185
|
}
|
|
175
186
|
static get events() {
|
|
@@ -84,7 +84,7 @@ export class EzpUserMenu {
|
|
|
84
84
|
*
|
|
85
85
|
*/
|
|
86
86
|
render() {
|
|
87
|
-
return (h(Host, { key: '
|
|
87
|
+
return (h(Host, { key: 'a6967dc3eb3b13630dbf652681c6c5c1f769f584', class: this.open ? 'is-open' : '' }, h("div", { key: '5cbf232927f4b26c1c05b01a6025b5f33fe3bfaa', id: "header" }, h("ezp-label", { key: '83987303c029d9d01f42d5d817edaf6c72629513', ellipsis: true, id: "name", weight: "heavy", text: this.name }), h("ezp-icon-button", { key: '45a64f18578adf35aeb824e393a359368e32e35a', id: "close", level: "tertiary", icon: "close", onClick: this.handleClose })), h("div", { key: '8bd44e5b32662baad24ee9a39abca4e772b0ef4b', id: "links" }, this.links.map((link) => (h("a", { class: "link", href: link.href, target: "_blank", rel: "noopener noreferrer" }, h("ezp-icon", { class: "link__icon", name: link.icon }), h("ezp-label", { text: link.title })))), h("a", { key: '64f041741f7760f85dd5090d0c9feebd7dec3289', class: "link", onClick: this.logOut }, h("ezp-icon", { key: 'bd0beefa519acb37328d9c3fd33c4286ff7e1ddc', class: "link__icon", name: "logout" }), h("ezp-label", { key: 'a37c8e9ffc43d0d89fe4d5dadf1dde5e36155074', text: i18next.t('user_menu.logout') }))), h("div", { key: 'ad74827637906199b94f61d5f617fcaa9044c553', id: "theme" }, h("ezp-label", { key: 'c420ad169436c96acd4add9951e02f2d6fd43240', class: "caption", text: `${i18next.t('user_menu.theme')}:`, weight: "heavy" }), h("div", { key: '04d383554f2cdfd6b7864c3e23295e2bc6f244b8', id: "swatches" }, this.themes.map((theme) => (h("button", { class: `swatch swatch--${theme} ${theme === userStore.state.theme ? 'selected' : ''}`, onClick: () => this.handleTheme(theme) }, h("span", { class: "dot" })))))), h("div", { key: '4e40758f22b322cbcd3d26054c6c4801c555430a', id: "appearance" }, h("ezp-label", { key: '3034f9eaa028ce4928c8bf2c36dc223b98eba45d', class: "caption", text: `${i18next.t('user_menu.appearance')}:`, weight: "heavy" }), h("div", { key: 'dfa6a115e24db557891295f3a8e1ab1cfa4332f0', id: "tabs" }, this.appearances.map((appearance) => (h("button", { class: `tab ${appearance.name === userStore.state.appearance ? 'selected' : ''}`, onClick: () => this.handleAppearance(appearance.name) }, h("ezp-icon", { name: appearance.name }), h("ezp-label", { text: appearance.title, level: "tertiary", weight: "strong" }))))))));
|
|
88
88
|
}
|
|
89
89
|
static get is() { return "ezp-user-menu"; }
|
|
90
90
|
static get encapsulation() { return "shadow"; }
|
|
@@ -53,6 +53,7 @@ export type TextButtonTypeTypes = 'button'
|
|
|
53
53
|
export type LabelLevelTypes = 'primary' | 'secondary' | 'tertiary'
|
|
54
54
|
export type WeightTypes = 'soft' | 'strong' | 'heavy'
|
|
55
55
|
export type TooltipPlacementTypes = 'top' | 'bottom'
|
|
56
|
+
export type TooltipAnchorTypes = 'container' | 'parent'
|
|
56
57
|
export type ThemeTypes = 'pink' | 'red' | 'orange' | 'green' | 'teal' | 'cyan' | 'blue' | 'violet'
|
|
57
58
|
export type AppearanceTypes = 'system' | 'light' | 'dark'
|
|
58
59
|
export type TriggerTypes = 'custom' | 'file' | 'button'
|
|
@@ -17,6 +17,35 @@ export function subscribeToLanguageChange(component) {
|
|
|
17
17
|
i18next.on('languageChanged', rerender);
|
|
18
18
|
return () => i18next.off('languageChanged', rerender);
|
|
19
19
|
}
|
|
20
|
+
/** Index of the first child of a scroll container that is at least half in
|
|
21
|
+
* view, or -1 when it has none. Lists use it to open the topmost visible row's
|
|
22
|
+
* tooltip downwards, as nothing in the list is left above that row to cover.
|
|
23
|
+
* A row showing only a sliver doesn't count: the row below it is the one the
|
|
24
|
+
* user reads first, and that one should open downwards. */
|
|
25
|
+
export function firstVisibleChild(container) {
|
|
26
|
+
const top = container.getBoundingClientRect().top;
|
|
27
|
+
return Array.from(container.children).findIndex((child) => {
|
|
28
|
+
const rect = child.getBoundingClientRect();
|
|
29
|
+
return (rect.top + rect.bottom) / 2 > top;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Side a tooltip should open on, given where it was asked to open and the room
|
|
34
|
+
* there is. The requested side wins whenever the bubble fits there; otherwise
|
|
35
|
+
* it flips to the other side if that fits, or if that simply has more room.
|
|
36
|
+
* All values are in the same (screen) pixels.
|
|
37
|
+
*/
|
|
38
|
+
export function pickTooltipSide(requested, row, needed, visible) {
|
|
39
|
+
const above = row.top - visible.top;
|
|
40
|
+
const below = visible.bottom - row.bottom;
|
|
41
|
+
const room = { top: above, bottom: below };
|
|
42
|
+
const other = requested === 'top' ? 'bottom' : 'top';
|
|
43
|
+
if (room[requested] >= needed)
|
|
44
|
+
return requested;
|
|
45
|
+
if (room[other] >= needed || room[other] > room[requested])
|
|
46
|
+
return other;
|
|
47
|
+
return requested;
|
|
48
|
+
}
|
|
20
49
|
export function encodeFormData(data) {
|
|
21
50
|
return Object.keys(data)
|
|
22
51
|
.map((key) => encodeURIComponent(key) + '=' + encodeURIComponent(data[key]))
|
package/dist/components/auth.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as e from"@stencil/core/internal/client";import{
|
|
1
|
+
import*as e from"@stencil/core/internal/client";import{k as t}from"./utils.js";const r=(()=>{let e;return(...t)=>{e&&clearTimeout(e),e=setTimeout((()=>{e=0,(e=>{for(let t of e.keys()){const r=e.get(t).filter((e=>{const t=e.deref();return t&&(!("isConnected"in(r=t))||r.isConnected);var r}));e.set(t,r)}})(...t)}),2e3)}})(),n=e.forceUpdate,o=e.getRenderingRef,s=(e,t)=>{const r=e.indexOf(t);r>=0&&(e[r]=e[e.length-1],e.length--)},i=(e,t)=>{const i=((e,t=(e,t)=>e!==t)=>{const r=()=>{return("function"==typeof(t=e)?t():t)??{};var t},n=r();let o=new Map(Object.entries(n));const i="undefined"!=typeof Proxy,c=i?null:{},a={dispose:[],get:[],set:[],reset:[]},h=new Map,l=()=>{o=new Map(Object.entries(r())),i||S(),a.reset.forEach((e=>e()))},u=e=>(a.get.forEach((t=>t(e))),o.get(e)),d=(e,r)=>{const n=o.get(e);t(r,n,e)&&(o.set(e,r),i||p(e),a.set.forEach((t=>t(e,r,n))))},f=i?new Proxy(n,{get:(e,t)=>u(t),ownKeys:()=>Array.from(o.keys()),getOwnPropertyDescriptor:()=>({enumerable:!0,configurable:!0}),has:(e,t)=>o.has(t),set:(e,t,r)=>(d(t,r),!0)}):(S(),c),g=(e,t)=>(a[e].push(t),()=>{s(a[e],t)});function p(e){!i&&c&&(Object.prototype.hasOwnProperty.call(c,e)||Object.defineProperty(c,e,{configurable:!0,enumerable:!0,get:()=>u(e),set(t){d(e,t)}}))}function S(){if(i||!c)return;const e=new Set(o.keys());for(const t of Object.keys(c))e.has(t)||delete c[t];for(const t of e)p(t)}return{state:f,get:u,set:d,on:g,onChange:(e,t)=>{const n=(r,n)=>{r===e&&t(n)},o=()=>{const n=r();t(n[e])},s=g("set",n),i=g("reset",o);return h.set(t,{setHandler:n,resetHandler:o,propName:e}),()=>{s(),i(),h.delete(t)}},use:(...e)=>{const t=e.reduce(((e,t)=>(t.set&&e.push(g("set",t.set)),t.get&&e.push(g("get",t.get)),t.reset&&e.push(g("reset",t.reset)),t.dispose&&e.push(g("dispose",t.dispose)),e)),[]);return()=>t.forEach((e=>e()))},dispose:()=>{a.dispose.forEach((e=>e())),l()},reset:l,forceUpdate:e=>{const t=o.get(e);a.set.forEach((r=>r(e,t,t)))},removeListener:(e,t)=>{const r=h.get(t);r&&r.propName===e&&(s(a.set,r.setHandler),s(a.reset,r.resetHandler),h.delete(t))}}})(e,t);return i.use((()=>{if("function"!=typeof o||"function"!=typeof n)return{};const e=n,t=o,s=new Map;return{dispose:()=>s.clear(),get:e=>{const r=t();r&&((e,t,r)=>{let n=e.get(t);n||(n=[],e.set(t,n)),n.some((e=>e.deref()===r))||n.push(new WeakRef(r))})(s,e,r)},set:t=>{const n=s.get(t);if(n){const r=n.filter((t=>{const r=t.deref();return!!r&&e(r)}));s.set(t,r)}r(s)},reset:()=>{s.forEach((t=>{t.forEach((t=>{const r=t.deref();r&&e(r)}))})),r(s)}}})()),i},c="refreshToken",a="isAuthorized",h="printer",l="printerSettings";function u(e){const t=localStorage.getItem(e);if(null===t)return null;try{return JSON.parse(t)}catch(e){return null}}const d={getRefreshToken:()=>localStorage.getItem(c),setRefreshToken(e){localStorage.setItem(c,e)},getIsAuthorized:()=>"true"===localStorage.getItem(a),setIsAuthorized(e){localStorage.setItem(a,e.toString())},hasIsAuthorized:()=>null!==localStorage.getItem(a),getPrinterSettings(e){var t;return null!==(t=f()[e])&&void 0!==t?t:null},setPrinterSettings(e,t){const r=f();r[e]=t,localStorage.setItem(l,JSON.stringify(r))},getPrinter:()=>u(h),setPrinter(e){localStorage.setItem(h,JSON.stringify(e))},clearSession(){localStorage.removeItem(c),localStorage.removeItem("access_token"),localStorage.removeItem(a)},clearSavedPrinter(){localStorage.removeItem(h)}};function f(){const e=u(l);if(e)return e;const t=u("properties"),r=u(h);return t&&(null==r?void 0:r.id)?{[r.id]:t}:{}}class g{constructor(e,t){this.urlParams=new URLSearchParams,this.isAuthorized=!1,this.redirectURI=e,this.clientID=t,p.state.clientID=t,this.oauthUrl=p.state.authApiHostUrl,this.authURI=new URL(`https://${this.oauthUrl}/oauth/authorize/`),this.accessTokenURL=`https://${this.oauthUrl}/oauth/access_token/`}generateCodeVerifier(){if(""!==p.state.codeVerifier)this.codeVerifier=p.state.codeVerifier;else{const e=new Uint8Array(128),t=crypto.getRandomValues(e),r=btoa(t.toString()).substr(0,128);this.codeVerifier=r,p.state.codeVerifier=this.codeVerifier}}async generateCodeChallenge(e){const t=(new TextEncoder).encode(e),r=await crypto.subtle.digest("SHA-256",t),n=btoa(String.fromCharCode(...new Uint8Array(r)));this.codeChallenge=n.replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}buildAuthURI(){this.urlParams.append("response_type","code"),this.urlParams.append("client_id",this.clientID),this.urlParams.append("redirect_uri",this.redirectURI),this.urlParams.append("code_challenge",this.codeChallenge),this.urlParams.append("code_challenge_method","S256"),this.authURI.search=this.urlParams.toString(),p.state.authUri=this.authURI.toString()}oauthHeaders(){return{Authorization:"Basic "+btoa(this.clientID+":"),"Content-Type":"application/x-www-form-urlencoded"}}persistTokens(e,t){this.accessToken=e,p.state.accessToken=e,this.refreshToken=t,p.state.refreshToken=t,d.setRefreshToken(t),this.isAuthorized=!0,p.state.isAuthorized=!0,d.setIsAuthorized(!0)}getAccessToken(){return fetch(this.accessTokenURL,{credentials:"include",headers:this.oauthHeaders(),method:"POST",body:t({grant_type:"authorization_code",scope:"printing",code:p.state.code,redirect_uri:this.redirectURI,code_verifier:p.state.codeVerifier})}).then((e=>e.json())).then((e=>{e.access_token&&this.persistTokens(e.access_token,e.refresh_token)}))}refreshTokens(){return fetch(this.accessTokenURL,{credentials:"include",headers:this.oauthHeaders(),method:"POST",body:t({grant_type:"refresh_token",scope:"printing",refresh_token:p.state.refreshToken})}).then((e=>e.json())).then((e=>{e.access_token&&this.persistTokens(e.access_token,e.refresh_token)}))}revokeRefreshToken(){p.state.refreshToken&&fetch(`https://${this.oauthUrl}/oauth/revoke/`,{credentials:"include",headers:this.oauthHeaders(),method:"POST",body:t({token:p.state.refreshToken})}).catch((()=>{}))}}const p=i({code:"",codeVerifier:"",accessToken:"",refreshToken:"",isAuthorized:!1,devApi:!1,authApiHostUrl:"",redirectUri:"",authUri:"",clientID:""});function S(){const e=new URLSearchParams(window.location.search).get("code");window.opener&&e&&(window.opener.postMessage(e,p.state.redirectUri),window.close())}export{g as E,p as a,S as b,i as c,d as s}
|