@idevs/corelib 0.0.38 → 0.0.40

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.
@@ -8,5 +8,4 @@ export declare class DateMonthEditor extends SelectEditor {
8
8
  export interface DateMonthEditorOptions extends SelectEditorOptions {
9
9
  display?: '2-digit' | 'short' | 'long';
10
10
  locale?: 'en' | 'th';
11
- descending?: boolean;
12
11
  }
@@ -15,7 +15,7 @@ let DateMonthEditor = class DateMonthEditor extends SelectEditor {
15
15
  return indexOf(this.months, x => x == this.value);
16
16
  }
17
17
  getItems() {
18
- var _a, _b, _c;
18
+ var _a, _b;
19
19
  const opt = this.options;
20
20
  if (opt.items != null && opt.items.length >= 1) {
21
21
  return opt.items;
@@ -26,14 +26,7 @@ let DateMonthEditor = class DateMonthEditor extends SelectEditor {
26
26
  for (let i = 0; i <= 11; i++) {
27
27
  this.months.push(new Date(2000, i, 1).toLocaleDateString(locale, options));
28
28
  }
29
- if (!((_c = opt.descending) !== null && _c !== void 0 ? _c : false)) {
30
- return this.months;
31
- }
32
- const months = [];
33
- for (let i1 = 11; i1 >= 0; 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,YAAY,MAAc,EAAE,GAA2B;QACrD,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;QAElB,IAAI,CAAC,WAAW,EAAE,CAAA;IACpB,CAAC;IAED,IAAI,Y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CAAC,cAAc,CAAC,iBAAiB,CAAC;GAChC,eAAe,CAuC3B;SAvCY,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 if (!(opt.descending ?? false)) {\n return this.months\n }\n\n const months: string[] = []\n for (let i1 = 11; i1 >= 0; i1--) {\n months.push(new Date(2000, i1, 1).toLocaleDateString(locale, options))\n }\n\n return 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 descending?: boolean\n}\n"]}
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,YAAY,MAAc,EAAE,GAA2B;QACrD,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;QAElB,IAAI,CAAC,WAAW,EAAE,CAAA;IACpB,CAAC;IAED,IAAI,YAAY;QACd,OAAO,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAA;IACnD,CAAC;IAED,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":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C,CAAA;YAC1C,IAAI,CAAC,CAAC;gBAAE,OAAO,CAAC,CAAA;YAEhB,OAAO,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAA;QACjC,CAAC,CAAC;aACD,IAAI,CAAC,IAAI,CAAC,CAAA;IACf,CAAC;CACF,CAAA;AAvBC;IADC,UAAU,CAAC,MAAM,EAAE;kDACI;AAFb,eAAe;IAD3B,UAAU,CAAC,iBAAiB,CAAC,uBAAuB,CAAC;GACzC,eAAe,CAyB3B;SAzBY,eAAe;AA2B5B,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\nexport class idevsFormatters {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n public static load() {}\n}\n"]}
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,C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,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"]}
@@ -0,0 +1,49 @@
1
+ /// <reference types="jquery" />
2
+ export type DropdownToolButtonOptions = {
3
+ title?: string;
4
+ cssClass?: string;
5
+ icon?: string;
6
+ disabled?: boolean;
7
+ dropdownMenuPosition?: 'right';
8
+ isDropUp?: boolean;
9
+ };
10
+ export type DropdownToolButtonItem = {
11
+ key: string;
12
+ title?: string;
13
+ hint?: string;
14
+ cssClass?: string;
15
+ icon?: string;
16
+ onClick?: (e: JQuery.ClickEvent<HTMLElement, null, HTMLElement, HTMLElement>) => void;
17
+ isSeparator?: boolean;
18
+ disabled?: boolean;
19
+ isDropdownHeader?: boolean;
20
+ dropdownHeaderTitle?: string;
21
+ };
22
+ export type ToolDropdownSideButtonItem = {
23
+ key: string;
24
+ title?: string;
25
+ hint?: string;
26
+ cssClass?: string;
27
+ icon?: string;
28
+ onClick?: (e: JQuery.ClickEvent<HTMLElement, null, HTMLElement, HTMLElement>) => void;
29
+ disabled?: boolean;
30
+ };
31
+ export declare class DropdownToolButton {
32
+ element: JQuery;
33
+ private isDisabled;
34
+ private itemDisablingState;
35
+ private options;
36
+ constructor(container: JQuery, buttons: DropdownToolButtonItem[], opt?: DropdownToolButtonOptions);
37
+ private getDisablingStateItem;
38
+ private setDisablingStateItem;
39
+ private removeDisablingStateItem;
40
+ private buildBaseDropdown;
41
+ addDropdownItems(buttons: DropdownToolButtonItem[]): void;
42
+ addDropdownItem(button: DropdownToolButtonItem, idx?: number): void;
43
+ enableDropdown(enable: boolean): void;
44
+ enableDropdownItemByKey(key: string, enable: boolean): void;
45
+ enableSideButtonByKey(key: string, enable: boolean): void;
46
+ removeDropdownItem(key: string): void;
47
+ removeSideButtonItem(key: string): void;
48
+ addSideButtonItem(button: ToolDropdownSideButtonItem, idx?: number): void;
49
+ }
@@ -0,0 +1,230 @@
1
+ /// <reference types="bootstrap" />
2
+ import { coalesce, first, isEmptyOrNull, tryFirst } from '@serenity-is/corelib/q';
3
+ export class DropdownToolButton {
4
+ constructor(container, buttons, opt) {
5
+ this.element = null;
6
+ this.isDisabled = false;
7
+ this.itemDisablingState = [];
8
+ this.options = opt || {};
9
+ this.isDisabled = this.options.disabled || false;
10
+ this.element = this.buildBaseDropdown();
11
+ this.addDropdownItems(buttons);
12
+ this.element.on('click', () => {
13
+ $('.dropdown-toggle', this.element).dropdown('toggle');
14
+ });
15
+ container.append(this.element);
16
+ }
17
+ getDisablingStateItem(key) {
18
+ if (tryFirst(this.itemDisablingState, x => x.key == key) != null) {
19
+ return first(this.itemDisablingState, x => x.key == key).disabled || false;
20
+ }
21
+ return false;
22
+ }
23
+ setDisablingStateItem(key, value) {
24
+ if (tryFirst(this.itemDisablingState, x => x.key == key) != null) {
25
+ first(this.itemDisablingState, x => x.key == key).disabled = value || false;
26
+ return;
27
+ }
28
+ this.itemDisablingState.push({ key: key, disabled: value || false });
29
+ }
30
+ removeDisablingStateItem(key) {
31
+ this.itemDisablingState.some((item, idx) => {
32
+ if (item.key == key) {
33
+ this.itemDisablingState.splice(idx, 1);
34
+ return true;
35
+ }
36
+ });
37
+ }
38
+ buildBaseDropdown() {
39
+ const dropdownTemplate = `<div class="buttons-inner dropdown" style="overflow: visible">
40
+ <div class="idevs-tool-dropdown-button tool-button icon-tool-button ${coalesce(this.options.cssClass, '')} ${this.options.isDropUp ? 'dropup' : ''} ${this.isDisabled ? 'disabled' : ''}" style="cursor: unset;">
41
+ <div class="button-outer dropdown-toggle ${this.isDisabled ? 'disabled' : ''}"
42
+ data-bs-toggle="dropdown"
43
+ style="cursor: pointer;">
44
+ <span class="button-inner">
45
+ <i class="${this.options.icon}"></i>
46
+ ${coalesce(this.options.title, '')}
47
+ </span>
48
+ <i class="caret"></i>
49
+ </div>
50
+ <ul class="dropdown-menu ${this.options.dropdownMenuPosition == 'right' ? 'dropdown-menu-right' : ''}"></ul>
51
+ </div>
52
+ </div>`;
53
+ return $(dropdownTemplate);
54
+ }
55
+ addDropdownItems(buttons) {
56
+ if (buttons && buttons.length > 0) {
57
+ buttons.forEach(button => {
58
+ this.addDropdownItem(button);
59
+ });
60
+ }
61
+ }
62
+ addDropdownItem(button, idx) {
63
+ if (!isEmptyOrNull(button.key)) {
64
+ if (this.itemDisablingState.map(x => x.key).indexOf(button.key) > -1) {
65
+ alert(`Dropdown has existed key: ${button.key}`);
66
+ return;
67
+ }
68
+ this.setDisablingStateItem(button.key, button.disabled || false);
69
+ }
70
+ let dropdownItemElement;
71
+ if (button.isDropdownHeader && !isEmptyOrNull(button.dropdownHeaderTitle)) {
72
+ dropdownItemElement = $(`<li class="dropdown-header ${coalesce(button.cssClass, '')}">${button.dropdownHeaderTitle}</li>`);
73
+ }
74
+ else {
75
+ if (button.isSeparator) {
76
+ dropdownItemElement = $(`<li class="dropdown-divider"></li>`);
77
+ }
78
+ else {
79
+ dropdownItemElement = $(`<li class="${button.disabled ? 'disabled' : ''}"
80
+ title="${coalesce(button.hint, '')}"
81
+ data-idevs-key="${coalesce(button.key, '')}">
82
+ <a href="#" class="${coalesce(button.cssClass, 'dropdown-item')}">
83
+ <i class="${coalesce(button.icon, '')}"></i>
84
+ ${button.title}
85
+ </a>
86
+ </li>`);
87
+ dropdownItemElement.on('click', (e) => {
88
+ e.preventDefault();
89
+ if (this.isDisabled) {
90
+ return;
91
+ }
92
+ let buttonIsDisabled = button.disabled;
93
+ if (!isEmptyOrNull(button.key)) {
94
+ buttonIsDisabled = this.getDisablingStateItem(button.key);
95
+ }
96
+ if (buttonIsDisabled) {
97
+ return;
98
+ }
99
+ button.onClick(e);
100
+ });
101
+ }
102
+ }
103
+ if (idx === null || typeof idx === 'undefined') {
104
+ this.element.find('.dropdown-menu').append(dropdownItemElement);
105
+ return;
106
+ }
107
+ if (idx <= 0) {
108
+ this.element.find('.dropdown-menu').prepend(dropdownItemElement);
109
+ return;
110
+ }
111
+ const nbrOfButtons = this.element.find(`.dropdown-menu > li`).length;
112
+ if (idx > nbrOfButtons) {
113
+ idx = nbrOfButtons;
114
+ }
115
+ this.element.find(`.dropdown-menu > li:nth-child(${idx})`).after(dropdownItemElement);
116
+ }
117
+ enableDropdown(enable) {
118
+ const drd = this.element.find('.dropdown').first();
119
+ if (drd) {
120
+ if (enable) {
121
+ if (drd.hasClass('disabled')) {
122
+ drd.removeClass('disabled');
123
+ }
124
+ }
125
+ else {
126
+ if (!drd.hasClass('disabled')) {
127
+ drd.addClass('disabled');
128
+ }
129
+ }
130
+ }
131
+ const drdToggle = this.element.find('.dropdown-toggle').first();
132
+ if (drdToggle) {
133
+ if (enable) {
134
+ if (drdToggle.hasClass('disabled')) {
135
+ drd.removeClass('disabled');
136
+ }
137
+ else {
138
+ if (!drdToggle.hasClass('disabled')) {
139
+ drdToggle.addClass('disabled');
140
+ }
141
+ }
142
+ }
143
+ }
144
+ this.isDisabled = !enable;
145
+ }
146
+ enableDropdownItemByKey(key, enable) {
147
+ const drdItem = this.element.find(`.dropdown-menu li[data-idevs-key="${key}"]`).first();
148
+ if (drdItem) {
149
+ if (enable) {
150
+ if (drdItem.hasClass('disabled')) {
151
+ drdItem.removeClass('disabled');
152
+ }
153
+ }
154
+ else {
155
+ if (!drdItem.hasClass('disabled')) {
156
+ drdItem.addClass('disabled');
157
+ }
158
+ }
159
+ }
160
+ this.setDisablingStateItem(key, !enable);
161
+ }
162
+ enableSideButtonByKey(key, enable) {
163
+ const tButton = this.element.find(`.tool-button[data-idevs-key="${key}"]`).first();
164
+ if (tButton) {
165
+ if (enable) {
166
+ if (tButton.hasClass('disabled')) {
167
+ tButton.removeClass('disabled');
168
+ }
169
+ }
170
+ else {
171
+ if (!tButton.hasClass('disabled')) {
172
+ tButton.addClass('disabled');
173
+ }
174
+ }
175
+ }
176
+ this.setDisablingStateItem(key, !enable);
177
+ }
178
+ removeDropdownItem(key) {
179
+ this.element.find(`.dropdown-menu li[data-idevs-key="${key}"]`).remove();
180
+ this.removeDisablingStateItem(key);
181
+ }
182
+ removeSideButtonItem(key) {
183
+ this.element.find(`.tool-button[data-idevs-key="${key}"]`).remove();
184
+ this.removeDisablingStateItem(key);
185
+ }
186
+ addSideButtonItem(button, idx) {
187
+ if (!isEmptyOrNull(button.key)) {
188
+ if (this.itemDisablingState.map(x => x.key).indexOf(button.key) > -1) {
189
+ alert(`Dropdown has existed key: ${button.key}`);
190
+ return;
191
+ }
192
+ this.setDisablingStateItem(button.key, button.disabled || false);
193
+ }
194
+ const sideButtonTemplate = `<div class="tool-button add-button icon-tool-button ${coalesce(button.cssClass, '')} ${button.disabled ? 'disabled' : ''}"
195
+ data-idevs-key="${coalesce(button.key, '')}"
196
+ title="${coalesce(button.title, '')}">
197
+ <div class="button-outer">
198
+ <span class="button-inner">
199
+ <i class="${coalesce(button.icon, '')}"></i>
200
+ </span>
201
+ </div>
202
+ </div>`;
203
+ const sideButton = $(sideButtonTemplate);
204
+ sideButton.on('click', (e) => {
205
+ e.preventDefault();
206
+ let buttonIsDisabled = button.disabled;
207
+ if (!isEmptyOrNull(button.key)) {
208
+ buttonIsDisabled = this.getDisablingStateItem(button.key);
209
+ }
210
+ if (buttonIsDisabled) {
211
+ return;
212
+ }
213
+ button.onClick(e);
214
+ });
215
+ if (idx === null || typeof idx === 'undefined') {
216
+ this.element.append(sideButton);
217
+ return;
218
+ }
219
+ if (idx <= 0) {
220
+ this.element.prepend(sideButton);
221
+ return;
222
+ }
223
+ const nbrOfButtons = this.element.find(`div.tool-button`).length;
224
+ if (idx > nbrOfButtons) {
225
+ idx = nbrOfButtons;
226
+ }
227
+ this.element.find(`div.tool-button:nth-child(${idx})`).after(sideButton);
228
+ }
229
+ }
230
+ //# sourceMappingURL=DropdownToolButton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DropdownToolButton.js","sourceRoot":"","sources":["../../src/ui/DropdownToolButton.ts"],"names":[],"mappings":"AAAA,mCAAmC;AAEnC,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAA;AAkCjF,MAAM,OAAO,kBAAkB;IAM7B,YAAmB,SAAiB,EAAE,OAAiC,EAAE,GAA+B;QALjG,YAAO,GAAW,IAAI,CAAA;QACrB,eAAU,GAAG,KAAK,CAAA;QAClB,uBAAkB,GAAyC,EAAE,CAAA;QAInE,IAAI,CAAC,OAAO,GAAG,GAAG,IAAI,EAAE,CAAA;QACxB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,IAAI,KAAK,CAAA;QAChD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,iBAAiB,EAAE,CAAA;QACvC,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAA;QAE9B,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;YAC5B,CAAC,CAAC,kBAAkB,EAAE,IAAI,CAAC,OAAO,CAAC,CA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ownToolButtonOptions = {\n title?: string\n cssClass?: string\n icon?: string\n disabled?: boolean\n dropdownMenuPosition?: 'right'\n isDropUp?: boolean\n}\n\nexport type DropdownToolButtonItem = {\n key: string\n title?: string\n hint?: string\n cssClass?: string\n icon?: string\n onClick?: (e: JQuery.ClickEvent<HTMLElement, null, HTMLElement, HTMLElement>) => void\n isSeparator?: boolean\n disabled?: boolean\n isDropdownHeader?: boolean\n dropdownHeaderTitle?: string\n}\n\nexport type ToolDropdownSideButtonItem = {\n key: string\n title?: string\n hint?: string\n cssClass?: string\n icon?: string\n onClick?: (e: JQuery.ClickEvent<HTMLElement, null, HTMLElement, HTMLElement>) => void\n disabled?: boolean\n}\n\nexport class DropdownToolButton {\n public element: JQuery = null\n private isDisabled = false\n private itemDisablingState: { key: string; disabled: boolean }[] = []\n private options: DropdownToolButtonOptions\n\n public constructor(container: JQuery, buttons: DropdownToolButtonItem[], opt?: DropdownToolButtonOptions) {\n this.options = opt || {}\n this.isDisabled = this.options.disabled || false\n this.element = this.buildBaseDropdown()\n this.addDropdownItems(buttons)\n\n this.element.on('click', () => {\n $('.dropdown-toggle', this.element).dropdown('toggle')\n })\n\n container.append(this.element)\n }\n\n private getDisablingStateItem(key: string): boolean {\n if (tryFirst(this.itemDisablingState, x => x.key == key) != null) {\n return first(this.itemDisablingState, x => x.key == key).disabled || false\n }\n\n return false\n }\n\n private setDisablingStateItem(key: string, value: boolean) {\n if (tryFirst(this.itemDisablingState, x => x.key == key) != null) {\n first(this.itemDisablingState, x => x.key == key).disabled = value || false\n return\n }\n\n this.itemDisablingState.push({ key: key, disabled: value || false })\n }\n\n private removeDisablingStateItem(key: string) {\n this.itemDisablingState.some((item, idx) => {\n if (item.key == key) {\n this.itemDisablingState.splice(idx, 1)\n\n return true\n }\n })\n }\n\n private buildBaseDropdown(): JQuery {\n const dropdownTemplate = `<div class=\"buttons-inner dropdown\" style=\"overflow: visible\">\n <div class=\"idevs-tool-dropdown-button tool-button icon-tool-button ${coalesce(this.options.cssClass, '')} ${\n this.options.isDropUp ? 'dropup' : ''\n } ${this.isDisabled ? 'disabled' : ''}\" style=\"cursor: unset;\">\n <div class=\"button-outer dropdown-toggle ${this.isDisabled ? 'disabled' : ''}\"\n data-bs-toggle=\"dropdown\"\n style=\"cursor: pointer;\">\n <span class=\"button-inner\">\n <i class=\"${this.options.icon}\"></i>\n ${coalesce(this.options.title, '')}\n </span>\n <i class=\"caret\"></i>\n </div>\n <ul class=\"dropdown-menu ${this.options.dropdownMenuPosition == 'right' ? 'dropdown-menu-right' : ''}\"></ul>\n </div>\n</div>`\n\n return $(dropdownTemplate)\n }\n\n public addDropdownItems(buttons: DropdownToolButtonItem[]) {\n if (buttons && buttons.length > 0) {\n buttons.forEach(button => {\n this.addDropdownItem(button)\n })\n }\n }\n\n public addDropdownItem(button: DropdownToolButtonItem, idx?: number) {\n if (!isEmptyOrNull(button.key)) {\n if (this.itemDisablingState.map(x => x.key).indexOf(button.key) > -1) {\n alert(`Dropdown has existed key: ${button.key}`)\n return\n }\n\n this.setDisablingStateItem(button.key, button.disabled || false)\n }\n\n let dropdownItemElement: JQuery\n\n if (button.isDropdownHeader && !isEmptyOrNull(button.dropdownHeaderTitle)) {\n dropdownItemElement = $(\n `<li class=\"dropdown-header ${coalesce(button.cssClass, '')}\">${button.dropdownHeaderTitle}</li>`,\n )\n } else {\n if (button.isSeparator) {\n dropdownItemElement = $(`<li class=\"dropdown-divider\"></li>`)\n } else {\n dropdownItemElement = $(`<li class=\"${button.disabled ? 'disabled' : ''}\"\n title=\"${coalesce(button.hint, '')}\"\n data-idevs-key=\"${coalesce(button.key, '')}\">\n <a href=\"#\" class=\"${coalesce(button.cssClass, 'dropdown-item')}\">\n <i class=\"${coalesce(button.icon, '')}\"></i>\n ${button.title}\n </a>\n </li>`)\n\n dropdownItemElement.on('click', (e: JQuery.ClickEvent<HTMLElement, null, HTMLElement, HTMLElement>) => {\n e.preventDefault()\n\n if (this.isDisabled) {\n return\n }\n\n let buttonIsDisabled = button.disabled\n\n if (!isEmptyOrNull(button.key)) {\n buttonIsDisabled = this.getDisablingStateItem(button.key)\n }\n if (buttonIsDisabled) {\n return\n }\n\n button.onClick(e)\n })\n }\n }\n\n if (idx === null || typeof idx === 'undefined') {\n this.element.find('.dropdown-menu').append(dropdownItemElement)\n return\n }\n\n if (idx <= 0) {\n this.element.find('.dropdown-menu').prepend(dropdownItemElement)\n return\n }\n\n const nbrOfButtons = this.element.find(`.dropdown-menu > li`).length\n\n if (idx > nbrOfButtons) {\n idx = nbrOfButtons\n }\n\n this.element.find(`.dropdown-menu > li:nth-child(${idx})`).after(dropdownItemElement)\n }\n\n public enableDropdown(enable: boolean) {\n const drd = this.element.find('.dropdown').first()\n if (drd) {\n if (enable) {\n if (drd.hasClass('disabled')) {\n drd.removeClass('disabled')\n }\n } else {\n if (!drd.hasClass('disabled')) {\n drd.addClass('disabled')\n }\n }\n }\n\n const drdToggle = this.element.find('.dropdown-toggle').first()\n if (drdToggle) {\n if (enable) {\n if (drdToggle.hasClass('disabled')) {\n drd.removeClass('disabled')\n } else {\n if (!drdToggle.hasClass('disabled')) {\n drdToggle.addClass('disabled')\n }\n }\n }\n }\n\n this.isDisabled = !enable\n }\n\n public enableDropdownItemByKey(key: string, enable: boolean) {\n const drdItem = this.element.find(`.dropdown-menu li[data-idevs-key=\"${key}\"]`).first()\n if (drdItem) {\n if (enable) {\n if (drdItem.hasClass('disabled')) {\n drdItem.removeClass('disabled')\n }\n } else {\n if (!drdItem.hasClass('disabled')) {\n drdItem.addClass('disabled')\n }\n }\n }\n\n this.setDisablingStateItem(key, !enable)\n }\n\n public enableSideButtonByKey(key: string, enable: boolean) {\n const tButton = this.element.find(`.tool-button[data-idevs-key=\"${key}\"]`).first()\n if (tButton) {\n if (enable) {\n if (tButton.hasClass('disabled')) {\n tButton.removeClass('disabled')\n }\n } else {\n if (!tButton.hasClass('disabled')) {\n tButton.addClass('disabled')\n }\n }\n }\n\n this.setDisablingStateItem(key, !enable)\n }\n\n public removeDropdownItem(key: string) {\n this.element.find(`.dropdown-menu li[data-idevs-key=\"${key}\"]`).remove()\n this.removeDisablingStateItem(key)\n }\n\n public removeSideButtonItem(key: string) {\n this.element.find(`.tool-button[data-idevs-key=\"${key}\"]`).remove()\n this.removeDisablingStateItem(key)\n }\n\n public addSideButtonItem(button: ToolDropdownSideButtonItem, idx?: number) {\n if (!isEmptyOrNull(button.key)) {\n if (this.itemDisablingState.map(x => x.key).indexOf(button.key) > -1) {\n alert(`Dropdown has existed key: ${button.key}`)\n return\n }\n\n this.setDisablingStateItem(button.key, button.disabled || false)\n }\n\n const sideButtonTemplate = `<div class=\"tool-button add-button icon-tool-button ${coalesce(button.cssClass, '')} ${\n button.disabled ? 'disabled' : ''\n }\"\n data-idevs-key=\"${coalesce(button.key, '')}\"\n title=\"${coalesce(button.title, '')}\">\n <div class=\"button-outer\">\n <span class=\"button-inner\">\n <i class=\"${coalesce(button.icon, '')}\"></i>\n </span>\n </div>\n </div>`\n\n const sideButton = $(sideButtonTemplate)\n\n sideButton.on('click', (e: JQuery.ClickEvent<HTMLElement, null, HTMLElement, HTMLElement>) => {\n e.preventDefault()\n\n let buttonIsDisabled = button.disabled\n\n if (!isEmptyOrNull(button.key)) {\n buttonIsDisabled = this.getDisablingStateItem(button.key)\n }\n\n if (buttonIsDisabled) {\n return\n }\n\n button.onClick(e)\n })\n\n if (idx === null || typeof idx === 'undefined') {\n this.element.append(sideButton)\n return\n }\n\n if (idx <= 0) {\n this.element.prepend(sideButton)\n return\n }\n\n const nbrOfButtons = this.element.find(`div.tool-button`).length\n\n if (idx > nbrOfButtons) {\n idx = nbrOfButtons\n }\n\n this.element.find(`div.tool-button:nth-child(${idx})`).after(sideButton)\n }\n}\n"]}
@@ -0,0 +1,18 @@
1
+ /// <reference types="jquery" />
2
+ export type ToggleToolButtonOptions = {
3
+ title?: string;
4
+ hint?: string;
5
+ cssClass?: string;
6
+ altCssClass?: string;
7
+ icon?: string;
8
+ altIcon?: string;
9
+ onClick?: (e: JQuery.ClickEvent<HTMLElement, null, HTMLElement, HTMLElement>) => void;
10
+ disabled?: boolean;
11
+ };
12
+ export declare class ToggleToolButton {
13
+ element: JQuery;
14
+ private isDisabled;
15
+ private options;
16
+ constructor(container: JQuery, opt?: ToggleToolButtonOptions);
17
+ private buildBaseButton;
18
+ }
@@ -0,0 +1,53 @@
1
+ import { coalesce } from '@serenity-is/corelib/q';
2
+ import { neededTarget } from '../globals';
3
+ export class ToggleToolButton {
4
+ constructor(container, opt) {
5
+ this.element = null;
6
+ this.isDisabled = false;
7
+ this.options = opt || {};
8
+ this.isDisabled = this.options.disabled || false;
9
+ this.element = this.buildBaseButton();
10
+ this.element.on('click', e => {
11
+ if (this.isDisabled)
12
+ return;
13
+ const target = neededTarget(e.target, '.idevs-toggle-button');
14
+ if (this.options.altIcon) {
15
+ const icon = target.querySelector(`i`);
16
+ if (icon.className == this.options.icon) {
17
+ icon.className = this.options.altIcon;
18
+ }
19
+ else {
20
+ icon.className = this.options.icon;
21
+ }
22
+ }
23
+ if (this.options.cssClass && this.options.altCssClass) {
24
+ if (target.className.includes(this.options.cssClass)) {
25
+ target.className = target.className.replace(this.options.cssClass, this.options.altCssClass);
26
+ }
27
+ else {
28
+ target.className = target.className.replace(this.options.altCssClass, this.options.cssClass);
29
+ }
30
+ }
31
+ if (this.options.onClick) {
32
+ this.options.onClick(e);
33
+ }
34
+ });
35
+ container.append(this.element);
36
+ }
37
+ buildBaseButton() {
38
+ const buttonTemplate = `<div class="buttons-inner" style="overflow: visible">
39
+ <div class="idevs-toggle-button tool-button icon-tool-button ${coalesce(this.options.cssClass, '')} ${this.isDisabled ? 'disabled' : ''}" style="cursor: unset;">
40
+ <div class="button-outer ${this.isDisabled ? 'disabled' : ''}"
41
+ style="cursor: pointer;">
42
+ <span class="button-inner">
43
+ <i class="${this.options.icon}"></i>
44
+ ${coalesce(this.options.title, '')}
45
+ </span>
46
+ <i class="caret"></i>
47
+ </div>
48
+ </div>
49
+ </div>`;
50
+ return $(buttonTemplate);
51
+ }
52
+ }
53
+ //# sourceMappingURL=ToggleToolButton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ToggleToolButton.js","sourceRoot":"","sources":["../../src/ui/ToggleToolButton.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAA;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAazC,MAAM,OAAO,gBAAgB;IAK3B,YAAmB,SAAiB,EAAE,GAA6B;QAJ5D,YAAO,GAAW,IAAI,CAAA;QACrB,eAAU,GAAG,KAAK,CAAA;QAIxB,IAAI,CAAC,OAAO,GAAG,GAAG,IAAI,EAAE,CAAA;QACxB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,IAAI,KAAK,CAAA;QAChD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,eAAe,EAAE,CAAA;QAErC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE;YAC3B,IAAI,IAAI,CAAC,UAAU;gBAAE,OAAM;YAE3B,MAAM,MAAM,GAAG,YAAY,CAAC,CAAC,CAAC,MAAqB,EAAE,sBAAsB,CAAC,CAAA;YAC5E,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE;gBACxB,MAAM,IAAI,GAAG,MAAM,CAAC,aAAa,CAAC,GAAG,CAAC,CAAA;gBACtC,IAAI,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;oBACvC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAA;iBACtC;qBAAM;oBACL,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAA;iBACnC;aACF;YAED,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,IAAI,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE;gBACrD,IAAI,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;oBACpD,MAAM,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;iBAC7F;qBAAM;oBACL,MAAM,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;iBAC7F;aACF;YAED,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE;gBACxB,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;aACxB;QACH,CAAC,CAAC,CAAA;QAEF,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAChC,CAAC;IAEO,eAAe;QACrB,MAAM,cAAc,GAAG;mEACwC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,IAChG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EACjC;mCAC+B,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE;;;4BAGxC,IAAI,CAAC,OAAO,CAAC,IAAI;kBAC3B,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;;;;;OAK3C,CAAA;QAEH,OAAO,CAAC,CAAC,cAAc,CAAC,CAAA;IAC1B,CAAC;CACF","sourcesContent":["import { coalesce } from '@serenity-is/corelib/q'\nimport { neededTarget } from '../globals'\n\nexport type ToggleToolButtonOptions = {\n title?: string\n hint?: string\n cssClass?: string\n altCssClass?: string\n icon?: string\n altIcon?: string\n onClick?: (e: JQuery.ClickEvent<HTMLElement, null, HTMLElement, HTMLElement>) => void\n disabled?: boolean\n}\n\nexport class ToggleToolButton {\n public element: JQuery = null\n private isDisabled = false\n private options: ToggleToolButtonOptions\n\n public constructor(container: JQuery, opt?: ToggleToolButtonOptions) {\n this.options = opt || {}\n this.isDisabled = this.options.disabled || false\n this.element = this.buildBaseButton()\n\n this.element.on('click', e => {\n if (this.isDisabled) return\n\n const target = neededTarget(e.target as HTMLElement, '.idevs-toggle-button')\n if (this.options.altIcon) {\n const icon = target.querySelector(`i`)\n if (icon.className == this.options.icon) {\n icon.className = this.options.altIcon\n } else {\n icon.className = this.options.icon\n }\n }\n\n if (this.options.cssClass && this.options.altCssClass) {\n if (target.className.includes(this.options.cssClass)) {\n target.className = target.className.replace(this.options.cssClass, this.options.altCssClass)\n } else {\n target.className = target.className.replace(this.options.altCssClass, this.options.cssClass)\n }\n }\n\n if (this.options.onClick) {\n this.options.onClick(e)\n }\n })\n\n container.append(this.element)\n }\n\n private buildBaseButton(): JQuery {\n const buttonTemplate = `<div class=\"buttons-inner\" style=\"overflow: visible\">\n <div class=\"idevs-toggle-button tool-button icon-tool-button ${coalesce(this.options.cssClass, '')} ${\n this.isDisabled ? 'disabled' : ''\n }\" style=\"cursor: unset;\">\n <div class=\"button-outer ${this.isDisabled ? 'disabled' : ''}\"\n style=\"cursor: pointer;\">\n <span class=\"button-inner\">\n <i class=\"${this.options.icon}\"></i>\n ${coalesce(this.options.title, '')}\n </span>\n <i class=\"caret\"></i>\n </div>\n </div>\n</div>`\n\n return $(buttonTemplate)\n }\n}\n"]}
@@ -1 +1,2 @@
1
- export * from './ToolDropdownButton';
1
+ export * from './DropdownToolButton';
2
+ export * from './ToggleToolButton';
package/dist/ui/index.js CHANGED
@@ -1,2 +1,3 @@
1
- export * from './ToolDropdownButton';
1
+ export * from './DropdownToolButton';
2
+ export * from './ToggleToolButton';
2
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ui/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAA","sourcesContent":["export * from './ToolDropdownButton'\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ui/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAA;AACpC,cAAc,oBAAoB,CAAA","sourcesContent":["export * from './DropdownToolButton'\nexport * from './ToggleToolButton'\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@idevs/corelib",
3
- "version": "0.0.38",
3
+ "version": "0.0.40",
4
4
  "description": "Extended library for Serenity Framework",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -30,16 +30,7 @@ export class DateMonthEditor extends SelectEditor {
30
30
  this.months.push(new Date(2000, i, 1).toLocaleDateString(locale, options))
31
31
  }
32
32
 
33
- if (!(opt.descending ?? false)) {
34
- return this.months
35
- }
36
-
37
- const months: string[] = []
38
- for (let i1 = 11; i1 >= 0; 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() {}
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { coalesce, first, isEmptyOrNull, tryFirst } from '@serenity-is/corelib/q'
4
4
 
5
- export type ToolDropdownButtonOptions = {
5
+ export type DropdownToolButtonOptions = {
6
6
  title?: string
7
7
  cssClass?: string
8
8
  icon?: string
@@ -11,7 +11,7 @@ export type ToolDropdownButtonOptions = {
11
11
  isDropUp?: boolean
12
12
  }
13
13
 
14
- export type ToolDropdownButtonItem = {
14
+ export type DropdownToolButtonItem = {
15
15
  key: string
16
16
  title?: string
17
17
  hint?: string
@@ -34,13 +34,13 @@ export type ToolDropdownSideButtonItem = {
34
34
  disabled?: boolean
35
35
  }
36
36
 
37
- export class ToolDropdownButton {
37
+ export class DropdownToolButton {
38
38
  public element: JQuery = null
39
39
  private isDisabled = false
40
40
  private itemDisablingState: { key: string; disabled: boolean }[] = []
41
- private options: ToolDropdownButtonOptions
41
+ private options: DropdownToolButtonOptions
42
42
 
43
- public constructor(container: JQuery, buttons: ToolDropdownButtonItem[], opt?: ToolDropdownButtonOptions) {
43
+ public constructor(container: JQuery, buttons: DropdownToolButtonItem[], opt?: DropdownToolButtonOptions) {
44
44
  this.options = opt || {}
45
45
  this.isDisabled = this.options.disabled || false
46
46
  this.element = this.buildBaseDropdown()
@@ -101,7 +101,7 @@ export class ToolDropdownButton {
101
101
  return $(dropdownTemplate)
102
102
  }
103
103
 
104
- public addDropdownItems(buttons: ToolDropdownButtonItem[]) {
104
+ public addDropdownItems(buttons: DropdownToolButtonItem[]) {
105
105
  if (buttons && buttons.length > 0) {
106
106
  buttons.forEach(button => {
107
107
  this.addDropdownItem(button)
@@ -109,7 +109,7 @@ export class ToolDropdownButton {
109
109
  }
110
110
  }
111
111
 
112
- public addDropdownItem(button: ToolDropdownButtonItem, idx?: number) {
112
+ public addDropdownItem(button: DropdownToolButtonItem, idx?: number) {
113
113
  if (!isEmptyOrNull(button.key)) {
114
114
  if (this.itemDisablingState.map(x => x.key).indexOf(button.key) > -1) {
115
115
  alert(`Dropdown has existed key: ${button.key}`)
@@ -0,0 +1,72 @@
1
+ import { coalesce } from '@serenity-is/corelib/q'
2
+ import { neededTarget } from '../globals'
3
+
4
+ export type ToggleToolButtonOptions = {
5
+ title?: string
6
+ hint?: string
7
+ cssClass?: string
8
+ altCssClass?: string
9
+ icon?: string
10
+ altIcon?: string
11
+ onClick?: (e: JQuery.ClickEvent<HTMLElement, null, HTMLElement, HTMLElement>) => void
12
+ disabled?: boolean
13
+ }
14
+
15
+ export class ToggleToolButton {
16
+ public element: JQuery = null
17
+ private isDisabled = false
18
+ private options: ToggleToolButtonOptions
19
+
20
+ public constructor(container: JQuery, opt?: ToggleToolButtonOptions) {
21
+ this.options = opt || {}
22
+ this.isDisabled = this.options.disabled || false
23
+ this.element = this.buildBaseButton()
24
+
25
+ this.element.on('click', e => {
26
+ if (this.isDisabled) return
27
+
28
+ const target = neededTarget(e.target as HTMLElement, '.idevs-toggle-button')
29
+ if (this.options.altIcon) {
30
+ const icon = target.querySelector(`i`)
31
+ if (icon.className == this.options.icon) {
32
+ icon.className = this.options.altIcon
33
+ } else {
34
+ icon.className = this.options.icon
35
+ }
36
+ }
37
+
38
+ if (this.options.cssClass && this.options.altCssClass) {
39
+ if (target.className.includes(this.options.cssClass)) {
40
+ target.className = target.className.replace(this.options.cssClass, this.options.altCssClass)
41
+ } else {
42
+ target.className = target.className.replace(this.options.altCssClass, this.options.cssClass)
43
+ }
44
+ }
45
+
46
+ if (this.options.onClick) {
47
+ this.options.onClick(e)
48
+ }
49
+ })
50
+
51
+ container.append(this.element)
52
+ }
53
+
54
+ private buildBaseButton(): JQuery {
55
+ const buttonTemplate = `<div class="buttons-inner" style="overflow: visible">
56
+ <div class="idevs-toggle-button tool-button icon-tool-button ${coalesce(this.options.cssClass, '')} ${
57
+ this.isDisabled ? 'disabled' : ''
58
+ }" style="cursor: unset;">
59
+ <div class="button-outer ${this.isDisabled ? 'disabled' : ''}"
60
+ style="cursor: pointer;">
61
+ <span class="button-inner">
62
+ <i class="${this.options.icon}"></i>
63
+ ${coalesce(this.options.title, '')}
64
+ </span>
65
+ <i class="caret"></i>
66
+ </div>
67
+ </div>
68
+ </div>`
69
+
70
+ return $(buttonTemplate)
71
+ }
72
+ }
package/src/ui/index.ts CHANGED
@@ -1 +1,2 @@
1
- export * from './ToolDropdownButton'
1
+ export * from './DropdownToolButton'
2
+ export * from './ToggleToolButton'