@claspo/common 7.3.1-dev.1 → 7.3.1-dev.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.
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/jest.config.ts +204 -0
- package/out/velocity/SysVelocityRenderer.js +1 -0
- package/package.json +1 -1
- package/src/DefaultEventEmitter.test.ts +84 -0
- package/src/DefaultEventEmitter.ts +96 -0
- package/src/HttpAbortableLoader.ts +35 -0
- package/src/InAppLayoutType.ts +6 -0
- package/src/LayoutType.ts +18 -0
- package/src/PrizePool.interface.ts +32 -0
- package/src/RenderMode.ts +10 -0
- package/src/UuidGenerator.ts +16 -0
- package/src/WidgetInitConfig.interface.ts +163 -0
- package/src/WidgetType.ts +18 -0
- package/src/action/type.ts +7 -0
- package/src/async/createAsyncIterator.ts +33 -0
- package/src/async/debounce.ts +28 -0
- package/src/async/timeout.ts +3 -0
- package/src/component-manifest/ComponentManifest.interface.ts +160 -0
- package/src/component-manifest/ContextMenuManifest.interface.ts +52 -0
- package/src/component-manifest/DisplayCondition.interface.ts +65 -0
- package/src/component-manifest/FloatingControlManifest.interface.ts +89 -0
- package/src/component-manifest/PropPathCondition.interface.ts +4 -0
- package/src/component-manifest/PropertyPaneManifest.interface.ts +614 -0
- package/src/converter/time/TimeConverter.spec.ts +11 -0
- package/src/converter/time/TimeUnit.spec.ts +12 -0
- package/src/converter/time/TimeUnit.ts +34 -0
- package/src/converter/time/TimerConverter.ts +29 -0
- package/src/document/ComponentInsertType.ts +6 -0
- package/src/document/Document.interface.ts +625 -0
- package/src/document/DocumentCssVarsReplace.test.ts +2947 -0
- package/src/document/DocumentCssVarsReplace.ts +31 -0
- package/src/document/DocumentUtils.test.ts +595 -0
- package/src/document/DocumentUtils.ts +194 -0
- package/src/document/hidden-fields.interface.ts +54 -0
- package/src/dom/ViewportSize.ts +61 -0
- package/src/dom/copyToClipboard.ts +17 -0
- package/src/dom/getMostNestedNode.ts +9 -0
- package/src/dom/insertHtmlIntoElement.ts +36 -0
- package/src/dom/sanitizeHTML.test.ts +59 -0
- package/src/dom/sanitizeHTML.ts +78 -0
- package/src/element/BaseElementInViewportHandler.ts +41 -0
- package/src/element/CssVarsOperations.ts +37 -0
- package/src/element/ThemeCssVars.ts +28 -0
- package/src/element/recursiveFindParentNodeByAttribute.test.ts +63 -0
- package/src/element/recursiveFindParentNodeByAttribute.ts +25 -0
- package/src/flat.ts +16 -0
- package/src/handler/HandlerTypes.ts +4 -0
- package/src/math/RandomDistributor.test.ts +35 -0
- package/src/math/RandomDistributor.ts +58 -0
- package/src/math/sum.ts +3 -0
- package/src/network/HttpClient.ts +28 -0
- package/src/network/HttpStatus.ts +4 -0
- package/src/object/isDictionary.test.ts +24 -0
- package/src/object/isDictionary.ts +13 -0
- package/src/object/omitKeys.test.ts +19 -0
- package/src/object/omitKeys.ts +20 -0
- package/src/storage/BaseCachingStorage.test.ts +70 -0
- package/src/storage/BaseCachingStorage.ts +37 -0
- package/src/storage/CachingCookieStorage.test.ts +75 -0
- package/src/storage/CachingCookieStorage.ts +36 -0
- package/src/storage/CachingLocalStorage.test.ts +59 -0
- package/src/storage/CachingLocalStorage.ts +34 -0
- package/src/storage/getCookie.test.ts +53 -0
- package/src/storage/getCookie.ts +10 -0
- package/src/storage/setCookie.test.ts +97 -0
- package/src/storage/setCookie.ts +49 -0
- package/src/theme/theme.utils.ts +50 -0
- package/src/url/sanitizeUrl.test.ts +62 -0
- package/src/url/sanitizeUrl.ts +51 -0
- package/src/utils/CaseTransformer.test.ts +16 -0
- package/src/utils/CaseTransformer.ts +10 -0
- package/src/utils/NullishCoalescingOperator.ts +3 -0
- package/src/utils/NumericDecline.ts +25 -0
- package/src/utils/addEventListener.ts +23 -0
- package/src/utils/allSettled.ts +6 -0
- package/src/utils/checkTimeZone.spec.ts +18 -0
- package/src/utils/checkTimeZone.ts +6 -0
- package/src/utils/deviceUtils.ts +12 -0
- package/src/utils/flatMap.test.ts +21 -0
- package/src/utils/flatMap.ts +3 -0
- package/src/utils/fromEntries.ts +6 -0
- package/src/utils/generateRandomNumber.test.ts +23 -0
- package/src/utils/generateRandomNumber.ts +3 -0
- package/src/utils/objectSort.ts +41 -0
- package/src/utils/orientationUtils.ts +18 -0
- package/src/velocity/SysVelocityContext.spec.ts +88 -0
- package/src/velocity/SysVelocityContext.ts +129 -0
- package/src/velocity/SysVelocityRenderer.spec.ts +36 -0
- package/src/velocity/SysVelocityRenderer.ts +11 -0
- package/test/__mocks/jestGlobalMocks.js +1887 -0
- package/velocity/SysVelocityRenderer.js +0 -1
- /package/{DefaultEventEmitter.d.ts → out/DefaultEventEmitter.d.ts} +0 -0
- /package/{DefaultEventEmitter.js → out/DefaultEventEmitter.js} +0 -0
- /package/{HttpAbortableLoader.d.ts → out/HttpAbortableLoader.d.ts} +0 -0
- /package/{HttpAbortableLoader.js → out/HttpAbortableLoader.js} +0 -0
- /package/{InAppLayoutType.d.ts → out/InAppLayoutType.d.ts} +0 -0
- /package/{InAppLayoutType.js → out/InAppLayoutType.js} +0 -0
- /package/{LayoutType.d.ts → out/LayoutType.d.ts} +0 -0
- /package/{LayoutType.js → out/LayoutType.js} +0 -0
- /package/{PrizePool.interface.d.ts → out/PrizePool.interface.d.ts} +0 -0
- /package/{PrizePool.interface.js → out/PrizePool.interface.js} +0 -0
- /package/{RenderMode.d.ts → out/RenderMode.d.ts} +0 -0
- /package/{RenderMode.js → out/RenderMode.js} +0 -0
- /package/{UuidGenerator.d.ts → out/UuidGenerator.d.ts} +0 -0
- /package/{UuidGenerator.js → out/UuidGenerator.js} +0 -0
- /package/{WidgetInitConfig.interface.d.ts → out/WidgetInitConfig.interface.d.ts} +0 -0
- /package/{WidgetInitConfig.interface.js → out/WidgetInitConfig.interface.js} +0 -0
- /package/{WidgetType.d.ts → out/WidgetType.d.ts} +0 -0
- /package/{WidgetType.js → out/WidgetType.js} +0 -0
- /package/{action → out/action}/type.d.ts +0 -0
- /package/{action → out/action}/type.js +0 -0
- /package/{async → out/async}/createAsyncIterator.d.ts +0 -0
- /package/{async → out/async}/createAsyncIterator.js +0 -0
- /package/{async → out/async}/debounce.d.ts +0 -0
- /package/{async → out/async}/debounce.js +0 -0
- /package/{async → out/async}/timeout.d.ts +0 -0
- /package/{async → out/async}/timeout.js +0 -0
- /package/{component-manifest → out/component-manifest}/ComponentManifest.interface.d.ts +0 -0
- /package/{component-manifest → out/component-manifest}/ComponentManifest.interface.js +0 -0
- /package/{component-manifest → out/component-manifest}/ContextMenuManifest.interface.d.ts +0 -0
- /package/{component-manifest → out/component-manifest}/ContextMenuManifest.interface.js +0 -0
- /package/{component-manifest → out/component-manifest}/DisplayCondition.interface.d.ts +0 -0
- /package/{component-manifest → out/component-manifest}/DisplayCondition.interface.js +0 -0
- /package/{component-manifest → out/component-manifest}/FloatingControlManifest.interface.d.ts +0 -0
- /package/{component-manifest → out/component-manifest}/FloatingControlManifest.interface.js +0 -0
- /package/{component-manifest → out/component-manifest}/PropPathCondition.interface.d.ts +0 -0
- /package/{component-manifest → out/component-manifest}/PropPathCondition.interface.js +0 -0
- /package/{component-manifest → out/component-manifest}/PropertyPaneManifest.interface.d.ts +0 -0
- /package/{component-manifest → out/component-manifest}/PropertyPaneManifest.interface.js +0 -0
- /package/{converter → out/converter}/time/TimeUnit.d.ts +0 -0
- /package/{converter → out/converter}/time/TimeUnit.js +0 -0
- /package/{converter → out/converter}/time/TimerConverter.d.ts +0 -0
- /package/{converter → out/converter}/time/TimerConverter.js +0 -0
- /package/{document → out/document}/ComponentInsertType.d.ts +0 -0
- /package/{document → out/document}/ComponentInsertType.js +0 -0
- /package/{document → out/document}/Document.interface.d.ts +0 -0
- /package/{document → out/document}/Document.interface.js +0 -0
- /package/{document → out/document}/DocumentCssVarsReplace.d.ts +0 -0
- /package/{document → out/document}/DocumentCssVarsReplace.js +0 -0
- /package/{document → out/document}/DocumentUtils.d.ts +0 -0
- /package/{document → out/document}/DocumentUtils.js +0 -0
- /package/{document → out/document}/hidden-fields.interface.d.ts +0 -0
- /package/{document → out/document}/hidden-fields.interface.js +0 -0
- /package/{dom → out/dom}/ViewportSize.d.ts +0 -0
- /package/{dom → out/dom}/ViewportSize.js +0 -0
- /package/{dom → out/dom}/copyToClipboard.d.ts +0 -0
- /package/{dom → out/dom}/copyToClipboard.js +0 -0
- /package/{dom → out/dom}/getMostNestedNode.d.ts +0 -0
- /package/{dom → out/dom}/getMostNestedNode.js +0 -0
- /package/{dom → out/dom}/insertHtmlIntoElement.d.ts +0 -0
- /package/{dom → out/dom}/insertHtmlIntoElement.js +0 -0
- /package/{dom → out/dom}/sanitizeHTML.d.ts +0 -0
- /package/{dom → out/dom}/sanitizeHTML.js +0 -0
- /package/{element → out/element}/BaseElementInViewportHandler.d.ts +0 -0
- /package/{element → out/element}/BaseElementInViewportHandler.js +0 -0
- /package/{element → out/element}/CssVarsOperations.d.ts +0 -0
- /package/{element → out/element}/CssVarsOperations.js +0 -0
- /package/{element → out/element}/ThemeCssVars.d.ts +0 -0
- /package/{element → out/element}/ThemeCssVars.js +0 -0
- /package/{element → out/element}/recursiveFindParentNodeByAttribute.d.ts +0 -0
- /package/{element → out/element}/recursiveFindParentNodeByAttribute.js +0 -0
- /package/{flat.d.ts → out/flat.d.ts} +0 -0
- /package/{flat.js → out/flat.js} +0 -0
- /package/{handler → out/handler}/HandlerTypes.d.ts +0 -0
- /package/{handler → out/handler}/HandlerTypes.js +0 -0
- /package/{math → out/math}/RandomDistributor.d.ts +0 -0
- /package/{math → out/math}/RandomDistributor.js +0 -0
- /package/{math → out/math}/sum.d.ts +0 -0
- /package/{math → out/math}/sum.js +0 -0
- /package/{network → out/network}/HttpClient.d.ts +0 -0
- /package/{network → out/network}/HttpClient.js +0 -0
- /package/{network → out/network}/HttpStatus.d.ts +0 -0
- /package/{network → out/network}/HttpStatus.js +0 -0
- /package/{object → out/object}/isDictionary.d.ts +0 -0
- /package/{object → out/object}/isDictionary.js +0 -0
- /package/{object → out/object}/omitKeys.d.ts +0 -0
- /package/{object → out/object}/omitKeys.js +0 -0
- /package/{storage → out/storage}/BaseCachingStorage.d.ts +0 -0
- /package/{storage → out/storage}/BaseCachingStorage.js +0 -0
- /package/{storage → out/storage}/CachingCookieStorage.d.ts +0 -0
- /package/{storage → out/storage}/CachingCookieStorage.js +0 -0
- /package/{storage → out/storage}/CachingLocalStorage.d.ts +0 -0
- /package/{storage → out/storage}/CachingLocalStorage.js +0 -0
- /package/{storage → out/storage}/getCookie.d.ts +0 -0
- /package/{storage → out/storage}/getCookie.js +0 -0
- /package/{storage → out/storage}/setCookie.d.ts +0 -0
- /package/{storage → out/storage}/setCookie.js +0 -0
- /package/{theme → out/theme}/theme.utils.d.ts +0 -0
- /package/{theme → out/theme}/theme.utils.js +0 -0
- /package/{url → out/url}/sanitizeUrl.d.ts +0 -0
- /package/{url → out/url}/sanitizeUrl.js +0 -0
- /package/{utils → out/utils}/CaseTransformer.d.ts +0 -0
- /package/{utils → out/utils}/CaseTransformer.js +0 -0
- /package/{utils → out/utils}/NullishCoalescingOperator.d.ts +0 -0
- /package/{utils → out/utils}/NullishCoalescingOperator.js +0 -0
- /package/{utils → out/utils}/NumericDecline.d.ts +0 -0
- /package/{utils → out/utils}/NumericDecline.js +0 -0
- /package/{utils → out/utils}/addEventListener.d.ts +0 -0
- /package/{utils → out/utils}/addEventListener.js +0 -0
- /package/{utils → out/utils}/allSettled.d.ts +0 -0
- /package/{utils → out/utils}/allSettled.js +0 -0
- /package/{utils → out/utils}/checkTimeZone.d.ts +0 -0
- /package/{utils → out/utils}/checkTimeZone.js +0 -0
- /package/{utils → out/utils}/deviceUtils.d.ts +0 -0
- /package/{utils → out/utils}/deviceUtils.js +0 -0
- /package/{utils → out/utils}/flatMap.d.ts +0 -0
- /package/{utils → out/utils}/flatMap.js +0 -0
- /package/{utils → out/utils}/fromEntries.d.ts +0 -0
- /package/{utils → out/utils}/fromEntries.js +0 -0
- /package/{utils → out/utils}/generateRandomNumber.d.ts +0 -0
- /package/{utils → out/utils}/generateRandomNumber.js +0 -0
- /package/{utils → out/utils}/objectSort.d.ts +0 -0
- /package/{utils → out/utils}/objectSort.js +0 -0
- /package/{utils → out/utils}/orientationUtils.d.ts +0 -0
- /package/{utils → out/utils}/orientationUtils.js +0 -0
- /package/{velocity → out/velocity}/SysVelocityContext.d.ts +0 -0
- /package/{velocity → out/velocity}/SysVelocityContext.js +0 -0
- /package/{velocity → out/velocity}/SysVelocityRenderer.d.ts +0 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
type NumberLike = number | string;
|
|
2
|
+
|
|
3
|
+
export interface SysVelocityContextI {
|
|
4
|
+
mathTool: {
|
|
5
|
+
add: (a: NumberLike, b: NumberLike) => number;
|
|
6
|
+
sub: (a: NumberLike, b: NumberLike) => number;
|
|
7
|
+
mul: (a: NumberLike, b: NumberLike) => number;
|
|
8
|
+
div: (a: NumberLike, b: NumberLike) => number;
|
|
9
|
+
};
|
|
10
|
+
stringTool: {
|
|
11
|
+
equalsIgnoreCase: (a: string, b: string) => boolean;
|
|
12
|
+
};
|
|
13
|
+
numberTool: {
|
|
14
|
+
integer: (a: NumberLike) => number;
|
|
15
|
+
format: (f: string | null, v: NumberLike) => string;
|
|
16
|
+
number: (v: NumberLike, separator?: string, precision?: number) => string;
|
|
17
|
+
};
|
|
18
|
+
dateTool: {
|
|
19
|
+
currentDate: (format?: string) => string | number;
|
|
20
|
+
currentTimeStamp: () => number;
|
|
21
|
+
formatDate: (format: string | null, date: Date | string | number) => string | number;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default class SysVelocityContext {
|
|
26
|
+
|
|
27
|
+
create(): SysVelocityContextI {
|
|
28
|
+
return {
|
|
29
|
+
mathTool: {
|
|
30
|
+
add: function(a: NumberLike, b: NumberLike): number {
|
|
31
|
+
return Number(a) + Number(b);
|
|
32
|
+
},
|
|
33
|
+
sub: function(a: NumberLike, b: NumberLike): number {
|
|
34
|
+
return (a as number) - (b as number);
|
|
35
|
+
},
|
|
36
|
+
mul: function(a: NumberLike, b: NumberLike): number {
|
|
37
|
+
return (a as number) * (b as number);
|
|
38
|
+
},
|
|
39
|
+
div: function(a: NumberLike, b: NumberLike): number {
|
|
40
|
+
return (a as number) / (b as number);
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
stringTool: {
|
|
44
|
+
equalsIgnoreCase: function(a: string, b: string): boolean {
|
|
45
|
+
return String(a).toLowerCase() === String(b).toLowerCase();
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
numberTool: {
|
|
49
|
+
integer: function(a: NumberLike): number {
|
|
50
|
+
return Math.floor(a as number);
|
|
51
|
+
},
|
|
52
|
+
format: function(f: string | null, v: NumberLike): string {
|
|
53
|
+
const precision = (f || '').split('.')[1];
|
|
54
|
+
return Number(v).toFixed((precision || '').length);
|
|
55
|
+
},
|
|
56
|
+
number: function(v: NumberLike, separator: string = ',', precision: number = 3): string {
|
|
57
|
+
return Number(v)
|
|
58
|
+
.toFixed(precision)
|
|
59
|
+
.replace(new RegExp(`[.]0{${precision}}`), '')
|
|
60
|
+
.split('.')
|
|
61
|
+
.map((item: string, i: number) => {
|
|
62
|
+
if (i === 0) {
|
|
63
|
+
return item
|
|
64
|
+
.split('')
|
|
65
|
+
.reverse()
|
|
66
|
+
.join('')
|
|
67
|
+
.split('')
|
|
68
|
+
.map((char: string, i: number) => {
|
|
69
|
+
if (i % 3 === 0 && i !== 0) {
|
|
70
|
+
char += separator;
|
|
71
|
+
return char;
|
|
72
|
+
}
|
|
73
|
+
return char;
|
|
74
|
+
})
|
|
75
|
+
.reverse()
|
|
76
|
+
.join('');
|
|
77
|
+
} else if (i === 1) {
|
|
78
|
+
return item;
|
|
79
|
+
}
|
|
80
|
+
return undefined;
|
|
81
|
+
})
|
|
82
|
+
.join('.');
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
dateTool: {
|
|
86
|
+
currentDate: function(format?: string): string | number {
|
|
87
|
+
return this.formatDate(format || 'ISO', new Date());
|
|
88
|
+
},
|
|
89
|
+
currentTimeStamp: function(): number {
|
|
90
|
+
return this.formatDate(null, new Date()) as number;
|
|
91
|
+
},
|
|
92
|
+
formatDate: function(format: string | null, date: Date | string | number): string | number {
|
|
93
|
+
const formatNumberLess10 = (number: number): string => number < 9 ? `0${number}` : `${number}`;
|
|
94
|
+
const dateObject = new Date(date);
|
|
95
|
+
if (dateObject.toString() === 'Invalid Date') {
|
|
96
|
+
return date as string;
|
|
97
|
+
}
|
|
98
|
+
if (format === 'ISO') {
|
|
99
|
+
return dateObject.toISOString();
|
|
100
|
+
}
|
|
101
|
+
if (!format || typeof format !== 'string') {
|
|
102
|
+
return dateObject.getTime();
|
|
103
|
+
}
|
|
104
|
+
const parsedFormat = format.split(' ');
|
|
105
|
+
let result = '';
|
|
106
|
+
parsedFormat.forEach((piece: string) => {
|
|
107
|
+
const upperPiece = piece.toUpperCase();
|
|
108
|
+
result = result.length === 0 ? result : result + ' ';
|
|
109
|
+
if (upperPiece.includes('HH')) {
|
|
110
|
+
result += upperPiece
|
|
111
|
+
.replace('HH', formatNumberLess10(dateObject.getHours()))
|
|
112
|
+
.replace('MM', formatNumberLess10(dateObject.getMinutes()))
|
|
113
|
+
.replace('SS', formatNumberLess10(dateObject.getSeconds()))
|
|
114
|
+
}
|
|
115
|
+
if (upperPiece.includes('YYYY') || upperPiece.includes('DD')) {
|
|
116
|
+
result += upperPiece
|
|
117
|
+
.replace('YYYY', String(dateObject.getFullYear()))
|
|
118
|
+
.replace('DD', formatNumberLess10(dateObject.getDate()))
|
|
119
|
+
.replace('MM', formatNumberLess10(dateObject.getMonth() + 1));
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import SysVelocityRenderer from "./SysVelocityRenderer";
|
|
2
|
+
import SysVelocityContext from "./SysVelocityContext";
|
|
3
|
+
|
|
4
|
+
describe('SysVelocityRenderer', function () {
|
|
5
|
+
const baseCtx = new SysVelocityContext().create();
|
|
6
|
+
const instance = new SysVelocityRenderer();
|
|
7
|
+
|
|
8
|
+
const context = {
|
|
9
|
+
"FIRSTNAME": "Kate",
|
|
10
|
+
"nestedObject": {
|
|
11
|
+
"prop1": "value1"
|
|
12
|
+
},
|
|
13
|
+
"array": [
|
|
14
|
+
{
|
|
15
|
+
"el": 1
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"el": 2
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
};
|
|
22
|
+
const render = (template: string) => instance.render(template, {...baseCtx, data: context});
|
|
23
|
+
|
|
24
|
+
it('should support syntax', function () {
|
|
25
|
+
|
|
26
|
+
expect(render('$data.get("FIRSTNAME")')).toEqual("Kate");
|
|
27
|
+
expect(render('$data.get("nestedObject").get("prop1")')).toEqual("value1");
|
|
28
|
+
expect(render('$data.nestedObject.prop1')).toEqual("value1");
|
|
29
|
+
expect(render('#foreach($item in $!data.get(\'array\'))$item.el#end')).toEqual("12");
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('should have sys ctx', function () {
|
|
33
|
+
|
|
34
|
+
expect(render('$mathTool.add(1,1)')).toEqual("2");
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
import * as Velocity from 'velocityjs';
|
|
3
|
+
import SysVelocityContext from "./SysVelocityContext";
|
|
4
|
+
|
|
5
|
+
const sysCtx = new SysVelocityContext().create();
|
|
6
|
+
|
|
7
|
+
export default class SysVelocityRenderer {
|
|
8
|
+
render(template: string, context: Record<string, any>): string {
|
|
9
|
+
return Velocity.render(template, {...sysCtx, ...context});
|
|
10
|
+
}
|
|
11
|
+
}
|