@nectary/components 5.1.4 → 5.2.1

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/bundle.js CHANGED
@@ -8092,6 +8092,10 @@ class Radio extends NectaryElement {
8092
8092
  }
8093
8093
  }
8094
8094
  #onOptionKeyDown = (e) => {
8095
+ const option = e.target?.closest("sinch-radio-option") ?? null;
8096
+ if (option === null) {
8097
+ return;
8098
+ }
8095
8099
  switch (e.code) {
8096
8100
  case "ArrowUp":
8097
8101
  case "ArrowLeft": {
@@ -8119,11 +8123,15 @@ class Radio extends NectaryElement {
8119
8123
  this.#onValueChange(this.value);
8120
8124
  };
8121
8125
  #onOptionClick = (e) => {
8122
- const target = getTargetByAttribute(e, "value");
8123
- if (target === null || target.hasAttribute("disabled")) {
8126
+ const target = e.target;
8127
+ if (target === null) {
8128
+ return;
8129
+ }
8130
+ const option = target.closest("sinch-radio-option");
8131
+ if (option === null || option.hasAttribute("disabled")) {
8124
8132
  return;
8125
8133
  }
8126
- const value = getAttribute(target, "value");
8134
+ const value = getAttribute(option, "value");
8127
8135
  this.dispatchEvent(
8128
8136
  new CustomEvent("-change", { detail: value })
8129
8137
  );
package/bundle.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  // Reminder: Keep this list updated as we add new components
2
-
3
2
  export * from './accordion-item/index.js'
4
3
  export * from './accordion/index.js'
5
4
  export * from './action-menu-option/index.js'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nectary/components",
3
- "version": "5.1.4",
3
+ "version": "5.2.1",
4
4
  "files": [
5
5
  "**/*/*.css",
6
6
  "**/*/*.json",
@@ -24,7 +24,7 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "@babel/runtime": "^7.22.15",
27
- "@nectary/assets": "3.1.0"
27
+ "@nectary/assets": "3.1.1"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@babel/cli": "^7.22.15",
package/radio/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { getBooleanAttribute, updateAttribute, getAttribute, updateBooleanAttribute, isAttrTrue } from "../utils/dom.js";
2
2
  import { defineCustomElement, NectaryElement } from "../utils/element.js";
3
3
  import { getReactEventHandler } from "../utils/get-react-event-handler.js";
4
- import { getTargetByAttribute } from "../utils/event-target.js";
5
4
  import { setFormValue } from "../utils/form.js";
6
5
  const templateHTML = '<style>:host{display:block}#wrapper{display:flex;flex-direction:var(--sinch-comp-radio-direction,column);gap:var(--sinch-comp-radio-gap,8px);box-sizing:border-box;width:100%}</style><div id="wrapper"><slot></slot></div>';
7
6
  const template = document.createElement("template");
@@ -85,6 +84,10 @@ class Radio extends NectaryElement {
85
84
  }
86
85
  }
87
86
  #onOptionKeyDown = (e) => {
87
+ const option = e.target?.closest("sinch-radio-option") ?? null;
88
+ if (option === null) {
89
+ return;
90
+ }
88
91
  switch (e.code) {
89
92
  case "ArrowUp":
90
93
  case "ArrowLeft": {
@@ -112,11 +115,15 @@ class Radio extends NectaryElement {
112
115
  this.#onValueChange(this.value);
113
116
  };
114
117
  #onOptionClick = (e) => {
115
- const target = getTargetByAttribute(e, "value");
116
- if (target === null || target.hasAttribute("disabled")) {
118
+ const target = e.target;
119
+ if (target === null) {
120
+ return;
121
+ }
122
+ const option = target.closest("sinch-radio-option");
123
+ if (option === null || option.hasAttribute("disabled")) {
117
124
  return;
118
125
  }
119
- const value = getAttribute(target, "value");
126
+ const value = getAttribute(option, "value");
120
127
  this.dispatchEvent(
121
128
  new CustomEvent("-change", { detail: value })
122
129
  );
@@ -58,6 +58,7 @@ declare abstract class GlobalElementsManager {
58
58
  private createLoader;
59
59
  private preloadBundle;
60
60
  init(options?: GlobalManagerInitOptions): Promise<void>;
61
+ whenLoaded(): Promise<void>;
61
62
  private getImportPathFromName;
62
63
  preload(name: SinchElementName | SinchElementName[] | "all"): Promise<void>;
63
64
  }
@@ -56,6 +56,7 @@ export declare abstract class GlobalElementsManager {
56
56
  private createLoader;
57
57
  private preloadBundle;
58
58
  init(options?: GlobalManagerInitOptions): Promise<void>;
59
+ whenLoaded(): Promise<void>;
59
60
  private getImportPathFromName;
60
61
  preload(name: SinchElementName | SinchElementName[] | 'all'): Promise<void>;
61
62
  }
@@ -109,31 +109,39 @@ class GlobalElementsManager {
109
109
  store.preload = options.preload ?? false;
110
110
  store.patchPerviousVersions = options.patchPerviousVersions ?? true;
111
111
  store.useFallbackExclusively = options.useFallbackExclusively ?? false;
112
- if (store.preload) {
113
- const version = options.targetlibVersion;
114
- store.targetlibVersion = version ?? store.targetlibVersion;
115
- const importPath = version != null ? `${this.config.cdnUrl}@${version}/es2022/bundle.mjs` : `${this.config.cdnUrl}/bundle`;
116
- await this.preloadBundle(importPath, options.fallbackLoaderBundle, store.useFallbackExclusively);
117
- return;
118
- }
119
- if (store.patchPerviousVersions) {
120
- this.patchCustomElements();
121
- }
122
- this.config.baseElementNames.forEach((name) => {
123
- const importPath = `${this.config.cdnUrl}/${this.getImportPathFromName(name)}`;
124
- store.definitions.set(`sinch-${name}`, this.createLoader(importPath, name, options.fallbackLoader, store.useFallbackExclusively));
125
- });
126
- if (options.targetlibVersion != null) {
127
- store.targetlibVersion = options.targetlibVersion;
128
- } else {
129
- const registry = await fetch(`${this.config.registryUrl}/latest`);
130
- const registryData = await registry.json();
131
- store.targetlibVersion = registryData.version;
112
+ try {
113
+ if (store.preload) {
114
+ const version = options.targetlibVersion;
115
+ store.targetlibVersion = version ?? store.targetlibVersion;
116
+ const importPath = version != null ? `${this.config.cdnUrl}@${version}/es2022/bundle.mjs` : `${this.config.cdnUrl}/bundle`;
117
+ await this.preloadBundle(importPath, options.fallbackLoaderBundle, store.useFallbackExclusively);
118
+ } else {
119
+ if (store.patchPerviousVersions) {
120
+ this.patchCustomElements();
121
+ }
122
+ this.config.baseElementNames.forEach((name) => {
123
+ const importPath = `${this.config.cdnUrl}/${this.getImportPathFromName(name)}`;
124
+ store.definitions.set(`sinch-${name}`, this.createLoader(importPath, name, options.fallbackLoader, store.useFallbackExclusively));
125
+ });
126
+ if (options.targetlibVersion != null) {
127
+ store.targetlibVersion = options.targetlibVersion;
128
+ } else {
129
+ const registry = await fetch(`${this.config.registryUrl}/latest`);
130
+ const registryData = await registry.json();
131
+ store.targetlibVersion = registryData.version;
132
+ }
133
+ this.config.baseElementNames.forEach((name) => {
134
+ const importPath = `${this.config.cdnUrl}@${store.targetlibVersion}/es2022/${this.getImportPathFromName(name)}.mjs`;
135
+ store.definitions.set(`sinch-${name}`, this.createLoader(importPath, name, options.fallbackLoader, store.useFallbackExclusively));
136
+ });
137
+ }
138
+ } finally {
139
+ store.loadPromise.resolve();
132
140
  }
133
- this.config.baseElementNames.forEach((name) => {
134
- const importPath = `${this.config.cdnUrl}@${store.targetlibVersion}/es2022/${this.getImportPathFromName(name)}.mjs`;
135
- store.definitions.set(`sinch-${name}`, this.createLoader(importPath, name, options.fallbackLoader, store.useFallbackExclusively));
136
- });
141
+ }
142
+ whenLoaded() {
143
+ const store = getStore(this.config.storeKey);
144
+ return store.loadPromise.promise;
137
145
  }
138
146
  getImportPathFromName(name) {
139
147
  for (const [key, value] of this.config.nameToPathMap ?? []) {
@@ -1,11 +1,15 @@
1
1
  import type { SinchElementName } from './nectary-element-base';
2
2
  interface GlobalStore {
3
+ definitions: Map<SinchElementName, () => Promise<any>>;
3
4
  hasInitialized: boolean;
4
5
  targetlibVersion: string;
5
6
  patchPerviousVersions: boolean;
6
7
  useFallbackExclusively: boolean;
7
8
  preload: boolean;
8
- definitions: Map<SinchElementName, () => Promise<any>>;
9
+ loadPromise: {
10
+ promise: Promise<void>;
11
+ resolve: (value: void) => void;
12
+ };
9
13
  }
10
14
  export declare const getStore: (storeKey: symbol) => GlobalStore;
11
15
  export declare const getConstructor: (storeKey: symbol, name: SinchElementName) => Promise<CustomElementConstructor> | null;
@@ -1,14 +1,22 @@
1
+ const createDeferredPromise = () => {
2
+ let resolve;
3
+ const promise = new Promise((r) => {
4
+ resolve = r;
5
+ });
6
+ return { promise, resolve };
7
+ };
1
8
  const getStore = (storeKey) => {
2
9
  if (window[storeKey] != null) {
3
10
  return window[storeKey];
4
11
  }
5
12
  const store = {
13
+ definitions: /* @__PURE__ */ new Map(),
6
14
  hasInitialized: false,
7
15
  targetlibVersion: "",
8
16
  patchPerviousVersions: false,
9
17
  useFallbackExclusively: false,
10
18
  preload: false,
11
- definitions: /* @__PURE__ */ new Map()
19
+ loadPromise: createDeferredPromise()
12
20
  };
13
21
  Object.defineProperty(window, storeKey, {
14
22
  value: store,