@penn-libraries/web 1.1.0-dev.4 → 1.1.0-dev.6

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.
@@ -10,22 +10,18 @@ export interface ActivatedEvent {
10
10
  }
11
11
  export declare class Autocomplete {
12
12
  el: HTMLElement;
13
- /**
14
- * The id of the input element to attach autocomplete functionality to
15
- */
16
13
  for?: string;
17
14
  showSuggestions: boolean;
18
15
  currentIndex: number;
19
16
  originalValue: string;
20
17
  options: ListboxOption[];
21
- /**
22
- * Emitted when a user activates (selects) an autocomplete option
23
- */
24
18
  activated: EventEmitter<ActivatedEvent>;
25
19
  private blurTimeout;
20
+ private mutationObserver;
26
21
  componentWillLoad(): void;
27
22
  componentDidLoad(): void;
28
23
  disconnectedCallback(): void;
24
+ private setupMutationObserver;
29
25
  private parseOptionsFromDOM;
30
26
  private findListbox;
31
27
  private createOption;
@@ -9,9 +9,6 @@ import { ActivatedEvent } from "./components/pennlibs-autocomplete/pennlibs-auto
9
9
  export { ActivatedEvent } from "./components/pennlibs-autocomplete/pennlibs-autocomplete";
10
10
  export namespace Components {
11
11
  interface PennlibsAutocomplete {
12
- /**
13
- * The id of the input element to attach autocomplete functionality to
14
- */
15
12
  "for"?: string;
16
13
  }
17
14
  interface PennlibsBanner {
@@ -223,13 +220,7 @@ declare global {
223
220
  }
224
221
  declare namespace LocalJSX {
225
222
  interface PennlibsAutocomplete {
226
- /**
227
- * The id of the input element to attach autocomplete functionality to
228
- */
229
223
  "for"?: string;
230
- /**
231
- * Emitted when a user activates (selects) an autocomplete option
232
- */
233
224
  "onPl:activated"?: (event: PennlibsAutocompleteCustomEvent<ActivatedEvent>) => void;
234
225
  }
235
226
  interface PennlibsBanner {
@@ -1,6 +1,6 @@
1
1
  import { r as registerInstance, c as createEvent, h, a as getElement, g as getAssetPath } from './p-CE_ILdTo.js';
2
2
 
3
- const pennlibsAutocompleteCss = ":host {\n display: block;\n width: 100%;\n border-radius: 1.25rem;\n padding: 0;\n border-top: 0;\n position: relative;\n}\n\n[role=listbox] {\n position: absolute;\n margin-top: var(--pl-space-xs);\n background: var(--pl-color-bg-default);\n border-radius: 1.25rem;\n box-shadow: rgba(140, 149, 159, 0.3) 0px 8px 24px 0px;\n width: 100%;\n overflow: hidden;\n z-index: 1;\n\n display: flex;\n flex-direction: column;\n}\n\np {\n margin: 0;\n font-size: var(--pl-font-size-s);\n color: var(--pl-color-fg-subtle);\n padding: var(--pl-space-xs) calc(var(--pl-space-m) + var(--pl-space-2xs));\n font-size: var(--pl-font-size-s);\n order: 2;\n font-weight: 500;\n background: var(--pl-color-bg-subtle);\n border-radius: 0 0 1.25rem 1.25rem;\n\n display: flex;\n gap: var(--pl-space-s) var(--pl-space-l);\n flex-wrap: wrap;\n}\n\nol {\n list-style: none;\n margin: 0;\n padding: var(--pl-space-xs) 0;\n order: 1;\n}\n\n[role=option] {\n color: var(--pl-color-fg-default);\n padding: var(--pl-space-s) calc(var(--pl-space-m) + var(--pl-space-2xs));\n text-decoration: none;\n font-weight: 700; \n\n &:hover {\n cursor: pointer;\n }\n\n &:hover,\n &:focus {\n text-decoration-thickness: 2px;\n text-underline-offset: 2px;\n text-decoration: underline;\n }\n}\n\n[aria-selected=true] {\n text-decoration-thickness: 2px;\n text-underline-offset: 2px;\n text-decoration: underline;\n}\n\nmark {\n background: none;\n font-weight: 400;\n}\n\n.suggestion--border {\n border-bottom: solid 1px rgb(from var(--pl-color-fg-default) r g b / 0.2);\n padding-bottom: calc(var(--pl-space-2xs) + var(--pl-space-s));\n margin-bottom: var(--pl-space-2xs);\n}";
3
+ const pennlibsAutocompleteCss = ":host {\n display: block;\n width: 100%;\n border-radius: 1.25rem;\n padding: 0;\n border-top: 0;\n position: relative;\n}\n\n[role=listbox] {\n position: absolute;\n margin-top: var(--pl-space-xs);\n background: var(--pl-color-bg-default);\n border-radius: 1.25rem;\n box-shadow: rgba(140, 149, 159, 0.3) 0px 8px 24px 0px;\n width: 100%;\n overflow: hidden;\n z-index: 1;\n\n display: flex;\n flex-direction: column;\n}\n\np {\n margin: 0;\n font-size: var(--pl-font-size-s);\n color: var(--pl-color-fg-subtle);\n padding: var(--pl-space-xs) calc(var(--pl-space-m) + var(--pl-space-2xs));\n font-size: var(--pl-font-size-s);\n order: 2;\n font-weight: 500;\n background: var(--pl-color-bg-subtle);\n border-radius: 0 0 1.25rem 1.25rem;\n\n display: flex;\n gap: var(--pl-space-s) var(--pl-space-l);\n flex-wrap: wrap;\n}\n\nol {\n list-style: none;\n margin: 0;\n padding: var(--pl-space-xs) 0;\n order: 1;\n}\n\n[role=option] {\n color: var(--pl-color-fg-default);\n padding: var(--pl-space-s) calc(var(--pl-space-m) + var(--pl-space-2xs));\n text-decoration: none;\n font-weight: 700; \n\n &:hover {\n cursor: pointer;\n }\n\n &:hover,\n &:focus {\n text-decoration-thickness: 2px;\n text-underline-offset: 2px;\n text-decoration: underline;\n }\n}\n\n[aria-selected=true] {\n text-decoration-thickness: 2px;\n text-underline-offset: 2px;\n text-decoration: underline;\n}\n\nmark,\nb {\n background: none;\n font-weight: 400;\n}\n\n.suggestion--border {\n border-bottom: solid 1px rgb(from var(--pl-color-fg-default) r g b / 0.2);\n padding-bottom: calc(var(--pl-space-2xs) + var(--pl-space-s));\n margin-bottom: var(--pl-space-2xs);\n}";
4
4
 
5
5
  const Autocomplete = class {
6
6
  constructor(hostRef) {
@@ -20,10 +20,23 @@ const Autocomplete = class {
20
20
  }
21
21
  componentDidLoad() {
22
22
  this.setupInput();
23
+ this.setupMutationObserver();
23
24
  }
24
25
  disconnectedCallback() {
25
26
  if (this.blurTimeout)
26
27
  clearTimeout(this.blurTimeout);
28
+ if (this.mutationObserver)
29
+ this.mutationObserver.disconnect();
30
+ }
31
+ setupMutationObserver() {
32
+ this.mutationObserver = new MutationObserver(() => {
33
+ this.options = this.parseOptionsFromDOM();
34
+ });
35
+ this.mutationObserver.observe(this.el, {
36
+ childList: true,
37
+ subtree: true,
38
+ characterData: true
39
+ });
27
40
  }
28
41
  parseOptionsFromDOM() {
29
42
  const listbox = this.findListbox();
@@ -84,7 +97,6 @@ const Autocomplete = class {
84
97
  handleInputEvent(event) {
85
98
  const input = event.target;
86
99
  if (this.isTrackedInput(input)) {
87
- // Reset active option when user manually changes input
88
100
  this.currentIndex = -1;
89
101
  this.openSuggestions();
90
102
  }
@@ -207,7 +219,6 @@ const Autocomplete = class {
207
219
  const active = document.activeElement;
208
220
  return !((_a = this.el.shadowRoot) === null || _a === void 0 ? void 0 : _a.contains(active)) && active !== this.getInput();
209
221
  }
210
- // Input State Sync
211
222
  syncInputState() {
212
223
  const input = this.getInput();
213
224
  if (!input)
@@ -237,7 +248,7 @@ const Autocomplete = class {
237
248
  return this.showSuggestions && this.options.length > 0 && this.isInputFocused();
238
249
  }
239
250
  render() {
240
- return (h("div", { key: 'c9d88ed9a19ef99b53d0849d03c0a64d4e08a39c' }, h("slot", { key: 'bc5c0c3e42f40269818cd7a8f78ec4bb5f5f0d49', name: "start" }), this.shouldShowListbox() && (h("ol", { key: '4ad4f80d38a7de2537f343ec02e1bad3e5c2b100', role: "listbox", id: "listbox" }, this.options.map((option, index) => (h("li", { role: "option", id: option.id, "aria-selected": this.currentIndex === index ? 'true' : 'false', tabindex: "-1", onClick: () => this.handleOptionClick(index), innerHTML: option.html })))))));
251
+ return (h("div", { key: '71422b55533372a9d8697e648e49f87fe223f4e0' }, h("slot", { key: '951511fd2090b9816c2e6c1a5a40169ea08e72fd', name: "start" }), this.shouldShowListbox() && (h("ol", { key: 'e3f6f14686bc99b6e25d34d8e053f01174f23438', role: "listbox", id: "listbox" }, this.options.map((option, index) => (h("li", { role: "option", id: option.id, "aria-selected": this.currentIndex === index ? 'true' : 'false', tabindex: "-1", onClick: () => this.handleOptionClick(index), innerHTML: option.html })))))));
241
252
  }
242
253
  get el() { return getElement(this); }
243
254
  };
@@ -360,4 +371,4 @@ Header.style = pennlibsHeaderCss;
360
371
  export { Autocomplete as pennlibs_autocomplete, Footer as pennlibs_footer, Header as pennlibs_header };
361
372
  //# sourceMappingURL=pennlibs-autocomplete.pennlibs-footer.pennlibs-header.entry.esm.js.map
362
373
 
363
- //# sourceMappingURL=p-40119068.entry.js.map
374
+ //# sourceMappingURL=p-909144f6.entry.js.map