@ethlete/cdk 5.0.0-next.34 → 5.0.0-next.36

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/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @ethlete/cdk
2
2
 
3
+ ## 5.0.0-next.36
4
+
5
+ ### Patch Changes
6
+
7
+ - `etIcon` reports an icon named after an `Object.prototype` member (e.g. `constructor`) as not found instead of throwing a `TypeError`, and the not-found error prints the icon name.
8
+ - `<et-pagination>` reads the current url from `DOCUMENT` instead of `window`, so it no longer throws under SSR; `paginate()` accepts a `currentUrl` option for use outside a browser.
9
+ - Query button: the success/failure reset timer is cleared on destroy and no longer calls `window` directly.
10
+ - The swiss `new-bracket` escapes `swissColors` values before writing them into the SVG, so a color string can no longer inject markup.
11
+
12
+ ## 5.0.0-next.35
13
+
14
+ ### Patch Changes
15
+
16
+ - The v5 migration moves `ProvideColorDirective` and `COLOR_PROVIDER` imports from `@ethlete/cdk` to `@ethlete/core`, so a `ProvideThemeDirective` import that the core migration renamed first no longer stays behind on `@ethlete/cdk`.
17
+
3
18
  ## 5.0.0-next.34
4
19
 
5
20
  ### Patch Changes
@@ -133,12 +133,14 @@ const CHEVRON_ICON = {
133
133
  */
134
134
  const ICONS_TOKEN = new InjectionToken('ET_ICONS_TOKEN');
135
135
  /**
136
+ * Registers the icons `etIcon` can render. The SVG strings are inserted without sanitization, so pass only trusted, static SVG - never markup from an API or CMS.
137
+ *
136
138
  * @deprecated `@ethlete/cdk` is in maintenance mode. Use the `@ethlete/components` equivalent instead - see https://ethlete-sdk-docs.web.app/cdk/migration, and run `nx g @ethlete/cdk:migrate-from-cdk` to rewrite the mechanical parts. Intent to remove in v6.
137
139
  */
138
140
  const provideIcons = (...icons) => {
139
141
  const map = {};
140
142
  for (const def of icons) {
141
- if (map[def.name]) {
143
+ if (Object.hasOwn(map, def.name)) {
142
144
  throw new Error(`Icon with name ${def.name} already exists. Please provide unique icon names.`);
143
145
  }
144
146
  map[def.name] = def;
@@ -167,9 +169,9 @@ class IconDirective {
167
169
  if (!this.icons) {
168
170
  return null;
169
171
  }
170
- const icon = this.icons[this.iconNameToUse()];
172
+ const icon = Object.hasOwn(this.icons, this.iconNameToUse()) ? this.icons[this.iconNameToUse()] : undefined;
171
173
  if (!icon) {
172
- throw new Error(`Icon with name ${this.iconNameToUse} not found. Please provide a valid icon name. Available icons are: ${Object.keys(this.icons).join(', ')}`);
174
+ throw new Error(`Icon with name ${this.iconNameToUse()} not found. Please provide a valid icon name. Available icons are: ${Object.keys(this.icons).join(', ')}`);
173
175
  }
174
176
  const svg = icon.data.trim();
175
177
  if (isDevMode()) {
@@ -4340,11 +4342,14 @@ const groupBorderRect = (group, border, color) => {
4340
4342
  // right, so user space coordinates can be used (they also work for straight lines, where
4341
4343
  // the bounding box has no height).
4342
4344
  const lineGradientDef = (id, fromX, toX, from, neutral, to) => `<linearGradient id="${id}" gradientUnits="userSpaceOnUse" x1="${fromX}" y1="0" x2="${toX}" y2="0"><stop offset="0%" stop-color="${from}" /><stop offset="50%" stop-color="${neutral}" /><stop offset="100%" stop-color="${to}" /></linearGradient>`;
4345
+ const escapeSvgAttribute = (value) => value.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
4346
+ const escapeSwissColors = (colors) => colors &&
4347
+ Object.fromEntries(Object.entries(colors).map(([type, color]) => [type, color === undefined ? color : escapeSvgAttribute(color)]));
4343
4348
  const drawSwissMan = (dimensions) => {
4344
4349
  const svgParts = [];
4345
4350
  const gradientDefs = [];
4346
4351
  const roundGeometries = collectSwissRoundGeometries(dimensions.bracketGrid);
4347
- const colors = dimensions.colors;
4352
+ const colors = escapeSwissColors(dimensions.colors);
4348
4353
  for (const roundGeometry of roundGeometries) {
4349
4354
  for (const group of roundGeometry.groups.values()) {
4350
4355
  svgParts.push(groupBorderRect(group, dimensions.groupBorder, colors?.[group.colorType]));
@@ -12214,9 +12219,7 @@ class QueryButtonDirective {
12214
12219
  set query(v) {
12215
12220
  this._query$.next(v);
12216
12221
  const classList = this._elementRef.nativeElement.classList;
12217
- if (this._cleanupTimeout !== null) {
12218
- window.clearTimeout(this._cleanupTimeout);
12219
- }
12222
+ this._clearCleanupTimeout();
12220
12223
  classList.remove(CLASSES.success);
12221
12224
  classList.remove(CLASSES.failure);
12222
12225
  classList.remove(CLASSES.loading);
@@ -12251,7 +12254,9 @@ class QueryButtonDirective {
12251
12254
  if (!this.didLoadOnce$.value) {
12252
12255
  this.didLoadOnce$.next(true);
12253
12256
  }
12254
- this._cleanupTimeout = window.setTimeout(() => {
12257
+ this._clearCleanupTimeout();
12258
+ this._cleanupTimeout = setTimeout(() => {
12259
+ this._cleanupTimeout = null;
12255
12260
  this.showFailure$.next(false);
12256
12261
  this.showSuccess$.next(false);
12257
12262
  classList.remove(CLASSES.success);
@@ -12290,6 +12295,13 @@ class QueryButtonDirective {
12290
12295
  }))),
12291
12296
  });
12292
12297
  this._button._removeDisabledBindings();
12298
+ inject(DestroyRef).onDestroy(() => this._clearCleanupTimeout());
12299
+ }
12300
+ _clearCleanupTimeout() {
12301
+ if (this._cleanupTimeout === null)
12302
+ return;
12303
+ clearTimeout(this._cleanupTimeout);
12304
+ this._cleanupTimeout = null;
12293
12305
  }
12294
12306
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.6", ngImport: i0, type: QueryButtonDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
12295
12307
  static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "16.1.0", version: "22.1.6", type: QueryButtonDirective, isStandalone: true, inputs: { skipSuccess: ["skipSuccess", "skipSuccess", booleanAttribute], skipFailure: ["skipFailure", "skipFailure", booleanAttribute], skipLoading: ["skipLoading", "skipLoading", booleanAttribute], query: "query" }, exportAs: ["etQueryButton"], ngImport: i0 }); }
@@ -19083,7 +19095,7 @@ class PaginationHeadService {
19083
19095
  queryParamsHandling: 'merge',
19084
19096
  });
19085
19097
  const relativeUrl = this._router.serializeUrl(urlTree);
19086
- const canonicalUrl = `${window.location.origin}${relativeUrl}`;
19098
+ const canonicalUrl = `${this._document.location.origin}${relativeUrl}`;
19087
19099
  const element = this._getCanonicalElement(true);
19088
19100
  element.setAttribute('rel', 'canonical');
19089
19101
  element.setAttribute('href', canonicalUrl);
@@ -19120,7 +19132,7 @@ const paginate = (value) => {
19120
19132
  if (value.totalPageCount === 0) {
19121
19133
  return null;
19122
19134
  }
19123
- const currentUrl = new URL(window.location.href);
19135
+ const currentUrl = new URL(value.currentUrl ?? window.location.href);
19124
19136
  const createUrl = (page) => {
19125
19137
  const url = new URL(currentUrl.href);
19126
19138
  if (page === 1) {
@@ -19214,6 +19226,7 @@ class PaginationComponent {
19214
19226
  constructor() {
19215
19227
  this._pageControlSubscription = Subscription.EMPTY;
19216
19228
  this._paginationHeadService = inject(PaginationHeadService);
19229
+ this._document = inject(DOCUMENT$1);
19217
19230
  this._pageControl = null;
19218
19231
  this._totalPages = 0;
19219
19232
  this.ariaLabel = input('Pagination', /* @ts-ignore */
@@ -19293,7 +19306,11 @@ class PaginationComponent {
19293
19306
  return;
19294
19307
  }
19295
19308
  const pageValue = this.pageControl.value ?? 1;
19296
- this.pages$.next(paginate({ currentPage: pageValue, totalPageCount: this.totalPages }));
19309
+ this.pages$.next(paginate({
19310
+ currentPage: pageValue,
19311
+ totalPageCount: this.totalPages,
19312
+ currentUrl: this._document.location.href,
19313
+ }));
19297
19314
  }
19298
19315
  _updateHead() {
19299
19316
  if (this.pageControl?.value) {