-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
style: add prefixes to all helpers/enums/constats fp-69 (#121)
- Loading branch information
1 parent
c8448ae
commit 2511c94
Showing
40 changed files
with
523 additions
and
459 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export { ControlType } from './libs/enums/enums.js'; | ||
export { ControlElementType } from './libs/enums/enums.js'; | ||
export { FormPayloadError } from './libs/exceptions/exceptions.js'; | ||
export { getFormControlPayload } from './packages/get-form-control-payload/get-form-control-payload.js'; | ||
export { getFormPayload } from './packages/get-form-payload/get-form-payload.js'; |
10 changes: 10 additions & 0 deletions
10
src/libs/constants/banned-control-element-types.constant.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { ControlElementType } from '../enums/enums.js'; | ||
|
||
const BANNED_CONTROL_ELEMENT_TYPES = /** @type {const} */ ([ | ||
ControlElementType.BUTTON, | ||
ControlElementType.RESET, | ||
ControlElementType.SUBMIT, | ||
ControlElementType.IMAGE, | ||
]); | ||
|
||
export { BANNED_CONTROL_ELEMENT_TYPES }; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export { BANNED_CONTROL_TYPES } from './banned-control-types.constant.js'; | ||
export { VALUE_AS_ARRAY_CUSTOM_CONTROL_TYPES } from './value-as-array-custom-control-types.constant.js'; | ||
export { BANNED_CONTROL_ELEMENT_TYPES } from './banned-control-element-types.constant.js'; | ||
export { VALUE_AS_ARRAY_CUSTOM_CONTROL_ELEMENT_TYPES } from './value-as-array-custom-control-element-types.constant.js'; | ||
export { VALUE_AS_ARRAY_IDENTIFIER } from './value-as-array-identifier.constant.js'; |
8 changes: 8 additions & 0 deletions
8
src/libs/constants/value-as-array-custom-control-element-types.constant.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { ControlElementType } from '../enums/enums.js'; | ||
|
||
const VALUE_AS_ARRAY_CUSTOM_CONTROL_ELEMENT_TYPES = [ | ||
ControlElementType.CHECKBOX, | ||
ControlElementType.FIELDSET, | ||
]; | ||
|
||
export { VALUE_AS_ARRAY_CUSTOM_CONTROL_ELEMENT_TYPES }; |
8 changes: 0 additions & 8 deletions
8
src/libs/constants/value-as-array-custom-control-types.constant.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export { ControlType } from './control-type.enum.js'; | ||
export { ControlElementType } from './control-element-type.enum.js'; |
114 changes: 60 additions & 54 deletions
114
src/packages/get-form-control-payload/get-form-control-payload.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,118 +1,124 @@ | ||
import { ControlType } from '../../libs/enums/enums.js'; | ||
import { ControlElementType } from '../../libs/enums/enums.js'; | ||
import { FormPayloadError } from '../../libs/exceptions/exceptions.js'; | ||
import { | ||
getCheckboxValue, | ||
getDatetimeLocalValue, | ||
getFieldsetValue, | ||
getFormControlValue, | ||
getInputDateValue, | ||
getInputEmailValue, | ||
getInputFileValue, | ||
getInputNumericValue, | ||
getMultiSelectValues, | ||
getCheckboxControlElementValue, | ||
getControlElementValue, | ||
getDateControlElementValue, | ||
getDatetimeLocaControlElementValue, | ||
getEmailControlElementValue, | ||
getFieldsetControlElementValue, | ||
getFileControlElementValue, | ||
getMultiselectControlElementValue, | ||
getNumericControlElementValue, | ||
} from './helpers/helpers.js'; | ||
|
||
/** @typedef {import('../../libs/types/types.js').HTMLFormOperationalControlElement} HTMLFormOperationalControlElement */ | ||
|
||
/** | ||
* @template {unknown} T | ||
* @param {HTMLFormOperationalControlElement} controlNode | ||
* @param {HTMLFormOperationalControlElement} controlElement | ||
* @returns {T} | ||
* @throws {FormPayloadError} | ||
*/ | ||
const getFormControlPayload = (controlNode) => { | ||
const hasType = 'type' in controlNode; | ||
const getFormControlPayload = (controlElement) => { | ||
const hasType = 'type' in controlElement; | ||
|
||
if (!hasType) { | ||
throw new FormPayloadError({ | ||
message: 'Control element has no type attribute.', | ||
}); | ||
} | ||
|
||
switch (controlNode.type) { | ||
case ControlType.TEXT: | ||
case ControlType.PASSWORD: | ||
case ControlType.SEARCH: | ||
case ControlType.URL: | ||
case ControlType.TEL: | ||
case ControlType.COLOR: | ||
case ControlType.RADIO: | ||
case ControlType.HIDDEN: | ||
case ControlType.TEXTAREA: | ||
case ControlType.SELECT_ONE: | ||
case ControlType.OUTPUT: { | ||
switch (controlElement.type) { | ||
case ControlElementType.TEXT: | ||
case ControlElementType.PASSWORD: | ||
case ControlElementType.SEARCH: | ||
case ControlElementType.URL: | ||
case ControlElementType.TEL: | ||
case ControlElementType.COLOR: | ||
case ControlElementType.RADIO: | ||
case ControlElementType.HIDDEN: | ||
case ControlElementType.TEXTAREA: | ||
case ControlElementType.SELECT_ONE: | ||
case ControlElementType.OUTPUT: { | ||
return /** @type {T} */ ( | ||
getFormControlValue( | ||
getControlElementValue( | ||
/** | ||
* @type {HTMLInputElement | ||
* | HTMLOutputElement | ||
* | HTMLTextAreaElement | ||
* | HTMLSelectElement} | ||
*/ (controlNode), | ||
*/ (controlElement), | ||
) | ||
); | ||
} | ||
case ControlType.EMAIL: { | ||
case ControlElementType.EMAIL: { | ||
return /** @type {T} */ ( | ||
getInputEmailValue( | ||
/** @type {HTMLInputElement} */ (controlNode), | ||
getEmailControlElementValue( | ||
/** @type {HTMLInputElement} */ (controlElement), | ||
) | ||
); | ||
} | ||
case ControlType.NUMBER: | ||
case ControlType.RANGE: { | ||
case ControlElementType.NUMBER: | ||
case ControlElementType.RANGE: { | ||
return /** @type {T} */ ( | ||
getInputNumericValue( | ||
/** @type {HTMLInputElement} */ (controlNode), | ||
getNumericControlElementValue( | ||
/** @type {HTMLInputElement} */ (controlElement), | ||
) | ||
); | ||
} | ||
case ControlType.CHECKBOX: { | ||
case ControlElementType.CHECKBOX: { | ||
return /** @type {T} */ ( | ||
getCheckboxValue(/** @type {HTMLInputElement} */ (controlNode)) | ||
getCheckboxControlElementValue( | ||
/** @type {HTMLInputElement} */ (controlElement), | ||
) | ||
); | ||
} | ||
case ControlType.DATE: | ||
case ControlType.TIME: | ||
case ControlType.MONTH: | ||
case ControlType.WEEK: { | ||
case ControlElementType.DATE: | ||
case ControlElementType.TIME: | ||
case ControlElementType.MONTH: | ||
case ControlElementType.WEEK: { | ||
return /** @type {T} */ ( | ||
getInputDateValue(/** @type {HTMLInputElement} */ (controlNode)) | ||
getDateControlElementValue( | ||
/** @type {HTMLInputElement} */ (controlElement), | ||
) | ||
); | ||
} | ||
case ControlType.DATETIME_LOCAL: { | ||
case ControlElementType.DATETIME_LOCAL: { | ||
return /** @type {T} */ ( | ||
getDatetimeLocalValue( | ||
/** @type {HTMLInputElement} */ (controlNode), | ||
getDatetimeLocaControlElementValue( | ||
/** @type {HTMLInputElement} */ (controlElement), | ||
) | ||
); | ||
} | ||
case ControlType.FILE: { | ||
case ControlElementType.FILE: { | ||
return /** @type {T} */ ( | ||
getInputFileValue(/** @type {HTMLInputElement} */ (controlNode)) | ||
getFileControlElementValue( | ||
/** @type {HTMLInputElement} */ (controlElement), | ||
) | ||
); | ||
} | ||
case ControlType.SELECT_MULTIPLE: { | ||
case ControlElementType.SELECT_MULTIPLE: { | ||
return /** @type {T} */ ( | ||
getMultiSelectValues( | ||
/** @type {HTMLSelectElement} */ (controlNode), | ||
getMultiselectControlElementValue( | ||
/** @type {HTMLSelectElement} */ (controlElement), | ||
) | ||
); | ||
} | ||
case ControlType.FIELDSET: { | ||
case ControlElementType.FIELDSET: { | ||
return /** @type {T} */ ( | ||
getFieldsetValue( | ||
getFieldsetControlElementValue( | ||
getFormControlPayload, | ||
/** @type {HTMLFieldSetElement} */ (controlNode), | ||
/** @type {HTMLFieldSetElement} */ (controlElement), | ||
) | ||
); | ||
} | ||
} | ||
|
||
throw new FormPayloadError({ | ||
message: `Unsupported control element type – ${controlNode.type}.`, | ||
message: `Unsupported control element type – ${controlElement.type}.`, | ||
}); | ||
}; | ||
|
||
export { getFormControlsPayload } from './helpers/helpers.js'; | ||
export { getFormControlElementsPayload } from './helpers/helpers.js'; | ||
export { getFormControlPayload }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...oad/helpers/check-is-refer-to-another-element/check-is-refer-to-another-element.helper.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** @typedef {import('../../../../libs/types/types.js').HTMLFormOperationalControlElement} HTMLFormOperationalControlElement */ | ||
|
||
/** | ||
* @param {HTMLFormOperationalControlElement} currentElement | ||
* @param {HTMLFormOperationalControlElement[]} checkedElements | ||
* @returns {boolean} | ||
*/ | ||
const checkIsReferToAnotherElement = (currentElement, checkedElements) => { | ||
return checkedElements.some((checkedElement) => { | ||
const hasElements = | ||
'elements' in checkedElement && checkedElement.elements.length > 0; | ||
|
||
if (!hasElements) { | ||
return false; | ||
} | ||
|
||
return [...checkedElement.elements].some((element) => | ||
element.contains(currentElement), | ||
); | ||
}); | ||
}; | ||
|
||
export { checkIsReferToAnotherElement }; |
24 changes: 0 additions & 24 deletions
24
...l-payload/helpers/check-is-refer-to-another-node/check-is-refer-to-another-node.helper.js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.