@idevs/corelib 0.0.97 → 1.0.1

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.
Files changed (119) hide show
  1. package/CHANGELOG.md +743 -0
  2. package/README.md +221 -24
  3. package/dist/editors/checkboxButtonEditor.d.ts +3 -1
  4. package/dist/editors/checkboxButtonEditor.d.ts.map +1 -0
  5. package/dist/editors/checkboxButtonEditor.js +28 -18
  6. package/dist/editors/checkboxButtonEditor.js.map +1 -1
  7. package/dist/editors/dateMonthEditor.d.ts +3 -1
  8. package/dist/editors/dateMonthEditor.d.ts.map +1 -0
  9. package/dist/editors/dateMonthEditor.js +14 -7
  10. package/dist/editors/dateMonthEditor.js.map +1 -1
  11. package/dist/editors/index.d.ts +2 -1
  12. package/dist/editors/index.d.ts.map +1 -0
  13. package/dist/editors/index.js +18 -2
  14. package/dist/editors/index.js.map +1 -1
  15. package/dist/formatters/formatters.d.ts +2 -1
  16. package/dist/formatters/formatters.d.ts.map +1 -0
  17. package/dist/formatters/formatters.js +35 -23
  18. package/dist/formatters/formatters.js.map +1 -1
  19. package/dist/formatters/index.d.ts +2 -1
  20. package/dist/formatters/index.d.ts.map +1 -0
  21. package/dist/formatters/index.js +17 -1
  22. package/dist/formatters/index.js.map +1 -1
  23. package/dist/globals/index.d.ts +17 -10
  24. package/dist/globals/index.d.ts.map +1 -0
  25. package/dist/globals/index.js +65 -105
  26. package/dist/globals/index.js.map +1 -1
  27. package/dist/helpers/custom-fonts.d.ts +2 -1
  28. package/dist/helpers/custom-fonts.d.ts.map +1 -0
  29. package/dist/helpers/custom-fonts.js +4 -1
  30. package/dist/helpers/custom-fonts.js.map +1 -1
  31. package/dist/helpers/dialogHelper.d.ts +6 -9
  32. package/dist/helpers/dialogHelper.d.ts.map +1 -0
  33. package/dist/helpers/dialogHelper.js +17 -10
  34. package/dist/helpers/dialogHelper.js.map +1 -1
  35. package/dist/helpers/excelExportHelper.d.ts +2 -1
  36. package/dist/helpers/excelExportHelper.d.ts.map +1 -0
  37. package/dist/helpers/excelExportHelper.js +7 -4
  38. package/dist/helpers/excelExportHelper.js.map +1 -1
  39. package/dist/helpers/gridHelper.d.ts +2 -1
  40. package/dist/helpers/gridHelper.d.ts.map +1 -0
  41. package/dist/helpers/gridHelper.js +14 -9
  42. package/dist/helpers/gridHelper.js.map +1 -1
  43. package/dist/helpers/index.d.ts +2 -1
  44. package/dist/helpers/index.d.ts.map +1 -0
  45. package/dist/helpers/index.js +20 -4
  46. package/dist/helpers/index.js.map +1 -1
  47. package/dist/helpers/pdfExportHelper.d.ts +2 -1
  48. package/dist/helpers/pdfExportHelper.d.ts.map +1 -0
  49. package/dist/helpers/pdfExportHelper.js +83 -17
  50. package/dist/helpers/pdfExportHelper.js.map +1 -1
  51. package/dist/index.d.ts +5 -2
  52. package/dist/index.d.ts.map +1 -0
  53. package/dist/index.js +26 -5
  54. package/dist/index.js.map +1 -1
  55. package/dist/types/common.d.ts +12 -0
  56. package/dist/types/common.d.ts.map +1 -0
  57. package/dist/types/common.js +3 -0
  58. package/dist/types/common.js.map +1 -0
  59. package/dist/types/export.d.ts +50 -0
  60. package/dist/types/export.d.ts.map +1 -0
  61. package/dist/types/export.js +24 -0
  62. package/dist/types/export.js.map +1 -0
  63. package/dist/types/index.d.ts +3 -0
  64. package/dist/types/index.d.ts.map +1 -0
  65. package/dist/types/index.js +19 -0
  66. package/dist/types/index.js.map +1 -0
  67. package/dist/ui/DropdownToolButton.d.ts +2 -1
  68. package/dist/ui/DropdownToolButton.d.ts.map +1 -0
  69. package/dist/ui/DropdownToolButton.js +15 -11
  70. package/dist/ui/DropdownToolButton.js.map +1 -1
  71. package/dist/ui/ToggleToolButton.d.ts +2 -1
  72. package/dist/ui/ToggleToolButton.d.ts.map +1 -0
  73. package/dist/ui/ToggleToolButton.js +7 -3
  74. package/dist/ui/ToggleToolButton.js.map +1 -1
  75. package/dist/ui/index.d.ts +2 -1
  76. package/dist/ui/index.d.ts.map +1 -0
  77. package/dist/ui/index.js +18 -2
  78. package/dist/ui/index.js.map +1 -1
  79. package/dist/utils/date.d.ts +16 -0
  80. package/dist/utils/date.d.ts.map +1 -0
  81. package/dist/utils/date.js +85 -0
  82. package/dist/utils/date.js.map +1 -0
  83. package/dist/utils/dom.d.ts +13 -0
  84. package/dist/utils/dom.d.ts.map +1 -0
  85. package/dist/utils/dom.js +78 -0
  86. package/dist/utils/dom.js.map +1 -0
  87. package/dist/utils/format.d.ts +22 -0
  88. package/dist/utils/format.d.ts.map +1 -0
  89. package/dist/utils/format.js +100 -0
  90. package/dist/utils/format.js.map +1 -0
  91. package/dist/utils/index.d.ts +4 -0
  92. package/dist/utils/index.d.ts.map +1 -0
  93. package/dist/utils/index.js +20 -0
  94. package/dist/utils/index.js.map +1 -0
  95. package/package.json +48 -29
  96. package/dist/ui/ToolDropdownButton.d.ts +0 -49
  97. package/dist/ui/ToolDropdownButton.js +0 -230
  98. package/dist/ui/ToolDropdownButton.js.map +0 -1
  99. package/src/editors/checkboxButtonEditor.ts +0 -184
  100. package/src/editors/dateMonthEditor.ts +0 -47
  101. package/src/editors/index.ts +0 -2
  102. package/src/formatters/formatters.ts +0 -185
  103. package/src/formatters/index.ts +0 -1
  104. package/src/globals/index.ts +0 -385
  105. package/src/helpers/custom-fonts.d.ts +0 -5
  106. package/src/helpers/custom-fonts.ts +0 -18
  107. package/src/helpers/dialogHelper.ts +0 -143
  108. package/src/helpers/excelExportHelper.ts +0 -29
  109. package/src/helpers/gridHelper.ts +0 -107
  110. package/src/helpers/html2pdf.d.ts +0 -19
  111. package/src/helpers/index.ts +0 -4
  112. package/src/helpers/pdfExportHelper.ts +0 -179
  113. package/src/index.ts +0 -5
  114. package/src/tsconfig.json +0 -29
  115. package/src/ui/DropdownToolButton.ts +0 -305
  116. package/src/ui/ToggleToolButton.ts +0 -71
  117. package/src/ui/index.ts +0 -2
  118. /package/{css → dist/css}/idevs.dropdown.css +0 -0
  119. /package/{css → dist/css}/idevs.print.css +0 -0
@@ -1,184 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- /* eslint-disable @typescript-eslint/adjacent-overload-signatures */
3
- // reference: https://github-wiki-see.page/m/serenity-is/Serenity/wiki/CheckBox-Group-Editor
4
-
5
- import {
6
- Decorators,
7
- EditorProps,
8
- EditorWidget,
9
- Enum,
10
- EnumKeyAttribute,
11
- EnumTypeRegistry,
12
- Fluent,
13
- IReadOnly,
14
- getCustomAttributes,
15
- getLookup,
16
- isEmptyOrNull,
17
- toId,
18
- tryGetText,
19
- } from '@serenity-is/corelib'
20
-
21
- export type CheckboxButtonEditorOptions = {
22
- enumKey?: string
23
- enumType?: any
24
- lookupKey?: string
25
- isStringId?: boolean
26
- }
27
-
28
- @Decorators.registerEditor('CheckboxButtonEditor')
29
- export class CheckboxButtonEditor<P extends CheckboxButtonEditorOptions = CheckboxButtonEditorOptions>
30
- extends EditorWidget<P>
31
- implements IReadOnly
32
- {
33
- private _items: Array<{ [key: string]: any }>
34
- private readonly _idField: string
35
- private readonly _textField: string
36
- private readonly _isStringId: boolean
37
-
38
- static override createDefaultElement() {
39
- return Fluent('div').getNode()
40
- }
41
- declare readonly domNode: HTMLElement
42
-
43
- constructor(props: EditorProps<P>) {
44
- super(props)
45
-
46
- if (isEmptyOrNull(this.options.enumKey) && this.options.enumType == null && isEmptyOrNull(this.options.lookupKey)) {
47
- return
48
- }
49
-
50
- this._isStringId = this.options.isStringId
51
-
52
- if (!isEmptyOrNull(this.options.lookupKey)) {
53
- const lookup = getLookup(this.options.lookupKey)
54
- this._idField = lookup.idField
55
- this._textField = lookup.textField
56
- this.set_items(lookup.items as Array<{ [key: string]: any }>)
57
- } else {
58
- const enumType = this.options.enumType || EnumTypeRegistry.get(this.options.enumKey)
59
- let enumKey = this.options.enumKey
60
-
61
- if (enumKey == null && enumType != null) {
62
- const enumKeyAttr = getCustomAttributes(enumType, EnumKeyAttribute, false)
63
- if (enumKeyAttr.length > 0) {
64
- enumKey = enumKeyAttr[0].value
65
- }
66
- }
67
- const values = Enum.getValues(enumType)
68
- for (const x of values) {
69
- const name = Enum.toString(enumType, x)
70
- this.addCheckbox(x.toString(), tryGetText('Enums.' + enumKey + '.' + name) ?? name)
71
- }
72
- }
73
-
74
- this.domNode.classList.add('d-flex', 'flex-wrap')
75
- }
76
-
77
- protected renderCheckboxes() {
78
- const childDivs = this.domNode.querySelectorAll('div')
79
- childDivs.forEach(function (child) {
80
- this.domNode.removeChild(child)
81
- })
82
-
83
- for (const item of this._items) {
84
- const textValue = item[this._textField]
85
- const text = textValue == null ? '' : textValue.toString()
86
- const idValue = item[this._idField]
87
- const id = idValue == null ? '' : idValue.toString()
88
- this.addCheckbox(id, text)
89
- }
90
- }
91
-
92
- protected addCheckbox(value: string, text: string) {
93
- const div = $('<div class="col-12 col-sm-6 col-md-4 col-xl-3" />')
94
- const label = $('<label/>').text(text.replace(/, /g, ',').replace(/,/g, ', '))
95
- $('<input type="checkbox" class="me-2" />')
96
- .attr('name', this.uniqueName)
97
- .attr('id', this.uniqueName + '_' + value)
98
- .attr('value', value)
99
- .prependTo(label)
100
- label.appendTo(div)
101
- div.appendTo(this.domNode)
102
- }
103
-
104
- get_items(): Array<{ [key: string]: any }> {
105
- return this._items
106
- }
107
-
108
- get items(): Array<{ [key: string]: any }> {
109
- return this.get_items()
110
- }
111
-
112
- set_items(value: Array<{ [key: string]: any }>) {
113
- this._items = value
114
- this.renderCheckboxes()
115
- }
116
-
117
- set items(v: Array<{ [key: string]: any }>) {
118
- this.set_items(v)
119
- }
120
-
121
- get_value() {
122
- const val: string[] = []
123
- const inputs = this.domNode.querySelectorAll('input:checked')
124
-
125
- inputs.forEach((input: HTMLInputElement) => {
126
- val.push(this._isStringId ? input.value : toId(input.value))
127
- })
128
-
129
- return val.join(',')
130
- }
131
-
132
- get value(): string {
133
- return this.get_value()
134
- }
135
-
136
- set_value(value: string): void {
137
- if (value !== this.get_value()) {
138
- let values: unknown[] = []
139
- if (!isEmptyOrNull(value)) {
140
- values = this._isStringId ? value.split(',') : value.split(',').map(p => Number(p))
141
- }
142
- const inputs = this.domNode.querySelectorAll<HTMLInputElement>('input')
143
- inputs.forEach(input => {
144
- input.checked = false
145
- })
146
-
147
- values.forEach(v => {
148
- const checks = Array.from(inputs).filter(input => (input as HTMLInputElement).value === v)
149
- if (checks.length > 0) {
150
- ;(checks[0] as HTMLInputElement).checked = true
151
- }
152
- })
153
- }
154
- }
155
-
156
- set value(v: string) {
157
- this.set_value(v)
158
- }
159
-
160
- get_readOnly(): boolean {
161
- return this.domNode.getAttribute('disabled') != null
162
- }
163
-
164
- set_readOnly(value: boolean): void {
165
- if (this.get_readOnly() !== value) {
166
- if (value) {
167
- this.domNode.setAttribute('disabled', 'disabled')
168
- this.domNode.querySelectorAll<HTMLInputElement>('input').forEach(input => {
169
- input.setAttribute('disabled', 'disabled')
170
- })
171
- } else {
172
- this.domNode.removeAttribute('disabled')
173
- this.domNode.querySelectorAll<HTMLInputElement>('input').forEach(input => {
174
- input.removeAttribute('disabled')
175
- })
176
- }
177
- }
178
- }
179
- }
180
-
181
- export class idevsEditors {
182
- // eslint-disable-next-line @typescript-eslint/no-empty-function
183
- public static load() {}
184
- }
@@ -1,47 +0,0 @@
1
- import { Decorators, EditorProps, SelectEditor, SelectEditorOptions, indexOf } from '@serenity-is/corelib'
2
-
3
- @Decorators.registerEditor('DateMonthEditor')
4
- export class DateMonthEditor<P extends DateMonthEditorOptions = DateMonthEditorOptions> extends SelectEditor<P> {
5
- private months: string[]
6
-
7
- constructor(props: EditorProps<P>) {
8
- super(props)
9
-
10
- this.updateItems()
11
- }
12
-
13
- get valueAsMonth() {
14
- return indexOf(this.months, x => x == this.value)
15
- }
16
-
17
- getItems() {
18
- const opt = this.options as DateMonthEditorOptions
19
-
20
- if (opt.items != null && opt.items.length >= 1) {
21
- return opt.items
22
- }
23
-
24
- const today = new Date()
25
- this.months = []
26
- const locale = opt.locale ?? 'en'
27
- const options = { month: opt.display ?? '2-digit' }
28
- const upperCase = opt.upperCase ?? false
29
-
30
- for (let i = 0; i <= 11; i++) {
31
- let m = new Date(today.getFullYear(), i, 1).toLocaleDateString(locale, options)
32
- if (upperCase) {
33
- m = m.toUpperCase()
34
- }
35
- this.months.push(m)
36
- }
37
-
38
- return this.months
39
- }
40
- }
41
-
42
- // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
43
- export interface DateMonthEditorOptions extends SelectEditorOptions {
44
- display?: '2-digit' | 'short' | 'long'
45
- locale?: 'en' | 'th'
46
- upperCase?: boolean
47
- }
@@ -1,2 +0,0 @@
1
- export * from './checkboxButtonEditor'
2
- export * from './dateMonthEditor'
@@ -1,185 +0,0 @@
1
- import { Decorators } from '@serenity-is/corelib'
2
- import { FormatterContext } from '@serenity-is/sleekgrid'
3
- import { getLookup, htmlEncode } from '@serenity-is/corelib'
4
-
5
- export type Formatter = {
6
- format(ctx: FormatterContext): string
7
- }
8
-
9
- @Decorators.registerFormatter('Idevs.ZeroDisplayFormatter')
10
- export class ZeroDisplayFormatter implements Formatter {
11
- constructor(public readonly props: { displayText?: string } = {}) {
12
- this.props ??= {}
13
- this.props.displayText ??= ''
14
- }
15
-
16
- get displayText() {
17
- return this.props.displayText
18
- }
19
- set displayText(value: string) {
20
- this.props.displayText = value
21
- }
22
-
23
- format(ctx: FormatterContext): string {
24
- return ZeroDisplayFormatter.format(ctx.value, this.displayText)
25
- }
26
-
27
- static format(src: string, displayText?: string): string {
28
- const value = parseFloat(String(src || '0').replace(',', ''))
29
- if (value == 0) {
30
- return htmlEncode(displayText)
31
- }
32
-
33
- return htmlEncode(src)
34
- }
35
- }
36
-
37
- @Decorators.registerFormatter('Idevs.CheckboxFormatter')
38
- export class CheckboxFormatter implements Formatter {
39
- constructor(
40
- public readonly props: {
41
- trueText?: string
42
- falseText?: string
43
- cssClass?: string
44
- trueValueIcon?: string
45
- falseValueIcon?: string
46
- },
47
- ) {
48
- this.props.cssClass ??= 'text-center fs-2 text-gray-1'
49
- this.props.trueText ??= '1'
50
- this.props.falseText ??= '0'
51
- this.props.trueValueIcon ??= 'mdi mdi-checkbox-marked-outline'
52
- this.props.falseValueIcon ??= 'mdi mdi-checkbox-blank-outline'
53
- }
54
-
55
- get cssClass() {
56
- return this.props.cssClass
57
- }
58
- set cssClass(value: string) {
59
- this.props.cssClass = value
60
- }
61
-
62
- get trueText() {
63
- return this.props.trueText
64
- }
65
- set trueText(value: string) {
66
- this.props.trueText = value
67
- }
68
-
69
- get falseText() {
70
- return this.props.falseText
71
- }
72
- set falseText(value: string) {
73
- this.props.falseText = value
74
- }
75
-
76
- get trueValueIcon() {
77
- return this.props.trueValueIcon
78
- }
79
- set trueValueIcon(value: string) {
80
- this.props.trueValueIcon = value
81
- }
82
-
83
- get falseValueIcon() {
84
- return this.props.falseValueIcon
85
- }
86
- set falseValueIcon(value: string) {
87
- this.props.falseValueIcon = value
88
- }
89
-
90
- format(ctx: FormatterContext): string {
91
- return CheckboxFormatter.format(
92
- ctx.value,
93
- this.cssClass,
94
- this.trueText,
95
- this.falseText,
96
- this.trueValueIcon,
97
- this.falseValueIcon,
98
- )
99
- }
100
-
101
- static format(
102
- src: string,
103
- cssClass?: string,
104
- trueText?: string,
105
- falseText?: string,
106
- trueValueIcon?: string,
107
- falseValueIcon?: string,
108
- ): string {
109
- if (src == trueText) {
110
- return `<i class="${trueValueIcon} ${cssClass}"></i>`
111
- } else if (src == falseText) {
112
- return `<i class="${falseValueIcon} ${cssClass}"></i>`
113
- } else {
114
- return htmlEncode(src)
115
- }
116
- }
117
- }
118
-
119
- @Decorators.registerFormatter('Idevs.LookupFormatter')
120
- export class LookupFormatter implements Formatter {
121
- constructor(public readonly props: { lookupKey?: string } = {}) {
122
- this.props ??= {}
123
- }
124
-
125
- get lookupKey() {
126
- return this.props.lookupKey
127
- }
128
- set lookupKey(value: string) {
129
- this.props.lookupKey = value
130
- }
131
-
132
- format(ctx: FormatterContext): string {
133
- return LookupFormatter.format(ctx.value, this.lookupKey)
134
- }
135
-
136
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
137
- static format(src: any, lookupKey?: string): string {
138
- if (!src) return ''
139
-
140
- if (!lookupKey) return src
141
-
142
- const lookup = getLookup(lookupKey)
143
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
144
- const items = lookup.items as Array<{ [key: string]: any }>
145
- const idField = lookup.idField
146
- const textField = lookup.textField
147
- const idList = src.toString().split(',')
148
-
149
- return (
150
- idList
151
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
152
- .map((x: any) => {
153
- const g = items.find(i => i[idField] == x)
154
- if (!g) return x
155
-
156
- return htmlEncode(g[textField])
157
- })
158
- .join(', ')
159
- )
160
- }
161
- }
162
-
163
- @Decorators.registerFormatter('Idevs.DateMonthFormatter')
164
- export class DateMonthFormatter implements Formatter {
165
- @Decorators.option()
166
- public display: '2-digit' | 'short' | 'long'
167
-
168
- @Decorators.option()
169
- public locale: 'en' | 'th'
170
-
171
- format(ctx: FormatterContext): string {
172
- const src = ctx.value as number
173
- if (!src) return ''
174
-
175
- const locale = this.locale ?? 'en'
176
- const options = { month: this.display ?? '2-digit' }
177
-
178
- return new Date(2000, src - 1, 1).toLocaleDateString(locale, options)
179
- }
180
- }
181
-
182
- export class idevsFormatters {
183
- // eslint-disable-next-line @typescript-eslint/no-empty-function
184
- public static load() {}
185
- }
@@ -1 +0,0 @@
1
- export * from './formatters'