@arbetsformedlingen/yrkesvaljaren 2.0.12 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/README.md +52 -21
  2. package/dist/cjs/{af-validation-message-Cy89nVEv.js → af-validation-message-BdR9X_qh.js} +1 -1
  3. package/dist/cjs/core-selector.cjs.entry.js +342 -23
  4. package/dist/cjs/digi-service-job-selector.cjs.entry.js +352 -61
  5. package/dist/cjs/{index-hZgOvC17.js → index-DMQDFAL7.js} +0 -22
  6. package/dist/cjs/index.cjs.js +4 -7
  7. package/dist/cjs/loader.cjs.js +2 -2
  8. package/dist/{esm/fuse-BPnhMTul.js → cjs/types-DdzCbiye.js} +965 -1
  9. package/dist/cjs/yrkesvaljaren.cjs.js +2 -2
  10. package/dist/collection/collection-manifest.json +0 -1
  11. package/dist/collection/components/core-selector/core-selector.css +70 -49
  12. package/dist/collection/components/core-selector/core-selector.js +309 -14
  13. package/dist/collection/components/design-compat/af-icon.js +8 -7
  14. package/dist/collection/components/job-selector/job-selector-controller.js +13 -3
  15. package/dist/collection/components/job-selector/job-selector.css +188 -34
  16. package/dist/collection/components/job-selector/job-selector.js +199 -10
  17. package/dist/components/core-selector2.js +1 -1
  18. package/dist/components/digi-service-job-selector.js +1 -1
  19. package/dist/components/index.js +1 -1
  20. package/dist/components/types.js +1 -1
  21. package/dist/esm/{af-validation-message-BgoGzzBf.js → af-validation-message-DMoOu-0k.js} +1 -1
  22. package/dist/esm/core-selector.entry.js +342 -23
  23. package/dist/esm/digi-service-job-selector.entry.js +310 -19
  24. package/dist/esm/{index-HNd02eQb.js → index-vJ-tamti.js} +1 -22
  25. package/dist/esm/index.js +2 -4
  26. package/dist/esm/loader.js +3 -3
  27. package/dist/{cjs/fuse-BTLNKxuL.js → esm/types-DVos4HHS.js} +948 -2
  28. package/dist/esm/yrkesvaljaren.js +3 -3
  29. package/dist/types/components/core-selector/core-selector.d.ts +68 -0
  30. package/dist/types/components/job-selector/job-selector-controller.d.ts +5 -0
  31. package/dist/types/components/job-selector/job-selector.d.ts +21 -3
  32. package/dist/types/components/job-selector/types.d.ts +12 -0
  33. package/dist/types/components.d.ts +20 -99
  34. package/dist/types/index.d.ts +1 -1
  35. package/dist/vendor/taxonomy-core/af-data-layer.d.ts +16 -0
  36. package/dist/vendor/taxonomy-core/af-data-layer.js +24 -0
  37. package/dist/vendor/taxonomy-core/index.d.ts +1 -1
  38. package/dist/vendor/taxonomy-core/index.js +1 -1
  39. package/dist/vendor/taxonomy-core/pii-sanitizer.d.ts +25 -0
  40. package/dist/vendor/taxonomy-core/pii-sanitizer.js +137 -0
  41. package/dist/vendor/taxonomy-core/selector-navigation.d.ts +9 -1
  42. package/dist/vendor/taxonomy-core/selector-navigation.js +28 -1
  43. package/dist/vendor/taxonomy-core/selector-types.d.ts +12 -0
  44. package/dist/yrkesvaljaren/index.esm.js +1 -1
  45. package/dist/yrkesvaljaren/p-0f19a308.entry.js +1 -0
  46. package/dist/yrkesvaljaren/{p-BUviBbwX.js → p-DHK95AvZ.js} +1 -1
  47. package/dist/yrkesvaljaren/p-DVos4HHS.js +1 -0
  48. package/dist/yrkesvaljaren/p-b81496c8.entry.js +1 -0
  49. package/dist/yrkesvaljaren/p-vJ-tamti.js +3 -0
  50. package/dist/yrkesvaljaren/yrkesvaljaren.esm.js +1 -1
  51. package/package.json +12 -10
  52. package/dist/cjs/geo-valjaren.cjs.entry.js +0 -14910
  53. package/dist/cjs/job-selector-demo.cjs.entry.js +0 -690
  54. package/dist/cjs/neobrutal-search.cjs.entry.js +0 -171
  55. package/dist/cjs/search.engine-D4cpbVzd.js +0 -504
  56. package/dist/cjs/taxonomy-registry-Dzt0SPzT.js +0 -454
  57. package/dist/cjs/types-CtHBl6Ra.js +0 -14
  58. package/dist/collection/components/geovaljaren/geovaljaren.css +0 -21
  59. package/dist/collection/components/geovaljaren/geovaljaren.js +0 -304
  60. package/dist/collection/components/geovaljaren/logic/adapter.utils.js +0 -20
  61. package/dist/collection/components/geovaljaren/logic/data.utils.js +0 -12
  62. package/dist/collection/components/geovaljaren/logic/history-service.js +0 -25
  63. package/dist/collection/components/geovaljaren/logic/search.engine.js +0 -28
  64. package/dist/collection/verkstad/verkstad.js +0 -408
  65. package/dist/components/fuse.js +0 -1
  66. package/dist/components/geo-valjaren.d.ts +0 -11
  67. package/dist/components/geo-valjaren.js +0 -1
  68. package/dist/components/job-selector-demo.d.ts +0 -11
  69. package/dist/components/job-selector-demo.js +0 -1
  70. package/dist/components/job-selector.js +0 -1
  71. package/dist/components/neobrutal-search.d.ts +0 -11
  72. package/dist/components/neobrutal-search.js +0 -1
  73. package/dist/components/search.engine.js +0 -1
  74. package/dist/esm/geo-valjaren.entry.js +0 -14908
  75. package/dist/esm/job-selector-demo.entry.js +0 -688
  76. package/dist/esm/neobrutal-search.entry.js +0 -169
  77. package/dist/esm/search.engine-BaWUTc3r.js +0 -493
  78. package/dist/esm/taxonomy-registry-C-pSh51L.js +0 -449
  79. package/dist/esm/types-DHUftoZJ.js +0 -12
  80. package/dist/types/components/geovaljaren/geovaljaren.d.ts +0 -24
  81. package/dist/types/components/geovaljaren/logic/adapter.utils.d.ts +0 -7
  82. package/dist/types/components/geovaljaren/logic/data.utils.d.ts +0 -7
  83. package/dist/types/components/geovaljaren/logic/history-service.d.ts +0 -6
  84. package/dist/types/components/geovaljaren/logic/search.engine.d.ts +0 -7
  85. package/dist/types/components/job-selector-demo/job-selector-demo.d.ts +0 -65
  86. package/dist/types/components/neobrutal-search/neobrutal-search.d.ts +0 -18
  87. package/dist/types/verkstad/verkstad.d.ts +0 -1
  88. package/dist/types/vitest-globals.d.ts +0 -1
  89. package/dist/yrkesvaljaren/p-5c3a5308.entry.js +0 -1
  90. package/dist/yrkesvaljaren/p-9ecd5177.entry.js +0 -1
  91. package/dist/yrkesvaljaren/p-BPnhMTul.js +0 -1
  92. package/dist/yrkesvaljaren/p-C-pSh51L.js +0 -1
  93. package/dist/yrkesvaljaren/p-CjMoDiZD.js +0 -1
  94. package/dist/yrkesvaljaren/p-DHUftoZJ.js +0 -1
  95. package/dist/yrkesvaljaren/p-HNd02eQb.js +0 -3
  96. package/dist/yrkesvaljaren/p-b6130085.entry.js +0 -1
  97. package/dist/yrkesvaljaren/p-dbbea724.entry.js +0 -1
  98. package/dist/yrkesvaljaren/p-df3fa43b.entry.js +0 -1
@@ -1,171 +0,0 @@
1
- 'use strict';
2
-
3
- var index = require('./index-hZgOvC17.js');
4
- var search_engine = require('./search.engine-D4cpbVzd.js');
5
- var taxonomyRegistry = require('./taxonomy-registry-Dzt0SPzT.js');
6
- require('./fuse-BTLNKxuL.js');
7
-
8
- const neobrutalSearchCss = () => `:host{display:block;font-family:'Courier New', Courier, monospace;--bg-color:#fff4e6;--primary:#ff00ff;--secondary:#00ffff;--text:#000;--border:4px solid #000;--shadow:8px 8px 0px #000}.neobrutal-container{background-color:var(--bg-color);padding:40px;border:var(--border);box-shadow:var(--shadow);max-width:600px;margin:20px auto;min-height:600px;position:relative;box-sizing:border-box;display:flex;flex-direction:column;transition:min-height 0.6s cubic-bezier(0.23, 1, 0.32, 1)}.flip-container{perspective:1000px;width:100%}.flipper{transition:0.6s;transform-style:preserve-3d;position:relative;width:100%}.flip-container.flipped .flipper{transform:rotateY(180deg)}.front,.back{backface-visibility:hidden;top:0;left:0;width:100%}.front{z-index:2;transform:rotateY(0deg);position:relative}.flip-container.flipped .front{position:absolute}.back{transform:rotateY(180deg);box-sizing:border-box;position:absolute}.flip-container.flipped .back{position:relative;z-index:3}h1.glitch{font-size:3rem;font-weight:900;text-transform:uppercase;margin-bottom:30px;background-color:var(--primary);color:var(--text);display:inline-block;padding:5px 15px;border:var(--border);box-shadow:4px 4px 0px #000}.input-wrapper{margin-bottom:50px;padding-right:10px;padding-bottom:10px}input{width:100%;padding:20px;font-size:1.5rem;font-family:inherit;font-weight:bold;border:var(--border);background:white;outline:none;text-transform:uppercase;box-shadow:8px 8px 0px #000;transition:all 0.1s;box-sizing:border-box}.status{font-size:1.5rem;font-weight:bold;background-color:yellow;border:var(--border);padding:10px;margin-bottom:20px;text-align:center}.fire-status{font-size:1.8rem;font-weight:900;background-color:#ff4500;color:#fff;border:var(--border);padding:15px;margin-bottom:15px;text-align:center;position:relative;box-shadow:10px 10px 0px #000;animation:fire-flicker 0.2s infinite alternate}@keyframes fire-flicker{0%{transform:scale(1) rotate(-0.5deg)}100%{transform:scale(1.01) rotate(0.5deg)}}.fire-emoji{font-size:2rem;display:inline-block;margin:0 10px}.raw-data-container{margin-top:10px;margin-bottom:30px;background:#000;border:2px solid #fff;padding:15px;text-align:left;box-shadow:5px 5px 0px #ff00ff}.raw-label{font-size:0.8rem;color:#0f0;margin-bottom:5px;font-weight:bold}.raw-output{font-family:'Courier New', Courier, monospace;font-size:0.8rem;color:#0f0;margin:0;white-space:pre-wrap;word-break:break-all}.flip-btn{position:absolute;top:10px;right:10px;background:#000;color:#fff;border:2px solid #fff;padding:5px 10px;font-weight:bold;cursor:pointer;font-family:'Courier New', Courier, monospace;z-index:10}.flip-btn:hover{background:#ff00ff;color:#000}.source-view{background:#0d1117 !important;color:#e6edf3 !important;border-color:#30363d !important;padding:30px !important;display:flex;flex-direction:column}.source-header{font-size:2rem;color:#ff00ff;margin-bottom:20px;text-shadow:2px 2px 0 #000}.code-scroll-container{flex:1;background:#161b22;border:1px solid #30363d;border-radius:6px;padding:10px}.code-block{margin-bottom:25px;text-align:left}.code-label{background:#238636;color:#fff;display:inline-block;padding:4px 8px;font-weight:bold;font-size:0.8rem;border-radius:4px 4px 0 0}pre{background:#0d1117;margin:0;padding:10px;border:1px solid #30363d}pre code{font-family:'Courier New', Courier, monospace;font-size:0.85rem;line-height:1.4;background:transparent !important;color:#e6edf3}.result-card{background-color:white;border:var(--border);box-shadow:5px 5px 0px #000;padding:15px;transition:all 0.1s;cursor:pointer}.result-card:hover{transform:translate(2px, 2px);box-shadow:3px 3px 0px #000;background-color:var(--secondary)}.card-header{display:flex;justify-content:space-between;margin-bottom:10px;border-bottom:2px solid #000;padding-bottom:5px}.type-badge{background-color:yellow;padding:2px 8px;font-weight:bold;border:2px solid #000}.score-badge{background-color:lime;padding:2px 8px;font-weight:bold;border:2px solid #000}.label{font-size:1.2rem;font-weight:800}`;
9
-
10
- // VIKTIGT: Dessa strängar representerar den FAKTISKA källkoden som användaren ser.
11
- const SOURCE_CODE_JS = `import { Component, h, State, Element } from '@stencil/core';
12
- import { TaxonomySearchEngine } from '../job-selector/logic/search.engine';
13
- import { getRegisteredTaxonomy } from '../job-selector/taxonomy-registry';
14
-
15
- @Component({ tag: 'neobrutal-search', styleUrl: 'neobrutal-search.css', shadow: true })
16
- export class NeobrutalSearch {
17
- @Element() el!: HTMLElement;
18
- @State() engine: TaxonomySearchEngine | null = null;
19
- @State() results: any[] = [];
20
- @State() inputValue: string = '';
21
- @State() isLoading: boolean = true;
22
- @State() error: string = '';
23
- @State() selectedItem: any | null = null;
24
- @State() isFlipped: boolean = false;
25
-
26
- async componentWillLoad() {
27
- try {
28
- const taxonomyData = getRegisteredTaxonomy();
29
- this.engine = new TaxonomySearchEngine(taxonomyData);
30
- this.isLoading = false;
31
- } catch (err) {
32
- this.error = 'DATA FAILURE';
33
- this.isLoading = false;
34
- }
35
- }
36
-
37
- componentDidUpdate() {
38
- if (this.isFlipped) this.highlightCode();
39
- }
40
-
41
- highlightCode() {
42
- const hljs = (window as any).hljs;
43
- if (hljs && this.el?.shadowRoot) {
44
- const blocks = this.el.shadowRoot.querySelectorAll('pre code');
45
- blocks.forEach((block) => hljs.highlightElement(block));
46
- }
47
- }
48
-
49
- handleInput(event: Event) {
50
- const query = (event.target as HTMLInputElement).value;
51
- this.inputValue = query;
52
- this.selectedItem = null;
53
-
54
- if (!this.engine || query.length < 2) {
55
- this.results = [];
56
- return;
57
- }
58
-
59
- this.results = this.engine.search(query, 3);
60
- }
61
-
62
- handleSelect(item: any) {
63
- this.selectedItem = item;
64
- this.results = [];
65
- this.inputValue = item.label;
66
- }
67
-
68
- toggleFlip() {
69
- this.isFlipped = !this.isFlipped;
70
- if (this.isFlipped) setTimeout(() => this.highlightCode(), 100);
71
- }
72
-
73
- render() {
74
- return (
75
- <div class="neobrutal-container">
76
- {/* ... UI structure ... */}
77
- </div>
78
- );
79
- }
80
- }`;
81
- const SOURCE_CODE_CSS = `.neobrutal-container {
82
- background-color: #fff4e6;
83
- padding: 40px;
84
- border: 4px solid #000;
85
- box-shadow: 8px 8px 0px #000;
86
- font-family: 'Courier New', Courier, monospace;
87
- }
88
-
89
- .fire-status {
90
- background-color: #ff4500;
91
- animation: fire-flicker 0.2s infinite alternate;
92
- }
93
-
94
- .raw-data-container {
95
- background: #000;
96
- color: #0f0;
97
- padding: 15px;
98
- box-shadow: 5px 5px 0px #ff00ff;
99
- }`;
100
- const NeobrutalSearch = class {
101
- constructor(hostRef) {
102
- index.registerInstance(this, hostRef);
103
- }
104
- get el() { return index.getElement(this); }
105
- engine = null;
106
- results = [];
107
- inputValue = '';
108
- isLoading = true;
109
- error = '';
110
- selectedItem = null;
111
- isFlipped = false;
112
- async componentWillLoad() {
113
- try {
114
- console.log('[NeobrutalSearch] Initializing...');
115
- const taxonomyData = taxonomyRegistry.getRegisteredTaxonomy();
116
- this.engine = new search_engine.TaxonomySearchEngine(taxonomyData);
117
- this.isLoading = false;
118
- }
119
- catch (err) {
120
- console.error('[NeobrutalSearch] Init failed:', err);
121
- this.error = 'DATA FAILURE';
122
- this.isLoading = false;
123
- }
124
- }
125
- componentDidUpdate() {
126
- if (this.isFlipped) {
127
- this.highlightCode();
128
- }
129
- }
130
- highlightCode() {
131
- const hljs = window.hljs;
132
- if (hljs && this.el?.shadowRoot) {
133
- const blocks = this.el.shadowRoot.querySelectorAll('pre code');
134
- blocks.forEach((block) => {
135
- hljs.highlightElement(block);
136
- });
137
- }
138
- }
139
- handleInput(event) {
140
- const query = event.target.value;
141
- this.inputValue = query;
142
- this.selectedItem = null;
143
- if (!this.engine || query.length < 2) {
144
- this.results = [];
145
- return;
146
- }
147
- const searchResults = this.engine.search(query, 3);
148
- this.results = searchResults;
149
- }
150
- handleSelect(item) {
151
- this.selectedItem = item;
152
- this.results = [];
153
- this.inputValue = item.label;
154
- }
155
- toggleFlip() {
156
- this.isFlipped = !this.isFlipped;
157
- if (this.isFlipped) {
158
- setTimeout(() => this.highlightCode(), 100);
159
- }
160
- }
161
- render() {
162
- return (index.h("div", { key: '2326ca3128950ef2b22c6238b97f4db57df81a13', class: `flip-container ${this.isFlipped ? 'flipped' : ''}` }, index.h("link", { key: '37c748c29be0e59cad0a14a20ff8399ec5248817', rel: "stylesheet", href: "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/styles/atom-one-dark.min.css" }), index.h("div", { key: '66add224c867540d1078c92c76893ebf50387320', class: "flipper" }, index.h("div", { key: '27d18fb961d80585530aff7029144fd946b1ccdd', class: "front neobrutal-container" }, index.h("button", { key: '1aabe2fbc948cfb76526dff29f620248a1325ec5', class: "flip-btn", onClick: () => this.toggleFlip() }, "FLIP_ME \uD83D\uDD04"), index.h("h1", { key: 'f5410f277dc43bfe1b89281242ff521f8d08742f', class: "glitch", "data-text": "YRKE_S\u00D6K" }, "YRKE_S\u00D6K"), index.h("div", { key: '9170d0e78c5f903b19f955a1804a9bdca49cf081', class: "input-wrapper" }, index.h("input", { key: '9641844ab0ab97256d05dc9e1c633c7700119a67', type: "text", placeholder: "VAD VILL DU BLI?", onInput: (e) => this.handleInput(e), value: this.inputValue, disabled: this.isLoading })), this.isLoading && index.h("div", { key: 'd231d5e3b3a86613aaec89230d6fc8fd2e55ada0', class: "status" }, "LOADING_DATA..."), this.error && index.h("div", { key: '25c5761b8e6de67ae47d2c08f6c15ddfd2504833', class: "status error" }, this.error), this.selectedItem && (index.h("div", { key: 'a60af6d7dde8b25b031d43e05cb190d9d31cf37e' }, index.h("div", { key: 'b667fb72c949820edd1a073ba31ebdd4df93d54a', class: "fire-status" }, index.h("span", { key: 'b952ad20cc645909570dc6c9a84100d61d6e2d78', class: "fire-emoji" }, "\uD83D\uDD25 \uD83D\uDD25 \uD83D\uDD25"), "HETT VAL: ", this.selectedItem.label.toUpperCase(), "!", index.h("span", { key: '8f1848507e40b9d2441d7613a82ed0b9afb2cbe7', class: "fire-emoji" }, "\uD83D\uDD25 \uD83D\uDD25 \uD83D\uDD25")), index.h("div", { key: '82a9f8eaaa1a88569be1541252bb307b749a80eb', class: "raw-data-container" }, index.h("div", { key: 'cd7d8fa66b4622a0e86a510d03ebe9c4303b636a', class: "raw-label" }, "RAW_JSON_DATA:"), index.h("pre", { key: 'e4999d974d34c88bbdc5585b93bfe59b9948808f', class: "raw-output" }, JSON.stringify(this.selectedItem, null, 2))))), index.h("div", { key: '2914c9e3d999d1cabb2ce5c7dcb46b7fa2409d85', class: "results-container" }, this.results.map(result => {
163
- const metadata = result?.metadata || {};
164
- const original = metadata?.originalResult;
165
- return (index.h("div", { class: "result-card", onClick: () => this.handleSelect(result) }, index.h("div", { class: "card-header" }, index.h("span", { class: "type-badge" }, original?.category === 'job-title' ? 'YRK' : 'GRP'), index.h("span", { class: "score-badge" }, "SCR: ", Math.round((metadata?.score || 0) * 10))), index.h("div", { class: "card-body" }, index.h("div", { class: "label" }, result.displayLabel || result.label))));
166
- }))), index.h("div", { key: '8031a4fb997e85aacd76a460eaee571306e285d4', class: "back neobrutal-container source-view" }, index.h("button", { key: '955937496ec6474313f9a15559e6828197e97ce6', class: "flip-btn", onClick: () => this.toggleFlip() }, "BACK \uD83D\uDD19"), index.h("h1", { key: 'd0258b6959b68fa86cdd35fd2dac54c6ea7912ea', class: "source-header" }, "FULL_SOURCE_CODE"), index.h("p", { key: 'a1d6b33dcc033b3bcd2c4bf4ec88c8ca99e93281', class: "source-desc" }, "Exakt den koden du ser, inga fejk snippets h\u00E4r inte:"), index.h("div", { key: 'b594d873613c455ceab357b3c525f4019d1a72af', class: "code-scroll-container" }, index.h("div", { key: '1b0a9d936ac1f3f256ad6aa30070e4ea6910171a', class: "code-block" }, index.h("div", { key: 'c6620f3e982cfffc09bff2c46ab7f3c01e6bfe63', class: "code-label" }, "neobrutal-search.tsx"), index.h("pre", { key: 'dd34c079acf518f4af6817ffc0d7ec4c9f8b95de' }, index.h("code", { key: '258c896f87ad00d8ff79e07782b16f2c673e2ea9', class: "language-typescript" }, SOURCE_CODE_JS))), index.h("div", { key: '6764eb04625fbf82149314fff70b447bca3afbd1', class: "code-block" }, index.h("div", { key: '0f9635180c41e03245b686ec8c440cdb347b160e', class: "code-label" }, "neobrutal-search.css"), index.h("pre", { key: '4822b0436c8c3440a1f6ac67445a05a55a6ad3d9' }, index.h("code", { key: '5c1965bf6757ad2aa67f378cc225f05071f05ea6', class: "language-css" }, SOURCE_CODE_CSS))))))));
167
- }
168
- };
169
- NeobrutalSearch.style = neobrutalSearchCss();
170
-
171
- exports.neobrutal_search = NeobrutalSearch;
@@ -1,504 +0,0 @@
1
- 'use strict';
2
-
3
- var fuse = require('./fuse-BTLNKxuL.js');
4
- var taxonomyRegistry = require('./taxonomy-registry-Dzt0SPzT.js');
5
-
6
- // Minimum number of characters required to trigger search
7
- const MIN_INPUT_LENGTH = 1;
8
- // Debounce time for search input (ms)
9
- const DEBOUNCE_TIME = 100; // ms - Återställt till 250 baserat på sok-box.tsx initialt
10
- // Default maximum number of results to display
11
- const MAX_RESULTS = 20;
12
- // Configuration for Fuse.js
13
- const FUSE_OPTIONS = {
14
- keys: ['preferred_label'], // Ändrat från 'label' till 'preferred_label' för att matcha datastrukturen
15
- includeScore: true,
16
- ignoreDiacritics: true, // Lägg till för att matcha t.ex. vard -> vård
17
- ignoreFieldNorm: true, // Lägg till för att ignorera fältlängd vid poängsättning
18
- threshold: 0.6, // Behåll 0.6
19
- minMatchCharLength: MIN_INPUT_LENGTH, // Refererar till konstant ovan
20
- ignoreLocation: true, // Match anywhere in the string
21
- distance: 100, // Allow matches further apart
22
- };
23
- // UI Text Strings
24
- const PLACEHOLDER_TEXT = "T.ex. målare, florist, kock";
25
-
26
- const LabelFormatter = {
27
- format: (label, query, occupationLabel) => {
28
- // 1. Highlight the main label based on query
29
- const labelSegments = highlightText(label, query);
30
- // 2. Append occupation label if it exists (the "metadata" part)
31
- if (occupationLabel) {
32
- return [
33
- ...labelSegments,
34
- { text: ' ', isMatch: false },
35
- { text: `(${occupationLabel})`, isMetadata: true }
36
- ];
37
- }
38
- return labelSegments;
39
- }
40
- };
41
- function calculateEditDistance$1(a, b) {
42
- const m = a.length;
43
- const n = b.length;
44
- const dp = Array.from({ length: m + 1 }, () => new Array(n + 1).fill(0));
45
- for (let i = 0; i <= m; i++)
46
- dp[i][0] = i;
47
- for (let j = 0; j <= n; j++)
48
- dp[0][j] = j;
49
- for (let i = 1; i <= m; i++) {
50
- for (let j = 1; j <= n; j++) {
51
- dp[i][j] = a[i - 1] === b[j - 1]
52
- ? dp[i - 1][j - 1]
53
- : 1 + Math.min(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1]);
54
- }
55
- }
56
- return dp[m][n];
57
- }
58
- function findBestFuzzySubstring$1(text, qToken) {
59
- const lowerText = text.toLowerCase();
60
- const targetLen = qToken.length;
61
- let bestDist = 99;
62
- let bestStart = -1;
63
- let bestLen = 0;
64
- const minLen = Math.max(3, targetLen - 2);
65
- const maxLen = Math.min(lowerText.length, targetLen + 2);
66
- for (let start = 0; start <= lowerText.length - minLen; start++) {
67
- for (let len = minLen; len <= maxLen && start + len <= lowerText.length; len++) {
68
- const sub = lowerText.slice(start, start + len);
69
- const dist = calculateEditDistance$1(qToken, sub);
70
- if (dist < bestDist) {
71
- bestDist = dist;
72
- bestStart = start;
73
- bestLen = len;
74
- }
75
- }
76
- }
77
- const maxAllowedDist = Math.max(2, Math.floor(targetLen * 0.25));
78
- if (bestDist <= maxAllowedDist && bestStart !== -1) {
79
- return { start: bestStart, length: bestLen };
80
- }
81
- return null;
82
- }
83
- /**
84
- * Highlights matches in text based on query.
85
- * Supports multi-word queries.
86
- */
87
- function highlightText(text, query) {
88
- if (!text)
89
- return [];
90
- if (!query || query.trim().length === 0) {
91
- return [{ text, isMatch: false }];
92
- }
93
- const lowerText = text.toLowerCase();
94
- const tokens = query.toLowerCase().split(/\s+/).filter(t => t.length > 0);
95
- // Set of indices in the original text that should be highlighted
96
- const highlightedIndices = new Set();
97
- tokens.forEach(token => {
98
- let startIndex = 0;
99
- while ((startIndex = lowerText.indexOf(token, startIndex)) !== -1) {
100
- for (let i = 0; i < token.length; i++) {
101
- highlightedIndices.add(startIndex + i);
102
- }
103
- startIndex += token.length;
104
- }
105
- });
106
- if (highlightedIndices.size === 0) {
107
- // Fuzzy highlight fallback: Hitta bästa matchande delsträng i sammansatta ord eller felstavningar
108
- tokens.forEach(qToken => {
109
- const match = findBestFuzzySubstring$1(text, qToken);
110
- if (match) {
111
- for (let i = 0; i < match.length; i++) {
112
- highlightedIndices.add(match.start + i);
113
- }
114
- }
115
- });
116
- }
117
- if (highlightedIndices.size === 0) {
118
- return [{ text, isMatch: false }];
119
- }
120
- const segments = [];
121
- let currentSegmentText = '';
122
- let currentIsMatch = highlightedIndices.has(0);
123
- for (let i = 0; i < text.length; i++) {
124
- const isMatch = highlightedIndices.has(i);
125
- if (isMatch !== currentIsMatch) {
126
- // Push previous segment
127
- if (currentSegmentText.length > 0) {
128
- segments.push({ text: currentSegmentText, isMatch: currentIsMatch });
129
- }
130
- // Start new segment
131
- currentSegmentText = text[i];
132
- currentIsMatch = isMatch;
133
- }
134
- else {
135
- currentSegmentText += text[i];
136
- }
137
- }
138
- // Push the last segment
139
- if (currentSegmentText.length > 0) {
140
- segments.push({ text: currentSegmentText, isMatch: currentIsMatch });
141
- }
142
- return segments;
143
- }
144
-
145
- const MAX_WEAK_FUZZY_RESULTS = 3;
146
- const MIN_FUZZY_SCORE = 0.4;
147
- const MAX_FUZZY_SCORE = 0.84;
148
- {
149
- taxonomyRegistry.log.setLevel(taxonomyRegistry.log.levels.DEBUG); // Set log level to DEBUG for development/testing
150
- }
151
- const normalizeForComparison = (text) => {
152
- if (!text) {
153
- return '';
154
- }
155
- const normalized = text.toLowerCase().trim();
156
- return normalized;
157
- };
158
- function formatDisplayLabel(item) {
159
- if (item.occupation_name_preferred_label) {
160
- return `${item.preferred_label || ''} (${item.occupation_name_preferred_label})`;
161
- }
162
- return item.preferred_label || '';
163
- }
164
- /**
165
- * Job titles can appear once per related occupation, so the ID alone does not
166
- * identify a row. Compare ID and occupation, falling back to the raw label.
167
- */
168
- function isSameSearchResult(a, b) {
169
- if (a.id && b.id) {
170
- const occupationA = a.occupationId ?? a.occupation_name_id ?? '';
171
- const occupationB = b.occupationId ?? b.occupation_name_id ?? '';
172
- return a.id === b.id && occupationA === occupationB;
173
- }
174
- return a.rawLabel === b.rawLabel;
175
- }
176
- function sortResultsStrict(results) {
177
- return results.sort((a, b) => {
178
- const scoreA = a.score ?? 0;
179
- const scoreB = b.score ?? 0;
180
- if (scoreA !== scoreB) {
181
- return scoreB - scoreA;
182
- }
183
- const weightA = a.weight ?? 0;
184
- const weightB = b.weight ?? 0;
185
- if (weightA !== weightB) {
186
- return weightB - weightA;
187
- }
188
- return a.displayLabel.localeCompare(b.displayLabel, 'sv');
189
- });
190
- }
191
- function segmentsToHtml(segments) {
192
- return segments.map(seg => {
193
- if (seg.isMatch) {
194
- return `<strong>${seg.text}</strong>`;
195
- }
196
- if (seg.isMetadata) {
197
- return `<span class="occupation-variant-label">${seg.text}</span>`;
198
- }
199
- return seg.text;
200
- }).join('');
201
- }
202
- const styleParentheticalText = (text) => {
203
- if (!text)
204
- return '';
205
- return text.replace(/ (\([^)]+\))/g, ' <span class="occupation-variant-label">$1</span>');
206
- };
207
- function getDirectScore(normalizedLabel, normalizedQuery, searchTokens) {
208
- if (normalizedLabel === normalizedQuery) {
209
- return 1.0;
210
- }
211
- if (searchTokens.length > 1) {
212
- return searchTokens.every(token => normalizedLabel.includes(token)) ? 0.98 : null;
213
- }
214
- if (normalizedLabel.startsWith(normalizedQuery)) {
215
- return 0.99;
216
- }
217
- if (normalizedLabel.includes(normalizedQuery)) {
218
- return 0.95;
219
- }
220
- return null;
221
- }
222
- function calculateEditDistance(a, b) {
223
- const m = a.length;
224
- const n = b.length;
225
- const dp = Array.from({ length: m + 1 }, () => new Array(n + 1).fill(0));
226
- for (let i = 0; i <= m; i++)
227
- dp[i][0] = i;
228
- for (let j = 0; j <= n; j++)
229
- dp[0][j] = j;
230
- for (let i = 1; i <= m; i++) {
231
- for (let j = 1; j <= n; j++) {
232
- dp[i][j] = a[i - 1] === b[j - 1]
233
- ? dp[i - 1][j - 1]
234
- : 1 + Math.min(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1]);
235
- }
236
- }
237
- return dp[m][n];
238
- }
239
- function findBestFuzzySubstring(text, qToken) {
240
- const lowerText = text.toLowerCase();
241
- const targetLen = qToken.length;
242
- let bestDist = 99;
243
- const minLen = Math.max(3, targetLen - 2);
244
- const maxLen = Math.min(lowerText.length, targetLen + 2);
245
- for (let start = 0; start <= lowerText.length - minLen; start++) {
246
- for (let len = minLen; len <= maxLen && start + len <= lowerText.length; len++) {
247
- const sub = lowerText.slice(start, start + len);
248
- const dist = calculateEditDistance(qToken, sub);
249
- if (dist < bestDist) {
250
- bestDist = dist;
251
- }
252
- }
253
- }
254
- const maxAllowedDist = Math.max(2, Math.floor(targetLen * 0.25));
255
- return bestDist <= maxAllowedDist ? bestDist : null;
256
- }
257
- function isSingleWordOrCompoundRoot(query, label) {
258
- const normQ = query.toLowerCase().trim();
259
- const normL = label.toLowerCase().trim();
260
- if (normL.includes(' ')) {
261
- const dist = calculateEditDistance(normQ, normL);
262
- return dist <= Math.max(2, Math.floor(normQ.length * 0.25)) && Math.abs(normQ.length - normL.length) <= 2;
263
- }
264
- const subDist = findBestFuzzySubstring(normL, normQ);
265
- return subDist !== null;
266
- }
267
- // Canonical aliases (alternative/hidden labels from the taxonomy) only match
268
- // exactly; they never feed fuzzy search.
269
- function hasExactSearchAlias(item, normalizedQuery) {
270
- return (item.search_aliases ?? []).some((alias) => normalizeForComparison(alias) === normalizedQuery);
271
- }
272
- function createSearchResult(item, query, score) {
273
- const displayLabel = formatDisplayLabel(item);
274
- const displaySegments = LabelFormatter.format(item.preferred_label || '', query, item.occupation_name_preferred_label);
275
- return {
276
- id: item.id,
277
- type: item.type,
278
- preferred_label: item.preferred_label || '',
279
- rawLabel: item.preferred_label || '',
280
- displayLabel,
281
- highlightedLabel: segmentsToHtml(displaySegments),
282
- displaySegments,
283
- weight: item.weight ?? 0,
284
- score,
285
- occupationId: item.occupation_name_id,
286
- occupationLabel: item.occupation_name_preferred_label,
287
- ssyk_level_4_id: item.ssyk_level_4_id,
288
- ssyk_code_2012: item.ssyk_code_2012,
289
- };
290
- }
291
- function searchIdentity(item) {
292
- if (item.type === 'job-title') {
293
- return `${item.id}|${item.occupation_name_id ?? ''}`;
294
- }
295
- return item.id;
296
- }
297
- function searchConcepts(query, items, fuseInstance, maxResults) {
298
- if (!fuseInstance) {
299
- return [];
300
- }
301
- if (!items || !Array.isArray(items)) {
302
- taxonomyRegistry.log.warn('[searchConcepts] Ogiltig items array.');
303
- return [];
304
- }
305
- if (!query || query.length < MIN_INPUT_LENGTH) {
306
- return [];
307
- }
308
- const normalizedQuery = normalizeForComparison(query);
309
- const searchTokens = normalizedQuery.split(' ').filter(t => t.length > 0);
310
- const directResults = [];
311
- const processedIdentities = new Set();
312
- for (const item of items) {
313
- const normalizedLabel = normalizeForComparison(item.preferred_label);
314
- const preferredLabelScore = getDirectScore(normalizedLabel, normalizedQuery, searchTokens);
315
- const score = hasExactSearchAlias(item, normalizedQuery) ? 1.0 : preferredLabelScore;
316
- if (score !== null) {
317
- directResults.push(createSearchResult(item, query, score));
318
- processedIdentities.add(searchIdentity(item));
319
- }
320
- }
321
- if (directResults.length > 0) {
322
- return sortResultsStrict(directResults).slice(0, maxResults);
323
- }
324
- // Fuzzy is a pure fallback when there are no direct matches.
325
- if (fuseInstance) {
326
- const fuseSearchOutput = fuseInstance.search(normalizedQuery);
327
- if (fuseSearchOutput.length === 0) {
328
- return [];
329
- }
330
- const bestRawScore = fuseSearchOutput[0].score ?? 1.0;
331
- const candidateResults = [];
332
- let hasStrongRootMatch = false;
333
- for (const fr of fuseSearchOutput) {
334
- const identity = searchIdentity(fr.item);
335
- if (processedIdentities.has(identity)) {
336
- continue;
337
- }
338
- const rawScore = fr.score ?? 1.0;
339
- const baseFuzzyScore = 1 - rawScore;
340
- if (baseFuzzyScore < MIN_FUZZY_SCORE) {
341
- continue;
342
- }
343
- // Strict gap filter: never allow hits more than 0.12 raw-score worse than the best hit.
344
- if (rawScore > bestRawScore + 0.12) {
345
- continue;
346
- }
347
- const label = normalizeForComparison(fr.item.preferred_label);
348
- const weight = fr.item.weight ?? 0;
349
- const isRootMatch = isSingleWordOrCompoundRoot(normalizedQuery, label);
350
- if (isRootMatch && rawScore <= 0.25) {
351
- hasStrongRootMatch = true;
352
- }
353
- let score = baseFuzzyScore * 0.70 + (weight * 0.10);
354
- if (isRootMatch) {
355
- score += 0.12;
356
- }
357
- const boundedScore = Math.min(MAX_FUZZY_SCORE, Math.max(MIN_FUZZY_SCORE, score));
358
- candidateResults.push(createSearchResult(fr.item, query, boundedScore));
359
- processedIdentities.add(identity);
360
- }
361
- const sortedFuzzy = sortResultsStrict(candidateResults);
362
- if (sortedFuzzy.length === 0) {
363
- return [];
364
- }
365
- // Dynamic fuzzy result limit:
366
- // - strong root match: up to 5 relevant suggestions;
367
- // - weak/uncertain match: at most 3 suggestions.
368
- const limit = hasStrongRootMatch ? Math.min(5, maxResults) : Math.min(MAX_WEAK_FUZZY_RESULTS, maxResults);
369
- return sortedFuzzy.slice(0, limit);
370
- }
371
- return [];
372
- }
373
-
374
- const TaxonomyAdapter = {
375
- /** Maps a raw TaxonomyItem to a GenericItem for the CoreSelector */
376
- toGenericItem(item) {
377
- return {
378
- id: item.id,
379
- label: item.preferred_label || '',
380
- description: item.occupation_name_preferred_label,
381
- metadata: {
382
- original: item,
383
- type: item.type,
384
- ssyk_level_4_id: item.ssyk_level_4_id,
385
- weight: item.weight
386
- }
387
- };
388
- },
389
- /** Maps a SearchResult (from our engine) to a GenericItem */
390
- searchResultToGenericItem(result, query) {
391
- const segments = LabelFormatter.format(result.preferred_label || '', query, result.occupation_name_preferred_label);
392
- return {
393
- id: result.id,
394
- label: result.preferred_label || '',
395
- displaySegments: segments,
396
- highlightedLabel: segmentsToHtml(segments),
397
- metadata: {
398
- original: result,
399
- ssyk_level_4_id: result.ssyk_level_4_id,
400
- weight: result.weight
401
- }
402
- };
403
- },
404
- /** Maps a GenericItem back to our internal SearchResult format */
405
- fromGenericItem(item) {
406
- return {
407
- id: item.id,
408
- preferred_label: item.label,
409
- weight: item.metadata?.weight,
410
- ...item.metadata?.original
411
- };
412
- },
413
- /** Maps an internal item to the public event format */
414
- toPublicSelection(item) {
415
- const id = item.id || '';
416
- const preferredLabel = item.preferred_label || item.rawLabel || '';
417
- if (!id) {
418
- return {
419
- type: 'manual-input',
420
- id: null,
421
- preferred_label: preferredLabel,
422
- };
423
- }
424
- if (item.type !== 'job-title' && item.type !== 'occupation-name') {
425
- throw new Error(`Ogiltig intern yrkestyp för ${id}: ${item.type}`);
426
- }
427
- const selection = {
428
- type: item.type,
429
- id,
430
- preferred_label: preferredLabel,
431
- };
432
- if (item.ssyk_code_2012) {
433
- selection.ssyk_code_2012 = item.ssyk_code_2012;
434
- }
435
- const occupationId = item.occupation_name_id || item.occupationId;
436
- const occupationLabel = item.occupation_name_preferred_label || item.occupationLabel;
437
- if (item.type === 'job-title' && occupationId && occupationLabel) {
438
- selection.related = {
439
- type: 'occupation-name',
440
- id: occupationId,
441
- preferred_label: occupationLabel,
442
- };
443
- }
444
- return selection;
445
- }
446
- };
447
-
448
- class TaxonomySearchEngine {
449
- fuseInstance = null;
450
- items = [];
451
- constructor(data) {
452
- this.items = data;
453
- this.fuseInstance = new fuse.entry_default(data, FUSE_OPTIONS);
454
- }
455
- /**
456
- * Public API: Performs a search and returns clean, official domain objects.
457
- * This is what external consumers (headless) should use.
458
- */
459
- search(query, maxResults = 20) {
460
- if (!this.fuseInstance)
461
- return [];
462
- const results = searchConcepts(query, this.items, this.fuseInstance, maxResults);
463
- // Map directly to public selection objects
464
- return results.map(result => TaxonomyAdapter.toPublicSelection(result));
465
- }
466
- /**
467
- * Internal API: Performs a search and returns GenericItems for the CoreSelector UI ("Bucky").
468
- * Includes highlighting, grouping and internal metadata.
469
- */
470
- searchAsGeneric(query, maxResults = 20) {
471
- if (!this.fuseInstance)
472
- return [];
473
- // Use the existing robust search function
474
- const results = searchConcepts(query, this.items, this.fuseInstance, maxResults);
475
- // Adapt SearchResult -> GenericItem
476
- return results.map(result => ({
477
- id: result.id,
478
- label: result.displayLabel, // Use the formatted label (e.g. "Nurse (Healthcare)")
479
- description: result.occupationLabel,
480
- group: result.type === 'job-title' ? 'Yrke' : 'Yrkesgrupp',
481
- metadata: {
482
- originalResult: result, // Keep full original result for consumers
483
- highlightedLabel: result.highlightedLabel,
484
- score: result.score,
485
- weight: result.weight
486
- }
487
- }));
488
- }
489
- updateData(newData) {
490
- this.items = newData;
491
- this.fuseInstance = new fuse.entry_default(newData, FUSE_OPTIONS);
492
- }
493
- }
494
-
495
- exports.DEBOUNCE_TIME = DEBOUNCE_TIME;
496
- exports.LabelFormatter = LabelFormatter;
497
- exports.MAX_RESULTS = MAX_RESULTS;
498
- exports.MIN_INPUT_LENGTH = MIN_INPUT_LENGTH;
499
- exports.PLACEHOLDER_TEXT = PLACEHOLDER_TEXT;
500
- exports.TaxonomyAdapter = TaxonomyAdapter;
501
- exports.TaxonomySearchEngine = TaxonomySearchEngine;
502
- exports.isSameSearchResult = isSameSearchResult;
503
- exports.segmentsToHtml = segmentsToHtml;
504
- exports.styleParentheticalText = styleParentheticalText;