@file-viewer/web 2.1.14 → 2.1.16

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.
@@ -223,12 +223,22 @@ const WEB_VIEWER_STYLE = `
223
223
  .file-viewer-web-toolbar .file-viewer-web-icon-button{width:30px;min-width:30px;padding:0;display:inline-flex;align-items:center;justify-content:center}
224
224
  .file-viewer-web-toolbar .file-viewer-web-zoom-meter{min-width:48px;height:30px;padding:0 8px;display:inline-flex;align-items:center;justify-content:center;box-sizing:border-box;color:#23465e}
225
225
  .file-viewer-web-toolbar .file-viewer-web-zoom-meter--readonly{font-size:12px;font-weight:800;line-height:1;white-space:nowrap}
226
+ .file-viewer-web-search{gap:4px}
227
+ .file-viewer-web-search input{width:clamp(128px,18vw,220px);height:30px;box-sizing:border-box;border:0;border-radius:999px;padding:0 10px;background:#fff;color:#172033;font:inherit;font-size:12px;line-height:30px;outline:0}
228
+ .file-viewer-web-search input:focus{box-shadow:0 0 0 2px rgba(31,157,103,.22)}
229
+ .file-viewer-web-search button{min-width:32px;height:30px;padding:0 8px;border-radius:999px}
230
+ .file-viewer-web-search-count{min-width:42px;text-align:center;color:#607282;font-size:12px;font-weight:800;line-height:30px;white-space:nowrap}
226
231
  .file-viewer-web-toolbar[data-toolbar-position="bottom-right"] button{min-width:48px;height:32px;border-radius:999px}
227
232
  .file-viewer-web-toolbar[data-toolbar-position="bottom-right"] .file-viewer-web-icon-button{width:32px;min-width:32px}
228
233
  .file-viewer-web-toolbar[data-toolbar-position="bottom-right"] .file-viewer-web-zoom-meter{min-width:54px;height:32px}
234
+ .file-viewer-web-toolbar[data-toolbar-position="bottom-right"] .file-viewer-web-search button{min-width:32px;height:32px}
235
+ .file-viewer-web-toolbar[data-toolbar-position="bottom-right"] .file-viewer-web-search input{height:32px;line-height:32px;width:clamp(120px,18vw,190px)}
229
236
  .file-viewer-web-shell[data-viewer-theme='dark'] .file-viewer-web-toolbar{border-color:rgba(148,163,184,.18);background:rgba(15,23,42,.9)}
230
237
  .file-viewer-web-shell[data-viewer-theme='dark'] .file-viewer-web-toolbar button{color:#d7dee8}
231
- @media (prefers-color-scheme:dark){.file-viewer-web-shell[data-viewer-theme='system'] .file-viewer-web-toolbar{border-color:rgba(148,163,184,.18);background:rgba(15,23,42,.9)}.file-viewer-web-shell[data-viewer-theme='system'] .file-viewer-web-toolbar button{color:#d7dee8}}
238
+ .file-viewer-web-shell[data-viewer-theme='dark'] .file-viewer-web-search input{background:rgba(15,23,42,.78);color:#f8fafc}
239
+ .file-viewer-web-shell[data-viewer-theme='dark'] .file-viewer-web-search-count{color:#cbd5e1}
240
+ @media (prefers-color-scheme:dark){.file-viewer-web-shell[data-viewer-theme='system'] .file-viewer-web-toolbar{border-color:rgba(148,163,184,.18);background:rgba(15,23,42,.9)}.file-viewer-web-shell[data-viewer-theme='system'] .file-viewer-web-toolbar button{color:#d7dee8}.file-viewer-web-shell[data-viewer-theme='system'] .file-viewer-web-search input{background:rgba(15,23,42,.78);color:#f8fafc}.file-viewer-web-shell[data-viewer-theme='system'] .file-viewer-web-search-count{color:#cbd5e1}}
241
+ @media (max-width:640px){.file-viewer-web-toolbar{max-width:100%;overflow-x:auto}.file-viewer-web-toolbar[data-toolbar-position="bottom-right"]{max-width:calc(100% - 32px)}.file-viewer-web-search input{width:120px}}
232
242
  `;
233
243
  const createButton = (documentRef, label, className, onClick) => {
234
244
  const button = documentRef.createElement('button');
@@ -317,7 +327,20 @@ export const mountViewer = (container, initialOptions = {}, coreOptions = {}) =>
317
327
  shell.dataset.viewerTheme = ((_a = currentOptions.options) === null || _a === void 0 ? void 0 : _a.theme) || 'light';
318
328
  };
319
329
  let controller = null;
330
+ let searchDraft = '';
331
+ const isSearchToolbarVisible = (toolbar, options) => {
332
+ var _a;
333
+ if (toolbar.search === false || options.search === false || !state.ready || state.loading || state.error) {
334
+ return false;
335
+ }
336
+ if (contentEl.querySelector('.file-viewer-missing-renderer')) {
337
+ return false;
338
+ }
339
+ const renderer = instance.getRenderer(getCurrentExtension());
340
+ return !!((_a = renderer === null || renderer === void 0 ? void 0 : renderer.capabilities) === null || _a === void 0 ? void 0 : _a.search);
341
+ };
320
342
  const renderToolbar = () => {
343
+ var _a, _b;
321
344
  if (disposed) {
322
345
  return;
323
346
  }
@@ -326,7 +349,8 @@ export const mountViewer = (container, initialOptions = {}, coreOptions = {}) =>
326
349
  const toolbar = normalizeFileViewerToolbar(options);
327
350
  const availability = getToolbarAvailability();
328
351
  const visibleToolbar = resolveVisibleFileViewerToolbar(toolbar, availability);
329
- const showToolbar = hasVisibleFileViewerToolbarActions(visibleToolbar);
352
+ const showSearchToolbar = isSearchToolbarVisible(toolbar, options);
353
+ const showToolbar = hasVisibleFileViewerToolbarActions(visibleToolbar) || showSearchToolbar;
330
354
  const toolbarPosition = resolveFileViewerToolbarPosition(options, getCurrentExtension());
331
355
  const toolbarDisabled = state.loading || !!state.error;
332
356
  const zoomState = getToolbarZoomState();
@@ -337,6 +361,58 @@ export const mountViewer = (container, initialOptions = {}, coreOptions = {}) =>
337
361
  if (!showToolbar) {
338
362
  return;
339
363
  }
364
+ if (showSearchToolbar) {
365
+ const searchState = state.search;
366
+ const searchTotal = (_a = searchState === null || searchState === void 0 ? void 0 : searchState.total) !== null && _a !== void 0 ? _a : 0;
367
+ const currentIndex = searchTotal > 0 ? ((_b = searchState === null || searchState === void 0 ? void 0 : searchState.currentIndex) !== null && _b !== void 0 ? _b : -1) + 1 : 0;
368
+ const group = documentRef.createElement('form');
369
+ group.className = 'file-viewer-web-toolbar-group file-viewer-web-search';
370
+ group.setAttribute('role', 'search');
371
+ group.setAttribute('aria-label', t('toolbar.search'));
372
+ const input = documentRef.createElement('input');
373
+ input.type = 'search';
374
+ input.value = searchDraft;
375
+ input.placeholder = t('toolbar.searchPlaceholder');
376
+ input.title = t('toolbar.searchPlaceholder');
377
+ input.setAttribute('aria-label', t('toolbar.searchPlaceholder'));
378
+ input.disabled = toolbarDisabled;
379
+ input.addEventListener('input', () => {
380
+ searchDraft = input.value;
381
+ });
382
+ const searchButton = documentRef.createElement('button');
383
+ searchButton.type = 'submit';
384
+ searchButton.textContent = t('toolbar.search');
385
+ searchButton.title = t('toolbar.search');
386
+ searchButton.setAttribute('aria-label', t('toolbar.search'));
387
+ searchButton.disabled = toolbarDisabled;
388
+ const previousButton = createButton(documentRef, '<', 'file-viewer-web-icon-button', () => controller === null || controller === void 0 ? void 0 : controller.previousSearchResult());
389
+ previousButton.title = t('toolbar.searchPrevious');
390
+ previousButton.setAttribute('aria-label', t('toolbar.searchPrevious'));
391
+ previousButton.disabled = toolbarDisabled || searchTotal < 1;
392
+ const nextButton = createButton(documentRef, '>', 'file-viewer-web-icon-button', () => controller === null || controller === void 0 ? void 0 : controller.nextSearchResult());
393
+ nextButton.title = t('toolbar.searchNext');
394
+ nextButton.setAttribute('aria-label', t('toolbar.searchNext'));
395
+ nextButton.disabled = toolbarDisabled || searchTotal < 1;
396
+ const clearButton = createButton(documentRef, 'x', 'file-viewer-web-icon-button', async () => {
397
+ searchDraft = '';
398
+ await (controller === null || controller === void 0 ? void 0 : controller.clearDocumentSearch());
399
+ });
400
+ clearButton.title = t('toolbar.searchClear');
401
+ clearButton.setAttribute('aria-label', t('toolbar.searchClear'));
402
+ clearButton.disabled = toolbarDisabled || (!searchDraft && !(searchState === null || searchState === void 0 ? void 0 : searchState.query));
403
+ const count = documentRef.createElement('span');
404
+ count.className = 'file-viewer-web-search-count';
405
+ count.textContent = `${currentIndex}/${searchTotal}`;
406
+ count.setAttribute('aria-live', 'polite');
407
+ group.addEventListener('submit', event => {
408
+ event.preventDefault();
409
+ searchDraft = input.value;
410
+ const query = searchDraft.trim();
411
+ void (query ? controller === null || controller === void 0 ? void 0 : controller.searchDocument(query) : controller === null || controller === void 0 ? void 0 : controller.clearDocumentSearch());
412
+ });
413
+ group.append(input, searchButton, previousButton, nextButton, clearButton, count);
414
+ toolbarEl.appendChild(group);
415
+ }
340
416
  if (visibleToolbar.zoom) {
341
417
  const group = documentRef.createElement('div');
342
418
  group.className = 'file-viewer-web-toolbar-group';
@@ -429,6 +505,8 @@ export const mountViewer = (container, initialOptions = {}, coreOptions = {}) =>
429
505
  state.ready = false;
430
506
  state.error = null;
431
507
  state.lifecycle = event.payload;
508
+ state.search = null;
509
+ searchDraft = '';
432
510
  }
433
511
  else if (event.type === 'load-complete') {
434
512
  state.loading = false;
@@ -450,6 +528,7 @@ export const mountViewer = (container, initialOptions = {}, coreOptions = {}) =>
450
528
  }
451
529
  else if (event.type === 'search-change') {
452
530
  state.search = event.payload;
531
+ searchDraft = event.payload.query;
453
532
  }
454
533
  else if (event.type === 'location-change') {
455
534
  state.location = event.payload;