@idevs/corelib 0.0.37 → 0.0.39
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/dist/editors/dateMonthEditor.d.ts +0 -1
- package/dist/editors/dateMonthEditor.js +2 -9
- package/dist/editors/dateMonthEditor.js.map +1 -1
- package/dist/formatters/formatters.d.ts +5 -0
- package/dist/formatters/formatters.js +21 -0
- package/dist/formatters/formatters.js.map +1 -1
- package/package.json +1 -1
- package/src/editors/dateMonthEditor.ts +2 -12
- package/src/formatters/formatters.ts +19 -0
|
@@ -23,17 +23,10 @@ let DateMonthEditor = class DateMonthEditor extends SelectEditor {
|
|
|
23
23
|
this.months = [];
|
|
24
24
|
const locale = (_a = opt.locale) !== null && _a !== void 0 ? _a : 'en';
|
|
25
25
|
const options = { month: (_b = opt.display) !== null && _b !== void 0 ? _b : '2-digit' };
|
|
26
|
-
for (let i =
|
|
26
|
+
for (let i = 0; i <= 11; i++) {
|
|
27
27
|
this.months.push(new Date(2000, i, 1).toLocaleDateString(locale, options));
|
|
28
28
|
}
|
|
29
|
-
|
|
30
|
-
return this.months;
|
|
31
|
-
}
|
|
32
|
-
const months = [];
|
|
33
|
-
for (let i1 = 0; i1 <= 11; i1++) {
|
|
34
|
-
months.push(new Date(2000, i1, 1).toLocaleDateString(locale, options));
|
|
35
|
-
}
|
|
36
|
-
return months;
|
|
29
|
+
return this.months;
|
|
37
30
|
}
|
|
38
31
|
};
|
|
39
32
|
DateMonthEditor = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dateMonthEditor.js","sourceRoot":"","sources":["../../src/editors/dateMonthEditor.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAuB,MAAM,sBAAsB,CAAA;AACpF,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AAGzC,IAAM,eAAe,GAArB,MAAM,eAAgB,SAAQ,YAAY;IAG/C,Y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,QAAQ;;QACN,MAAM,GAAG,GAAG,IAAI,CAAC,OAAiC,CAAA;QAElD,IAAI,GAAG,CAAC,KAAK,IAAI,IAAI,IAAI,GAAG,CAAC,KAAK,CAAC,MAAM,IAAI,CAAC,EAAE;YAC9C,OAAO,GAAG,CAAC,KAAK,CAAA;SACjB;QAED,IAAI,CAAC,MAAM,GAAG,EAAE,CAAA;QAChB,MAAM,MAAM,GAAG,MAAA,GAAG,CAAC,MAAM,mCAAI,IAAI,CAAA;QACjC,MAAM,OAAO,GAAG,EAAE,KAAK,EAAE,MAAA,GAAG,CAAC,OAAO,mCAAI,SAAS,EAAE,CAAA;QAEnD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE;YAC5B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;SAC3E;QAED,OAAO,IAAI,CAAC,MAAM,CAAA;IACpB,CAAC;CACF,CAAA;AA9BY,eAAe;IAD3B,UAAU,CAAC,cAAc,CAAC,iBAAiB,CAAC;GAChC,eAAe,CA8B3B;SA9BY,eAAe","sourcesContent":["import { Decorators, SelectEditor, SelectEditorOptions } from '@serenity-is/corelib'\nimport { indexOf } from '@serenity-is/corelib/q'\n\n@Decorators.registerEditor('DateMonthEditor')\nexport class DateMonthEditor extends SelectEditor {\n private months: string[]\n\n constructor(hidden: JQuery, opt: DateMonthEditorOptions) {\n super(hidden, opt)\n\n this.updateItems()\n }\n\n get valueAsMonth() {\n return indexOf(this.months, x => x == this.value)\n }\n\n getItems() {\n const opt = this.options as DateMonthEditorOptions\n\n if (opt.items != null && opt.items.length >= 1) {\n return opt.items\n }\n\n this.months = []\n const locale = opt.locale ?? 'en'\n const options = { month: opt.display ?? '2-digit' }\n\n for (let i = 0; i <= 11; i++) {\n this.months.push(new Date(2000, i, 1).toLocaleDateString(locale, options))\n }\n\n return this.months\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface DateMonthEditorOptions extends SelectEditorOptions {\n display?: '2-digit' | 'short' | 'long'\n locale?: 'en' | 'th'\n}\n"]}
|
|
@@ -20,6 +20,11 @@ export declare class LookupFormatter implements Formatter {
|
|
|
20
20
|
lookupKey: string;
|
|
21
21
|
format(ctx: FormatterContext): string;
|
|
22
22
|
}
|
|
23
|
+
export declare class DateMonthFormatter implements Formatter {
|
|
24
|
+
display: '2-digit' | 'short' | 'long';
|
|
25
|
+
locale: 'en' | 'th';
|
|
26
|
+
format(ctx: FormatterContext): string;
|
|
27
|
+
}
|
|
23
28
|
export declare class idevsFormatters {
|
|
24
29
|
static load(): void;
|
|
25
30
|
}
|
|
@@ -95,6 +95,27 @@ LookupFormatter = __decorate([
|
|
|
95
95
|
Decorators.registerFormatter('Idevs.LookupFormatter')
|
|
96
96
|
], LookupFormatter);
|
|
97
97
|
export { LookupFormatter };
|
|
98
|
+
let DateMonthFormatter = class DateMonthFormatter {
|
|
99
|
+
format(ctx) {
|
|
100
|
+
var _a, _b;
|
|
101
|
+
const src = ctx.value;
|
|
102
|
+
if (!src)
|
|
103
|
+
return '';
|
|
104
|
+
const locale = (_a = this.locale) !== null && _a !== void 0 ? _a : 'en';
|
|
105
|
+
const options = { month: (_b = this.display) !== null && _b !== void 0 ? _b : '2-digit' };
|
|
106
|
+
return new Date(2000, src - 1, 1).toLocaleDateString(locale, options);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
__decorate([
|
|
110
|
+
Decorators.option()
|
|
111
|
+
], DateMonthFormatter.prototype, "display", void 0);
|
|
112
|
+
__decorate([
|
|
113
|
+
Decorators.option()
|
|
114
|
+
], DateMonthFormatter.prototype, "locale", void 0);
|
|
115
|
+
DateMonthFormatter = __decorate([
|
|
116
|
+
Decorators.registerFormatter('Idevs.DateMonthFormatter')
|
|
117
|
+
], DateMonthFormatter);
|
|
118
|
+
export { DateMonthFormatter };
|
|
98
119
|
export class idevsFormatters {
|
|
99
120
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
100
121
|
static load() { }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatters.js","sourceRoot":"","sources":["../../src/formatters/formatters.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAEjD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAOvD,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAC/B;QACE,IAAI,CAAC,WAAW,GAAG,EAAE,CAAA;IACvB,CAAC;IAKD,MAAM,CAAC,GAAqB;QAC1B,MAAM,GAAG,GAAG,GAAG,CAAC,KAAe,CAAA;QAE/B,MAAM,KAAK,GAAG,UAAU,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAA;QAC7D,IAAI,KAAK,IAAI,CAAC,EAAE;YACd,OAAO,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;SACpC;QAED,OAAO,UAAU,CAAC,GAAG,CAAC,CAAA;IACxB,CAAC;CACF,CAAA;AAZC;IADC,UAAU,CAAC,MAAM,EAAE;yDACM;AANf,oBAAoB;IADhC,UAAU,CAAC,iBAAiB,CAAC,4BAA4B,CAAC;GAC9C,oBAAoB,CAkBhC;SAlBY,oBAAoB;AAqB1B,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAC5B;QACE,IAAI,CAAC,QAAQ,GAAG,8BAA8B,CAAA;QAC9C,IAAI,CAAC,QAAQ,GAAG,GAAG,CAAA;QACnB,IAAI,CAAC,SAAS,GAAG,GAAG,CAAA;QACpB,IAAI,CAAC,aAAa,GAAG,iCAAiC,CAAA;QACtD,IAAI,CAAC,cAAc,GAAG,gCAAgC,CAAA;IACxD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GAAG,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACvE,CAAC;CACF,CAAA;AAdC;IADC,UAAU,CAAC,MAAM,EAAE;mDACwB;AAG5C;IADC,UAAU,CAAC,MAAM,EAAE;kDACM;AALf,kBAAkB;IAD9B,UAAU,CAAC,iBAAiB,CAAC,0BAA0B,CAAC;GAC5C,kBAAkB,CAgB9B;SAhBY,kBAAkB;AAkB/B,MAAM,OAAO,eAAe;IAC1B,gEAAgE;IACzD,MAAM,CAAC,IAAI,KAAI,CAAC;CACxB","sourcesContent":["import { Decorators } from '@serenity-is/corelib'\nimport { FormatterContext } from '@serenity-is/sleekgrid'\nimport { getLookup, htmlEncode } from '@serenity-is/corelib/q'\n\nexport type Formatter = {\n format(ctx: FormatterContext): string\n}\n\n@Decorators.registerFormatter('Idevs.ZeroDisplayFormatter')\nexport class ZeroDisplayFormatter implements Formatter {\n constructor() {\n this.displayText = ''\n }\n\n @Decorators.option()\n public displayText: string\n\n format(ctx: FormatterContext): string {\n const src = ctx.value as string\n\n const value = parseFloat(String(src || '0').replace(',', ''))\n if (value == 0) {\n return htmlEncode(this.displayText)\n }\n\n return htmlEncode(src)\n }\n}\n\n@Decorators.registerFormatter('Idevs.CheckboxFormatter')\nexport class CheckboxFormatter implements Formatter {\n constructor() {\n this.cssClass = 'text-center fs-2 text-gray-1'\n this.trueText = '1'\n this.falseText = '0'\n this.trueValueIcon = 'mdi mdi-checkbox-marked-outline'\n this.falseValueIcon = 'mdi mdi-checkbox-blank-outline'\n }\n\n @Decorators.option()\n public trueText: string\n\n @Decorators.option()\n public falseText: string\n\n @Decorators.option()\n public cssClass: string\n\n @Decorators.option()\n public trueValueIcon: string\n\n @Decorators.option()\n public falseValueIcon: string\n\n format(ctx: FormatterContext): string {\n const src = ctx.value as string\n if (src == this.trueText) {\n return `<i class=\"${this.trueValueIcon} ${this.cssClass}\"></i>`\n } else if (src == this.falseText) {\n return `<i class=\"${this.falseValueIcon} ${this.cssClass}\"></i>`\n } else {\n return htmlEncode(src)\n }\n }\n}\n\n@Decorators.registerFormatter('Idevs.LookupFormatter')\nexport class LookupFormatter implements Formatter {\n @Decorators.option()\n public lookupKey: string\n\n format(ctx: FormatterContext): string {\n const src = ctx.value as string\n if (!src) return ''\n\n if (!this.lookupKey) return src\n\n const lookup = getLookup(this.lookupKey)\n const items = lookup.items\n const idField = lookup.idField\n const textField = lookup.textField\n const idList = src.split(',')\n\n return idList\n .map(x => {\n const g = items.find(i => i[idField] == x)\n if (!g) return x\n\n return htmlEncode(g[textField])\n })\n .join(', ')\n }\n}\n\n@Decorators.registerFormatter('Idevs.DateMonthFormatter')\nexport class DateMonthFormatter implements Formatter {\n @Decorators.option()\n public display: '2-digit' | 'short' | 'long'\n\n @Decorators.option()\n public locale: 'en' | 'th'\n\n format(ctx: FormatterContext): string {\n const src = ctx.value as number\n if (!src) return ''\n\n const locale = this.locale ?? 'en'\n const options = { month: this.display ?? '2-digit' }\n\n return new Date(2000, src - 1, 1).toLocaleDateString(locale, options)\n }\n}\n\nexport class idevsFormatters {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n public static load() {}\n}\n"]}
|
package/package.json
CHANGED
|
@@ -26,20 +26,11 @@ export class DateMonthEditor extends SelectEditor {
|
|
|
26
26
|
const locale = opt.locale ?? 'en'
|
|
27
27
|
const options = { month: opt.display ?? '2-digit' }
|
|
28
28
|
|
|
29
|
-
for (let i =
|
|
29
|
+
for (let i = 0; i <= 11; i++) {
|
|
30
30
|
this.months.push(new Date(2000, i, 1).toLocaleDateString(locale, options))
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
return this.months
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const months: string[] = []
|
|
38
|
-
for (let i1 = 0; i1 <= 11; i1++) {
|
|
39
|
-
months.push(new Date(2000, i1, 1).toLocaleDateString(locale, options))
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return months
|
|
33
|
+
return this.months
|
|
43
34
|
}
|
|
44
35
|
}
|
|
45
36
|
|
|
@@ -47,5 +38,4 @@ export class DateMonthEditor extends SelectEditor {
|
|
|
47
38
|
export interface DateMonthEditorOptions extends SelectEditorOptions {
|
|
48
39
|
display?: '2-digit' | 'short' | 'long'
|
|
49
40
|
locale?: 'en' | 'th'
|
|
50
|
-
descending?: boolean
|
|
51
41
|
}
|
|
@@ -92,6 +92,25 @@ export class LookupFormatter implements Formatter {
|
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
+
@Decorators.registerFormatter('Idevs.DateMonthFormatter')
|
|
96
|
+
export class DateMonthFormatter implements Formatter {
|
|
97
|
+
@Decorators.option()
|
|
98
|
+
public display: '2-digit' | 'short' | 'long'
|
|
99
|
+
|
|
100
|
+
@Decorators.option()
|
|
101
|
+
public locale: 'en' | 'th'
|
|
102
|
+
|
|
103
|
+
format(ctx: FormatterContext): string {
|
|
104
|
+
const src = ctx.value as number
|
|
105
|
+
if (!src) return ''
|
|
106
|
+
|
|
107
|
+
const locale = this.locale ?? 'en'
|
|
108
|
+
const options = { month: this.display ?? '2-digit' }
|
|
109
|
+
|
|
110
|
+
return new Date(2000, src - 1, 1).toLocaleDateString(locale, options)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
95
114
|
export class idevsFormatters {
|
|
96
115
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
97
116
|
public static load() {}
|