@fluid-topics/ft-wc-utils 1.3.26 → 1.3.27

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.
@@ -1,4 +1,4 @@
1
- import { Optional, Provider } from "./generic-types";
1
+ import { Constructor, Optional, Provider } from "./generic-types";
2
2
  export declare const delay: (ms: number) => Promise<unknown>;
3
3
  export declare function waitUntil(condition: Provider<boolean | Promise<boolean>>, interval?: number, timeout?: Optional<number>): Promise<void>;
4
4
  export declare function waitFor<T>(provider: Provider<Optional<T> | Promise<Optional<T>>>, interval?: number, timeout?: Optional<number>): Promise<T>;
@@ -14,3 +14,4 @@ export declare function unslotText(node: any): string;
14
14
  export declare function getComposedPathTo(element: EventTarget): EventTarget[];
15
15
  export declare function deepCopy<T = any>(value: T): T;
16
16
  export declare function randomId(size: number, prefix?: string): string;
17
+ export declare function applyMixinOnce<IN extends Constructor<unknown>, OUT>(mixinIdentifier: symbol, mixin: (c: IN) => OUT): (c: IN) => OUT;
package/build/helpers.js CHANGED
@@ -1,4 +1,4 @@
1
- export const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
1
+ export const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
2
2
  export async function waitUntil(condition, interval = 10, timeout = 20000) {
3
3
  await waitFor(async () => await condition() || undefined, interval, timeout);
4
4
  }
@@ -17,7 +17,7 @@ export async function waitFor(provider, interval = 10, timeout = 20000) {
17
17
  return value;
18
18
  }
19
19
  export function flatDeep(arr, getChildren) {
20
- return arr.flatMap(o => [o, ...flatDeep(getChildren(o), getChildren)]);
20
+ return arr.flatMap((o) => [o, ...flatDeep(getChildren(o), getChildren)]);
21
21
  }
22
22
  export function dateReviver(...dateKeys) {
23
23
  return (key, value) => dateKeys.includes(key) ? parseDate(value) : value;
@@ -39,7 +39,7 @@ function eq(a, b) {
39
39
  if (a.constructor !== b.constructor) {
40
40
  return false;
41
41
  }
42
- var length, i, keys;
42
+ let length, i, keys;
43
43
  if (Array.isArray(a)) {
44
44
  length = a.length;
45
45
  if (length != b.length) {
@@ -85,7 +85,7 @@ function eq(a, b) {
85
85
  if (a.valueOf !== Object.prototype.valueOf) {
86
86
  return a.valueOf() === b.valueOf();
87
87
  }
88
- const keysWithNonNullValues = (o) => Object.keys(o).filter(k => o[k] != null);
88
+ const keysWithNonNullValues = (o) => Object.keys(o).filter((k) => o[k] != null);
89
89
  keys = keysWithNonNullValues(a);
90
90
  length = keys.length;
91
91
  if (length !== keysWithNonNullValues(b).length) {
@@ -123,11 +123,11 @@ export function hasChanged(a, b) {
123
123
  export function eventPathContainsMatchingElement(e, matchers, containerElement = window.document.body) {
124
124
  if (matchers.length > 0) {
125
125
  const path = e.composedPath();
126
- for (let e of path) {
126
+ for (const e of path) {
127
127
  if (e === containerElement) {
128
128
  return false;
129
129
  }
130
- if (e.matches && matchers.some(matcher => e.matches(matcher))) {
130
+ if (e.matches && matchers.some((matcher) => e.matches(matcher))) {
131
131
  return true;
132
132
  }
133
133
  }
@@ -142,7 +142,7 @@ export function last(arr) {
142
142
  }
143
143
  export function unslotText(node) {
144
144
  if (node instanceof HTMLSlotElement) {
145
- return node.assignedNodes().map(n => unslotText(n)).join("");
145
+ return node.assignedNodes().map((n) => unslotText(n)).join("");
146
146
  }
147
147
  return (node === null || node === void 0 ? void 0 : node.textContent) || "";
148
148
  }
@@ -166,3 +166,14 @@ export function deepCopy(value) {
166
166
  export function randomId(size, prefix) {
167
167
  return (prefix !== null && prefix !== void 0 ? prefix : "") + ("" + Math.floor(Math.random() * (10 ** size))).padStart(size, "0");
168
168
  }
169
+ export function applyMixinOnce(mixinIdentifier, mixin) {
170
+ const isMixinAlreadyApplied = (o) => o[mixinIdentifier] === true;
171
+ return (Class) => {
172
+ if (isMixinAlreadyApplied(Class)) {
173
+ return Class;
174
+ }
175
+ const result = mixin(Class);
176
+ result[mixinIdentifier] = true;
177
+ return result;
178
+ };
179
+ }
@@ -14,7 +14,7 @@ type FtLitElementWithReduxType<T extends Constructor<FtLitElement>> = T & Constr
14
14
  reduxReactiveProperties: Set<string>;
15
15
  reduxEventListeners: Map<string, ReduxEventListenerInit>;
16
16
  };
17
- export declare function withRedux<T extends Constructor<FtLitElement>>(Class: T): FtLitElementWithReduxType<T>;
17
+ export declare const withRedux: <T extends Constructor<FtLitElement>>(c: T) => FtLitElementWithReduxType<T>;
18
18
  declare const FtLitElementRedux_base: FtLitElementWithReduxType<typeof FtLitElement>;
19
19
  export declare class FtLitElementRedux extends FtLitElementRedux_base {
20
20
  }
@@ -1,9 +1,10 @@
1
1
  import { FtLitElement } from "../FtLitElement";
2
2
  import { isFtReduxStore } from "./models";
3
+ import { applyMixinOnce } from "../helpers";
3
4
  const internalReduxEventsUnsubscribers = Symbol("internalReduxEventsUnsubscribers");
4
5
  const internalStoresUnsubscribers = Symbol("internalStoresUnsubscribers");
5
6
  const internalStores = Symbol("internalStores");
6
- export function withRedux(Class) {
7
+ export const withRedux = applyMixinOnce(Symbol("withRedux"), function (Class) {
7
8
  var _a, _b, _c;
8
9
  class FtLitElementWithReduxClass extends Class {
9
10
  constructor() {
@@ -17,7 +18,7 @@ export function withRedux(Class) {
17
18
  }
18
19
  willUpdate(props) {
19
20
  super.willUpdate(props);
20
- if ([...this.reduxConstructor.reduxReactiveProperties].some(prop => props.has(prop))) {
21
+ if ([...this.reduxConstructor.reduxReactiveProperties].some((prop) => props.has(prop))) {
21
22
  this.updateFromStores();
22
23
  }
23
24
  }
@@ -88,9 +89,10 @@ export function withRedux(Class) {
88
89
  this[internalStoresUnsubscribers].get(name)();
89
90
  }
90
91
  this[internalStoresUnsubscribers].delete(name);
91
- (_d = this[internalReduxEventsUnsubscribers].get(name)) === null || _d === void 0 ? void 0 : _d.forEach(unsub => unsub());
92
+ (_d = this[internalReduxEventsUnsubscribers].get(name)) === null || _d === void 0 ? void 0 : _d.forEach((unsub) => unsub());
92
93
  this[internalReduxEventsUnsubscribers].delete(name);
93
94
  }
95
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
94
96
  onStoreAvailable(name) {
95
97
  }
96
98
  connectedCallback() {
@@ -107,6 +109,6 @@ export function withRedux(Class) {
107
109
  FtLitElementWithReduxClass.reduxReactiveProperties = new Set();
108
110
  FtLitElementWithReduxClass.reduxEventListeners = new Map();
109
111
  return FtLitElementWithReduxClass;
110
- }
112
+ });
111
113
  export class FtLitElementRedux extends withRedux(FtLitElement) {
112
114
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluid-topics/ft-wc-utils",
3
- "version": "1.3.26",
3
+ "version": "1.3.27",
4
4
  "description": "Internal web components tools",
5
5
  "author": "Fluid Topics <devtopics@antidot.net>",
6
6
  "license": "ISC",
@@ -15,7 +15,7 @@
15
15
  "dependencies": {
16
16
  "@floating-ui/dom": "1.5.3",
17
17
  "@fluid-topics/design-system-variables": "2.53.0",
18
- "@fluid-topics/public-api": "1.0.105",
18
+ "@fluid-topics/public-api": "1.0.106",
19
19
  "@reduxjs/toolkit": "1.9.5",
20
20
  "@types/mark.js": "8.11.12",
21
21
  "@webcomponents/scoped-custom-element-registry": "0.0.9",
@@ -24,5 +24,5 @@
24
24
  "mark.js": "8.11.1",
25
25
  "moment": "2.29.4"
26
26
  },
27
- "gitHead": "2801b1f3a132753af33d5d62b8001164737e2a4f"
27
+ "gitHead": "51aa199a231fa71dee36bf98dfde51007100da86"
28
28
  }