@zcomponent/core 1.8.1-beta → 1.9.0

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.
@@ -0,0 +1,5 @@
1
+ import { Component } from "../component";
2
+ import { Context } from "../context";
3
+ export declare class GlobalTagContext extends Context {
4
+ componentsByGlobalTag: Map<string, Set<Component<any, import("../component").ConstructorProps>>>;
5
+ }
@@ -0,0 +1,7 @@
1
+ import { Context } from "../context";
2
+ export class GlobalTagContext extends Context {
3
+ constructor() {
4
+ super(...arguments);
5
+ this.componentsByGlobalTag = new Map();
6
+ }
7
+ }
@@ -3,7 +3,7 @@ import { ContextManager, Context } from "../context";
3
3
  export declare class TagContext extends Context {
4
4
  tagsByComponent: Map<Component<any, import("../component").ConstructorProps>, Set<string>>;
5
5
  componentsByLocalTag: Map<string, Set<Component<any, import("../component").ConstructorProps>>>;
6
- componentsByGlobalTag: Map<string, Set<Component<any, import("../component").ConstructorProps>>>;
6
+ private _global;
7
7
  registerComponent(component: Component, tags: string[]): void;
8
8
  unregisterComponent(component: Component): void;
9
9
  getComponentsByTag(tag: string): Set<Component>;
@@ -1,15 +1,16 @@
1
1
  import { Context } from "../context";
2
+ import { GlobalTagContext } from "./globaltagcontext";
2
3
  export class TagContext extends Context {
3
4
  constructor() {
4
5
  super(...arguments);
5
6
  this.tagsByComponent = new Map();
6
7
  this.componentsByLocalTag = new Map();
7
- this.componentsByGlobalTag = new Map();
8
+ this._global = this.contextManager.get(GlobalTagContext);
8
9
  }
9
10
  registerComponent(component, tags) {
10
11
  this.unregisterComponent(component);
11
12
  for (const tag of tags) {
12
- const map = tag.startsWith('global:') ? this.componentsByGlobalTag : this.componentsByLocalTag;
13
+ const map = !tag.startsWith('local:') ? this._global.componentsByGlobalTag : this.componentsByLocalTag;
13
14
  const set = map.get(tag) ?? new Set();
14
15
  set.add(component);
15
16
  map.set(tag, set);
@@ -22,7 +23,7 @@ export class TagContext extends Context {
22
23
  if (!tags)
23
24
  return;
24
25
  for (const tag of tags.values()) {
25
- const map = tag.startsWith('global:') ? this.componentsByGlobalTag : this.componentsByLocalTag;
26
+ const map = !tag.startsWith('local:') ? this._global.componentsByGlobalTag : this.componentsByLocalTag;
26
27
  const entry = map.get(tag);
27
28
  if (!entry)
28
29
  continue;
@@ -31,7 +32,7 @@ export class TagContext extends Context {
31
32
  this.tagsByComponent.delete(component);
32
33
  }
33
34
  getComponentsByTag(tag) {
34
- return ((tag.startsWith('global:') ? this.componentsByGlobalTag : this.componentsByLocalTag).get(tag)) ?? new Set();
35
+ return ((tag.startsWith('global:') ? this._global.componentsByGlobalTag : this.componentsByLocalTag).get(tag)) ?? new Set();
35
36
  }
36
37
  getComponentsByTags(tags) {
37
38
  if (tags.length === 0)
@@ -40,7 +41,7 @@ export class TagContext extends Context {
40
41
  return this.getComponentsByTag(tags[0]);
41
42
  const ret = new Set();
42
43
  for (const tag of tags) {
43
- const map = tag.startsWith('global:') ? this.componentsByGlobalTag : this.componentsByLocalTag;
44
+ const map = !tag.startsWith('local:') ? this._global.componentsByGlobalTag : this.componentsByLocalTag;
44
45
  const entries = map.get(tag);
45
46
  if (!entries)
46
47
  continue;
package/lib/types.d.ts CHANGED
@@ -29,7 +29,8 @@ export interface BooleanPrimitiveType extends BaseType {
29
29
  }
30
30
  export interface LiteralType extends BaseType {
31
31
  name: 'literal';
32
- value: string | number | boolean | undefined | null;
32
+ value?: string | number | boolean | null;
33
+ isUndefined?: boolean;
33
34
  }
34
35
  export interface ArrayType extends BaseType {
35
36
  name: 'array';
package/lib/types.js CHANGED
@@ -220,6 +220,7 @@ export function mergeTypes(a, b) {
220
220
  name: a.name,
221
221
  typeHint,
222
222
  value: a.value,
223
+ isUndefined: a.isUndefined,
223
224
  comments: mergeComments(a.comments ?? [], b.comments ?? []),
224
225
  };
225
226
  case 'array': {
@@ -323,6 +324,8 @@ export function isValidValueForType(def, t, allowUndefined) {
323
324
  return false;
324
325
  }
325
326
  case 'literal':
327
+ if (def === undefined && t.isUndefined)
328
+ return true;
326
329
  return def === t.value;
327
330
  case 'function':
328
331
  return false;
@@ -352,7 +355,7 @@ function getBasicType(t) {
352
355
  case 'entity':
353
356
  return t.name;
354
357
  case 'literal': {
355
- if (t.value === undefined)
358
+ if (t.isUndefined || t.value === undefined)
356
359
  return 'undefined';
357
360
  return JSON.stringify(t.value);
358
361
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zcomponent/core",
3
- "version": "1.8.1-beta",
3
+ "version": "1.9.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",