element-vir 12.4.0 → 12.4.2

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,6 +1,6 @@
1
1
  import { JsonCompatibleValue, UnPromise } from '@augment-vir/common';
2
2
  import { PickAndBlockOthers } from '../../augments/type';
3
- import { ObservablePropertyHandler, observablePropertyHandlerMarkerKey, ObservablePropertyListener } from './observable-property/observable-property-handler';
3
+ import { ObservablePropertyHandlerCreator, ObservablePropertyHandlerInstance, observablePropertyHandlerInstanceMarkerKey, ObservablePropertyListener } from './observable-property/observable-property-handler';
4
4
  export type AsyncState<ValueGeneric> = Error | UnPromise<ValueGeneric> | Promise<UnPromise<ValueGeneric>>;
5
5
  declare const notSetSymbol: unique symbol;
6
6
  type AllSetValueProperties<ValueGeneric> = {
@@ -21,9 +21,9 @@ type AllSetValueProperties<ValueGeneric> = {
21
21
  forceUpdate: true;
22
22
  };
23
23
  export type AsyncStateSetValue<ValueGeneric> = PickAndBlockOthers<AllSetValueProperties<ValueGeneric>, 'createPromise' | 'trigger'> | PickAndBlockOthers<AllSetValueProperties<ValueGeneric>, 'newPromise'> | PickAndBlockOthers<AllSetValueProperties<ValueGeneric>, 'forceUpdate'> | PickAndBlockOthers<AllSetValueProperties<ValueGeneric>, 'resolvedValue'>;
24
- export declare class AsyncObservablePropertyHandler<ValueGeneric> implements asyncObservablePropertyHandler<ValueGeneric> {
24
+ export declare class AsyncObservablePropertyHandler<ValueGeneric> implements ObservablePropertyHandlerInstance<AsyncStateSetValue<ValueGeneric>, AsyncState<ValueGeneric>> {
25
25
  #private;
26
- [observablePropertyHandlerMarkerKey]: true;
26
+ [observablePropertyHandlerInstanceMarkerKey]: true;
27
27
  constructor(initialValue: Promise<UnPromise<ValueGeneric>> | UnPromise<ValueGeneric> | ValueGeneric | typeof notSetSymbol);
28
28
  resetValue(rawValue: Promise<UnPromise<ValueGeneric>> | UnPromise<ValueGeneric> | ValueGeneric | typeof notSetSymbol): void;
29
29
  setValue(setInputs: AsyncStateSetValue<ValueGeneric>): void;
@@ -34,6 +34,6 @@ export declare class AsyncObservablePropertyHandler<ValueGeneric> implements asy
34
34
  removeListener(listener: ObservablePropertyListener<AsyncState<ValueGeneric>>): boolean;
35
35
  removeAllListeners(): number;
36
36
  }
37
- export type asyncObservablePropertyHandler<ValueGeneric> = ObservablePropertyHandler<AsyncStateSetValue<ValueGeneric>, AsyncState<ValueGeneric>>;
38
- export declare function asyncState<ValueGeneric>(...args: [Promise<UnPromise<ValueGeneric>> | UnPromise<ValueGeneric> | ValueGeneric] | []): AsyncObservablePropertyHandler<ValueGeneric>;
37
+ export type AsyncObservablePropertyHandlerCreator<ValueGeneric> = ObservablePropertyHandlerCreator<AsyncStateSetValue<ValueGeneric>, AsyncState<ValueGeneric>>;
38
+ export declare function asyncState<ValueGeneric>(...args: [Promise<UnPromise<ValueGeneric>> | UnPromise<ValueGeneric> | ValueGeneric] | []): AsyncObservablePropertyHandlerCreator<ValueGeneric>;
39
39
  export {};
@@ -11,7 +11,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
11
11
  };
12
12
  var _AsyncObservablePropertyHandler_instances, _AsyncObservablePropertyHandler_lastTrigger, _AsyncObservablePropertyHandler_resolutionValue, _AsyncObservablePropertyHandler_rejectionError, _AsyncObservablePropertyHandler_listeners, _AsyncObservablePropertyHandler_lastSetPromise, _AsyncObservablePropertyHandler_waitingForValuePromise, _AsyncObservablePropertyHandler_fireListeners, _AsyncObservablePropertyHandler_setPromise, _AsyncObservablePropertyHandler_resolveValue, _AsyncObservablePropertyHandler_resetWaitingForValuePromise, _a;
13
13
  import { areJsonEqual, createDeferredPromiseWrapper, ensureError, isLengthAtLeast, } from '@augment-vir/common';
14
- import { observablePropertyHandlerMarkerKey, } from './observable-property/observable-property-handler';
14
+ import { observablePropertyHandlerCreatorMarkerKey, observablePropertyHandlerInstanceMarkerKey, } from './observable-property/observable-property-handler';
15
15
  const notSetSymbol = Symbol('not set');
16
16
  export class AsyncObservablePropertyHandler {
17
17
  constructor(initialValue) {
@@ -112,7 +112,7 @@ export class AsyncObservablePropertyHandler {
112
112
  return count;
113
113
  }
114
114
  }
115
- _AsyncObservablePropertyHandler_lastTrigger = new WeakMap(), _AsyncObservablePropertyHandler_resolutionValue = new WeakMap(), _AsyncObservablePropertyHandler_rejectionError = new WeakMap(), _AsyncObservablePropertyHandler_listeners = new WeakMap(), _AsyncObservablePropertyHandler_lastSetPromise = new WeakMap(), _AsyncObservablePropertyHandler_waitingForValuePromise = new WeakMap(), _AsyncObservablePropertyHandler_instances = new WeakSet(), _a = observablePropertyHandlerMarkerKey, _AsyncObservablePropertyHandler_fireListeners = function _AsyncObservablePropertyHandler_fireListeners() {
115
+ _AsyncObservablePropertyHandler_lastTrigger = new WeakMap(), _AsyncObservablePropertyHandler_resolutionValue = new WeakMap(), _AsyncObservablePropertyHandler_rejectionError = new WeakMap(), _AsyncObservablePropertyHandler_listeners = new WeakMap(), _AsyncObservablePropertyHandler_lastSetPromise = new WeakMap(), _AsyncObservablePropertyHandler_waitingForValuePromise = new WeakMap(), _AsyncObservablePropertyHandler_instances = new WeakSet(), _a = observablePropertyHandlerInstanceMarkerKey, _AsyncObservablePropertyHandler_fireListeners = function _AsyncObservablePropertyHandler_fireListeners() {
116
116
  const value = this.getValue();
117
117
  __classPrivateFieldGet(this, _AsyncObservablePropertyHandler_listeners, "f").forEach((listener) => {
118
118
  listener(value);
@@ -168,5 +168,10 @@ export function asyncState(...args) {
168
168
  * at all.
169
169
  */
170
170
  const initValue = isLengthAtLeast(args, 1) ? args[0] : notSetSymbol;
171
- return new AsyncObservablePropertyHandler(initValue);
171
+ return {
172
+ [observablePropertyHandlerCreatorMarkerKey]: true,
173
+ init() {
174
+ return new AsyncObservablePropertyHandler(initValue);
175
+ },
176
+ };
172
177
  }
@@ -1,4 +1,4 @@
1
- import { isObservablePropertyHandler } from './observable-property/observable-property-handler';
1
+ import { isObservablePropertyHandlerCreator, isObservablePropertyHandlerInstance, } from './observable-property/observable-property-handler';
2
2
  function assertValidPropertyName(propKey, element, elementTagName) {
3
3
  if (typeof propKey !== 'string' && typeof propKey !== 'number' && typeof propKey !== 'symbol') {
4
4
  throw new Error(`Property name must be a string, got type '${typeof propKey}' from: '${String(propKey)}' for '${elementTagName.toLowerCase()}'`);
@@ -36,8 +36,11 @@ export function createElementUpdaterProxy(element, verifyExists) {
36
36
  target[propertyKey] = value;
37
37
  elementAsProps[propertyKey] = value;
38
38
  }
39
- /** If we're creating a new observable property */
40
- if (isObservablePropertyHandler(newValue)) {
39
+ if (isObservablePropertyHandlerCreator(newValue)) {
40
+ newValue = newValue.init();
41
+ }
42
+ /** If we're using an existing observable property */
43
+ if (isObservablePropertyHandlerInstance(newValue)) {
41
44
  if (existingObservablePropertyHandler &&
42
45
  newValue !== existingObservablePropertyHandler) {
43
46
  newValue.addMultipleListeners(existingObservablePropertyHandler.getAllListeners());
@@ -1,2 +1,2 @@
1
- import { ObservablePropertyHandler } from './observable-property-handler';
2
- export declare function createObservableProperty<ValueType>(initValue: ValueType): ObservablePropertyHandler<ValueType, ValueType>;
1
+ import { ObservablePropertyHandlerInstance } from './observable-property-handler';
2
+ export declare function createObservableProperty<ValueType>(initValue: ValueType): ObservablePropertyHandlerInstance<ValueType, ValueType>;
@@ -1,4 +1,4 @@
1
- import { observablePropertyHandlerMarkerKey, } from './observable-property-handler';
1
+ import { observablePropertyHandlerInstanceMarkerKey, } from './observable-property-handler';
2
2
  export function createObservableProperty(initValue) {
3
3
  const listeners = new Set();
4
4
  let value = initValue;
@@ -6,7 +6,7 @@ export function createObservableProperty(initValue) {
6
6
  listeners.forEach((listener) => listener(value));
7
7
  }
8
8
  const propertyHandler = {
9
- [observablePropertyHandlerMarkerKey]: true,
9
+ [observablePropertyHandlerInstanceMarkerKey]: true,
10
10
  setValue(newValue) {
11
11
  if (value !== newValue) {
12
12
  value = newValue;
@@ -1,18 +1,24 @@
1
1
  import { PropertyInitMapBase } from '../element-properties';
2
- export declare const observablePropertyHandlerMarkerKey: "_is_element_vir_observable_property_handler";
2
+ export declare const observablePropertyHandlerInstanceMarkerKey: "_is_element_vir_observable_property_handler_instance";
3
+ export declare const observablePropertyHandlerCreatorMarkerKey: "_is_element_vir_observable_property_handler_creator";
3
4
  export type ObservablePropertyListener<T> = (value: T) => void;
4
- export type ObservablePropertyHandlerMap<OriginalPropertyMap extends PropertyInitMapBase> = Partial<Record<keyof OriginalPropertyMap, ObservablePropertyHandler<any, any>>>;
5
+ export type ObservablePropertyHandlerMap<OriginalPropertyMap extends PropertyInitMapBase> = Partial<Record<keyof OriginalPropertyMap, ObservablePropertyHandlerInstance<any, any>>>;
6
+ type AnyObservablePropertyType<SetValue, GetValue> = ObservablePropertyHandlerCreator<SetValue, GetValue> | ObservablePropertyHandlerInstance<SetValue, GetValue>;
5
7
  export type AllowObservablePropertySetter<OriginalPropertyMap extends PropertyInitMapBase> = {
6
- [Prop in keyof OriginalPropertyMap]: OriginalPropertyMap[Prop] | ObservablePropertyHandler<any, Required<OriginalPropertyMap>[Prop]>;
8
+ [Prop in keyof OriginalPropertyMap]: OriginalPropertyMap[Prop] | AnyObservablePropertyType<any, Required<OriginalPropertyMap>[Prop]>;
7
9
  };
8
10
  export type FlattenObservablePropertyGetters<OriginalPropertyMap extends PropertyInitMapBase> = {
9
- [Prop in keyof OriginalPropertyMap]: OriginalPropertyMap[Prop] extends ObservablePropertyHandler<infer SetValue, infer GetValue> ? GetValue : OriginalPropertyMap[Prop];
11
+ [Prop in keyof OriginalPropertyMap]: OriginalPropertyMap[Prop] extends AnyObservablePropertyType<infer SetValue, infer GetValue> ? GetValue : Exclude<OriginalPropertyMap[Prop], AnyObservablePropertyType<any, any>>;
10
12
  };
11
13
  export type FlattenObservablePropertySetters<OriginalPropertyMap extends PropertyInitMapBase> = {
12
- [Prop in keyof OriginalPropertyMap]: OriginalPropertyMap[Prop] extends ObservablePropertyHandler<infer SetValue, infer GetValue> ? SetValue : OriginalPropertyMap[Prop];
14
+ [Prop in keyof OriginalPropertyMap]: OriginalPropertyMap[Prop] extends AnyObservablePropertyType<infer SetValue, infer GetValue> ? SetValue : Exclude<OriginalPropertyMap[Prop], AnyObservablePropertyType<any, any>>;
13
15
  };
14
- export type ObservablePropertyHandler<SetValue, GetValue> = {
15
- [observablePropertyHandlerMarkerKey]: true;
16
+ export type ObservablePropertyHandlerCreator<SetValue, GetValue> = {
17
+ [observablePropertyHandlerCreatorMarkerKey]: true;
18
+ init(): ObservablePropertyHandlerInstance<SetValue, GetValue>;
19
+ };
20
+ export type ObservablePropertyHandlerInstance<SetValue, GetValue> = {
21
+ [observablePropertyHandlerInstanceMarkerKey]: true;
16
22
  setValue(input: SetValue): void;
17
23
  getValue(): GetValue;
18
24
  /** Add the given listener. */
@@ -31,4 +37,6 @@ export type ObservablePropertyHandler<SetValue, GetValue> = {
31
37
  getAllListeners(): ReadonlySet<ObservablePropertyListener<GetValue>>;
32
38
  addMultipleListeners(listeners: ReadonlySet<ObservablePropertyListener<GetValue>>): void;
33
39
  };
34
- export declare function isObservablePropertyHandler(input: unknown): input is ObservablePropertyHandler<any, any>;
40
+ export declare function isObservablePropertyHandlerCreator(input: unknown): input is ObservablePropertyHandlerCreator<any, any>;
41
+ export declare function isObservablePropertyHandlerInstance(input: unknown): input is ObservablePropertyHandlerInstance<any, any>;
42
+ export {};
@@ -1,6 +1,11 @@
1
1
  import { typedHasProperty } from '@augment-vir/common';
2
- export const observablePropertyHandlerMarkerKey = '_is_element_vir_observable_property_handler';
3
- export function isObservablePropertyHandler(input) {
4
- return (typedHasProperty(input, observablePropertyHandlerMarkerKey) &&
5
- input[observablePropertyHandlerMarkerKey] === true);
2
+ export const observablePropertyHandlerInstanceMarkerKey = '_is_element_vir_observable_property_handler_instance';
3
+ export const observablePropertyHandlerCreatorMarkerKey = '_is_element_vir_observable_property_handler_creator';
4
+ export function isObservablePropertyHandlerCreator(input) {
5
+ return (typedHasProperty(input, observablePropertyHandlerCreatorMarkerKey) &&
6
+ input[observablePropertyHandlerCreatorMarkerKey] === true);
7
+ }
8
+ export function isObservablePropertyHandlerInstance(input) {
9
+ return (typedHasProperty(input, observablePropertyHandlerInstanceMarkerKey) &&
10
+ input[observablePropertyHandlerInstanceMarkerKey] === true);
6
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "element-vir",
3
- "version": "12.4.0",
3
+ "version": "12.4.2",
4
4
  "keywords": [
5
5
  "custom",
6
6
  "web",
@@ -39,13 +39,13 @@
39
39
  "test:types": "tsc --noEmit"
40
40
  },
41
41
  "dependencies": {
42
- "@augment-vir/browser": "^13.3.0",
43
- "@augment-vir/common": "^13.3.0",
44
- "lit": "2.7.3"
42
+ "@augment-vir/browser": "^13.4.0",
43
+ "@augment-vir/common": "^13.4.0",
44
+ "lit": "2.7.4"
45
45
  },
46
46
  "devDependencies": {
47
- "@augment-vir/browser-testing": "^13.3.0",
48
- "@augment-vir/node-js": "^13.3.0",
47
+ "@augment-vir/browser-testing": "^13.4.0",
48
+ "@augment-vir/node-js": "^13.4.0",
49
49
  "@istanbuljs/nyc-config-typescript": "^1.0.2",
50
50
  "@open-wc/testing": "^3.1.8",
51
51
  "@types/mocha": "^10.0.1",
@@ -60,7 +60,7 @@
60
60
  "istanbul-smart-text-reporter": "^1.1.1",
61
61
  "markdown-code-example-inserter": "^0.3.0",
62
62
  "mocha-spec-reporter-with-file-names": "^0.0.3",
63
- "npm-check-updates": "^16.10.9",
63
+ "npm-check-updates": "^16.10.10",
64
64
  "nyc": "^15.1.0",
65
65
  "prettier": "^2.8.8",
66
66
  "prettier-plugin-interpolated-html-tags": "^0.0.3",
@@ -71,10 +71,10 @@
71
71
  "prettier-plugin-sort-json": "^1.0.0",
72
72
  "prettier-plugin-toml": "^0.3.1",
73
73
  "ts-node": "^10.9.1",
74
- "type-fest": "^3.9.0",
74
+ "type-fest": "^3.10.0",
75
75
  "typescript": "^5.0.4",
76
- "virmator": "^6.5.0",
77
- "vite": "^4.3.3",
76
+ "virmator": "^6.5.1",
77
+ "vite": "^4.3.5",
78
78
  "vite-tsconfig-paths": "^4.2.0"
79
79
  }
80
80
  }