@panyam/tsutils 0.0.64 → 0.0.66
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/lib/cjs/index.d.ts +2 -0
- package/lib/cjs/index.js +4 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/numberutils.js.map +1 -1
- package/lib/cjs/scrolling.d.ts +49 -0
- package/lib/cjs/scrolling.js +195 -0
- package/lib/cjs/scrolling.js.map +1 -0
- package/lib/cjs/timer.d.ts +12 -0
- package/lib/cjs/timer.js +45 -0
- package/lib/cjs/timer.js.map +1 -0
- package/lib/esm/index.d.ts +2 -0
- package/lib/esm/index.js +3 -0
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/numberutils.js.map +1 -1
- package/lib/esm/scrolling.d.ts +49 -0
- package/lib/esm/scrolling.js +190 -0
- package/lib/esm/scrolling.js.map +1 -0
- package/lib/esm/timer.d.ts +12 -0
- package/lib/esm/timer.js +41 -0
- package/lib/esm/timer.js.map +1 -0
- package/package.json +1 -1
- package/lib/cjs/properties.d.ts +0 -54
- package/lib/cjs/properties.js +0 -158
- package/lib/cjs/properties.js.map +0 -1
- package/lib/esm/properties.d.ts +0 -54
- package/lib/esm/properties.js +0 -149
- package/lib/esm/properties.js.map +0 -1
package/lib/esm/properties.js
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import { EventBus } from "./comms/bus";
|
|
2
|
-
import { ifDefined } from "./misc";
|
|
3
|
-
export class PropertySchema {
|
|
4
|
-
constructor(name, config) {
|
|
5
|
-
this.units = "";
|
|
6
|
-
this.defaultValue = null;
|
|
7
|
-
this.minValue = null;
|
|
8
|
-
this.maxValue = null;
|
|
9
|
-
this.beforeSetterName = null;
|
|
10
|
-
this.name = name;
|
|
11
|
-
this.beforeSetterName = ifDefined(config.beforeSetterName);
|
|
12
|
-
this.units = ifDefined(config.units);
|
|
13
|
-
this.defaultValue = ifDefined(config.defaultValue);
|
|
14
|
-
this.minValue = ifDefined(config.minValue);
|
|
15
|
-
this.maxValue = ifDefined(config.maxValue);
|
|
16
|
-
}
|
|
17
|
-
validate(newValue) {
|
|
18
|
-
if (this.minValue != null && newValue < this.minValue)
|
|
19
|
-
return false;
|
|
20
|
-
if (this.maxValue != null && newValue > this.maxValue)
|
|
21
|
-
return false;
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
export class Property {
|
|
26
|
-
constructor(schema) {
|
|
27
|
-
this.currentValue = null;
|
|
28
|
-
this.beforeSetterFunc = null;
|
|
29
|
-
this.schema = schema;
|
|
30
|
-
}
|
|
31
|
-
clone() {
|
|
32
|
-
const out = new Property(this.schema);
|
|
33
|
-
out.currentValue = this.currentValue;
|
|
34
|
-
return out;
|
|
35
|
-
}
|
|
36
|
-
get value() {
|
|
37
|
-
return this.currentValue;
|
|
38
|
-
}
|
|
39
|
-
setValue(instance, value) {
|
|
40
|
-
if (this.schema.beforeSetterName != null) {
|
|
41
|
-
if (this.beforeSetterFunc == null) {
|
|
42
|
-
const beforeSetterFunc = instance[this.schema.beforeSetterName];
|
|
43
|
-
if (beforeSetterFunc == null) {
|
|
44
|
-
throw new Error("Cannot find beforeSetter function: " + this.schema.beforeSetterName);
|
|
45
|
-
}
|
|
46
|
-
this.beforeSetterFunc = beforeSetterFunc.bind(instance);
|
|
47
|
-
}
|
|
48
|
-
if (this.beforeSetterFunc(value) == false) {
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
if (!this.schema.validate(value)) {
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
this.currentValue = value;
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
export class PropertyStore {
|
|
60
|
-
constructor() {
|
|
61
|
-
this.__properties__ = {};
|
|
62
|
-
this.eventBus = EventBus.getInstance();
|
|
63
|
-
}
|
|
64
|
-
getPropertyNames() {
|
|
65
|
-
return Object.keys(this.__properties__);
|
|
66
|
-
}
|
|
67
|
-
getProperty(name) {
|
|
68
|
-
this[name];
|
|
69
|
-
return this.__properties__[name] || null;
|
|
70
|
-
}
|
|
71
|
-
setProperty(name, value) {
|
|
72
|
-
if (this.__properties__[name]) {
|
|
73
|
-
const old = this.__properties__[name].value;
|
|
74
|
-
this.__properties__[name].setValue(this, value);
|
|
75
|
-
this.eventBus.emit("PropertyChange", {
|
|
76
|
-
name: name,
|
|
77
|
-
old: old,
|
|
78
|
-
current: value,
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
export const mixinPropertyStore = (target) => {
|
|
84
|
-
return class extends target {
|
|
85
|
-
constructor() {
|
|
86
|
-
super(...arguments);
|
|
87
|
-
this.__properties__ = {};
|
|
88
|
-
}
|
|
89
|
-
getProperties() {
|
|
90
|
-
return this.__properties__;
|
|
91
|
-
}
|
|
92
|
-
getProperty(name) {
|
|
93
|
-
return this.__properties__[name];
|
|
94
|
-
}
|
|
95
|
-
setProperty(name, value) {
|
|
96
|
-
if (this.__properties__[name]) {
|
|
97
|
-
this.__properties__[name].setValue(this, value);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
};
|
|
102
|
-
function ensureProperty(schema, instance, propertyKey, propertiesName = "__properties__") {
|
|
103
|
-
if (!instance[propertiesName]) {
|
|
104
|
-
throw new Error(`Property store (${propertiesName}) does not exist in target.`);
|
|
105
|
-
}
|
|
106
|
-
const propertiesMap = instance[propertiesName];
|
|
107
|
-
if (propertyKey in propertiesMap) {
|
|
108
|
-
return propertiesMap[propertyKey];
|
|
109
|
-
}
|
|
110
|
-
const property = (propertiesMap[propertyKey] = new Property(schema));
|
|
111
|
-
property.setValue(instance, schema.defaultValue);
|
|
112
|
-
return property;
|
|
113
|
-
}
|
|
114
|
-
export function property({ propertiesName = "__properties__", defaultValue = null, beforeSetterName = null, units = "", minValue = null, maxValue = null, } = {}) {
|
|
115
|
-
return function (target, propertyKey) {
|
|
116
|
-
const root = target;
|
|
117
|
-
if (!(propertiesName in root)) {
|
|
118
|
-
root[propertiesName] = {};
|
|
119
|
-
}
|
|
120
|
-
const propertySchemas = root[propertiesName];
|
|
121
|
-
const newSchema = new PropertySchema(propertyKey, {
|
|
122
|
-
units: units,
|
|
123
|
-
beforeSetterName: beforeSetterName,
|
|
124
|
-
defaultValue: defaultValue,
|
|
125
|
-
minValue: minValue,
|
|
126
|
-
maxValue: maxValue,
|
|
127
|
-
});
|
|
128
|
-
if (propertyKey in propertySchemas) {
|
|
129
|
-
}
|
|
130
|
-
propertySchemas[propertyKey] = newSchema;
|
|
131
|
-
Object.defineProperty(target, propertyKey, {
|
|
132
|
-
get() {
|
|
133
|
-
const property = ensureProperty(newSchema, this, propertyKey, propertiesName);
|
|
134
|
-
return property.value;
|
|
135
|
-
},
|
|
136
|
-
set(newValue) {
|
|
137
|
-
const property = ensureProperty(newSchema, this, propertyKey, propertiesName);
|
|
138
|
-
property.setValue(this, newValue);
|
|
139
|
-
},
|
|
140
|
-
enumerable: true,
|
|
141
|
-
configurable: false,
|
|
142
|
-
});
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
export function propertyValidator(propertyName, propertiesName = "__properties__") {
|
|
146
|
-
return function (target, propertyKey, descriptor) {
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
//# sourceMappingURL=properties.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"properties.js","sourceRoot":"","sources":["../../src/properties.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAEnC,MAAM,OAAO,cAAc;IASzB,YAAY,IAAY,EAAE,MAAW;QAN9B,UAAK,GAAG,EAAE,CAAC;QACX,iBAAY,GAAQ,IAAI,CAAC;QACzB,aAAQ,GAAqB,IAAI,CAAC;QAClC,aAAQ,GAAqB,IAAI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YAAY,EAAE,KAAK;SACpB,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAI,YAAoB,EAAE,cAAc,GAAG,gBAAgB;IAC1F,OAAO,UAAU,MAAW,EAAE,WAAmB,EAAE,UAA8B;IAGjF,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { Nullable } from \"./types\";\nimport { EventBus } from \"./comms/bus\";\nimport { ifDefined } from \"./misc\";\n\nexport class PropertySchema {\n // Name of the property\n public name: string;\n public units = \"\";\n public defaultValue: any = null;\n public minValue: Nullable<number> = null;\n public maxValue: Nullable<number> = null;\n public beforeSetterName: Nullable<string> = null;\n\n constructor(name: string, config: any) {\n this.name = name;\n this.beforeSetterName = ifDefined(config.beforeSetterName);\n this.units = ifDefined(config.units);\n this.defaultValue = ifDefined(config.defaultValue);\n this.minValue = ifDefined(config.minValue);\n this.maxValue = ifDefined(config.maxValue);\n }\n\n validate(newValue: number): boolean {\n if (this.minValue != null && newValue < this.minValue) return false;\n if (this.maxValue != null && newValue > this.maxValue) return false;\n // TODO - other validations\n return true;\n }\n}\n\n/**\n * Proprties are values required to fully resolve a component.\n * Like disk needs seek latency or capacity.\n */\nexport class Property {\n // Value of the property\n readonly schema: PropertySchema;\n public currentValue: any = null;\n public beforeSetterFunc: any = null;\n\n constructor(schema: PropertySchema) {\n this.schema = schema;\n }\n\n clone(): Property {\n const out = new Property(this.schema);\n out.currentValue = this.currentValue;\n return out;\n }\n\n get value() {\n return this.currentValue;\n }\n\n setValue(instance: any, value: any): boolean {\n if (this.schema.beforeSetterName != null) {\n if (this.beforeSetterFunc == null) {\n const beforeSetterFunc = instance[this.schema.beforeSetterName];\n if (beforeSetterFunc == null) {\n throw new Error(\"Cannot find beforeSetter function: \" + this.schema.beforeSetterName);\n }\n this.beforeSetterFunc = beforeSetterFunc.bind(instance);\n }\n if (this.beforeSetterFunc(value) == false) {\n // validation failed\n return false;\n }\n }\n if (!this.schema.validate(value)) {\n return false;\n }\n this.currentValue = value;\n return true;\n }\n}\n\nexport class PropertyStore {\n /**\n * The properties for this Element\n */\n readonly __properties__: { [key: string]: Property } = {};\n\n private eventBus = EventBus.getInstance();\n\n getPropertyNames(): string[] {\n // return Object.keys((this.constructor as any).__properties__);\n return Object.keys(this.__properties__);\n }\n\n getProperty(name: string): Nullable<Property> {\n (this as any)[name];\n return this.__properties__[name] || null;\n }\n\n setProperty(name: string, value: any): void {\n if (this.__properties__[name]) {\n const old = this.__properties__[name].value;\n this.__properties__[name].setValue(this, value);\n // TODO: Maybe need a fully qualified name here.\n this.eventBus.emit(\"PropertyChange\", {\n name: name,\n old: old,\n current: value,\n });\n }\n }\n}\n\nexport const mixinPropertyStore = (target: any) => {\n return class extends target {\n /**\n * The properties for this Element\n */\n readonly __properties__: { [key: string]: Property } = {};\n\n getProperties(): { [key: string]: Property } {\n return this.__properties__;\n }\n\n getProperty(name: string): Property {\n return this.__properties__[name];\n }\n\n setProperty(name: string, value: any): void {\n if (this.__properties__[name]) {\n this.__properties__[name].setValue(this, value);\n }\n }\n };\n};\n\ninterface PropertyParams<T> {\n defaultValue?: Nullable<T>;\n propertiesName?: string;\n beforeSetterName?: Nullable<string>;\n units?: string;\n minValue?: Nullable<number>;\n maxValue?: Nullable<number>;\n}\n\nfunction ensureProperty<T>(\n schema: PropertySchema,\n instance: any,\n propertyKey: string,\n propertiesName = \"__properties__\",\n): Property {\n if (!instance[propertiesName]) {\n throw new Error(`Property store (${propertiesName}) does not exist in target.`);\n }\n const propertiesMap = instance[propertiesName];\n if (propertyKey in propertiesMap) {\n return propertiesMap[propertyKey];\n }\n const property = (propertiesMap[propertyKey] = new Property(schema));\n property.setValue(instance, schema.defaultValue);\n return property;\n}\n\n/**\n * property is a decorator factory. It returns a decorator that can be applied to a property.\n * This decorator allows us to have some properties of an Element be treated specially (so it\n * can be reflected, configured/enumerated via UI). This decorator in a way makes our Element\n * attributes metadata-able so we dont have to duplicate a property object and an attribute\n * manually.\n */\nexport function property<T>({\n propertiesName = \"__properties__\",\n defaultValue = null,\n beforeSetterName = null,\n units = \"\",\n minValue = null,\n maxValue = null,\n}: PropertyParams<T> = {}) {\n return function (target: any, propertyKey: string) {\n const root = target; // .constructor;\n if (!(propertiesName in root)) {\n root[propertiesName] = {};\n }\n const propertySchemas = root[propertiesName];\n const newSchema = new PropertySchema(propertyKey, {\n units: units,\n beforeSetterName: beforeSetterName,\n defaultValue: defaultValue,\n minValue: minValue,\n maxValue: maxValue,\n });\n if (propertyKey in propertySchemas) {\n // throw new Error(\"Duplicate property: \" + propertyKey);\n }\n propertySchemas[propertyKey] = newSchema;\n\n Object.defineProperty(target, propertyKey, {\n get() {\n const property = ensureProperty(newSchema, this, propertyKey, propertiesName);\n return property.value;\n },\n set(newValue: any) {\n const property = ensureProperty(newSchema, this, propertyKey, propertiesName);\n property.setValue(this, newValue);\n },\n enumerable: true,\n configurable: false,\n });\n };\n}\n\nexport function propertyValidator<T>(propertyName: string, propertiesName = \"__properties__\") {\n return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {\n // const property = ensureProperty(this, propertyKey, null, propertiesName);\n // property.setValue(\n };\n}\n"]}
|