@idevs/corelib 0.0.85 → 0.0.86
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.
|
@@ -52,8 +52,8 @@ let CheckboxButtonEditor = class CheckboxButtonEditor extends Widget {
|
|
|
52
52
|
}
|
|
53
53
|
addCheckbox(value, text) {
|
|
54
54
|
const div = $('<div class="col-12 col-sm-6 col-md-4 col-xl-3" />');
|
|
55
|
-
const label = $('<label/>').text(text);
|
|
56
|
-
$('<input type="checkbox" class="me-2"/>')
|
|
55
|
+
const label = $('<label/>').text(text.replace(/, /g, ',').replace(/,/g, ', '));
|
|
56
|
+
$('<input type="checkbox" class="me-2" />')
|
|
57
57
|
.attr('name', this.uniqueName)
|
|
58
58
|
.attr('id', this.uniqueName + '_' + value)
|
|
59
59
|
.attr('value', value)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkboxButtonEditor.js","sourceRoot":"","sources":["../../src/editors/checkboxButtonEditor.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,oEAAoE;AACpE,4FAA4F;;;;;;;AAE5F,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,gBAAgB,EAAa,MAAM,EAAE,MAAM,sBAAsB,CAAA;AACxG,OAAO,EACL,QAAQ,EACR,IAAI,EACJ,aAAa,EACb,SAAS,EACT,OAAO,EACP,aAAa,EACb,IAAI,EACJ,UAAU,GACX,MAAM,wBAAwB,CAAA;AAC/B,IAAO,OAAO,GAAG,UAAU,CAAC,OAAO,CAAA;AAWnC,IAAa,oBAAoB,GAAjC,MAAa,oBAAqB,SAAQ,MAAmC;IAM3E,YAAY,KAAa,EAAE,GAAgC;QACzD,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;QAEjB,IAAI,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,IAAI,IAAI,IAAI,aAAa,CAAC,IAAI,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I,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAA;aACrF;iBAAM;gBACL,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC,CAAA;aACzE;SACF;IACH,CAAC;CACF,CAAA;AAzIY,oBAAoB;IAFhC,UAAU,CAAC,cAAc,CAAC,sBAAsB,CAAC;IACjD,OAAO,CAAC,QAAQ,CAAC;GACL,oBAAoB,CAyIhC;SAzIY,oBAAoB;AA2IjC,MAAM,OAAO,YAAY;IACvB,gEAAgE;IACzD,MAAM,CAAC,IAAI,KAAI,CAAC;CACxB","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/adjacent-overload-signatures */\n// reference: https://github-wiki-see.page/m/serenity-is/Serenity/wiki/CheckBox-Group-Editor\n\nimport { Decorators, EnumKeyAttribute, EnumTypeRegistry, IReadOnly, Widget } from '@serenity-is/corelib'\nimport {\n coalesce,\n Enum,\n getAttributes,\n getLookup,\n isArray,\n isEmptyOrNull,\n toId,\n tryGetText,\n} from '@serenity-is/corelib/q'\nimport Element = Decorators.element\n\nexport type CheckboxButtonEditorOptions = {\n enumKey?: string\n enumType?: any\n lookupKey?: string\n isStringId?: boolean\n}\n\n@Decorators.registerEditor('CheckboxButtonEditor')\n@Element('<div/>')\nexport class CheckboxButtonEditor extends Widget<CheckboxButtonEditorOptions> implements IReadOnly {\n private _items: Array<{ [key: string]: any }>\n private readonly _idField: string\n private readonly _textField: string\n private readonly _isStringId: boolean\n\n constructor(input: JQuery, opt: CheckboxButtonEditorOptions) {\n super(input, opt)\n\n if (isEmptyOrNull(this.options.enumKey) && this.options.enumType == null && isEmptyOrNull(this.options.lookupKey)) {\n return\n }\n\n this._isStringId = this.options.isStringId\n\n if (!isEmptyOrNull(this.options.lookupKey)) {\n const lookup = getLookup(this.options.lookupKey)\n this._idField = lookup.idField\n this._textField = lookup.textField\n this.set_items(lookup.items as Array<{ [key: string]: any }>)\n } else {\n const enumType = this.options.enumType || EnumTypeRegistry.get(this.options.enumKey)\n let enumKey = this.options.enumKey\n\n if (enumKey == null && enumType != null) {\n const enumKeyAttr = getAttributes(enumType, EnumKeyAttribute, false)\n if (enumKeyAttr.length > 0) {\n enumKey = enumKeyAttr[0].value\n }\n }\n const values = Enum.getValues(enumType)\n for (const x of values) {\n const name = Enum.toString(enumType, x)\n this.addCheckbox(x.toString(), coalesce(tryGetText('Enums.' + enumKey + '.' + name), name))\n }\n }\n\n this.element.addClass('d-flex flex-wrap')\n }\n\n protected renderCheckboxes() {\n this.element.children('div').remove()\n\n for (const item of this._items) {\n const textValue = item[this._textField]\n const text = textValue == null ? '' : textValue.toString()\n const idValue = item[this._idField]\n const id = idValue == null ? '' : idValue.toString()\n this.addCheckbox(id, text)\n }\n }\n\n protected addCheckbox(value: string, text: string) {\n const div = $('<div class=\"col-12 col-sm-6 col-md-4 col-xl-3\" />')\n const label = $('<label/>').text(text)\n $('<input type=\"checkbox\" class=\"me-2\"/>')\n .attr('name', this.uniqueName)\n .attr('id', this.uniqueName + '_' + value)\n .attr('value', value)\n .prependTo(label)\n label.appendTo(div)\n div.appendTo(this.element)\n }\n\n get_items(): Array<{ [key: string]: any }> {\n return this._items\n }\n\n get items(): Array<{ [key: string]: any }> {\n return this.get_items()\n }\n\n set_items(value: Array<{ [key: string]: any }>) {\n this._items = value\n this.renderCheckboxes()\n }\n\n set items(v: Array<{ [key: string]: any }>) {\n this.set_items(v)\n }\n\n get_value(): string {\n const val: unknown[] = []\n this.element.find('input:checked').each((i, e) => {\n val.push(this._isStringId ? $(e).val() : toId($(e).val()))\n })\n return val.join(',')\n }\n\n get value(): string {\n return this.get_value()\n }\n\n set_value(value: string): void {\n if (value !== this.get_value()) {\n let values: unknown[] = []\n if (!isEmptyOrNull(value)) {\n values = this._isStringId ? value.split(',') : value.split(',').map(p => Number(p))\n }\n const inputs = this.element.find('input')\n inputs.each((i, e) => {\n ;(e as HTMLInputElement).checked = false\n })\n\n if (isArray(values)) {\n values.forEach(v => {\n const checks = inputs.filter('[value=' + v + ']')\n if (checks.length > 0) {\n ;(checks[0] as HTMLInputElement).checked = true\n }\n })\n } else {\n const checks = inputs.filter('[value=' + values + ']')\n if (checks.length > 0) {\n ;(checks[0] as HTMLInputElement).checked = true\n }\n }\n }\n }\n\n set value(v: string) {\n this.set_value(v)\n }\n\n get_readOnly(): boolean {\n return this.element.attr('disabled') != null\n }\n\n set_readOnly(value: boolean): void {\n if (this.get_readOnly() !== value) {\n if (value) {\n this.element.attr('disabled', 'disabled').find('input').attr('disabled', 'disabled')\n } else {\n this.element.removeAttr('disabled').find('input').removeAttr('disabled')\n }\n }\n }\n}\n\nexport class idevsEditors {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n public static load() {}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"checkboxButtonEditor.js","sourceRoot":"","sources":["../../src/editors/checkboxButtonEditor.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,oEAAoE;AACpE,4FAA4F;;;;;;;AAE5F,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,gBAAgB,EAAa,MAAM,EAAE,MAAM,sBAAsB,CAAA;AACxG,OAAO,EACL,QAAQ,EACR,IAAI,EACJ,aAAa,EACb,SAAS,EACT,OAAO,EACP,aAAa,EACb,IAAI,EACJ,UAAU,GACX,MAAM,wBAAwB,CAAA;AAC/B,IAAO,OAAO,GAAG,UAAU,CAAC,OAAO,CAAA;AAWnC,IAAa,oBAAoB,GAAjC,MAAa,oBAAqB,SAAQ,MAAmC;IAM3E,YAAY,KAAa,EAAE,GAAgC;QACzD,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;QAEjB,IAAI,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,IAAI,IAAI,IAAI,aAAa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ACjC,IAAI,KAAK,EAAE;gBACT,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAA;aACrF;iBAAM;gBACL,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC,CAAA;aACzE;SACF;IACH,CAAC;CACF,CAAA;AAzIY,oBAAoB;IAFhC,UAAU,CAAC,cAAc,CAAC,sBAAsB,CAAC;IACjD,OAAO,CAAC,QAAQ,CAAC;GACL,oBAAoB,CAyIhC;SAzIY,oBAAoB;AA2IjC,MAAM,OAAO,YAAY;IACvB,gEAAgE;IACzD,MAAM,CAAC,IAAI,KAAI,CAAC;CACxB","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/adjacent-overload-signatures */\n// reference: https://github-wiki-see.page/m/serenity-is/Serenity/wiki/CheckBox-Group-Editor\n\nimport { Decorators, EnumKeyAttribute, EnumTypeRegistry, IReadOnly, Widget } from '@serenity-is/corelib'\nimport {\n coalesce,\n Enum,\n getAttributes,\n getLookup,\n isArray,\n isEmptyOrNull,\n toId,\n tryGetText,\n} from '@serenity-is/corelib/q'\nimport Element = Decorators.element\n\nexport type CheckboxButtonEditorOptions = {\n enumKey?: string\n enumType?: any\n lookupKey?: string\n isStringId?: boolean\n}\n\n@Decorators.registerEditor('CheckboxButtonEditor')\n@Element('<div/>')\nexport class CheckboxButtonEditor extends Widget<CheckboxButtonEditorOptions> implements IReadOnly {\n private _items: Array<{ [key: string]: any }>\n private readonly _idField: string\n private readonly _textField: string\n private readonly _isStringId: boolean\n\n constructor(input: JQuery, opt: CheckboxButtonEditorOptions) {\n super(input, opt)\n\n if (isEmptyOrNull(this.options.enumKey) && this.options.enumType == null && isEmptyOrNull(this.options.lookupKey)) {\n return\n }\n\n this._isStringId = this.options.isStringId\n\n if (!isEmptyOrNull(this.options.lookupKey)) {\n const lookup = getLookup(this.options.lookupKey)\n this._idField = lookup.idField\n this._textField = lookup.textField\n this.set_items(lookup.items as Array<{ [key: string]: any }>)\n } else {\n const enumType = this.options.enumType || EnumTypeRegistry.get(this.options.enumKey)\n let enumKey = this.options.enumKey\n\n if (enumKey == null && enumType != null) {\n const enumKeyAttr = getAttributes(enumType, EnumKeyAttribute, false)\n if (enumKeyAttr.length > 0) {\n enumKey = enumKeyAttr[0].value\n }\n }\n const values = Enum.getValues(enumType)\n for (const x of values) {\n const name = Enum.toString(enumType, x)\n this.addCheckbox(x.toString(), coalesce(tryGetText('Enums.' + enumKey + '.' + name), name))\n }\n }\n\n this.element.addClass('d-flex flex-wrap')\n }\n\n protected renderCheckboxes() {\n this.element.children('div').remove()\n\n for (const item of this._items) {\n const textValue = item[this._textField]\n const text = textValue == null ? '' : textValue.toString()\n const idValue = item[this._idField]\n const id = idValue == null ? '' : idValue.toString()\n this.addCheckbox(id, text)\n }\n }\n\n protected addCheckbox(value: string, text: string) {\n const div = $('<div class=\"col-12 col-sm-6 col-md-4 col-xl-3\" />')\n const label = $('<label/>').text(text.replace(/, /g, ',').replace(/,/g, ', '))\n $('<input type=\"checkbox\" class=\"me-2\" />')\n .attr('name', this.uniqueName)\n .attr('id', this.uniqueName + '_' + value)\n .attr('value', value)\n .prependTo(label)\n label.appendTo(div)\n div.appendTo(this.element)\n }\n\n get_items(): Array<{ [key: string]: any }> {\n return this._items\n }\n\n get items(): Array<{ [key: string]: any }> {\n return this.get_items()\n }\n\n set_items(value: Array<{ [key: string]: any }>) {\n this._items = value\n this.renderCheckboxes()\n }\n\n set items(v: Array<{ [key: string]: any }>) {\n this.set_items(v)\n }\n\n get_value(): string {\n const val: unknown[] = []\n this.element.find('input:checked').each((i, e) => {\n val.push(this._isStringId ? $(e).val() : toId($(e).val()))\n })\n return val.join(',')\n }\n\n get value(): string {\n return this.get_value()\n }\n\n set_value(value: string): void {\n if (value !== this.get_value()) {\n let values: unknown[] = []\n if (!isEmptyOrNull(value)) {\n values = this._isStringId ? value.split(',') : value.split(',').map(p => Number(p))\n }\n const inputs = this.element.find('input')\n inputs.each((i, e) => {\n ;(e as HTMLInputElement).checked = false\n })\n\n if (isArray(values)) {\n values.forEach(v => {\n const checks = inputs.filter('[value=' + v + ']')\n if (checks.length > 0) {\n ;(checks[0] as HTMLInputElement).checked = true\n }\n })\n } else {\n const checks = inputs.filter('[value=' + values + ']')\n if (checks.length > 0) {\n ;(checks[0] as HTMLInputElement).checked = true\n }\n }\n }\n }\n\n set value(v: string) {\n this.set_value(v)\n }\n\n get_readOnly(): boolean {\n return this.element.attr('disabled') != null\n }\n\n set_readOnly(value: boolean): void {\n if (this.get_readOnly() !== value) {\n if (value) {\n this.element.attr('disabled', 'disabled').find('input').attr('disabled', 'disabled')\n } else {\n this.element.removeAttr('disabled').find('input').removeAttr('disabled')\n }\n }\n }\n}\n\nexport class idevsEditors {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n public static load() {}\n}\n"]}
|
package/package.json
CHANGED
|
@@ -78,8 +78,8 @@ export class CheckboxButtonEditor extends Widget<CheckboxButtonEditorOptions> im
|
|
|
78
78
|
|
|
79
79
|
protected addCheckbox(value: string, text: string) {
|
|
80
80
|
const div = $('<div class="col-12 col-sm-6 col-md-4 col-xl-3" />')
|
|
81
|
-
const label = $('<label/>').text(text)
|
|
82
|
-
$('<input type="checkbox" class="me-2"/>')
|
|
81
|
+
const label = $('<label/>').text(text.replace(/, /g, ',').replace(/,/g, ', '))
|
|
82
|
+
$('<input type="checkbox" class="me-2" />')
|
|
83
83
|
.attr('name', this.uniqueName)
|
|
84
84
|
.attr('id', this.uniqueName + '_' + value)
|
|
85
85
|
.attr('value', value)
|