@arbetsformedlingen/yrkesvaljaren 2.0.5
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/LICENSE +190 -0
- package/README.md +369 -0
- package/dist/cjs/af-validation-message-BzY5H0xU.js +16 -0
- package/dist/cjs/core-selector.cjs.entry.js +476 -0
- package/dist/cjs/digi-service-job-selector.cjs.entry.js +1619 -0
- package/dist/cjs/fuse-BTLNKxuL.js +1631 -0
- package/dist/cjs/geo-valjaren.cjs.entry.js +14910 -0
- package/dist/cjs/index-BOuTGlEp.js +1817 -0
- package/dist/cjs/index.cjs.js +14 -0
- package/dist/cjs/job-selector-demo.cjs.entry.js +692 -0
- package/dist/cjs/loader.cjs.js +12 -0
- package/dist/cjs/neobrutal-search.cjs.entry.js +171 -0
- package/dist/cjs/search.engine-D0cMelRi.js +489 -0
- package/dist/cjs/taxonomy-registry-DVmuDUpM.js +435 -0
- package/dist/cjs/types-CtHBl6Ra.js +14 -0
- package/dist/cjs/yrkesvaljaren.cjs.js +24 -0
- package/dist/collection/collection-manifest.json +15 -0
- package/dist/collection/components/core-selector/core-selector.css +803 -0
- package/dist/collection/components/core-selector/core-selector.js +761 -0
- package/dist/collection/components/core-selector/types.js +1 -0
- package/dist/collection/components/design-compat/af-icon.js +13 -0
- package/dist/collection/components/design-compat/af-label.js +2 -0
- package/dist/collection/components/design-compat/af-tag.js +6 -0
- package/dist/collection/components/design-compat/af-validation-message.js +11 -0
- package/dist/collection/components/design-compat/index.js +4 -0
- package/dist/collection/components/geovaljaren/geovaljaren.css +21 -0
- package/dist/collection/components/geovaljaren/geovaljaren.js +304 -0
- package/dist/collection/components/geovaljaren/logic/adapter.utils.js +20 -0
- package/dist/collection/components/geovaljaren/logic/data.utils.js +12 -0
- package/dist/collection/components/geovaljaren/logic/history-service.js +25 -0
- package/dist/collection/components/geovaljaren/logic/search.engine.js +28 -0
- package/dist/collection/components/job-selector/constants.js +26 -0
- package/dist/collection/components/job-selector/history-service.js +41 -0
- package/dist/collection/components/job-selector/job-selector-controller.js +835 -0
- package/dist/collection/components/job-selector/job-selector.css +318 -0
- package/dist/collection/components/job-selector/job-selector.js +1378 -0
- package/dist/collection/components/job-selector/keyboard-handlers.js +84 -0
- package/dist/collection/components/job-selector/logic/adapter.utils.js +75 -0
- package/dist/collection/components/job-selector/logic/label-formatter.js +118 -0
- package/dist/collection/components/job-selector/logic/search.engine.js +50 -0
- package/dist/collection/components/job-selector/search-logic.js +35 -0
- package/dist/collection/components/job-selector/search.utils.js +224 -0
- package/dist/collection/components/job-selector/suggestions-list.js +31 -0
- package/dist/collection/components/job-selector/taxonomy-registry.js +60 -0
- package/dist/collection/components/job-selector/test-data.mock.js +33 -0
- package/dist/collection/components/job-selector/types.js +10 -0
- package/dist/collection/components/job-selector/validation-message.js +24 -0
- package/dist/collection/demo-data.js +20 -0
- package/dist/collection/index.js +7 -0
- package/dist/collection/verkstad/verkstad.js +407 -0
- package/dist/components/core-selector.d.ts +11 -0
- package/dist/components/core-selector.js +1 -0
- package/dist/components/core-selector2.js +1 -0
- package/dist/components/digi-service-job-selector.d.ts +11 -0
- package/dist/components/digi-service-job-selector.js +1 -0
- package/dist/components/fuse.js +1 -0
- package/dist/components/geo-valjaren.d.ts +11 -0
- package/dist/components/geo-valjaren.js +1 -0
- package/dist/components/index.d.ts +35 -0
- package/dist/components/index.js +1 -0
- package/dist/components/job-selector-demo.d.ts +11 -0
- package/dist/components/job-selector-demo.js +1 -0
- package/dist/components/job-selector.js +1 -0
- package/dist/components/neobrutal-search.d.ts +11 -0
- package/dist/components/neobrutal-search.js +1 -0
- package/dist/components/search.engine.js +1 -0
- package/dist/components/types.js +1 -0
- package/dist/esm/af-validation-message-F8NIH2rC.js +14 -0
- package/dist/esm/core-selector.entry.js +474 -0
- package/dist/esm/digi-service-job-selector.entry.js +1617 -0
- package/dist/esm/fuse-BPnhMTul.js +1629 -0
- package/dist/esm/geo-valjaren.entry.js +14908 -0
- package/dist/esm/index-CGXZllj2.js +1806 -0
- package/dist/esm/index.js +10 -0
- package/dist/esm/job-selector-demo.entry.js +690 -0
- package/dist/esm/loader.js +10 -0
- package/dist/esm/neobrutal-search.entry.js +169 -0
- package/dist/esm/search.engine-nZ7AcXba.js +479 -0
- package/dist/esm/taxonomy-registry-Dw0VR9Aw.js +430 -0
- package/dist/esm/types-DHUftoZJ.js +12 -0
- package/dist/esm/yrkesvaljaren.js +20 -0
- package/dist/index.cjs.js +1 -0
- package/dist/index.js +1 -0
- package/dist/types/components/core-selector/core-selector.d.ts +46 -0
- package/dist/types/components/core-selector/types.d.ts +1 -0
- package/dist/types/components/design-compat/af-icon.d.ts +7 -0
- package/dist/types/components/design-compat/af-label.d.ts +8 -0
- package/dist/types/components/design-compat/af-tag.d.ts +8 -0
- package/dist/types/components/design-compat/af-validation-message.d.ts +9 -0
- package/dist/types/components/design-compat/index.d.ts +5 -0
- package/dist/types/components/geovaljaren/geovaljaren.d.ts +24 -0
- package/dist/types/components/geovaljaren/logic/adapter.utils.d.ts +7 -0
- package/dist/types/components/geovaljaren/logic/data.utils.d.ts +7 -0
- package/dist/types/components/geovaljaren/logic/history-service.d.ts +6 -0
- package/dist/types/components/geovaljaren/logic/search.engine.d.ts +7 -0
- package/dist/types/components/job-selector/ambient.d.ts +4 -0
- package/dist/types/components/job-selector/constants.d.ts +13 -0
- package/dist/types/components/job-selector/history-service.d.ts +6 -0
- package/dist/types/components/job-selector/job-selector-controller.d.ts +82 -0
- package/dist/types/components/job-selector/job-selector.d.ts +140 -0
- package/dist/types/components/job-selector/keyboard-handlers.d.ts +13 -0
- package/dist/types/components/job-selector/logic/adapter.utils.d.ts +12 -0
- package/dist/types/components/job-selector/logic/label-formatter.d.ts +4 -0
- package/dist/types/components/job-selector/logic/search.engine.d.ts +21 -0
- package/dist/types/components/job-selector/search-logic.d.ts +17 -0
- package/dist/types/components/job-selector/search.utils.d.ts +10 -0
- package/dist/types/components/job-selector/suggestions-list.d.ts +13 -0
- package/dist/types/components/job-selector/taxonomy-registry.d.ts +20 -0
- package/dist/types/components/job-selector/test-data.mock.d.ts +7 -0
- package/dist/types/components/job-selector/types.d.ts +107 -0
- package/dist/types/components/job-selector/validation-message.d.ts +8 -0
- package/dist/types/components/job-selector-demo/job-selector-demo.d.ts +55 -0
- package/dist/types/components/neobrutal-search/neobrutal-search.d.ts +18 -0
- package/dist/types/components.d.ts +425 -0
- package/dist/types/demo-data.d.ts +16 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/stencil-public-runtime.d.ts +1873 -0
- package/dist/types/verkstad/verkstad.d.ts +1 -0
- package/dist/yrkesvaljaren/fuse-B0eHOxow.js.map +1 -0
- package/dist/yrkesvaljaren/index-Cy4BCo5s.js.map +1 -0
- package/dist/yrkesvaljaren/index-DfJXTQqL.js.map +1 -0
- package/dist/yrkesvaljaren/index.esm.js +1 -0
- package/dist/yrkesvaljaren/index.esm.js.map +1 -0
- package/dist/yrkesvaljaren/p-16636162.entry.js +1 -0
- package/dist/yrkesvaljaren/p-273cf6df.entry.js +1 -0
- package/dist/yrkesvaljaren/p-9e48afa4.entry.js +1 -0
- package/dist/yrkesvaljaren/p-BPnhMTul.js +1 -0
- package/dist/yrkesvaljaren/p-CGXZllj2.js +3 -0
- package/dist/yrkesvaljaren/p-DHUftoZJ.js +1 -0
- package/dist/yrkesvaljaren/p-DYFAzvqX.js +1 -0
- package/dist/yrkesvaljaren/p-Dw0VR9Aw.js +1 -0
- package/dist/yrkesvaljaren/p-aef7b5ae.entry.js +1 -0
- package/dist/yrkesvaljaren/p-b0f16abd.entry.js +1 -0
- package/dist/yrkesvaljaren/p-uBrs3sSs.js +1 -0
- package/dist/yrkesvaljaren/search.engine-DPT6roRm.js.map +1 -0
- package/dist/yrkesvaljaren/taxonomy-registry-s5khf6s4.js.map +1 -0
- package/dist/yrkesvaljaren/types-DHUftoZJ.js.map +1 -0
- package/dist/yrkesvaljaren/yrkesvaljaren.css +1 -0
- package/dist/yrkesvaljaren/yrkesvaljaren.esm.js +1 -0
- package/dist/yrkesvaljaren/yrkesvaljaren.esm.js.map +1 -0
- package/loader/cdn.js +1 -0
- package/loader/index.cjs.js +1 -0
- package/loader/index.d.ts +24 -0
- package/loader/index.es2017.js +1 -0
- package/loader/index.js +2 -0
- package/package.json +126 -0
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var index = require('./index-BOuTGlEp.js');
|
|
4
|
+
var afValidationMessage = require('./af-validation-message-BzY5H0xU.js');
|
|
5
|
+
|
|
6
|
+
const svgMarkup = {
|
|
7
|
+
search: '<svg width="26" height="26" viewBox="0 0 26 26" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" style="width:100%;height:100%"><path d="M25.645 22.437l-5.063-5.053a1.22 1.22 0 00-.864-.355h-.827a10.477 10.477 0 002.234-6.487C21.125 4.719 16.397 0 10.562 0 4.729 0 0 4.719 0 10.542c0 5.823 4.728 10.542 10.563 10.542 2.452 0 4.707-.831 6.5-2.23v.826c0 .324.126.633.355.862l5.063 5.053c.477.476 1.25.476 1.721 0l1.437-1.435a1.22 1.22 0 00.006-1.723zm-15.082-5.408c-3.59 0-6.5-2.899-6.5-6.487a6.49 6.49 0 016.5-6.487c3.59 0 6.5 2.899 6.5 6.487a6.49 6.49 0 01-6.5 6.487z" fill="currentColor" fill-rule="nonzero"/></svg>',
|
|
8
|
+
check: '<svg width="23" height="18" viewBox="0 0 23 18" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" style="width:100%;height:100%"><path d="M20.547.18L7.315 13.627 2.453 8.686a.597.597 0 00-.853 0L.177 10.132a.62.62 0 000 .868l6.711 6.82c.236.24.618.24.854 0L22.823 2.493a.62.62 0 000-.867L21.4.18a.597.597 0 00-.853 0z" fill="currentColor"/></svg>',
|
|
9
|
+
x: '<svg width="12" height="12" viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" style="width:100%;height:100%"><g stroke="currentColor" stroke-width="2" fill="none" fill-rule="evenodd" stroke-linecap="square"><path d="M2 2l7.986 7.986M9.986 2L2 9.986"/></g></svg>',
|
|
10
|
+
};
|
|
11
|
+
const AfIcon = ({ name, class: className }) => (index.h("span", { class: className, "aria-hidden": "true", innerHTML: svgMarkup[name], style: {
|
|
12
|
+
display: 'flex',
|
|
13
|
+
width: className ? undefined : '12px',
|
|
14
|
+
height: className ? undefined : '12px',
|
|
15
|
+
minHeight: '1.4em',
|
|
16
|
+
alignItems: 'center',
|
|
17
|
+
} }));
|
|
18
|
+
|
|
19
|
+
const AfLabel = ({ label, forId, description, required = false }) => (index.h("div", { class: "af-form-label" }, index.h("label", { class: "af-form-label__label", htmlFor: forId }, label, required ? ' *' : ''), description && index.h("span", { class: "af-form-label__description" }, description)));
|
|
20
|
+
|
|
21
|
+
const AfTag = ({ text, breakWords = false, onRemove }) => (index.h("span", { class: "af-tag" }, index.h("button", { type: "button", class: "af-tag__button", "aria-label": `Ta bort ${text}`, onClick: (event) => {
|
|
22
|
+
event.preventDefault();
|
|
23
|
+
onRemove();
|
|
24
|
+
} }, index.h("span", { class: { 'af-tag__text': true, 'af-tag__text--break': breakWords } }, text), index.h(AfIcon, { name: "x", class: "af-tag__remove-icon" }))));
|
|
25
|
+
|
|
26
|
+
function shouldShowManualInput(state, requireSelection = false) {
|
|
27
|
+
if (!state || requireSelection)
|
|
28
|
+
return false;
|
|
29
|
+
const inputValue = state.inputValue.trim();
|
|
30
|
+
if (inputValue === '')
|
|
31
|
+
return false;
|
|
32
|
+
return !state.suggestions.some((suggestion) => suggestion.label.toLowerCase() === inputValue.toLowerCase());
|
|
33
|
+
}
|
|
34
|
+
function reconcileActiveIndex({ activeIndex, newState, oldState, requireSelection = false, }) {
|
|
35
|
+
if (oldState && newState.inputValue !== oldState.inputValue) {
|
|
36
|
+
return { activeIndex: -1, shouldRestoreFocus: false };
|
|
37
|
+
}
|
|
38
|
+
let nextActiveIndex = activeIndex;
|
|
39
|
+
if (newState.status === 'multiSelect'
|
|
40
|
+
&& oldState?.status === 'multiSelect'
|
|
41
|
+
&& newState.selectedItems.length > oldState.selectedItems.length) {
|
|
42
|
+
nextActiveIndex = 0;
|
|
43
|
+
}
|
|
44
|
+
const oldShowManualInput = shouldShowManualInput(oldState, requireSelection);
|
|
45
|
+
const wasManualInputActive = Boolean(oldState && oldShowManualInput && activeIndex === oldState.suggestions.length);
|
|
46
|
+
const showManualInput = shouldShowManualInput(newState, requireSelection);
|
|
47
|
+
const optionCount = newState.suggestions.length + (showManualInput ? 1 : 0);
|
|
48
|
+
if (wasManualInputActive) {
|
|
49
|
+
nextActiveIndex = showManualInput ? newState.suggestions.length : -1;
|
|
50
|
+
}
|
|
51
|
+
else if (optionCount === 0) {
|
|
52
|
+
nextActiveIndex = -1;
|
|
53
|
+
}
|
|
54
|
+
else if (nextActiveIndex >= optionCount) {
|
|
55
|
+
nextActiveIndex = optionCount - 1;
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
activeIndex: nextActiveIndex,
|
|
59
|
+
shouldRestoreFocus: newState.status === 'itemSelected' && oldState?.status !== 'itemSelected',
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const coreSelectorCss = () => `:host{--digi--grayscale-0:#ffffff;--digi--grayscale-50:#fbfbfb;--digi--grayscale-100:#f4f4f4;--digi--grayscale-200:#ededed;--digi--grayscale-300:#e4e4e4;--digi--grayscale-400:#dddddd;--digi--grayscale-500:#cacaca;--digi--grayscale-600:#acacac;--digi--grayscale-700:#757575;--digi--grayscale-800:#5c5c5c;--digi--grayscale-900:#333333;--digi--grayscale-1000:#000000;--digi--global--color--cta--link--base:#1616b2;--digi--global--color--function--danger--base:#da0000;--digi--global--color--function--success--base:#008a20;--digi--global--color--function--success--lightest-3:#d4edda;--digi--global--color--function--warning--base:#ffe200;--digi--color--text--primary:var(--digi--grayscale-900);--digi--color--text--secondary:var(--digi--grayscale-700);--digi--color--text--link:var(--digi--global--color--cta--link--base);--digi--color--icons--success:var(--digi--global--color--function--success--base);--digi--color--icons--warning:#8a7a00;--digi--color--icons--danger:var(--digi--global--color--function--danger--base);--digi--global--typography--font-family--default:"Open Sans", Arial, sans-serif;--digi--global--typography--font-size--base:1rem;--digi--global--typography--font-size--small:0.875rem;--digi--global--typography--font-weight--regular:400;--digi--global--typography--font-weight--semibold:600;--digi--global--typography--font-weight--bold:700;--digi--global--typography--line-height--base:1.5;--digi--typography--label--font-size--desktop:1rem;--digi--typography--label--font-weight--desktop:600;--digi--typography--label--line-height--desktop:1.5;--digi--typography--label-description--font-size--desktop:1rem;--digi--typography--label-description--line-height--desktop:1.5;--digi--typography--tag--font-size--desktop:0.875rem;--digi--gutter--icon:0.625rem;--digi--gutter--smaller:0.75rem;--digi--gutter--small:0.875rem;--digi--gutter--medium:1rem;--digi--border-width--primary:1px;--digi--border-style--primary:solid;--digi--border-radius--primary:0;--digi--border-radius--secondary:6px;--af-tag-color:#091d54;--af-tag-hover-background:#ddf1fc}.af-form-label{color:var(--digi--color--text--primary);display:flex;flex-direction:column;font-family:var(--digi--global--typography--font-family--default);font-size:var(--digi--typography--label--font-size--desktop);margin-bottom:0.5rem}.af-form-label__label{cursor:pointer;display:block;font-weight:var(--digi--typography--label--font-weight--desktop);line-height:var(--digi--typography--label--line-height--desktop)}.af-form-label__description{display:block;font-size:var(--digi--typography--label-description--font-size--desktop);line-height:var(--digi--typography--label-description--line-height--desktop);max-width:35rem}.af-validation-message{align-items:center;display:flex;flex-wrap:wrap}.af-validation-message__icon{flex:0 0 auto;height:1.25em;margin-inline-end:var(--digi--gutter--icon);width:1.25em}.af-validation-message__icon--success,.af-validation-message__icon--error{background-color:var(--af-validation-icon-color, currentColor);-webkit-mask-position:center;mask-position:center;-webkit-mask-repeat:no-repeat;mask-repeat:no-repeat;-webkit-mask-size:contain;mask-size:contain}.af-validation-message__icon--success{--af-validation-icon-color:var(--digi--color--icons--success);-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 25 25'%3E%3Cpath d='M25 12.5C25 19.404 19.404 25 12.5 25S0 19.404 0 12.5 5.596 0 12.5 0 25 5.596 25 12.5zm-13.946 6.619l9.274-9.275a.806.806 0 000-1.14l-1.14-1.14a.806.806 0 00-1.14 0l-7.564 7.563-3.531-3.531a.807.807 0 00-1.14 0l-1.141 1.14a.806.806 0 000 1.14l5.242 5.243a.806.806 0 001.14 0z'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 25 25'%3E%3Cpath d='M25 12.5C25 19.404 19.404 25 12.5 25S0 19.404 0 12.5 5.596 0 12.5 0 25 5.596 25 12.5zm-13.946 6.619l9.274-9.275a.806.806 0 000-1.14l-1.14-1.14a.806.806 0 00-1.14 0l-7.564 7.563-3.531-3.531a.807.807 0 00-1.14 0l-1.141 1.14a.806.806 0 000 1.14l5.242 5.243a.806.806 0 001.14 0z'/%3E%3C/svg%3E")}.af-validation-message__icon--error{--af-validation-icon-color:var(--digi--color--icons--danger);-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 48 48'%3E%3Cpath d='M34.4328058,0 C35.5494848,0 36.5900526,0.609146757 37.1483921,1.58958113 L47.5812454,19.9104189 C48.1395849,20.8909496 48.1395849,22.1090504 47.5812454,23.0895811 L37.1483921,41.4104189 C36.5900526,42.3908532 35.5494848,43 34.4328058,43 L13.5671942,43 C12.4505152,43 11.4099474,42.3908532 10.8516079,41.4104189 L0.41875464,23.0895811 C-0.13958488,22.1090504 -0.13958488,20.8909496 0.41875464,19.9104189 L10.8516079,1.58958113 C11.4099474,0.609146757 12.4505152,0 13.5671942,0 Z M18.6736823,12.3728178 C18.2711762,11.964729 17.6203819,11.964729 17.2178757,12.3728178 L15.2825964,14.334939 C14.8800903,14.7430278 14.8800903,15.4028485 15.2825964,15.8109373 L20.6089616,21.2111779 L15.2825964,26.6114185 C14.8800903,27.0195074 14.8800903,27.6793281 15.2825964,28.0874169 L17.2178757,30.049538 C17.6203819,30.4576269 18.2711762,30.4576269 18.6736823,30.049538 L24.0000475,24.6492974 L29.3264127,30.049538 C29.7289188,30.4576269 30.3797132,30.4576269 30.7822193,30.049538 L32.7174986,28.0874169 C33.1200048,27.6793281 33.1200048,27.0195074 32.7174986,26.6114185 L27.3911334,21.2111779 L32.7174986,15.8109373 C33.1200048,15.4028485 33.1200048,14.7430278 32.7174986,14.334939 L30.7822193,12.3728178 C30.3797132,11.964729 29.7289188,11.964729 29.3264127,12.3728178 L24.0000475,17.7730584 Z'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 48 48'%3E%3Cpath d='M34.4328058,0 C35.5494848,0 36.5900526,0.609146757 37.1483921,1.58958113 L47.5812454,19.9104189 C48.1395849,20.8909496 48.1395849,22.1090504 47.5812454,23.0895811 L37.1483921,41.4104189 C36.5900526,42.3908532 35.5494848,43 34.4328058,43 L13.5671942,43 C12.4505152,43 11.4099474,42.3908532 10.8516079,41.4104189 L0.41875464,23.0895811 C-0.13958488,22.1090504 -0.13958488,20.8909496 0.41875464,19.9104189 L10.8516079,1.58958113 C11.4099474,0.609146757 12.4505152,0 13.5671942,0 Z M18.6736823,12.3728178 C18.2711762,11.964729 17.6203819,11.964729 17.2178757,12.3728178 L15.2825964,14.334939 C14.8800903,14.7430278 14.8800903,15.4028485 15.2825964,15.8109373 L20.6089616,21.2111779 L15.2825964,26.6114185 C14.8800903,27.0195074 14.8800903,27.6793281 15.2825964,28.0874169 L17.2178757,30.049538 C17.6203819,30.4576269 18.2711762,30.4576269 18.6736823,30.049538 L24.0000475,24.6492974 L29.3264127,30.049538 C29.7289188,30.4576269 30.3797132,30.4576269 30.7822193,30.049538 L32.7174986,28.0874169 C33.1200048,27.6793281 33.1200048,27.0195074 32.7174986,26.6114185 L27.3911334,21.2111779 L32.7174986,15.8109373 C33.1200048,15.4028485 33.1200048,14.7430278 32.7174986,14.334939 L30.7822193,12.3728178 C30.3797132,11.964729 29.7289188,11.964729 29.3264127,12.3728178 L24.0000475,17.7730584 Z'/%3E%3C/svg%3E")}.af-validation-message__icon--warning{background:center / contain no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 18 18'%3E%3Ccircle cx='9' cy='9' r='6.75' fill='%23333'/%3E%3Cpath d='m18 9c0 4.9717-4.0298 9-9 9-4.9702 0-9-4.0283-9-9 0-4.9688 4.0298-9 9-9 4.9702 0 9 4.0312 9 9zm-9 1.8145c-0.92196 0-1.6694 0.7474-1.6694 1.6694 0 0.92196 0.7474 1.6694 1.6694 1.6694s1.6694-0.7474 1.6694-1.6694c0-0.92196-0.7474-1.6694-1.6694-1.6694zm-1.3157-1.065c0.012593 0.23095 0.20355 0.41175 0.43483 0.41175h1.7618c0.23128 0 0.42224-0.1808 0.43483-0.41175l0.2692-4.9355c0.013609-0.24946-0.18501-0.45922-0.43483-0.45922h-2.3002c-0.24982 0-0.4484 0.20976-0.43479 0.45922l0.2692 4.9355z' fill='%23FFE200'/%3E%3C/svg%3E");position:relative;top:3px}.af-validation-message__text{color:var(--digi--color--text--primary);flex:1;font-family:var(--digi--global--typography--font-family--default);font-size:var(--digi--typography--tag--font-size--desktop);transform:translateY(1px)}.af-tag{display:block;max-width:100%;min-width:0}.af-tag__button{align-items:center;background:var(--digi--grayscale-0);border:var(--digi--border-width--primary) var(--digi--border-style--primary) var(--af-tag-color);border-radius:var(--digi--border-radius--secondary);color:var(--af-tag-color);cursor:pointer;display:inline-flex;font-family:var(--digi--global--typography--font-family--default);font-size:0.875rem;font-weight:var(--digi--global--typography--font-weight--semibold);gap:10px;height:auto;max-width:100%;min-height:unset;min-width:0;padding:6px 8px;text-align:left;white-space:normal}.af-tag__button:hover{background:var(--af-tag-hover-background)}.af-tag__button:focus-visible{background:var(--af-tag-hover-background);border-color:var(--af-tag-color);outline:2px solid var(--digi--grayscale-1000);outline-offset:2px;box-shadow:0 0 0 5px var(--digi--grayscale-0)}.af-tag__button:active{background:var(--af-tag-hover-background)}.af-tag__text{display:inline-block;max-width:100%;min-width:0;white-space:normal}.af-tag__text--break{overflow-wrap:anywhere;word-break:break-word}.af-tag__remove-icon{flex:0 0 auto;height:1em;min-height:0 !important;width:1em}:host{--selector-width:var(--cs-width, 100%);--selector-min-width:var(--cs-min-width, 200px);--selector-max-width:var(--cs-max-width, none);--selector-height:var(--cs-height, auto);--selector-min-height:var(--cs-min-height, auto);--selector-max-height:var(--cs-max-height, none);--selector-font-family:var(--global-font-family, 'Open Sans', sans-serif);--selector-font-size:var(--cs-font-size, 1rem);--selector-text-color:var(--cs-text-color, #212529);--selector-placeholder-color:var(--cs-placeholder-color, #6c757d);--selector-border-color:var(--cs-border-color, #d1d5db);--selector-focus-border-color:var(--cs-focus-border-color, #86b7fe);--selector-focus-shadow:var(--cs-focus-shadow, 0 0 0 0.25rem rgba(13, 110, 253, 0.25));--selector-background-color:var(--cs-background-color, #fff);--selector-icon-color:var(--cs-icon-color, #6c757d);--selector-clear-button-color:var(--cs-clear-button-color, #6c757d);--selector-clear-button-hover-color:var(--cs-clear-button-hover-color, #212529);--selector-suggestion-background-color:var(--cs-suggestion-background-color, #fff);--selector-suggestion-border-color:var(--cs-suggestion-border-color, #ced4da);--selector-suggestion-hover-background:var(--cs-suggestion-hover-background, #e9ecef);--selector-suggestion-active-background:var(--cs-suggestion-active-background, #dde4eb);--selector-suggestion-text-color:var(--cs-suggestion-text-color, #212529);--selector-suggestion-highlight-weight:var(--cs-suggestion-highlight-weight, bold);--selector-error-color:var(--cs-error-color, #dc3545);--selector-loading-color:var(--cs-loading-color, #6c757d);--selector-container-min-height:40px;--selector-padding-y:6px;--selector-padding-x:10px;--selector-icon-size:1.1em;--selector-gap:6px;--cs-row-height:32px;display:flex;flex-direction:column;width:var(--selector-width);min-width:var(--selector-min-width);max-width:var(--selector-max-width);height:var(--selector-height);min-height:var(--selector-min-height);max-height:var(--selector-max-height);font-family:var(--selector-font-family);font-size:var(--selector-font-size);color:var(--selector-text-color);position:relative}:host([cs-size="small"]){--selector-container-min-height:32px;--selector-padding-y:2px;--selector-icon-size:1em;--selector-gap:4px;--cs-row-height:28px}:host([cs-size="medium"]){--selector-container-min-height:40px;--selector-padding-y:6px;--cs-row-height:32px}:host([cs-size="large"]){--selector-container-min-height:48px;--selector-padding-y:10px;--selector-icon-size:1.25em;--selector-gap:8px;--cs-row-height:40px}*{box-sizing:border-box}.core-selector-wrapper{display:flex;flex-direction:column;flex:1;min-height:inherit}.af-form-label{margin-bottom:0.5rem}.search-container{display:flex;align-items:center;flex-wrap:wrap;gap:6px;border:1px solid #757575;border-radius:0px;padding:var(--selector-padding-y) var(--selector-padding-x);flex:1;min-height:var(--selector-container-min-height);cursor:text;background-color:var(--selector-background-color);position:relative;overflow:hidden}.search-container:focus-within{outline:2px solid black;outline-offset:2px}.search-container.is-inactive-selected .selector-input-field{caret-color:transparent;cursor:default}.is-inactive-selected+.suggestions-box-container{display:none !important}.search-container.is-inactive-selected .search-icon-container{display:none}.search-container.is-inactive-selected .input-area{padding-left:0}.input-controls-wrapper{position:relative;width:100%;display:flex;align-items:center}.search-icon-container{position:absolute;left:0;top:50%;width:20px;height:20px;transform:translateY(-50%);z-index:1;pointer-events:none;display:flex;align-items:center;justify-content:center;transition:transform 0.2s ease-in-out, opacity 0.2s ease-in-out;opacity:1;max-height:100%}.search-icon-container.is-hidden{opacity:0;transform:translateY(-50%) scale(0.7)}.selector-search-icon{color:var(--digi--color--icon--primary, #333);display:block;flex:0 0 auto;width:20px;height:20px}.clear-button>span{color:var(--digi--color--icon--primary, #333)}.input-area{flex:1;min-width:0;padding-left:27px;display:flex;align-items:center;transition:padding-left 0.2s ease-in-out}.input-area.has-value{padding-left:0}.selector-input-field{width:100%;font-family:inherit;font-size:var(--selector-font-size);color:inherit;border:none;outline:none;background:transparent;transition:padding-right 0.2s ease-in-out}.search-container.has-input .selector-input-field{padding-right:0}.selector-input-field::placeholder{color:var(--selector-placeholder-color);opacity:1;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.clear-button{position:static;flex-shrink:0;opacity:0;pointer-events:none;z-index:2;background:none;border:none;padding:0;margin:0;height:20px;width:20px;cursor:pointer;color:var(--selector-clear-button-color);line-height:1;display:flex;align-items:center;transition:color 0.2s ease-in-out, opacity 0.2s ease-in-out}.clear-button.is-visible{opacity:1;pointer-events:auto}.clear-button:hover,.clear-button:focus{color:var(--selector-clear-button-hover-color);outline:none}.search-container.multi-search-container{display:flex;flex-direction:column;gap:0.5rem;align-items:stretch;padding-top:var(--selector-padding-y);padding-bottom:var(--selector-padding-y);width:100%;max-width:100%}.selected-tags-wrapper{display:flex;flex-wrap:wrap;gap:0.5rem;width:100%;max-width:100%;box-sizing:border-box}.selected-tags-wrapper .af-tag{display:block;max-width:100%;min-width:0}.selected-tags-wrapper .af-tag__button{white-space:normal !important;height:auto !important;text-align:left !important;word-break:break-word !important;overflow-wrap:anywhere !important;max-width:100% !important}.search-container.single-value-display{display:flex;align-items:center;flex-wrap:nowrap;gap:0.5rem;min-height:var(--selector-container-min-height);padding:var(--selector-padding-y) var(--selector-padding-x)}.selected-text-in-box{flex-grow:1;white-space:normal;word-break:break-word;min-width:0;line-height:inherit}.search-container.single-value-display .clear-button{position:static;transform:none;opacity:1;pointer-events:auto;flex-shrink:0}.combobox-container{position:relative;margin-top:0;display:flex;flex-direction:column;flex:1}.suggestions-box-container{position:absolute;top:100%;left:0;right:0;z-index:100}.suggestions-box-container.is-hidden-list{z-index:101;pointer-events:none}.suggestions-box{position:relative;background-color:white;border:1px solid var(--selector-suggestion-border-color);border-radius:4px;box-shadow:0 4px 12px rgba(0, 0, 0, 0.15);overflow-y:auto;margin:2px 0px;max-height:calc(var(--max-visible-rows, 10) * var(--cs-row-height) + 40px)}.suggestion-item{display:flex;align-items:center;min-height:var(--cs-row-height);height:auto;padding:6px 1rem;font-size:inherit;line-height:1.25;cursor:pointer;color:var(--selector-suggestion-text-color);list-style:none;transition:background-color 0.15s ease, color 0.15s ease;white-space:normal !important;word-break:break-word !important;overflow-wrap:anywhere !important;position:relative;z-index:1;box-sizing:border-box}.suggestion-item>span{transition:font-weight 0.2s ease, transform 0.2s ease;display:inline;vertical-align:middle;white-space:normal;word-break:break-word;overflow-wrap:anywhere}.suggestion-item:hover,.suggestion-item.active-suggestion{background-color:var(--selector-suggestion-active-background)}.suggestion-item.active-suggestion.is-keyboard-focus{outline:1px solid black;outline-offset:-1px}.suggestion-item.is-selected{color:var(--selector-suggestion-text-color) !important;cursor:default;background-color:#f2f2f2 !important}.suggestion-item.is-selected span{font-weight:600}.selection-indicator-icon{width:0;height:20px;opacity:0;transform:scale(0.5);margin-right:0;transition:width 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), margin-right 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);color:var(--digi--grayscale-800, #333);flex-shrink:0;display:flex;align-items:center;justify-content:center;overflow:hidden}.suggestion-item.is-selected .selection-indicator-icon{width:24px;opacity:1;transform:scale(1);margin-right:8px}.suggestion-item.is-selected.active-suggestion{background-color:#f2f2f2 !important}.suggestion-item .suggestion-text strong,.suggestion-item .match-highlight{font-weight:var(--selector-suggestion-highlight-weight);color:inherit;display:inline}.metadata-dimmed,.occupation-variant-label{font-size:1rem;color:var(--digi--grayscale-700, #757575);margin-left:0.25rem;display:inline;vertical-align:baseline;line-height:inherit;white-space:normal}.suggestion-item.no-results{color:var(--selector-placeholder-color);cursor:default;padding:0.5rem 1rem;font-style:italic;text-align:center;height:auto}.search-container.has-validation-error{border-color:var(--selector-error-color);border-width:2px;background-color:#fef3f2}.search-container.has-positive-validation{border-color:#155724;background-color:#d4edda}.status-message{margin-top:0.5rem}.selector-validation-message{margin-top:0.5rem;display:block}.visually-hidden{border:0;clip:rect(0 0 0 0);height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;width:1px;white-space:nowrap}input::-webkit-search-decoration,input::-webkit-search-cancel-button,input::-webkit-search-results-button,input::-webkit-search-results-decoration{-webkit-appearance:none;display:none}input::-ms-clear{display:none;width:0;height:0}.list-header-container{position:sticky;top:0;z-index:10;background-color:#f8f9fa;border-bottom:1px solid var(--selector-suggestion-border-color);min-height:auto;display:flex;flex-direction:column}.list-header-container ::slotted([slot="suggestions-overlay"]){position:absolute !important;top:0;left:0;width:100%;height:100%;z-index:20}.suggestions-box>::slotted([slot="suggestions-overlay"]){position:sticky !important;top:0;left:0;width:100%;z-index:20}.list-header{display:flex;align-items:center;min-height:var(--cs-row-height);padding:6px 1rem;font-size:0.875rem;line-height:1.25;color:var(--digi--grayscale-700, #757575);border-bottom:1px solid var(--selector-suggestion-border-color, #ced4da)}.list-header span{font-size:0.875rem;font-weight:normal}.history-clear-link{color:var(--digi--grayscale-700, #757575);text-decoration:underline;cursor:pointer;margin-left:0.25rem;background:transparent;border:0;padding:0;font:inherit}.history-clear-link:hover{color:var(--digi--grayscale-900, #222)}@keyframes cs-shrink-fade{from{opacity:1}to{opacity:1}}@keyframes cs-collapse{from{height:auto}to{height:auto}}.cs-toast{position:absolute;top:0;left:0;width:100%;height:100%;z-index:20;display:flex;align-items:center;justify-content:center;gap:8px;background-color:#f8fdf0;animation:cs-toastSlideDown 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;pointer-events:none;box-sizing:border-box}.cs-toast.is-closing{animation:cs-toastSlideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards}.cs-toast-text{margin:0;font-size:0.875rem;font-weight:500;color:#2e7d32}@keyframes cs-toastSlideDown{from{transform:translateY(-100%)}to{transform:translateY(0)}}@keyframes cs-toastSlideUp{from{transform:translateY(0)}to{transform:translateY(-100%)}}.selector-input-field.visually-hidden-selected{position:absolute;opacity:0;pointer-events:none;width:1px;height:1px;overflow:hidden}`;
|
|
64
|
+
|
|
65
|
+
const CoreSelector = class {
|
|
66
|
+
constructor(hostRef) {
|
|
67
|
+
index.registerInstance(this, hostRef);
|
|
68
|
+
this.csInput = index.createEvent(this, "csInput");
|
|
69
|
+
this.csSelect = index.createEvent(this, "csSelect");
|
|
70
|
+
this.csClear = index.createEvent(this, "csClear");
|
|
71
|
+
this.csRemoveItem = index.createEvent(this, "csRemoveItem");
|
|
72
|
+
this.csBlur = index.createEvent(this, "csBlur");
|
|
73
|
+
this.csEditSelection = index.createEvent(this, "csEditSelection");
|
|
74
|
+
this.csFocus = index.createEvent(this, "csFocus");
|
|
75
|
+
this.csLoadMore = index.createEvent(this, "csLoadMore");
|
|
76
|
+
this.csClearHistory = index.createEvent(this, "csClearHistory");
|
|
77
|
+
this.csRequestHistory = index.createEvent(this, "csRequestHistory");
|
|
78
|
+
}
|
|
79
|
+
historyRequestTimer;
|
|
80
|
+
disconnectedCallback() {
|
|
81
|
+
clearTimeout(this.historyRequestTimer);
|
|
82
|
+
this.historyRequestTimer = undefined;
|
|
83
|
+
}
|
|
84
|
+
static nextId = 0;
|
|
85
|
+
get hostElement() { return index.getElement(this); }
|
|
86
|
+
state;
|
|
87
|
+
config = {
|
|
88
|
+
disabled: false,
|
|
89
|
+
placeholder: 'Sök...',
|
|
90
|
+
minLength: 1,
|
|
91
|
+
maxResults: 10,
|
|
92
|
+
enableMultiple: false,
|
|
93
|
+
showSearchIcon: true,
|
|
94
|
+
requireSelection: true,
|
|
95
|
+
size: 'medium'
|
|
96
|
+
};
|
|
97
|
+
label = '';
|
|
98
|
+
labelDescription;
|
|
99
|
+
componentId = `cs-${CoreSelector.nextId++}`;
|
|
100
|
+
size = 'medium';
|
|
101
|
+
csInput;
|
|
102
|
+
csSelect;
|
|
103
|
+
csClear;
|
|
104
|
+
csRemoveItem;
|
|
105
|
+
csBlur;
|
|
106
|
+
csEditSelection;
|
|
107
|
+
csFocus;
|
|
108
|
+
csLoadMore;
|
|
109
|
+
csClearHistory;
|
|
110
|
+
csRequestHistory;
|
|
111
|
+
afFocused = false;
|
|
112
|
+
activeIndex = -1;
|
|
113
|
+
isFocusedInternal = false;
|
|
114
|
+
isNavigatingWithKeyboard = false;
|
|
115
|
+
async setFocus() {
|
|
116
|
+
if (this.inputRef) {
|
|
117
|
+
this.inputRef.focus();
|
|
118
|
+
const len = this.inputRef.value.length;
|
|
119
|
+
this.inputRef.setSelectionRange(len, len);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
this.shouldFocusAfterRender = true;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
inputRef;
|
|
126
|
+
listRef;
|
|
127
|
+
shouldFocusAfterRender = false;
|
|
128
|
+
handleKeyDown = (event) => {
|
|
129
|
+
if (this.config.disabled) {
|
|
130
|
+
event.preventDefault();
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (!this.state)
|
|
134
|
+
return;
|
|
135
|
+
if (event.target.tagName === 'BUTTON')
|
|
136
|
+
return;
|
|
137
|
+
if (event.key !== 'ArrowUp' && event.key !== 'ArrowDown' && event.key !== 'Enter' && event.key !== 'Escape') {
|
|
138
|
+
this.isNavigatingWithKeyboard = false;
|
|
139
|
+
}
|
|
140
|
+
if (this.state.status === 'itemSelected') {
|
|
141
|
+
if (event.key !== 'Tab' && event.key !== 'Shift' && !event.ctrlKey && !event.metaKey) {
|
|
142
|
+
this.csEditSelection.emit();
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (this.state.status !== 'searching' && this.state.status !== 'multiSelect')
|
|
147
|
+
return;
|
|
148
|
+
const suggestions = this.state.suggestions;
|
|
149
|
+
const showManualInput = shouldShowManualInput(this.state, this.config.requireSelection);
|
|
150
|
+
const totalOptions = suggestions.length + (showManualInput ? 1 : 0);
|
|
151
|
+
switch (event.key) {
|
|
152
|
+
case 'ArrowDown':
|
|
153
|
+
if (totalOptions > 0) {
|
|
154
|
+
event.preventDefault();
|
|
155
|
+
this.isNavigatingWithKeyboard = true;
|
|
156
|
+
if (this.activeIndex < totalOptions - 1) {
|
|
157
|
+
this.activeIndex = this.activeIndex + 1;
|
|
158
|
+
this.scrollToActive();
|
|
159
|
+
}
|
|
160
|
+
if (this.activeIndex >= suggestions.length - 3) {
|
|
161
|
+
this.csLoadMore.emit();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
this.csFocus.emit();
|
|
166
|
+
}
|
|
167
|
+
break;
|
|
168
|
+
case 'ArrowUp':
|
|
169
|
+
if (totalOptions > 0) {
|
|
170
|
+
event.preventDefault();
|
|
171
|
+
this.isNavigatingWithKeyboard = true;
|
|
172
|
+
if (this.activeIndex > 0) {
|
|
173
|
+
this.activeIndex = this.activeIndex - 1;
|
|
174
|
+
this.scrollToActive();
|
|
175
|
+
}
|
|
176
|
+
else if (this.activeIndex === 0 || this.activeIndex === -1) {
|
|
177
|
+
// Wrap around to the last option (which might be manual input)
|
|
178
|
+
this.activeIndex = totalOptions - 1;
|
|
179
|
+
this.scrollToActive();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
break;
|
|
183
|
+
case ' ':
|
|
184
|
+
case 'Enter':
|
|
185
|
+
// Only handle Space if we have an active suggestion (keyboard navigation)
|
|
186
|
+
// If index is -1, let the space go through to the input field
|
|
187
|
+
if (event.key === ' ' && this.activeIndex === -1) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
if (this.activeIndex >= 0 && this.activeIndex < suggestions.length) {
|
|
191
|
+
event.preventDefault();
|
|
192
|
+
const item = suggestions[this.activeIndex];
|
|
193
|
+
this.shouldFocusAfterRender = true;
|
|
194
|
+
if (item.isSelected) {
|
|
195
|
+
this.csRemoveItem.emit(item);
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
this.csSelect.emit(item);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
else if (showManualInput && this.activeIndex === suggestions.length && this.isNavigatingWithKeyboard) {
|
|
202
|
+
event.preventDefault();
|
|
203
|
+
this.handleManualSelect();
|
|
204
|
+
}
|
|
205
|
+
else if (event.key === 'Enter') {
|
|
206
|
+
// If Enter is pressed but no item is active,
|
|
207
|
+
// we prevent default to avoid accidental form submission
|
|
208
|
+
// and ensure the dropdown stays open if manual input is available.
|
|
209
|
+
if (showManualInput || suggestions.length > 0) {
|
|
210
|
+
event.preventDefault();
|
|
211
|
+
this.isNavigatingWithKeyboard = true;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
break;
|
|
215
|
+
case 'Escape':
|
|
216
|
+
this.activeIndex = -1;
|
|
217
|
+
this.csClear.emit();
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
onWrapperFocusIn = () => {
|
|
222
|
+
if (this.config.disabled)
|
|
223
|
+
return;
|
|
224
|
+
if (!this.state || !this.isFocusedInternal) {
|
|
225
|
+
if (this.state) {
|
|
226
|
+
this.isFocusedInternal = true;
|
|
227
|
+
this.activeIndex = -1;
|
|
228
|
+
this.csFocus.emit();
|
|
229
|
+
if (this.state.inputValue.trim() === '') {
|
|
230
|
+
this.csRequestHistory.emit();
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
onWrapperFocusOut = () => {
|
|
236
|
+
if (this.shouldFocusAfterRender)
|
|
237
|
+
return;
|
|
238
|
+
// Use requestAnimationFrame to wait for the next frame where focus
|
|
239
|
+
// will have settled on the new element.
|
|
240
|
+
requestAnimationFrame(() => {
|
|
241
|
+
const root = this.hostElement.shadowRoot;
|
|
242
|
+
const activeElement = root?.activeElement || document.activeElement;
|
|
243
|
+
// Check if the currently focused element is inside the component or its shadow DOM
|
|
244
|
+
const isInside = (activeElement && this.hostElement.contains(activeElement)) ||
|
|
245
|
+
(root && root.contains(activeElement));
|
|
246
|
+
if (!isInside) {
|
|
247
|
+
this.isFocusedInternal = false;
|
|
248
|
+
this.activeIndex = -1;
|
|
249
|
+
this.csBlur.emit();
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
};
|
|
253
|
+
handleAfFocusedChange(newValue) {
|
|
254
|
+
this.isFocusedInternal = newValue;
|
|
255
|
+
if (newValue) {
|
|
256
|
+
this.shouldFocusAfterRender = true;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
handleConfigChange(newConfig) {
|
|
260
|
+
if (newConfig.disabled) {
|
|
261
|
+
this.isFocusedInternal = false;
|
|
262
|
+
this.activeIndex = -1;
|
|
263
|
+
this.shouldFocusAfterRender = false;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
handleStateChange(newState, oldState) {
|
|
267
|
+
const result = reconcileActiveIndex({
|
|
268
|
+
activeIndex: this.activeIndex,
|
|
269
|
+
newState,
|
|
270
|
+
oldState,
|
|
271
|
+
requireSelection: this.config.requireSelection,
|
|
272
|
+
});
|
|
273
|
+
this.activeIndex = result.activeIndex;
|
|
274
|
+
if (result.shouldRestoreFocus) {
|
|
275
|
+
this.shouldFocusAfterRender = true;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
componentDidUpdate() {
|
|
279
|
+
if (this.shouldFocusAfterRender) {
|
|
280
|
+
this.performFocusRestoration();
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
performFocusRestoration(retryCount = 0) {
|
|
284
|
+
if (this.config.disabled) {
|
|
285
|
+
this.shouldFocusAfterRender = false;
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
if (this.inputRef) {
|
|
289
|
+
this.isFocusedInternal = true; // Ensure UI thinks it's focused to show suggestions
|
|
290
|
+
this.inputRef.focus();
|
|
291
|
+
const currentActive = this.hostElement.shadowRoot?.activeElement;
|
|
292
|
+
if (currentActive === this.inputRef || retryCount > 20) {
|
|
293
|
+
const len = this.inputRef.value.length;
|
|
294
|
+
this.inputRef.setSelectionRange(len, len);
|
|
295
|
+
this.shouldFocusAfterRender = false;
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
requestAnimationFrame(() => this.performFocusRestoration(retryCount + 1));
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
handleScroll(event) {
|
|
303
|
+
if (!this.config.enableInfiniteScroll)
|
|
304
|
+
return;
|
|
305
|
+
const target = event.target;
|
|
306
|
+
const threshold = 50;
|
|
307
|
+
const remaining = target.scrollHeight - (target.scrollTop + target.clientHeight);
|
|
308
|
+
if (remaining < threshold) {
|
|
309
|
+
this.csLoadMore.emit();
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
scrollToActive() {
|
|
313
|
+
if (!this.listRef || !this.state)
|
|
314
|
+
return;
|
|
315
|
+
const optionId = this.activeIndex === this.state.suggestions.length
|
|
316
|
+
? `${this.componentId}-list-option-manual-input`
|
|
317
|
+
: `${this.componentId}-list-option-${this.activeIndex}`;
|
|
318
|
+
const activeElement = this.listRef.querySelector(`#${optionId}`);
|
|
319
|
+
activeElement?.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
|
|
320
|
+
}
|
|
321
|
+
handleManualSelect() {
|
|
322
|
+
const item = { id: '', label: this.state.inputValue.trim(), metadata: { type: 'ManualInput' } };
|
|
323
|
+
this.shouldFocusAfterRender = true;
|
|
324
|
+
this.csSelect.emit(item);
|
|
325
|
+
if (this.config.enableMultiple && this.state?.inputValue?.trim() === '') {
|
|
326
|
+
this.csRequestHistory.emit();
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
render() {
|
|
330
|
+
if (!this.state)
|
|
331
|
+
return null;
|
|
332
|
+
const isSelected = this.state.status === 'itemSelected';
|
|
333
|
+
return (index.h("div", { class: { 'core-selector-wrapper': true, 'is-disabled': !!this.config.disabled }, "aria-disabled": this.config.disabled ? 'true' : 'false', onKeyDown: (e) => this.handleKeyDown(e), onMouseMove: () => { this.isNavigatingWithKeyboard = false; }, onFocusin: this.onWrapperFocusIn, onFocusout: this.onWrapperFocusOut }, this.label && (index.h(AfLabel, { label: this.label, forId: `${this.componentId}-input`, description: this.labelDescription })), this.labelDescription && (index.h("div", { id: `${this.componentId}-description`, class: "visually-hidden" }, this.labelDescription)), this.state && this.state.status === 'loading' && index.h("div", { class: "loading-indicator" }, "Laddar..."), this.state && this.state.status === 'error' && index.h("div", { class: "error-message" }, this.state.message), this.state && ['searching', 'itemSelected', 'multiSelect'].includes(this.state.status) && (index.h("div", { class: "combobox-container" }, this.renderSearchContainer(), this.isFocusedInternal && !isSelected && this.renderSuggestionsList())), this.state && this.state.validation !== 'idle' && this.state.status !== 'itemSelected' && (index.h(afValidationMessage.AfValidationMessage, { id: `${this.componentId}-validation-message`, variant: this.state.validation === 'error' ? 'error' : 'success', role: this.state.validation === 'error' ? 'alert' : undefined, class: "selector-validation-message" }, this.state.message))));
|
|
334
|
+
}
|
|
335
|
+
renderSearchContainer() {
|
|
336
|
+
const isSelected = this.state.status === 'itemSelected';
|
|
337
|
+
const displayValue = isSelected ? (this.state.selectedItem?.label || '') : this.state.inputValue;
|
|
338
|
+
const isMulti = this.state.status === 'multiSelect';
|
|
339
|
+
const hasInput = displayValue.length > 0;
|
|
340
|
+
const hasTags = isMulti && this.state.selectedItems.length > 0;
|
|
341
|
+
const hasSuggestions = this.state && (this.state.suggestions.length > 0 || shouldShowManualInput(this.state, this.config.requireSelection));
|
|
342
|
+
const activeDescendantId = (this.activeIndex >= 0 && this.isNavigatingWithKeyboard)
|
|
343
|
+
? (this.activeIndex === this.state.suggestions.length
|
|
344
|
+
? `${this.componentId}-list-option-manual-input`
|
|
345
|
+
: `${this.componentId}-list-option-${this.activeIndex}`)
|
|
346
|
+
: undefined;
|
|
347
|
+
const descriptionId = `${this.componentId}-description`;
|
|
348
|
+
const validationMessageId = `${this.componentId}-validation-message`;
|
|
349
|
+
const hasDescription = !!this.labelDescription;
|
|
350
|
+
const hasError = this.state && this.state.validation === 'error' && this.state.message;
|
|
351
|
+
const describedByList = [];
|
|
352
|
+
if (hasDescription && displayValue.length === 0)
|
|
353
|
+
describedByList.push(descriptionId);
|
|
354
|
+
if (hasError)
|
|
355
|
+
describedByList.push(validationMessageId);
|
|
356
|
+
const ariaDescribedBy = describedByList.length > 0 ? describedByList.join(' ') : undefined;
|
|
357
|
+
return (index.h("div", { class: {
|
|
358
|
+
'search-container': true,
|
|
359
|
+
'is-inactive-selected': isSelected,
|
|
360
|
+
'multi-search-container': isMulti,
|
|
361
|
+
'has-tags': hasTags,
|
|
362
|
+
'has-validation-error': this.state?.validation === 'error',
|
|
363
|
+
'has-positive-validation': !isSelected && this.state?.validation === 'success',
|
|
364
|
+
}, onClick: () => {
|
|
365
|
+
if (this.config.disabled)
|
|
366
|
+
return;
|
|
367
|
+
if (isSelected) {
|
|
368
|
+
this.csEditSelection.emit();
|
|
369
|
+
}
|
|
370
|
+
else if (this.state.inputValue.trim() === '') {
|
|
371
|
+
this.csRequestHistory.emit();
|
|
372
|
+
}
|
|
373
|
+
} }, isMulti && this.state.selectedItems.length > 0 && (index.h("div", { class: "selected-tags-wrapper" }, this.state.selectedItems.map((item) => (index.h(AfTag, { key: item.id, text: item.label, breakWords: true, onRemove: () => {
|
|
374
|
+
this.shouldFocusAfterRender = true;
|
|
375
|
+
this.csRemoveItem.emit(item);
|
|
376
|
+
} }))))), index.h("div", { class: "input-controls-wrapper" }, index.h(AfIcon, { name: "search", class: {
|
|
377
|
+
'search-icon-container': true,
|
|
378
|
+
'selector-search-icon': true,
|
|
379
|
+
'is-hidden': !this.config.showSearchIcon || hasInput || hasTags,
|
|
380
|
+
} }), index.h("div", { class: { 'input-area': true, 'has-value': !this.config.showSearchIcon || hasInput || hasTags } }, isSelected && (index.h("span", { class: "selected-text-in-box" }, displayValue)), index.h("input", { class: {
|
|
381
|
+
'selector-input-field': true,
|
|
382
|
+
'visually-hidden-selected': isSelected
|
|
383
|
+
}, ref: (el) => this.inputRef = el, id: `${this.componentId}-input`, type: "text", placeholder: this.config.placeholder, value: displayValue, onInput: (e) => {
|
|
384
|
+
if (this.config.disabled)
|
|
385
|
+
return;
|
|
386
|
+
this.isNavigatingWithKeyboard = false;
|
|
387
|
+
this.csInput.emit(e.target.value);
|
|
388
|
+
}, autocomplete: "off", role: "combobox", "aria-label": this.label, "aria-autocomplete": "list", "aria-haspopup": "listbox", "aria-expanded": !isSelected && hasSuggestions && this.isNavigatingWithKeyboard ? 'true' : 'false', "aria-controls": !isSelected && hasSuggestions && this.isNavigatingWithKeyboard ? `${this.componentId}-listbox` : undefined, "aria-activedescendant": activeDescendantId, "aria-invalid": hasError ? 'true' : 'false', "aria-describedby": ariaDescribedBy, readOnly: isSelected, disabled: !!this.config.disabled })), index.h("button", { type: "button", class: { 'clear-button': true, 'is-visible': hasInput || isSelected }, tabIndex: hasInput || isSelected ? 0 : -1, disabled: !!this.config.disabled, "aria-label": "Rensa inmatad text", onMouseDown: (e) => e.preventDefault(), onClick: () => {
|
|
389
|
+
if (this.config.disabled)
|
|
390
|
+
return;
|
|
391
|
+
this.csInput.emit('');
|
|
392
|
+
this.shouldFocusAfterRender = true;
|
|
393
|
+
this.csClear.emit();
|
|
394
|
+
this.csRequestHistory.emit();
|
|
395
|
+
} }, index.h(AfIcon, { name: "x" })))));
|
|
396
|
+
}
|
|
397
|
+
renderSuggestionsList() {
|
|
398
|
+
if (this.state.status === 'itemSelected')
|
|
399
|
+
return null;
|
|
400
|
+
const hasSearchInput = Boolean(this.state.inputValue && this.state.inputValue.trim().length > 0);
|
|
401
|
+
const showManualInput = shouldShowManualInput(this.state, this.config.requireSelection);
|
|
402
|
+
const hasSuggestions = Boolean(this.state.suggestions && this.state.suggestions.length > 0);
|
|
403
|
+
const noResults = hasSearchInput && !hasSuggestions && !showManualInput;
|
|
404
|
+
if (!hasSuggestions && !showManualInput && !noResults) {
|
|
405
|
+
return null;
|
|
406
|
+
}
|
|
407
|
+
const listHeader = this.state.listHeader || this.config.listHeader;
|
|
408
|
+
const showHistoryHeader = this.state.showHistoryHeader || (this.state.isHistoryView && this.config.showHistoryHeader);
|
|
409
|
+
return (index.h("div", { class: "suggestions-box-container" }, index.h("div", { class: "suggestions-box", ref: (el) => (this.listRef = el), onScroll: (e) => this.handleScroll(e) }, (listHeader || showHistoryHeader) && (index.h("div", { class: "list-header-container" }, index.h("slot", { name: "suggestions-overlay" }), listHeader && (index.h("div", { class: "list-header" }, index.h("span", null, listHeader))), showHistoryHeader && (index.h("div", { class: "list-header history-header" }, index.h("span", null, "Din privata historik"), " - ", index.h("button", { type: "button", class: "history-clear-link", "aria-label": "Rensa historik", disabled: !!this.config.disabled, onMouseDown: (e) => e.preventDefault(), onClick: () => {
|
|
410
|
+
if (!this.config.disabled)
|
|
411
|
+
this.csClearHistory.emit();
|
|
412
|
+
} }, "Rensa"))))), !listHeader && !showHistoryHeader && index.h("slot", { name: "suggestions-overlay" }), index.h("div", { id: `${this.componentId}-listbox`, role: "listbox" }, noResults && (index.h("div", { class: "suggestion-item no-results" }, "Inga resultat matchade din s\u00F6kning")), !noResults && this.state.suggestions.map((item, index$1) => (index.h("div", { key: item.id || index$1, role: "option", id: `${this.componentId}-list-option-${index$1}`, "aria-selected": !!item.isSelected, "aria-current": index$1 === this.activeIndex ? 'true' : 'false', class: {
|
|
413
|
+
'suggestion-item': true,
|
|
414
|
+
'active-suggestion': index$1 === this.activeIndex,
|
|
415
|
+
'is-selected': !!item.isSelected,
|
|
416
|
+
'is-keyboard-focus': index$1 === this.activeIndex && this.isNavigatingWithKeyboard
|
|
417
|
+
}, onMouseDown: (e) => {
|
|
418
|
+
e.preventDefault();
|
|
419
|
+
if (this.config.disabled)
|
|
420
|
+
return;
|
|
421
|
+
this.shouldFocusAfterRender = true;
|
|
422
|
+
if (item.isSelected) {
|
|
423
|
+
this.csRemoveItem.emit(item);
|
|
424
|
+
}
|
|
425
|
+
else {
|
|
426
|
+
this.csSelect.emit(item);
|
|
427
|
+
}
|
|
428
|
+
if (this.config.enableMultiple) {
|
|
429
|
+
// Trigger history refresh if we are in multi-mode
|
|
430
|
+
clearTimeout(this.historyRequestTimer);
|
|
431
|
+
this.historyRequestTimer = setTimeout(() => {
|
|
432
|
+
this.csRequestHistory.emit();
|
|
433
|
+
this.historyRequestTimer = undefined;
|
|
434
|
+
}, 50);
|
|
435
|
+
}
|
|
436
|
+
}, onMouseEnter: () => {
|
|
437
|
+
if (this.config.disabled)
|
|
438
|
+
return;
|
|
439
|
+
if (!item.isSelected) {
|
|
440
|
+
this.activeIndex = index$1;
|
|
441
|
+
this.isNavigatingWithKeyboard = false;
|
|
442
|
+
}
|
|
443
|
+
} }, index.h(AfIcon, { name: "check", class: "selection-indicator-icon" }), item.displaySegments ? (index.h("span", null, item.displaySegments.map((segment, segmentIndex) => (index.h("span", { key: segmentIndex, class: {
|
|
444
|
+
'match-highlight': !!segment.isMatch,
|
|
445
|
+
'metadata-dimmed': !!segment.isMetadata
|
|
446
|
+
} }, segment.text))))) : (index.h("span", null, item.label))))), !noResults && shouldShowManualInput(this.state, this.config.requireSelection) && (index.h("div", { role: "option", id: `${this.componentId}-list-option-manual-input`, class: {
|
|
447
|
+
'suggestion-item': true,
|
|
448
|
+
'active-suggestion': this.activeIndex === this.state.suggestions.length,
|
|
449
|
+
'is-keyboard-focus': this.activeIndex === this.state.suggestions.length && this.isNavigatingWithKeyboard
|
|
450
|
+
}, onMouseDown: (e) => {
|
|
451
|
+
e.preventDefault();
|
|
452
|
+
if (!this.config.disabled)
|
|
453
|
+
this.handleManualSelect();
|
|
454
|
+
}, onMouseEnter: () => {
|
|
455
|
+
if (this.config.disabled)
|
|
456
|
+
return;
|
|
457
|
+
this.activeIndex = this.state.suggestions.length;
|
|
458
|
+
this.isNavigatingWithKeyboard = false;
|
|
459
|
+
} }, index.h("span", null, "Anv\u00E4nd \"", index.h("strong", null, this.state.inputValue.trim()), "\"")))))));
|
|
460
|
+
}
|
|
461
|
+
static get delegatesFocus() { return true; }
|
|
462
|
+
static get watchers() { return {
|
|
463
|
+
"afFocused": [{
|
|
464
|
+
"handleAfFocusedChange": 0
|
|
465
|
+
}],
|
|
466
|
+
"config": [{
|
|
467
|
+
"handleConfigChange": 0
|
|
468
|
+
}],
|
|
469
|
+
"state": [{
|
|
470
|
+
"handleStateChange": 0
|
|
471
|
+
}]
|
|
472
|
+
}; }
|
|
473
|
+
};
|
|
474
|
+
CoreSelector.style = coreSelectorCss();
|
|
475
|
+
|
|
476
|
+
exports.core_selector = CoreSelector;
|