ability-attributes
Advanced tools
Comparing version 0.0.4 to 0.0.5
'use strict'; | ||
function _inheritsLoose(subClass, superClass) { | ||
subClass.prototype = Object.create(superClass.prototype); | ||
subClass.prototype.constructor = subClass; | ||
subClass.__proto__ = superClass; | ||
} | ||
function _getPrototypeOf(o) { | ||
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { | ||
return o.__proto__ || Object.getPrototypeOf(o); | ||
}; | ||
return _getPrototypeOf(o); | ||
} | ||
function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { | ||
o.__proto__ = p; | ||
return o; | ||
}; | ||
return _setPrototypeOf(o, p); | ||
} | ||
function isNativeReflectConstruct() { | ||
if (typeof Reflect === "undefined" || !Reflect.construct) return false; | ||
if (Reflect.construct.sham) return false; | ||
if (typeof Proxy === "function") return true; | ||
try { | ||
Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
function _construct(Parent, args, Class) { | ||
if (isNativeReflectConstruct()) { | ||
_construct = Reflect.construct; | ||
} else { | ||
_construct = function _construct(Parent, args, Class) { | ||
var a = [null]; | ||
a.push.apply(a, args); | ||
var Constructor = Function.bind.apply(Parent, a); | ||
var instance = new Constructor(); | ||
if (Class) _setPrototypeOf(instance, Class.prototype); | ||
return instance; | ||
}; | ||
} | ||
return _construct.apply(null, arguments); | ||
} | ||
function _isNativeFunction(fn) { | ||
return Function.toString.call(fn).indexOf("[native code]") !== -1; | ||
} | ||
function _wrapNativeSuper(Class) { | ||
var _cache = typeof Map === "function" ? new Map() : undefined; | ||
_wrapNativeSuper = function _wrapNativeSuper(Class) { | ||
if (Class === null || !_isNativeFunction(Class)) return Class; | ||
if (typeof Class !== "function") { | ||
throw new TypeError("Super expression must either be null or a function"); | ||
} | ||
if (typeof _cache !== "undefined") { | ||
if (_cache.has(Class)) return _cache.get(Class); | ||
_cache.set(Class, Wrapper); | ||
} | ||
function Wrapper() { | ||
return _construct(Class, arguments, _getPrototypeOf(this).constructor); | ||
} | ||
Wrapper.prototype = Object.create(Class.prototype, { | ||
constructor: { | ||
value: Wrapper, | ||
enumerable: false, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
return _setPrototypeOf(Wrapper, Class); | ||
}; | ||
return _wrapNativeSuper(Class); | ||
} | ||
function _assertThisInitialized(self) { | ||
if (self === void 0) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
return self; | ||
} | ||
/*! | ||
@@ -11,210 +109,605 @@ * Copyright (c) Microsoft Corporation. All rights reserved. | ||
var ATTRIBUTE_NAME_PROPS = 'data-aa-props'; | ||
var AbilityAttributesError = | ||
/*#__PURE__*/ | ||
function (_Error) { | ||
_inheritsLoose(AbilityAttributesError, _Error); | ||
/*! | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
function AbilityAttributesError() { | ||
return _Error.apply(this, arguments) || this; | ||
} | ||
return AbilityAttributesError; | ||
}(_wrapNativeSuper(Error)); | ||
var ErrorReporter = function ErrorReporter() {}; | ||
var _lastId = 0; | ||
var _lastDismissAllId = 0; | ||
function createElements() { | ||
var _errors = {}; | ||
var ErrorReporter$1 = | ||
/*#__PURE__*/ | ||
function (_ErrorReporterBase) { | ||
_inheritsLoose(ErrorReporter, _ErrorReporterBase); | ||
var style = document.createElement('style'); | ||
style.appendChild(document.createTextNode("\n.aa-error-container {\n background: #e07777;\n bottom: 0;\n box-shadow: 0 0 4px rgba(0, 0, 0, .3);\n color: #000;\n font-family: Helvetica;\n font-size: 14px;\n left: 0;\n line-height: 20px;\n max-height: 205px;\n opacity: .95;\n overflow: scroll;\n position: fixed;\n right: 0;\n z-index: 2147483647;\n}\n\n.aa-error-container * {\n box-sizing: border-box;\n}\n\n.aa-error-message {\n border-top: 1px solid #ddd;\n clear: both;\n min-height: 24px;\n padding: 8px 16px 8px 36px;\n position: relative;\n z-index: 1;\n}\n\n.aa-error-message.aa-error-message_render {\n background: #bbb;\n}\n\n.aa-error-locator {\n color: #333;\n display: none;\n float: right;\n font-size: 80%;\n}\n\n.aa-error-locator.aa-error-locator_available {\n display: block;\n}\n\n.aa-error-dismiss {\n background: #987575;\n border-radius: 4px;\n border: 1px solid #ec99a8;\n color: #fff;\n cursor: pointer;\n height: 21px;\n left: 8px;\n margin-top: -10px;\n position: absolute;\n top: 50%;\n width: 21px;\n}\n\n.aa-error-dismiss:hover {\n background: #aa8a8a;\n color: #777;\n}\n\n.aa-error-dismiss::before {\n content: '\xD7';\n left: 5px;\n line-height: 17px;\n position: absolute;\n}\n\n.aa-error-dismiss-all {\n background: #640d0d;\n border-bottom: none;\n border-radius: 10px 10px 2px 2px;\n border: 1px solid #ec99a8;\n bottom: 0;\n color: #fff;\n cursor: pointer;\n display: none;\n font-size: 80%;\n left: 50%;\n margin-left: -50px;\n opacity: .8;\n padding: 4px;\n position: fixed;\n text-align: center;\n width: 100px;\n z-index: 100500;\n}")); | ||
var container = document.createElement('div'); | ||
var elements = []; | ||
var elementByErrorId = {}; | ||
container.__aaAddError = addError; | ||
container.__aaGetError = getError; | ||
container.__aaDismissError = dismissError; | ||
container.className = 'aa-error-container'; | ||
var dismissAll = document.createElement('div'); | ||
dismissAll.className = 'aa-error-dismiss-all'; | ||
dismissAll.innerText = 'Dismiss all'; | ||
container.appendChild(dismissAll); | ||
container.addEventListener('click', function (e) { | ||
var shouldDismiss = false; | ||
function ErrorReporter(w) { | ||
var _this; | ||
for (var n = e.target; n; n = n.parentElement) { | ||
if (n.classList) { | ||
if (n.classList.contains('aa-error-dismiss')) { | ||
shouldDismiss = true; | ||
} else if (shouldDismiss && n.classList.contains('aa-error-message')) { | ||
dismissError(n); | ||
break; | ||
} else if (n.classList.contains('aa-error-dismiss-all')) { | ||
_lastDismissAllId = _lastId; | ||
_this = _ErrorReporterBase.call(this) || this; | ||
_this._isCollapsed = true; | ||
var _e = void 0; | ||
_this.toggle = function () { | ||
_this._isCollapsed = !_this._isCollapsed; | ||
elementByErrorId = {}; | ||
if (_this._isCollapsed) { | ||
Object.keys(_errors).forEach(function (id) { | ||
var meta = _errors[id]; | ||
while (_e = elements.pop()) { | ||
if (container.contains(_e)) { | ||
container.removeChild(_e); | ||
} | ||
if (meta.visible) { | ||
_this.dismiss(meta.element); | ||
} | ||
}); | ||
} else { | ||
Object.keys(_errors).forEach(function (id) { | ||
_errors[id].visible = true; | ||
}); | ||
} | ||
break; | ||
} | ||
} | ||
_this._render(); | ||
}; | ||
_this._window = w; | ||
if (_this._window.__abilityAttributesDev) { | ||
return _this._window.__abilityAttributesDev.error || _assertThisInitialized(_this); | ||
} | ||
updateState(); | ||
}); | ||
container.addEventListener('dblclick', function (e) { | ||
for (var n = e.target; n; n = n.parentElement) { | ||
if (n.classList && n.classList.contains('aa-error-message')) { | ||
dismissError(n); | ||
break; | ||
_this._initUI(false); | ||
return _this; | ||
} | ||
var _proto = ErrorReporter.prototype; | ||
_proto.report = function report(element, error) { | ||
var meta = element.__aaError; | ||
if (meta) { | ||
if (meta.error.message !== error.message) { | ||
meta.visible = true; | ||
meta.shouldRerender = true; | ||
meta.error.message = error.message; | ||
delete _errors[meta.id]; | ||
_errors[meta.id] = meta; | ||
} | ||
} else { | ||
meta = element.__aaError = { | ||
id: "" + ++_lastId, | ||
element: element, | ||
error: error, | ||
visible: true | ||
}; | ||
_errors[meta.id] = meta; | ||
} | ||
updateState(); | ||
}); | ||
return { | ||
style: style, | ||
container: container | ||
element.setAttribute(ATTRIBUTE_NAME_ERROR_ID, meta.id); | ||
element.setAttribute(ATTRIBUTE_NAME_ERROR_MESSAGE, meta.error.message); | ||
if (meta.visible) { | ||
meta.locator = "$('[" + ATTRIBUTE_NAME_ERROR_ID + "=\"" + meta.id + "\"]')"; | ||
this._render(); | ||
console.error(error.message + ", " + meta.locator); | ||
} | ||
}; | ||
function updateState() { | ||
dismissAll.style.display = elements.length > 1 ? 'block' : 'none'; | ||
} | ||
_proto.remove = function remove(element) { | ||
var meta = element.__aaError; | ||
function addError(id, e) { | ||
if (!elementByErrorId[id]) { | ||
elements.push(e); | ||
elementByErrorId[id] = e; | ||
if (meta) { | ||
delete _errors[meta.id]; | ||
delete element.__aaError; | ||
delete meta.element; | ||
element.removeAttribute(ATTRIBUTE_NAME_ERROR_ID); | ||
element.removeAttribute(ATTRIBUTE_NAME_ERROR_MESSAGE); | ||
this._removeErrorView(meta); | ||
this._render(); | ||
} | ||
}; | ||
if (container.firstChild) { | ||
if (container.firstChild !== e) { | ||
container.insertBefore(e, container.firstChild); | ||
} | ||
} else { | ||
container.appendChild(e); | ||
_proto.dismiss = function dismiss(element) { | ||
var meta = element.__aaError; | ||
if (meta) { | ||
meta.visible = false; | ||
this._removeErrorView(meta); | ||
this._render(); | ||
} | ||
}; | ||
updateState(); | ||
} | ||
_proto._initUI = function _initUI(append) { | ||
if (!this._styles) { | ||
this._styles = document.createElement('style'); | ||
function getError(id) { | ||
return elementByErrorId[id]; | ||
} | ||
this._styles.appendChild(document.createTextNode(".aa-error-container {\n bottom: 0;\n color: #000;\n display: flex;\n font-family: Arial, Helvetica, sans-serif;\n font-size: 14px;\n justify-content: center;\n left: 0;\n line-height: 20px;\n max-height: 205px;\n opacity: .90;\n position: fixed;\n right: 0;\n z-index: 2147483647;\n}\n\n.aa-error-expanded {\n background: #ffa0a0;\n border-top: 1px solid #000;\n flex-grow: 1;\n max-height: 205px;\n overflow: scroll;\n}\n\n.aa-error-container * {\n box-sizing: border-box;\n}\n\n.aa-error-message {\n border-bottom: 1px solid #ddd;\n display: flex;\n justify-content: space-between;\n min-height: 24px;\n padding: 8px 16px;\n position: relative;\n z-index: 1;\n}\n\n.aa-error-dismiss {\n align-self: baseline;\n cursor: pointer;\n font-size: 12px;\n margin-right: 8px;\n}\n\n.aa-error-text {\n flex-grow: 1;\n}\n\n.aa-error-locator {\n color: #333;\n font-size: 80%;\n white-space: nowrap;\n}\n\n.aa-error-toggle {\n background: #914040;\n border-radius: 20px 20px 0 0;\n border: 1px solid #000;\n color: #fff;\n cursor: pointer;\n font-size: 14px;\n line-height: 24px;\n padding: 0 16px;\n position: absolute;\n top: -25px;\n z-index: 2147483647;\n}\n")); | ||
function dismissError(e, keepInDOM) { | ||
if (!keepInDOM && container.contains(e)) { | ||
container.removeChild(e); | ||
this._container = document.createElement('div'); | ||
this._expanded = document.createElement('div'); | ||
this._toggle = document.createElement('button'); | ||
this._container.className = 'aa-error-container'; | ||
this._expanded.className = 'aa-error-expanded'; | ||
this._toggle.className = 'aa-error-toggle'; | ||
this._container.style.display = 'none'; | ||
this._expanded.style.display = 'none'; | ||
this._container.appendChild(this._expanded); | ||
this._container.appendChild(this._toggle); | ||
this._toggle.addEventListener('click', this.toggle); | ||
} | ||
var prevId = e.getAttribute(ATTRIBUTE_NAME_ERROR_ID); | ||
if (append) { | ||
if (!this._styles.parentNode) { | ||
this._window.document.head.appendChild(this._styles); | ||
} | ||
if (prevId) { | ||
delete elementByErrorId[prevId]; | ||
this._window.document.body.appendChild(this._container); | ||
} | ||
}; | ||
var index = elements.indexOf(e); | ||
_proto._render = function _render() { | ||
var _this2 = this; | ||
if (index >= 0) { | ||
elements.splice(index, 1); | ||
updateState(); | ||
if (this._renderTimer) { | ||
return; | ||
} | ||
} | ||
} | ||
function reportError(env, message, element, isRender) { | ||
var errorContainer = env.errorContainer; | ||
this._renderTimer = this._window.setTimeout(function () { | ||
_this2._renderTimer = undefined; | ||
if (!errorContainer.__aaAddError || !errorContainer.__aaGetError || !errorContainer.__aaDismissError) { | ||
return null; | ||
} | ||
_this2._reallyRender(); | ||
}, 0); | ||
}; | ||
var prevId = element ? element.getAttribute(ATTRIBUTE_NAME_ERROR_ID) : null; | ||
var errorElement; | ||
var errorText; | ||
var errorLocator; | ||
_proto._reallyRender = function _reallyRender() { | ||
var hasVisible = false; | ||
var ids = Object.keys(_errors); | ||
ids.forEach(function (id) { | ||
var e = _errors[id]; | ||
if (prevId) { | ||
errorElement = errorContainer.__aaGetError(prevId); | ||
} | ||
if (e.visible) { | ||
hasVisible = true; | ||
} | ||
}); | ||
if (!errorElement) { | ||
errorElement = document.createElement('div'); | ||
errorElement.className = 'aa-error-message' + (isRender ? ' aa-error-message_render' : ''); | ||
var dismiss = document.createElement('div'); | ||
this._initUI(true); | ||
if (ids.length > 0 && (this._isCollapsed || !hasVisible)) { | ||
this._isCollapsed = true; | ||
this._showCounter(ids.length); | ||
} else if (!this._isCollapsed && hasVisible) { | ||
this._showExpanded(); | ||
} else { | ||
this._hide(); | ||
} | ||
}; | ||
_proto._showCounter = function _showCounter(count) { | ||
this._toggle.innerText = "Show " + count + " accessibility error" + (count !== 1 ? 's' : ''); | ||
this._expanded.style.display = 'none'; | ||
this._container.style.display = 'flex'; | ||
}; | ||
_proto._showExpanded = function _showExpanded() { | ||
var _this3 = this; | ||
this._toggle.innerText = "Collapse errors"; | ||
Object.keys(_errors).forEach(function (id) { | ||
var meta = _errors[id]; | ||
if (meta.visible) { | ||
if (meta.shouldRerender) { | ||
delete meta.shouldRerender; | ||
_this3._removeErrorView(meta); | ||
} | ||
if (!meta.rendered) { | ||
meta.rendered = _this3._createErrorView(meta); | ||
} | ||
_this3._expanded.insertBefore(meta.rendered, _this3._expanded.firstChild || null); | ||
} | ||
}); | ||
this._expanded.style.display = null; | ||
this._container.style.display = 'flex'; | ||
}; | ||
_proto._hide = function _hide() { | ||
this._container.style.display = 'none'; | ||
}; | ||
_proto._createErrorView = function _createErrorView(meta) { | ||
var _this4 = this; | ||
var div = this._window.document.createElement('div'); | ||
div.className = 'aa-error-message'; | ||
var dismiss = this._window.document.createElement('button'); | ||
dismiss.className = 'aa-error-dismiss'; | ||
errorElement.appendChild(dismiss); | ||
errorText = document.createElement('span'); | ||
errorElement.appendChild(errorText); | ||
errorLocator = document.createElement('div'); | ||
errorElement.appendChild(errorLocator); | ||
} else { | ||
var _dismiss = errorElement.firstChild; | ||
dismiss.setAttribute('aria-label', "Dismiss error " + meta.id); | ||
dismiss.innerText = 'X'; | ||
dismiss.addEventListener('click', function () { | ||
_this4.dismiss(meta.element); | ||
}); | ||
div.appendChild(dismiss); | ||
if (_dismiss) { | ||
errorText = _dismiss.nextSibling; | ||
var text = this._window.document.createElement('span'); | ||
text.className = 'aa-error-text'; | ||
text.innerText = meta.error.message; | ||
div.appendChild(text); | ||
if (meta.locator) { | ||
var locator = this._window.document.createElement('div'); | ||
locator.className = 'aa-error-locator'; | ||
locator.innerText = meta.locator; | ||
div.appendChild(locator); | ||
} | ||
if (errorText) { | ||
errorLocator = errorText.nextSibling; | ||
div.addEventListener('dblclick', function () { | ||
_this4.dismiss(meta.element); | ||
}); | ||
return div; | ||
}; | ||
_proto._removeErrorView = function _removeErrorView(meta) { | ||
if (meta.rendered) { | ||
if (meta.rendered.parentNode) { | ||
meta.rendered.parentNode.removeChild(meta.rendered); | ||
} | ||
delete meta.rendered; | ||
} | ||
}; | ||
return ErrorReporter; | ||
}(ErrorReporter); | ||
var ErrorCode; | ||
(function (ErrorCode) { | ||
ErrorCode[ErrorCode["AmbiguousAssumption"] = 1] = "AmbiguousAssumption"; | ||
ErrorCode[ErrorCode["IllegalTag"] = 2] = "IllegalTag"; | ||
ErrorCode[ErrorCode["UnknownParameter"] = 3] = "UnknownParameter"; | ||
ErrorCode[ErrorCode["ExcessiveParameter"] = 4] = "ExcessiveParameter"; | ||
ErrorCode[ErrorCode["IllegalParameterValue"] = 5] = "IllegalParameterValue"; | ||
ErrorCode[ErrorCode["MissingParameter"] = 6] = "MissingParameter"; | ||
ErrorCode[ErrorCode["SchemaNoAttributeValue"] = 7] = "SchemaNoAttributeValue"; | ||
ErrorCode[ErrorCode["SchemaIllegalAttributeValue"] = 8] = "SchemaIllegalAttributeValue"; | ||
ErrorCode[ErrorCode["ExcessiveAttribute"] = 9] = "ExcessiveAttribute"; | ||
ErrorCode[ErrorCode["InconsistentParameterValue"] = 10] = "InconsistentParameterValue"; | ||
ErrorCode[ErrorCode["IllegalAttributeValue"] = 11] = "IllegalAttributeValue"; | ||
ErrorCode[ErrorCode["MissingAttribute"] = 12] = "MissingAttribute"; | ||
ErrorCode[ErrorCode["IllegalTagAttribute"] = 13] = "IllegalTagAttribute"; | ||
ErrorCode[ErrorCode["UnknownClass"] = 14] = "UnknownClass"; | ||
ErrorCode[ErrorCode["ValidationFailed"] = 15] = "ValidationFailed"; | ||
ErrorCode[ErrorCode["NoClass"] = 16] = "NoClass"; | ||
ErrorCode[ErrorCode["ConstraintNotSatisfied"] = 17] = "ConstraintNotSatisfied"; | ||
ErrorCode[ErrorCode["XPathExpressionFailed"] = 18] = "XPathExpressionFailed"; | ||
})(ErrorCode || (ErrorCode = {})); | ||
var AmbiguousAssumptionError = | ||
/*#__PURE__*/ | ||
function (_AbilityAttributesErr) { | ||
_inheritsLoose(AmbiguousAssumptionError, _AbilityAttributesErr); | ||
function AmbiguousAssumptionError(className1, className2) { | ||
var _this; | ||
_this = _AbilityAttributesErr.call(this, "Ambiguous class assumption: '" + className1 + "' and '" + className2 + "'") || this; | ||
_this.code = ErrorCode.AmbiguousAssumption; | ||
return _this; | ||
} | ||
if (!errorText || !errorLocator) { | ||
return null; | ||
return AmbiguousAssumptionError; | ||
}(AbilityAttributesError); | ||
var UnknownClassError = | ||
/*#__PURE__*/ | ||
function (_AbilityAttributesErr2) { | ||
_inheritsLoose(UnknownClassError, _AbilityAttributesErr2); | ||
function UnknownClassError(className) { | ||
var _this2; | ||
_this2 = _AbilityAttributesErr2.call(this, "Unknown class '" + className + "'") || this; | ||
_this2.code = ErrorCode.UnknownClass; | ||
return _this2; | ||
} | ||
if (!message) { | ||
if (prevId) { | ||
errorContainer.__aaDismissError(errorElement); | ||
return UnknownClassError; | ||
}(AbilityAttributesError); | ||
var ValidationFailedError = | ||
/*#__PURE__*/ | ||
function (_AbilityAttributesErr3) { | ||
_inheritsLoose(ValidationFailedError, _AbilityAttributesErr3); | ||
if (element) { | ||
element.removeAttribute(ATTRIBUTE_NAME_ERROR_ID); | ||
element.removeAttribute(ATTRIBUTE_NAME_ERROR_MESSAGE); | ||
function ValidationFailedError() { | ||
var _this3; | ||
_this3 = _AbilityAttributesErr3.call(this, 'Failed to validate element') || this; | ||
_this3.code = ErrorCode.ValidationFailed; | ||
return _this3; | ||
} | ||
return ValidationFailedError; | ||
}(AbilityAttributesError); | ||
var ConstraintNotSatisfiedError = | ||
/*#__PURE__*/ | ||
function (_AbilityAttributesErr4) { | ||
_inheritsLoose(ConstraintNotSatisfiedError, _AbilityAttributesErr4); | ||
function ConstraintNotSatisfiedError(description, constraint) { | ||
var _this4; | ||
_this4 = _AbilityAttributesErr4.call(this, function () { | ||
var errorMessage = description; | ||
if (constraint.param || constraint.name && constraint.value) { | ||
errorMessage += ' ('; | ||
if (constraint.param) { | ||
errorMessage += "when no " + constraint.param + " specified"; | ||
} | ||
if (constraint.name && constraint.value) { | ||
if (constraint.param) { | ||
errorMessage += ', '; | ||
} | ||
errorMessage += "parameter '" + constraint.name + "', value: '" + constraint.value + "'"; | ||
} | ||
errorMessage += ')'; | ||
} | ||
} | ||
return null; | ||
return errorMessage; | ||
}()) || this; | ||
_this4.code = ErrorCode.ConstraintNotSatisfied; | ||
return _this4; | ||
} | ||
var errorId; | ||
var sameError = element ? element.getAttribute(ATTRIBUTE_NAME_ERROR_MESSAGE) === message : errorText.innerText === message; | ||
return ConstraintNotSatisfiedError; | ||
}(AbilityAttributesError); | ||
var XPathExpressionFailedError = | ||
/*#__PURE__*/ | ||
function (_AbilityAttributesErr5) { | ||
_inheritsLoose(XPathExpressionFailedError, _AbilityAttributesErr5); | ||
if (sameError && prevId) { | ||
if (_lastDismissAllId > parseInt(prevId, 10)) { | ||
return null; | ||
} | ||
function XPathExpressionFailedError(xpath, message) { | ||
var _this5; | ||
errorId = prevId; | ||
} else { | ||
errorContainer.__aaDismissError(errorElement, true); | ||
_this5 = _AbilityAttributesErr5.call(this, "Failed to evaluate expression: " + xpath + ", " + message) || this; | ||
_this5.code = ErrorCode.XPathExpressionFailed; | ||
return _this5; | ||
} | ||
errorElement.className = 'aa-error-message' + (isRender ? ' aa-error-message_render' : ''); | ||
errorText.innerText = message; | ||
errorId = ++env.lastErrorId + ''; | ||
return XPathExpressionFailedError; | ||
}(AbilityAttributesError); | ||
var NoClassError = | ||
/*#__PURE__*/ | ||
function (_AbilityAttributesErr6) { | ||
_inheritsLoose(NoClassError, _AbilityAttributesErr6); | ||
var _locator = "$('[" + ATTRIBUTE_NAME_ERROR_ID + "=\"" + errorId + "\"]')"; | ||
function NoClassError() { | ||
var _this6; | ||
errorLocator.innerText = _locator; | ||
errorElement.setAttribute(ATTRIBUTE_NAME_ERROR_ID, errorId); | ||
_this6 = _AbilityAttributesErr6.call(this, 'Accessible element must have accessibility class assigned') || this; | ||
_this6.code = ErrorCode.NoClass; | ||
return _this6; | ||
} | ||
if (element) { | ||
element.setAttribute(ATTRIBUTE_NAME_ERROR_ID, errorId); | ||
element.setAttribute(ATTRIBUTE_NAME_ERROR_MESSAGE, message); | ||
} | ||
return NoClassError; | ||
}(AbilityAttributesError); | ||
console.error(message + "\n\n" + _locator); | ||
var ClassError = | ||
/*#__PURE__*/ | ||
function (_AbilityAttributesErr7) { | ||
_inheritsLoose(ClassError, _AbilityAttributesErr7); | ||
function ClassError(message, className) { | ||
return _AbilityAttributesErr7.call(this, message + " in class '" + className + "'") || this; | ||
} | ||
errorText.innerText = message; | ||
var locator = "$('[" + ATTRIBUTE_NAME_ERROR_ID + "=\"" + errorId + "\"]')"; | ||
errorLocator.innerText = locator; | ||
errorElement.setAttribute(ATTRIBUTE_NAME_ERROR_ID, errorId); | ||
errorLocator.className = 'aa-error-locator' + (element ? ' aa-error-locator_available' : ''); | ||
return ClassError; | ||
}(AbilityAttributesError); | ||
errorContainer.__aaAddError(errorId, errorElement); | ||
var IllegalTagError = | ||
/*#__PURE__*/ | ||
function (_ClassError) { | ||
_inheritsLoose(IllegalTagError, _ClassError); | ||
_lastId = env.lastErrorId; | ||
return errorId + ''; | ||
} | ||
function IllegalTagError(tagName, className) { | ||
var _this7; | ||
_this7 = _ClassError.call(this, "Illegal tag '" + tagName + "'", className) || this; | ||
_this7.code = ErrorCode.IllegalTag; | ||
return _this7; | ||
} | ||
return IllegalTagError; | ||
}(ClassError); | ||
var UnknownParameterError = | ||
/*#__PURE__*/ | ||
function (_ClassError2) { | ||
_inheritsLoose(UnknownParameterError, _ClassError2); | ||
function UnknownParameterError(paramName, className) { | ||
var _this8; | ||
_this8 = _ClassError2.call(this, "Unknown parameter '" + paramName + "'", className) || this; | ||
_this8.code = ErrorCode.UnknownParameter; | ||
return _this8; | ||
} | ||
return UnknownParameterError; | ||
}(ClassError); | ||
var ExcessiveParameterError = | ||
/*#__PURE__*/ | ||
function (_ClassError3) { | ||
_inheritsLoose(ExcessiveParameterError, _ClassError3); | ||
function ExcessiveParameterError(paramName1, paramName2, className) { | ||
var _this9; | ||
_this9 = _ClassError3.call(this, "Only one of '" + paramName1 + "' or '" + paramName2 + "' parameters can be present", className) || this; | ||
_this9.code = ErrorCode.ExcessiveParameter; | ||
return _this9; | ||
} | ||
return ExcessiveParameterError; | ||
}(ClassError); | ||
var IllegalParameterValueError = | ||
/*#__PURE__*/ | ||
function (_ClassError4) { | ||
_inheritsLoose(IllegalParameterValueError, _ClassError4); | ||
function IllegalParameterValueError(paramName, value, className) { | ||
var _this10; | ||
_this10 = _ClassError4.call(this, "Illegal parameter value '" + value + "' of parameter '" + paramName + "'", className) || this; | ||
_this10.code = ErrorCode.IllegalParameterValue; | ||
return _this10; | ||
} | ||
return IllegalParameterValueError; | ||
}(ClassError); | ||
var MissingParameterError = | ||
/*#__PURE__*/ | ||
function (_ClassError5) { | ||
_inheritsLoose(MissingParameterError, _ClassError5); | ||
function MissingParameterError(paramName, className) { | ||
var _this11; | ||
_this11 = _ClassError5.call(this, "Missing mandatory parameter " + paramName, className) || this; | ||
_this11.code = ErrorCode.MissingParameter; | ||
return _this11; | ||
} | ||
return MissingParameterError; | ||
}(ClassError); | ||
var SchemaNoAttributeValueError = | ||
/*#__PURE__*/ | ||
function (_ClassError6) { | ||
_inheritsLoose(SchemaNoAttributeValueError, _ClassError6); | ||
function SchemaNoAttributeValueError(attrName, className) { | ||
var _this12; | ||
_this12 = _ClassError6.call(this, "Schema error, attribute '" + attrName + "' does not have a value", className) || this; | ||
_this12.code = ErrorCode.SchemaNoAttributeValue; | ||
return _this12; | ||
} | ||
return SchemaNoAttributeValueError; | ||
}(ClassError); | ||
var SchemaIllegalAttributeValueError = | ||
/*#__PURE__*/ | ||
function (_ClassError7) { | ||
_inheritsLoose(SchemaIllegalAttributeValueError, _ClassError7); | ||
function SchemaIllegalAttributeValueError(paramName, attrName, className) { | ||
var _this13; | ||
_this13 = _ClassError7.call(this, "Schema error, parameter '" + paramName + "' sets illegal value of attribute '" + attrName + "'", className) || this; | ||
_this13.code = ErrorCode.SchemaIllegalAttributeValue; | ||
return _this13; | ||
} | ||
return SchemaIllegalAttributeValueError; | ||
}(ClassError); | ||
var ExcessiveAttributeError = | ||
/*#__PURE__*/ | ||
function (_ClassError8) { | ||
_inheritsLoose(ExcessiveAttributeError, _ClassError8); | ||
function ExcessiveAttributeError(attrName1, attrName2, className) { | ||
var _this14; | ||
_this14 = _ClassError8.call(this, "Only one of '" + attrName1 + "' and '" + attrName2 + "' attributes can be present", className) || this; | ||
_this14.code = ErrorCode.ExcessiveAttribute; | ||
return _this14; | ||
} | ||
return ExcessiveAttributeError; | ||
}(ClassError); | ||
var InconsistentParameterValueError = | ||
/*#__PURE__*/ | ||
function (_ClassError9) { | ||
_inheritsLoose(InconsistentParameterValueError, _ClassError9); | ||
function InconsistentParameterValueError(paramName, value1, value2, className) { | ||
var _this15; | ||
_this15 = _ClassError9.call(this, "Inconsistent value of parameter '" + paramName + "': '" + value1 + "' != '" + value2 + "'", className) || this; | ||
_this15.code = ErrorCode.InconsistentParameterValue; | ||
return _this15; | ||
} | ||
return InconsistentParameterValueError; | ||
}(ClassError); | ||
var IllegalAttributeValueError = | ||
/*#__PURE__*/ | ||
function (_ClassError10) { | ||
_inheritsLoose(IllegalAttributeValueError, _ClassError10); | ||
function IllegalAttributeValueError(attrName, value, className) { | ||
var _this16; | ||
_this16 = _ClassError10.call(this, "Illegal attribute value '" + value + "' of attribute '" + attrName + "'", className) || this; | ||
_this16.code = ErrorCode.IllegalAttributeValue; | ||
return _this16; | ||
} | ||
return IllegalAttributeValueError; | ||
}(ClassError); | ||
var MissingAttributeError = | ||
/*#__PURE__*/ | ||
function (_ClassError11) { | ||
_inheritsLoose(MissingAttributeError, _ClassError11); | ||
function MissingAttributeError(attrName, className) { | ||
var _this17; | ||
_this17 = _ClassError11.call(this, "Missing mandatory attribute " + attrName, className) || this; | ||
_this17.code = ErrorCode.MissingAttribute; | ||
return _this17; | ||
} | ||
return MissingAttributeError; | ||
}(ClassError); | ||
var IllegalTagAttributeError = | ||
/*#__PURE__*/ | ||
function (_ClassError12) { | ||
_inheritsLoose(IllegalTagAttributeError, _ClassError12); | ||
function IllegalTagAttributeError(attrName, tagName, className) { | ||
var _this18; | ||
_this18 = _ClassError12.call(this, "Illegal attribute '" + attrName + "' for tag '" + tagName + "'", className) || this; | ||
_this18.code = ErrorCode.IllegalTagAttribute; | ||
return _this18; | ||
} | ||
return IllegalTagAttributeError; | ||
}(ClassError); | ||
/*! | ||
@@ -373,3 +866,3 @@ * Copyright (c) Microsoft Corporation. All rights reserved. | ||
var _reportError; | ||
var _error; | ||
@@ -419,3 +912,3 @@ var _getClass; | ||
var a; | ||
var errorMessage; | ||
var error; | ||
@@ -436,3 +929,3 @@ try { | ||
} else if (!_ignoreUnknownClasses) { | ||
errorMessage = "Unknown class '" + className + "'"; | ||
error = new UnknownClassError(className); | ||
} else { | ||
@@ -446,3 +939,3 @@ return; | ||
if (isAccessibleElement(tagName, attributes)) { | ||
var _Class = _assumeClass(tagName, attributes, element, false); | ||
var _Class = _assumeClass(tagName, attributes, element); | ||
@@ -452,3 +945,3 @@ if (_Class) { | ||
} else { | ||
errorMessage = 'Accessible element must have accessibility class assigned.'; | ||
error = new NoClassError(); | ||
} | ||
@@ -462,6 +955,6 @@ } else { | ||
} catch (e) { | ||
errorMessage = e.message || 'Failed to validate element'; | ||
error = e instanceof AbilityAttributesError ? e : new ValidationFailedError(); | ||
} | ||
if (!errorMessage && a && a.getConstraints) { | ||
if (!error && a && a.getConstraints) { | ||
var constraints = a.getConstraints(); | ||
@@ -472,3 +965,3 @@ constraints.every(function (constraint) { | ||
if (!checkConstraint(element, c)) { | ||
errorMessage = makeConstraintErrorMessage(c.description, constraint); | ||
error = new ConstraintNotSatisfiedError(c.description, constraint); | ||
return false; | ||
@@ -481,3 +974,3 @@ } | ||
if (!checkConstraint(element, constraint)) { | ||
errorMessage = makeConstraintErrorMessage(constraint.description, constraint); | ||
error = new ConstraintNotSatisfiedError(constraint.description, constraint); | ||
return false; | ||
@@ -491,27 +984,7 @@ } | ||
_reportError(errorMessage || null, element, false); | ||
} | ||
function makeConstraintErrorMessage(description, constraint) { | ||
var errorMessage = description; | ||
if (constraint.param || constraint.name && constraint.value) { | ||
errorMessage += ' ('; | ||
if (constraint.param) { | ||
errorMessage += "when no " + constraint.param + " specified"; | ||
} | ||
if (constraint.name && constraint.value) { | ||
if (constraint.param) { | ||
errorMessage += ', '; | ||
} | ||
errorMessage += "parameter '" + constraint.name + "', value: '" + constraint.value + "'"; | ||
} | ||
errorMessage += ')'; | ||
if (error) { | ||
_error.report(element, error); | ||
} else { | ||
_error.remove(element); | ||
} | ||
return errorMessage; | ||
} | ||
@@ -533,3 +1006,3 @@ | ||
} catch (e) { | ||
_reportError("Failed to evaluate expression: " + xpath + ", " + e.message, element, false); | ||
_error.report(element, new XPathExpressionFailedError(xpath, e.message)); | ||
@@ -555,3 +1028,3 @@ return true; | ||
function setup(win, reportError, getClass, enforceClasses, assumeClass, ignoreUnknownClasses) { | ||
function setup(win, error, getClass, enforceClasses, assumeClass, ignoreUnknownClasses) { | ||
@@ -562,3 +1035,3 @@ if (typeof MutationObserver === 'undefined' || _isBrokenIE11 || typeof document.evaluate !== 'function') { | ||
_reportError = reportError; | ||
_error = error; | ||
_getClass = getClass; | ||
@@ -625,4 +1098,4 @@ _enforceClasses = enforceClasses; | ||
_validatorQueue = {}; | ||
toRemove.map(function (e) { | ||
return _reportError(null, e, false); | ||
toRemove.forEach(function (e) { | ||
return _error.remove(e); | ||
}); | ||
@@ -695,45 +1168,10 @@ toValidate.filter(function (e) { | ||
if (!w.__abilityAttributesDev) { | ||
var els = createElements(); | ||
if (els) { | ||
w.__abilityAttributesDev = { | ||
errorStyle: els.style, | ||
errorContainer: els.container, | ||
reportError: function reportError$1(message, element, isRender) { | ||
var env = getDevEnv(w); | ||
if (env) { | ||
if (env.errorStyle.parentNode !== w.document.body) { | ||
w.document.body.appendChild(env.errorStyle); | ||
} | ||
if (env.errorContainer.parentNode !== w.document.body) { | ||
w.document.body.appendChild(env.errorContainer); | ||
} | ||
return reportError(env, message, element, isRender); | ||
} | ||
return null; | ||
}, | ||
lastErrorId: 0 | ||
}; | ||
var enforceClasses = (settings && settings.enforceClasses) !== false; | ||
var ignoreUnknownClasses = !!(settings && settings.ignoreUnknownClasses); | ||
setup(w, w.__abilityAttributesDev.reportError, getClassByName, enforceClasses, assumeClass, ignoreUnknownClasses); | ||
} | ||
w.__abilityAttributesDev = { | ||
error: new ErrorReporter$1(w) | ||
}; | ||
var enforceClasses = (settings && settings.enforceClasses) !== false; | ||
var ignoreUnknownClasses = !!(settings && settings.ignoreUnknownClasses); | ||
setup(w, w.__abilityAttributesDev.error, getClassByName, enforceClasses, assumeClass, ignoreUnknownClasses); | ||
} | ||
} | ||
function getDevEnv(win) { | ||
return win.__abilityAttributesDev; | ||
} | ||
function reportError$1(win, message, element, isRender) { | ||
var env = getDevEnv(win); | ||
if (env) { | ||
return env.reportError(message, element, isRender); | ||
} | ||
return null; | ||
} | ||
function addClass(name, Class) { | ||
@@ -762,3 +1200,3 @@ if ( typeof window !== 'undefined') { | ||
} | ||
function assumeClass(tagName, attributes, element, isRender) { | ||
function assumeClass(tagName, attributes, element) { | ||
if ( typeof window !== 'undefined') { | ||
@@ -809,3 +1247,3 @@ var win = window; | ||
if (hasEqualAssumptions) { | ||
reportError$1(window, "Ambiguous class assumption: '" + hasEqualAssumptions[0].Class.className + "' and '" + hasEqualAssumptions[1].Class.className + "'", element, isRender); | ||
reportError(new AmbiguousAssumptionError(hasEqualAssumptions[0].Class.className, hasEqualAssumptions[1].Class.className), element); | ||
return undefined; | ||
@@ -821,13 +1259,31 @@ } | ||
function getDevEnv(win) { | ||
return win.__abilityAttributesDev; | ||
} | ||
function reportError(error, element, win) { | ||
var w = win || (typeof window !== 'undefined' ? window : undefined); | ||
if (!w) { | ||
return; | ||
} | ||
var env = getDevEnv(w); | ||
if (env) { | ||
env.error.report(element, error); | ||
} | ||
} | ||
var DevEnv = ({ | ||
setup: setup$1, | ||
getDevEnv: getDevEnv, | ||
reportError: reportError$1, | ||
addClass: addClass, | ||
getClassByName: getClassByName, | ||
assumeClass: assumeClass, | ||
ATTRIBUTE_NAME_CLASS: ATTRIBUTE_NAME_CLASS, | ||
ATTRIBUTE_NAME_ERROR_ID: ATTRIBUTE_NAME_ERROR_ID, | ||
ATTRIBUTE_NAME_ERROR_MESSAGE: ATTRIBUTE_NAME_ERROR_MESSAGE, | ||
ATTRIBUTE_NAME_PROPS: ATTRIBUTE_NAME_PROPS | ||
setup: setup$1, | ||
addClass: addClass, | ||
getClassByName: getClassByName, | ||
assumeClass: assumeClass, | ||
ATTRIBUTE_NAME_CLASS: ATTRIBUTE_NAME_CLASS, | ||
ATTRIBUTE_NAME_ERROR_ID: ATTRIBUTE_NAME_ERROR_ID, | ||
ATTRIBUTE_NAME_ERROR_MESSAGE: ATTRIBUTE_NAME_ERROR_MESSAGE, | ||
ATTRIBUTE_NAME_PROPS: ATTRIBUTE_NAME_PROPS, | ||
AbilityAttributesError: AbilityAttributesError, | ||
ErrorReporter: ErrorReporter | ||
}); | ||
@@ -850,4 +1306,4 @@ | ||
AttributeSchema._error = function _error(message, className) { | ||
throw new Error(message + " in class '" + className + "'"); | ||
AttributeSchema._error = function _error(error) { | ||
throw error; | ||
}; | ||
@@ -857,4 +1313,4 @@ | ||
_proto._error = function _error(message) { | ||
AttributeSchema._error(message, this._className); | ||
_proto._error = function _error(error) { | ||
AttributeSchema._error(error); | ||
}; | ||
@@ -866,8 +1322,21 @@ | ||
AttributeSchema._assignTagNames = function _assignTagNames(byTag, tagsByTag) { | ||
var tagNames = Object.keys(tagsByTag); | ||
var ret = {}; | ||
for (var _i = 0, _tagNames = tagNames; _i < _tagNames.length; _i++) { | ||
var tagName = _tagNames[_i]; | ||
ret[tagName] = byTag[tagsByTag[tagName]]; | ||
} | ||
return ret; | ||
}; | ||
_proto.getAttributes = function getAttributes() { | ||
var params = this._params; | ||
var allParams = this._allParams; | ||
var allParams = this._allParamsByTag[this._tagName]; | ||
var classes = {}; | ||
var attrs = {}; | ||
var nonParamAttrs = this._nonParamAttrs[this._tagName]; | ||
var attrToParam = this._attrToParamByTag[this._tagName]; | ||
var nonParamAttrs = this._nonParamAttrsByTag[this._tagName]; | ||
@@ -878,5 +1347,5 @@ { | ||
if (!nonParamAttrs) { | ||
if (!allParams || !nonParamAttrs) { | ||
{ | ||
this._error("Illegal tag '" + this._tagName + "'"); | ||
this._error(new IllegalTagError(this._tagName, this._className)); | ||
} | ||
@@ -887,12 +1356,12 @@ | ||
for (var _iterator = this._paramNames, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
for (var _iterator = this._paramNames, _isArray = Array.isArray(_iterator), _i2 = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref = _iterator[_i++]; | ||
if (_i2 >= _iterator.length) break; | ||
_ref = _iterator[_i2++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref = _i.value; | ||
_i2 = _iterator.next(); | ||
if (_i2.done) break; | ||
_ref = _i2.value; | ||
} | ||
@@ -905,3 +1374,3 @@ | ||
{ | ||
this._error("Unknown param '" + paramName + "'"); | ||
this._error(new UnknownParameterError(paramName, this._className)); | ||
} | ||
@@ -914,3 +1383,3 @@ | ||
{ | ||
this._error("Only one of '" + paramName + "' or '" + classes[paramDef["class"]] + "' parameters can be present"); | ||
this._error(new ExcessiveParameterError(paramName, classes[paramDef["class"]], this._className)); | ||
} | ||
@@ -922,33 +1391,53 @@ | ||
classes[paramDef["class"]] = paramName; | ||
var values = paramDef.param.value; | ||
if (values) { | ||
var illegalValue = true; | ||
for (var _iterator2 = paramDef.param.attributes, _isArray2 = Array.isArray(_iterator2), _i5 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { | ||
var _ref2; | ||
for (var _iterator2 = values, _isArray2 = Array.isArray(_iterator2), _i4 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { | ||
var _ref2; | ||
if (_isArray2) { | ||
if (_i5 >= _iterator2.length) break; | ||
_ref2 = _iterator2[_i5++]; | ||
} else { | ||
_i5 = _iterator2.next(); | ||
if (_i5.done) break; | ||
_ref2 = _i5.value; | ||
} | ||
if (_isArray2) { | ||
if (_i4 >= _iterator2.length) break; | ||
_ref2 = _iterator2[_i4++]; | ||
} else { | ||
_i4 = _iterator2.next(); | ||
if (_i4.done) break; | ||
_ref2 = _i4.value; | ||
} | ||
var a = _ref2; | ||
var value = _ref2; | ||
if (a.optional) { | ||
continue; | ||
} | ||
if (value.parameter === params[paramName]) { | ||
attrs[paramDef.param.attribute] = value.attribute; | ||
illegalValue = false; | ||
break; | ||
var values = a.value; | ||
if (values) { | ||
var illegalValue = true; | ||
for (var _iterator3 = values, _isArray3 = Array.isArray(_iterator3), _i6 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) { | ||
var _ref3; | ||
if (_isArray3) { | ||
if (_i6 >= _iterator3.length) break; | ||
_ref3 = _iterator3[_i6++]; | ||
} else { | ||
_i6 = _iterator3.next(); | ||
if (_i6.done) break; | ||
_ref3 = _i6.value; | ||
} | ||
var value = _ref3; | ||
if (value.parameter === params[paramName]) { | ||
attrs[a.name] = typeof value.attribute === 'boolean' ? '' : value.attribute; | ||
illegalValue = false; | ||
break; | ||
} | ||
} | ||
} | ||
if ( illegalValue) { | ||
this._error("Illegal parameter value '" + params[paramName] + "' of parameter '" + paramName + "'"); | ||
if ( illegalValue) { | ||
this._error(new IllegalParameterValueError(paramName, params[paramName], this._className)); | ||
} | ||
} else { | ||
attrs[a.name] = params[paramName]; | ||
} | ||
} else { | ||
attrs[paramDef.param.attribute] = params[paramName]; | ||
} | ||
@@ -958,9 +1447,9 @@ } | ||
{ | ||
for (var _i2 = 0, _Object$keys = Object.keys(this._mandatoryParams); _i2 < _Object$keys.length; _i2++) { | ||
var c = _Object$keys[_i2]; | ||
for (var _i3 = 0, _Object$keys = Object.keys(this._mandatoryParams); _i3 < _Object$keys.length; _i3++) { | ||
var c = _Object$keys[_i3]; | ||
if (!(c in classes)) { | ||
this._error("Missing mandatory parameter " + this._mandatoryParams[c].map(function (p) { | ||
this._error(new MissingParameterError(this._mandatoryParams[c].map(function (p) { | ||
return "'" + p + "'"; | ||
}).join(' or ')); | ||
}).join(' or '), this._className)); | ||
} | ||
@@ -970,16 +1459,18 @@ } | ||
for (var _i3 = 0, _Object$keys2 = Object.keys(nonParamAttrs); _i3 < _Object$keys2.length; _i3++) { | ||
var a = _Object$keys2[_i3]; | ||
var attr = nonParamAttrs[a].attr; | ||
for (var _i4 = 0, _Object$keys2 = Object.keys(nonParamAttrs); _i4 < _Object$keys2.length; _i4++) { | ||
var _a = _Object$keys2[_i4]; | ||
var attr = nonParamAttrs[_a].attr; | ||
if (!(a in attrs)) { | ||
var v = this._defaults && a in this._defaults ? this._defaults[a] : attr["default"]; | ||
if (v) { | ||
attrs[a] = v; | ||
if (!(_a in attrs)) { | ||
if (this._defaults && _a in this._defaults) { | ||
attrs[_a] = this._defaults[_a]; | ||
} else if (attr["default"] !== undefined) { | ||
if (!attr.optional) { | ||
attrs[_a] = attr["default"]; | ||
} | ||
} else { | ||
this._error("Schema error, attribute '" + a + "' does not have a value"); | ||
this._error(new SchemaNoAttributeValueError(_a, this._className)); | ||
} | ||
} else if ( (!attr.value || !(attrs[a] in attr.value))) { | ||
this._error("Schema error, parameter '" + this._attrToParam[a] + "' sets illegal value of attribute '" + a + "'"); | ||
} else if ( (!attr.value || !(attrs[_a] in attr.value))) { | ||
this._error(new SchemaIllegalAttributeValueError(attrToParam[_a], _a, this._className)); | ||
} | ||
@@ -991,7 +1482,10 @@ } | ||
AttributeSchema._getParamsFromAttributes = function _getParamsFromAttributes(tagName, attributes, className, allParams, attrToParam, paramToAttr, mandatoryParams, nonParamAttrs) { | ||
AttributeSchema._getParamsFromAttributes = function _getParamsFromAttributes(tagName, attributes, className, allParamsByTag, attrToParamByTag, paramToAttrByTag, mandatoryParams, nonParamAttrs) { | ||
var allParams = allParamsByTag[tagName]; | ||
var attrToParam = attrToParamByTag[tagName]; | ||
var paramToAttr = paramToAttrByTag[tagName]; | ||
var nonParamAttrsForTag = nonParamAttrs[tagName]; | ||
if ( !nonParamAttrsForTag) { | ||
AttributeSchema._error("Illegal tag '" + tagName + "'", className); | ||
AttributeSchema._error(new IllegalTagError(tagName, className)); | ||
} | ||
@@ -1005,6 +1499,6 @@ | ||
for (var _i5 = 0, _attrNames = attrNames; _i5 < _attrNames.length; _i5++) { | ||
var _attrName = _attrNames[_i5]; | ||
for (var _i7 = 0, _attrNames = attrNames; _i7 < _attrNames.length; _i7++) { | ||
var _attrName = _attrNames[_i7]; | ||
if (_attrName in attrToParam) { | ||
if (!attributesUsed[_attrName] && _attrName in attrToParam) { | ||
var paramName = attrToParam[_attrName]; | ||
@@ -1014,75 +1508,112 @@ var param = allParams[paramName]; | ||
if ( param["class"] in classes) { | ||
AttributeSchema._error("Only one of '" + _attrName + "' or '" + classes[param["class"]] + "' attributes can be present", className); | ||
AttributeSchema._error(new ExcessiveAttributeError(_attrName, classes[param["class"]], className)); | ||
} | ||
classes[param["class"]] = _attrName; | ||
var paramVal = void 0; | ||
if (param.param.value) { | ||
var illegalValue = true; | ||
for (var _iterator5 = param.param.attributes, _isArray5 = Array.isArray(_iterator5), _i11 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) { | ||
var _ref5; | ||
for (var _iterator3 = param.param.value, _isArray3 = Array.isArray(_iterator3), _i9 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) { | ||
var _ref3; | ||
if (_isArray5) { | ||
if (_i11 >= _iterator5.length) break; | ||
_ref5 = _iterator5[_i11++]; | ||
} else { | ||
_i11 = _iterator5.next(); | ||
if (_i11.done) break; | ||
_ref5 = _i11.value; | ||
} | ||
if (_isArray3) { | ||
if (_i9 >= _iterator3.length) break; | ||
_ref3 = _iterator3[_i9++]; | ||
} else { | ||
_i9 = _iterator3.next(); | ||
if (_i9.done) break; | ||
_ref3 = _i9.value; | ||
} | ||
var a = _ref5; | ||
var value = _ref3; | ||
if (a.value) { | ||
var illegalValue = true; | ||
if (value.attribute === attributes[_attrName]) { | ||
params[paramName] = value.parameter; | ||
illegalValue = false; | ||
break; | ||
for (var _iterator6 = a.value, _isArray6 = Array.isArray(_iterator6), _i12 = 0, _iterator6 = _isArray6 ? _iterator6 : _iterator6[Symbol.iterator]();;) { | ||
var _ref6; | ||
if (_isArray6) { | ||
if (_i12 >= _iterator6.length) break; | ||
_ref6 = _iterator6[_i12++]; | ||
} else { | ||
_i12 = _iterator6.next(); | ||
if (_i12.done) break; | ||
_ref6 = _i12.value; | ||
} | ||
var value = _ref6; | ||
var expected = value.attribute; | ||
var attrVal = attributes[a.name]; | ||
var valueMatched = !a.optional && expected === false && attrVal === undefined || expected === true && (attrVal === '' || attrVal === _attrName) || expected === attrVal; | ||
if (valueMatched || paramVal === value.parameter) { | ||
if ( paramVal !== undefined && paramVal !== value.parameter) { | ||
AttributeSchema._error(new InconsistentParameterValueError(param.param.name, paramVal, value.parameter, className)); | ||
} | ||
if (valueMatched || attrVal === undefined && a.optional) { | ||
illegalValue = false; | ||
} | ||
if (paramVal === undefined) { | ||
paramVal = value.parameter; | ||
break; | ||
} | ||
} | ||
} | ||
if ( illegalValue) { | ||
AttributeSchema._error(new IllegalAttributeValueError(a.name, attributes[a.name], className)); | ||
} | ||
} else { | ||
paramVal = attributes[_attrName]; | ||
} | ||
if ( illegalValue) { | ||
AttributeSchema._error("Illegal attribute value '" + attributes[_attrName] + "' of attribute '" + _attrName + "'", className); | ||
} | ||
} else { | ||
params[paramName] = attributes[_attrName]; | ||
attributesUsed[a.name] = true; | ||
} | ||
attributesUsed[_attrName] = true; | ||
if (paramVal !== undefined) { | ||
params[paramName] = paramVal; | ||
} | ||
} | ||
} | ||
for (var _i6 = 0, _Object$keys3 = Object.keys(mandatoryParams); _i6 < _Object$keys3.length; _i6++) { | ||
var c = _Object$keys3[_i6]; | ||
for (var _i8 = 0, _Object$keys3 = Object.keys(mandatoryParams); _i8 < _Object$keys3.length; _i8++) { | ||
var c = _Object$keys3[_i8]; | ||
if ( !(c in classes)) { | ||
AttributeSchema._error("Missing mandatory attribute " + mandatoryParams[c].map(function (p) { | ||
AttributeSchema._error(new MissingAttributeError(mandatoryParams[c].map(function (p) { | ||
return "'" + paramToAttr[p] + "'"; | ||
}).join(' or '), className); | ||
}).join(' or '), className)); | ||
} | ||
} | ||
for (var _i7 = 0, _Object$keys4 = Object.keys(nonParamAttrsForTag); _i7 < _Object$keys4.length; _i7++) { | ||
var a = _Object$keys4[_i7]; | ||
for (var _i9 = 0, _Object$keys4 = Object.keys(nonParamAttrsForTag); _i9 < _Object$keys4.length; _i9++) { | ||
var _a2 = _Object$keys4[_i9]; | ||
if (a in attributesUsed) { | ||
if (_a2 in attributesUsed) { | ||
continue; | ||
} | ||
if ( !(a in attributes)) { | ||
AttributeSchema._error("Missing mandatory attribute '" + a + "'", className); | ||
var attr = nonParamAttrsForTag[_a2].attr; | ||
var v = attributes[_a2]; | ||
if ( !(_a2 in attributes) && !(v === undefined && attr.optional)) { | ||
AttributeSchema._error(new MissingAttributeError(_a2, className)); | ||
} | ||
attributesUsed[a] = true; | ||
var attr = nonParamAttrsForTag[a].attr; | ||
var v = attributes[a]; | ||
attributesUsed[_a2] = true; | ||
if (v === undefined && attr.optional) { | ||
continue; | ||
} | ||
if (attr.value) { | ||
if (v in attr.value) { | ||
defaults[a] = v; | ||
defaults[_a2] = v; | ||
} else { | ||
AttributeSchema._error("Illegal attribute value '" + v + "' of attribute '" + a + "'", className); | ||
AttributeSchema._error(new IllegalAttributeValueError(_a2, v, className)); | ||
} | ||
} else { | ||
defaults[a] = v; | ||
defaults[_a2] = v; | ||
} | ||
@@ -1092,7 +1623,18 @@ } | ||
{ | ||
for (var _i8 = 0, _attrNames2 = attrNames; _i8 < _attrNames2.length; _i8++) { | ||
var attrName = _attrNames2[_i8]; | ||
for (var _iterator4 = attrNames, _isArray4 = Array.isArray(_iterator4), _i10 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) { | ||
var _ref4; | ||
if (_isArray4) { | ||
if (_i10 >= _iterator4.length) break; | ||
_ref4 = _iterator4[_i10++]; | ||
} else { | ||
_i10 = _iterator4.next(); | ||
if (_i10.done) break; | ||
_ref4 = _i10.value; | ||
} | ||
var attrName = _ref4; | ||
if (!(attrName in attributesUsed) && attrName in AccessibilityAttributes) { | ||
AttributeSchema._error("Illegal attribute '" + attrName + "' for tag '" + tagName + "'", className); | ||
AttributeSchema._error(new IllegalTagAttributeError(attrName, tagName, className)); | ||
} | ||
@@ -1112,3 +1654,3 @@ } | ||
var Schema = ({ | ||
AttributeSchema: AttributeSchema | ||
AttributeSchema: AttributeSchema | ||
}); | ||
@@ -1115,0 +1657,0 @@ |
@@ -1,2 +0,2 @@ | ||
"use strict";var a={a:!0,area:!0,article:!0,aside:!0,body:!0,button:!0,datalist:!0,details:!0,dialog:!0,dl:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,hr:!0,iframe:!0,img:!0,input:!0,li:!0,link:!0,main:!0,menu:!0,menuitem:!0,meter:!0,nav:!0,object:!0,ol:!0,option:!0,progress:!0,section:!0,select:!0,tbody:!0,textarea:!0,tfoot:!0,th:!0,thead:!0,ul:!0},r={role:!0,tabindex:!0,disabled:!0,required:!0,readonly:!0,hidden:!0,"aria-activedescendant":!0,"aria-atomic":!0,"aria-autocomplete":!0,"aria-busy":!0,"aria-checked":!0,"aria-colcount":!0,"aria-colindex":!0,"aria-colspan":!0,"aria-controls":!0,"aria-current":!0,"aria-describedby":!0,"aria-details":!0,"aria-disabled":!0,"aria-dropeffect":!0,"aria-errormessage":!0,"aria-expanded":!0,"aria-flowto":!0,"aria-grabbed":!0,"aria-haspopup":!0,"aria-hidden":!0,"aria-invalid":!0,"aria-keyshortcuts":!0,"aria-label":!0,"aria-labelledby":!0,"aria-level":!0,"aria-live":!0,"aria-modal":!0,"aria-multiline":!0,"aria-multiselectable":!0,"aria-orientation":!0,"aria-owns":!0,"aria-placeholder":!0,"aria-posinset":!0,"aria-pressed":!0,"aria-readonly":!0,"aria-relevant":!0,"aria-required":!0,"aria-roledescription":!0,"aria-rowcount":!0,"aria-rowindex":!0,"aria-rowspan":!0,"aria-selected":!0,"aria-setsize":!0,"aria-sort":!0,"aria-valuemax":!0,"aria-valuemin":!0,"aria-valuenow":!0,"aria-valuetext":!0};function e(a){for(var e=0,t=Object.keys(a);e<t.length;e++){var i=t[e];if(i in r&&("role"!==i||"none"!==a[i]&&"presentation"!==a[i]))return!0}return!1}try{document.createTreeWalker(document,NodeFilter.SHOW_ELEMENT)}catch(a){}function t(a){return a.__abilityAttributesDev}var i={setup:function(a){},getDevEnv:t,reportError:function(a,r,e,i){var s=t(a);return s?s.reportError(r,e,i):null},addClass:function(a,r){},getClassByName:function(a){},assumeClass:function(a,r,e,t){},ATTRIBUTE_NAME_CLASS:"data-aa-class",ATTRIBUTE_NAME_ERROR_ID:"data-aa-error-id",ATTRIBUTE_NAME_ERROR_MESSAGE:"data-aa-error-message",ATTRIBUTE_NAME_PROPS:"data-aa-props"},s={AttributeSchema:function(){function a(a,r){this._tagName=a.toLowerCase(),this._params=r,this._paramNames=Object.keys(r).filter(function(a){return void 0!==r[a]})}a._error=function(a,r){throw new Error(a+" in class '"+r+"'")};var r=a.prototype;return r._error=function(r){a._error(r,this._className)},r._setDefaults=function(a){this._defaults=a},r.getAttributes=function(){var a=this._params,r=this._allParams,e={},t={},i=this._nonParamAttrs[this._tagName];if(!i)return t;var s=this._paramNames,n=Array.isArray(s),o=0;for(s=n?s:s[Symbol.iterator]();;){var l;if(n){if(o>=s.length)break;l=s[o++]}else{if((o=s.next()).done)break;l=o.value}var u=l,c=r[u];if(c&&!(c.class in e)){e[c.class]=u;var d=c.param.value;if(d){var f=d,m=Array.isArray(f),v=0;for(f=m?f:f[Symbol.iterator]();;){var b;if(m){if(v>=f.length)break;b=f[v++]}else{if((v=f.next()).done)break;b=v.value}if(b.parameter===a[u]){t[c.param.attribute]=b.attribute;break}}}else t[c.param.attribute]=a[u]}}for(var h=0,p=Object.keys(i);h<p.length;h++){var _=p[h];if(!(_ in t)){var y=this._defaults&&_ in this._defaults?this._defaults[_]:i[_].attr.default;y&&(t[_]=y)}}return t},a._getParamsFromAttributes=function(a,r,e,t,i,s,n,o){for(var l=o[a],u={},c={},d={},f={},m=0,v=Object.keys(r);m<v.length;m++){var b=v[m];if(b in i){var h=i[b],p=t[h];if(c[p.class]=b,p.param.value){var _=p.param.value,y=Array.isArray(_),A=0;for(_=y?_:_[Symbol.iterator]();;){var E;if(y){if(A>=_.length)break;E=_[A++]}else{if((A=_.next()).done)break;E=A.value}if(E.attribute===r[b]){u[h]=E.parameter;break}}}else u[h]=r[b];d[b]=!0}}for(var g=0,k=Object.keys(n);g<k.length;g++);for(var x=0,T=Object.keys(l);x<T.length;x++){var N=T[x];if(!(N in d)){d[N]=!0;var R=l[N].attr,S=r[N];R.value?S in R.value&&(f[N]=S):f[N]=S}}return{params:u,defaults:f}},a}()};exports.AccessibilityAttributes=r,exports.AccessibleElements=a,exports.DevEnv=i,exports.Schema=s,exports.hasAccessibilityAttribute=e,exports.isAccessibleElement=function(r,t){return r in a||e(t)}; | ||
"use strict";function e(a){return(e=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(a)}function a(e,t){return(a=Object.setPrototypeOf||function(e,a){return e.__proto__=a,e})(e,t)}function t(e,r,i){return(t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}()?Reflect.construct:function(e,t,r){var i=[null];i.push.apply(i,t);var n=new(Function.bind.apply(e,i));return r&&a(n,r.prototype),n}).apply(null,arguments)}function r(i){var n="function"==typeof Map?new Map:void 0;return(r=function(r){if(null===r||-1===Function.toString.call(r).indexOf("[native code]"))return r;if("function"!=typeof r)throw new TypeError("Super expression must either be null or a function");if(void 0!==n){if(n.has(r))return n.get(r);n.set(r,i)}function i(){return t(r,arguments,e(this).constructor)}return i.prototype=Object.create(r.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),a(i,r)})(i)}var i,n=function(e){function a(){return e.apply(this,arguments)||this}return r=e,(t=a).prototype=Object.create(r.prototype),t.prototype.constructor=t,t.__proto__=r,a;var t,r}(r(Error));!function(e){e[e.AmbiguousAssumption=1]="AmbiguousAssumption",e[e.IllegalTag=2]="IllegalTag",e[e.UnknownParameter=3]="UnknownParameter",e[e.ExcessiveParameter=4]="ExcessiveParameter",e[e.IllegalParameterValue=5]="IllegalParameterValue",e[e.MissingParameter=6]="MissingParameter",e[e.SchemaNoAttributeValue=7]="SchemaNoAttributeValue",e[e.SchemaIllegalAttributeValue=8]="SchemaIllegalAttributeValue",e[e.ExcessiveAttribute=9]="ExcessiveAttribute",e[e.InconsistentParameterValue=10]="InconsistentParameterValue",e[e.IllegalAttributeValue=11]="IllegalAttributeValue",e[e.MissingAttribute=12]="MissingAttribute",e[e.IllegalTagAttribute=13]="IllegalTagAttribute",e[e.UnknownClass=14]="UnknownClass",e[e.ValidationFailed=15]="ValidationFailed",e[e.NoClass=16]="NoClass",e[e.ConstraintNotSatisfied=17]="ConstraintNotSatisfied",e[e.XPathExpressionFailed=18]="XPathExpressionFailed"}(i||(i={}));var o={a:!0,area:!0,article:!0,aside:!0,body:!0,button:!0,datalist:!0,details:!0,dialog:!0,dl:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,hr:!0,iframe:!0,img:!0,input:!0,li:!0,link:!0,main:!0,menu:!0,menuitem:!0,meter:!0,nav:!0,object:!0,ol:!0,option:!0,progress:!0,section:!0,select:!0,tbody:!0,textarea:!0,tfoot:!0,th:!0,thead:!0,ul:!0},s={role:!0,tabindex:!0,disabled:!0,required:!0,readonly:!0,hidden:!0,"aria-activedescendant":!0,"aria-atomic":!0,"aria-autocomplete":!0,"aria-busy":!0,"aria-checked":!0,"aria-colcount":!0,"aria-colindex":!0,"aria-colspan":!0,"aria-controls":!0,"aria-current":!0,"aria-describedby":!0,"aria-details":!0,"aria-disabled":!0,"aria-dropeffect":!0,"aria-errormessage":!0,"aria-expanded":!0,"aria-flowto":!0,"aria-grabbed":!0,"aria-haspopup":!0,"aria-hidden":!0,"aria-invalid":!0,"aria-keyshortcuts":!0,"aria-label":!0,"aria-labelledby":!0,"aria-level":!0,"aria-live":!0,"aria-modal":!0,"aria-multiline":!0,"aria-multiselectable":!0,"aria-orientation":!0,"aria-owns":!0,"aria-placeholder":!0,"aria-posinset":!0,"aria-pressed":!0,"aria-readonly":!0,"aria-relevant":!0,"aria-required":!0,"aria-roledescription":!0,"aria-rowcount":!0,"aria-rowindex":!0,"aria-rowspan":!0,"aria-selected":!0,"aria-setsize":!0,"aria-sort":!0,"aria-valuemax":!0,"aria-valuemin":!0,"aria-valuenow":!0,"aria-valuetext":!0};function l(e){for(var a=0,t=Object.keys(e);a<t.length;a++){var r=t[a];if(r in s&&("role"!==r||"none"!==e[r]&&"presentation"!==e[r]))return!0}return!1}try{document.createTreeWalker(document,NodeFilter.SHOW_ELEMENT)}catch(e){}var u={setup:function(e){},addClass:function(e,a){},getClassByName:function(e){},assumeClass:function(e,a,t){},ATTRIBUTE_NAME_CLASS:"data-aa-class",ATTRIBUTE_NAME_ERROR_ID:"data-aa-error-id",ATTRIBUTE_NAME_ERROR_MESSAGE:"data-aa-error-message",ATTRIBUTE_NAME_PROPS:"data-aa-props",AbilityAttributesError:n,ErrorReporter:function(){}},c={AttributeSchema:function(){function e(e,a){this._tagName=e.toLowerCase(),this._params=a,this._paramNames=Object.keys(a).filter(function(e){return void 0!==a[e]})}e._error=function(e){throw e};var a=e.prototype;return a._error=function(a){e._error(a)},a._setDefaults=function(e){this._defaults=e},e._assignTagNames=function(e,a){for(var t={},r=0,i=Object.keys(a);r<i.length;r++){var n=i[r];t[n]=e[a[n]]}return t},a.getAttributes=function(){var e=this._params,a=this._allParamsByTag[this._tagName],t={},r={},i=this._nonParamAttrsByTag[this._tagName];if(!a||!i)return r;var n=this._paramNames,o=Array.isArray(n),s=0;for(n=o?n:n[Symbol.iterator]();;){var l;if(o){if(s>=n.length)break;l=n[s++]}else{if((s=n.next()).done)break;l=s.value}var u=l,c=a[u];if(c&&!(c.class in t)){t[c.class]=u;var f=c.param.attributes,p=Array.isArray(f),d=0;for(f=p?f:f[Symbol.iterator]();;){var b;if(p){if(d>=f.length)break;b=f[d++]}else{if((d=f.next()).done)break;b=d.value}var m=b;if(!m.optional){var v=m.value;if(v){var y=v,h=Array.isArray(y),g=0;for(y=h?y:y[Symbol.iterator]();;){var A;if(h){if(g>=y.length)break;A=y[g++]}else{if((g=y.next()).done)break;A=g.value}if(A.parameter===e[u]){r[m.name]="boolean"==typeof A.attribute?"":A.attribute;break}}}else r[m.name]=e[u]}}}}for(var _=0,E=Object.keys(i);_<E.length;_++){var k=E[_],x=i[k].attr;k in r||(this._defaults&&k in this._defaults?r[k]=this._defaults[k]:void 0!==x.default&&(x.optional||(r[k]=x.default)))}return r},e._getParamsFromAttributes=function(e,a,t,r,i,n,o,s){for(var l=r[e],u=i[e],c=s[e],f={},p={},d={},b={},m=0,v=Object.keys(a);m<v.length;m++){var y=v[m];if(!d[y]&&y in u){var h=u[y],g=l[h];p[g.class]=y;var A=void 0,_=g.param.attributes,E=Array.isArray(_),k=0;for(_=E?_:_[Symbol.iterator]();;){var x;if(E){if(k>=_.length)break;x=_[k++]}else{if((k=_.next()).done)break;x=k.value}var O=x;if(O.value){var P=O.value,S=Array.isArray(P),T=0;for(P=S?P:P[Symbol.iterator]();;){var N;if(S){if(T>=P.length)break;N=P[T++]}else{if((T=P.next()).done)break;N=T.value}var w=N.attribute,I=a[O.name];if((!O.optional&&!1===w&&void 0===I||!0===w&&(""===I||I===y)||w===I||A===N.parameter)&&void 0===A){A=N.parameter;break}}}else A=a[y];d[O.name]=!0}void 0!==A&&(f[h]=A)}}for(var R=0,j=Object.keys(o);R<j.length;R++);for(var M=0,V=Object.keys(c);M<V.length;M++){var C=V[M];if(!(C in d)){var F=c[C].attr,U=a[C];d[C]=!0,void 0===U&&F.optional||(F.value?U in F.value&&(b[C]=U):b[C]=U)}}return{params:f,defaults:b}},e}()};exports.AccessibilityAttributes=s,exports.AccessibleElements=o,exports.DevEnv=u,exports.Schema=c,exports.hasAccessibilityAttribute=l,exports.isAccessibleElement=function(e,a){return e in o||l(a)}; | ||
//# sourceMappingURL=ability-attributes.cjs.production.min.js.map |
@@ -0,1 +1,99 @@ | ||
function _inheritsLoose(subClass, superClass) { | ||
subClass.prototype = Object.create(superClass.prototype); | ||
subClass.prototype.constructor = subClass; | ||
subClass.__proto__ = superClass; | ||
} | ||
function _getPrototypeOf(o) { | ||
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { | ||
return o.__proto__ || Object.getPrototypeOf(o); | ||
}; | ||
return _getPrototypeOf(o); | ||
} | ||
function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { | ||
o.__proto__ = p; | ||
return o; | ||
}; | ||
return _setPrototypeOf(o, p); | ||
} | ||
function isNativeReflectConstruct() { | ||
if (typeof Reflect === "undefined" || !Reflect.construct) return false; | ||
if (Reflect.construct.sham) return false; | ||
if (typeof Proxy === "function") return true; | ||
try { | ||
Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
function _construct(Parent, args, Class) { | ||
if (isNativeReflectConstruct()) { | ||
_construct = Reflect.construct; | ||
} else { | ||
_construct = function _construct(Parent, args, Class) { | ||
var a = [null]; | ||
a.push.apply(a, args); | ||
var Constructor = Function.bind.apply(Parent, a); | ||
var instance = new Constructor(); | ||
if (Class) _setPrototypeOf(instance, Class.prototype); | ||
return instance; | ||
}; | ||
} | ||
return _construct.apply(null, arguments); | ||
} | ||
function _isNativeFunction(fn) { | ||
return Function.toString.call(fn).indexOf("[native code]") !== -1; | ||
} | ||
function _wrapNativeSuper(Class) { | ||
var _cache = typeof Map === "function" ? new Map() : undefined; | ||
_wrapNativeSuper = function _wrapNativeSuper(Class) { | ||
if (Class === null || !_isNativeFunction(Class)) return Class; | ||
if (typeof Class !== "function") { | ||
throw new TypeError("Super expression must either be null or a function"); | ||
} | ||
if (typeof _cache !== "undefined") { | ||
if (_cache.has(Class)) return _cache.get(Class); | ||
_cache.set(Class, Wrapper); | ||
} | ||
function Wrapper() { | ||
return _construct(Class, arguments, _getPrototypeOf(this).constructor); | ||
} | ||
Wrapper.prototype = Object.create(Class.prototype, { | ||
constructor: { | ||
value: Wrapper, | ||
enumerable: false, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
return _setPrototypeOf(Wrapper, Class); | ||
}; | ||
return _wrapNativeSuper(Class); | ||
} | ||
function _assertThisInitialized(self) { | ||
if (self === void 0) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
return self; | ||
} | ||
/*! | ||
@@ -9,216 +107,605 @@ * Copyright (c) Microsoft Corporation. All rights reserved. | ||
var ATTRIBUTE_NAME_PROPS = 'data-aa-props'; | ||
var AbilityAttributesError = | ||
/*#__PURE__*/ | ||
function (_Error) { | ||
_inheritsLoose(AbilityAttributesError, _Error); | ||
/*! | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
var _lastId = 0; | ||
var _lastDismissAllId = 0; | ||
function createElements() { | ||
if (!(process.env.NODE_ENV !== "production")) { | ||
return; | ||
function AbilityAttributesError() { | ||
return _Error.apply(this, arguments) || this; | ||
} | ||
var style = document.createElement('style'); | ||
style.appendChild(document.createTextNode("\n.aa-error-container {\n background: #e07777;\n bottom: 0;\n box-shadow: 0 0 4px rgba(0, 0, 0, .3);\n color: #000;\n font-family: Helvetica;\n font-size: 14px;\n left: 0;\n line-height: 20px;\n max-height: 205px;\n opacity: .95;\n overflow: scroll;\n position: fixed;\n right: 0;\n z-index: 2147483647;\n}\n\n.aa-error-container * {\n box-sizing: border-box;\n}\n\n.aa-error-message {\n border-top: 1px solid #ddd;\n clear: both;\n min-height: 24px;\n padding: 8px 16px 8px 36px;\n position: relative;\n z-index: 1;\n}\n\n.aa-error-message.aa-error-message_render {\n background: #bbb;\n}\n\n.aa-error-locator {\n color: #333;\n display: none;\n float: right;\n font-size: 80%;\n}\n\n.aa-error-locator.aa-error-locator_available {\n display: block;\n}\n\n.aa-error-dismiss {\n background: #987575;\n border-radius: 4px;\n border: 1px solid #ec99a8;\n color: #fff;\n cursor: pointer;\n height: 21px;\n left: 8px;\n margin-top: -10px;\n position: absolute;\n top: 50%;\n width: 21px;\n}\n\n.aa-error-dismiss:hover {\n background: #aa8a8a;\n color: #777;\n}\n\n.aa-error-dismiss::before {\n content: '\xD7';\n left: 5px;\n line-height: 17px;\n position: absolute;\n}\n\n.aa-error-dismiss-all {\n background: #640d0d;\n border-bottom: none;\n border-radius: 10px 10px 2px 2px;\n border: 1px solid #ec99a8;\n bottom: 0;\n color: #fff;\n cursor: pointer;\n display: none;\n font-size: 80%;\n left: 50%;\n margin-left: -50px;\n opacity: .8;\n padding: 4px;\n position: fixed;\n text-align: center;\n width: 100px;\n z-index: 100500;\n}")); | ||
var container = document.createElement('div'); | ||
var elements = []; | ||
var elementByErrorId = {}; | ||
container.__aaAddError = addError; | ||
container.__aaGetError = getError; | ||
container.__aaDismissError = dismissError; | ||
container.className = 'aa-error-container'; | ||
var dismissAll = document.createElement('div'); | ||
dismissAll.className = 'aa-error-dismiss-all'; | ||
dismissAll.innerText = 'Dismiss all'; | ||
container.appendChild(dismissAll); | ||
container.addEventListener('click', function (e) { | ||
var shouldDismiss = false; | ||
return AbilityAttributesError; | ||
}(_wrapNativeSuper(Error)); | ||
var ErrorReporter = function ErrorReporter() {}; | ||
for (var n = e.target; n; n = n.parentElement) { | ||
if (n.classList) { | ||
if (n.classList.contains('aa-error-dismiss')) { | ||
shouldDismiss = true; | ||
} else if (shouldDismiss && n.classList.contains('aa-error-message')) { | ||
dismissError(n); | ||
break; | ||
} else if (n.classList.contains('aa-error-dismiss-all')) { | ||
_lastDismissAllId = _lastId; | ||
var _lastId = 0; | ||
var _errors = {}; | ||
var ErrorReporter$1 = | ||
/*#__PURE__*/ | ||
function (_ErrorReporterBase) { | ||
_inheritsLoose(ErrorReporter, _ErrorReporterBase); | ||
var _e = void 0; | ||
function ErrorReporter(w) { | ||
var _this; | ||
elementByErrorId = {}; | ||
_this = _ErrorReporterBase.call(this) || this; | ||
_this._isCollapsed = true; | ||
while (_e = elements.pop()) { | ||
if (container.contains(_e)) { | ||
container.removeChild(_e); | ||
} | ||
_this.toggle = function () { | ||
_this._isCollapsed = !_this._isCollapsed; | ||
if (_this._isCollapsed) { | ||
Object.keys(_errors).forEach(function (id) { | ||
var meta = _errors[id]; | ||
if (meta.visible) { | ||
_this.dismiss(meta.element); | ||
} | ||
}); | ||
} else { | ||
Object.keys(_errors).forEach(function (id) { | ||
_errors[id].visible = true; | ||
}); | ||
} | ||
break; | ||
} | ||
} | ||
_this._render(); | ||
}; | ||
_this._window = w; | ||
if (_this._window.__abilityAttributesDev) { | ||
return _this._window.__abilityAttributesDev.error || _assertThisInitialized(_this); | ||
} | ||
updateState(); | ||
}); | ||
container.addEventListener('dblclick', function (e) { | ||
for (var n = e.target; n; n = n.parentElement) { | ||
if (n.classList && n.classList.contains('aa-error-message')) { | ||
dismissError(n); | ||
break; | ||
_this._initUI(false); | ||
return _this; | ||
} | ||
var _proto = ErrorReporter.prototype; | ||
_proto.report = function report(element, error) { | ||
var meta = element.__aaError; | ||
if (meta) { | ||
if (meta.error.message !== error.message) { | ||
meta.visible = true; | ||
meta.shouldRerender = true; | ||
meta.error.message = error.message; | ||
delete _errors[meta.id]; | ||
_errors[meta.id] = meta; | ||
} | ||
} else { | ||
meta = element.__aaError = { | ||
id: "" + ++_lastId, | ||
element: element, | ||
error: error, | ||
visible: true | ||
}; | ||
_errors[meta.id] = meta; | ||
} | ||
updateState(); | ||
}); | ||
return { | ||
style: style, | ||
container: container | ||
element.setAttribute(ATTRIBUTE_NAME_ERROR_ID, meta.id); | ||
element.setAttribute(ATTRIBUTE_NAME_ERROR_MESSAGE, meta.error.message); | ||
if (meta.visible) { | ||
meta.locator = "$('[" + ATTRIBUTE_NAME_ERROR_ID + "=\"" + meta.id + "\"]')"; | ||
this._render(); | ||
console.error(error.message + ", " + meta.locator); | ||
} | ||
}; | ||
function updateState() { | ||
dismissAll.style.display = elements.length > 1 ? 'block' : 'none'; | ||
} | ||
_proto.remove = function remove(element) { | ||
var meta = element.__aaError; | ||
function addError(id, e) { | ||
if (!elementByErrorId[id]) { | ||
elements.push(e); | ||
elementByErrorId[id] = e; | ||
if (meta) { | ||
delete _errors[meta.id]; | ||
delete element.__aaError; | ||
delete meta.element; | ||
element.removeAttribute(ATTRIBUTE_NAME_ERROR_ID); | ||
element.removeAttribute(ATTRIBUTE_NAME_ERROR_MESSAGE); | ||
this._removeErrorView(meta); | ||
this._render(); | ||
} | ||
}; | ||
if (container.firstChild) { | ||
if (container.firstChild !== e) { | ||
container.insertBefore(e, container.firstChild); | ||
_proto.dismiss = function dismiss(element) { | ||
var meta = element.__aaError; | ||
if (meta) { | ||
meta.visible = false; | ||
this._removeErrorView(meta); | ||
this._render(); | ||
} | ||
}; | ||
_proto._initUI = function _initUI(append) { | ||
if (!this._styles) { | ||
this._styles = document.createElement('style'); | ||
this._styles.appendChild(document.createTextNode(".aa-error-container {\n bottom: 0;\n color: #000;\n display: flex;\n font-family: Arial, Helvetica, sans-serif;\n font-size: 14px;\n justify-content: center;\n left: 0;\n line-height: 20px;\n max-height: 205px;\n opacity: .90;\n position: fixed;\n right: 0;\n z-index: 2147483647;\n}\n\n.aa-error-expanded {\n background: #ffa0a0;\n border-top: 1px solid #000;\n flex-grow: 1;\n max-height: 205px;\n overflow: scroll;\n}\n\n.aa-error-container * {\n box-sizing: border-box;\n}\n\n.aa-error-message {\n border-bottom: 1px solid #ddd;\n display: flex;\n justify-content: space-between;\n min-height: 24px;\n padding: 8px 16px;\n position: relative;\n z-index: 1;\n}\n\n.aa-error-dismiss {\n align-self: baseline;\n cursor: pointer;\n font-size: 12px;\n margin-right: 8px;\n}\n\n.aa-error-text {\n flex-grow: 1;\n}\n\n.aa-error-locator {\n color: #333;\n font-size: 80%;\n white-space: nowrap;\n}\n\n.aa-error-toggle {\n background: #914040;\n border-radius: 20px 20px 0 0;\n border: 1px solid #000;\n color: #fff;\n cursor: pointer;\n font-size: 14px;\n line-height: 24px;\n padding: 0 16px;\n position: absolute;\n top: -25px;\n z-index: 2147483647;\n}\n")); | ||
this._container = document.createElement('div'); | ||
this._expanded = document.createElement('div'); | ||
this._toggle = document.createElement('button'); | ||
this._container.className = 'aa-error-container'; | ||
this._expanded.className = 'aa-error-expanded'; | ||
this._toggle.className = 'aa-error-toggle'; | ||
this._container.style.display = 'none'; | ||
this._expanded.style.display = 'none'; | ||
this._container.appendChild(this._expanded); | ||
this._container.appendChild(this._toggle); | ||
this._toggle.addEventListener('click', this.toggle); | ||
} | ||
if (append) { | ||
if (!this._styles.parentNode) { | ||
this._window.document.head.appendChild(this._styles); | ||
} | ||
this._window.document.body.appendChild(this._container); | ||
} | ||
}; | ||
_proto._render = function _render() { | ||
var _this2 = this; | ||
if (this._renderTimer) { | ||
return; | ||
} | ||
this._renderTimer = this._window.setTimeout(function () { | ||
_this2._renderTimer = undefined; | ||
_this2._reallyRender(); | ||
}, 0); | ||
}; | ||
_proto._reallyRender = function _reallyRender() { | ||
var hasVisible = false; | ||
var ids = Object.keys(_errors); | ||
ids.forEach(function (id) { | ||
var e = _errors[id]; | ||
if (e.visible) { | ||
hasVisible = true; | ||
} | ||
}); | ||
this._initUI(true); | ||
if (ids.length > 0 && (this._isCollapsed || !hasVisible)) { | ||
this._isCollapsed = true; | ||
this._showCounter(ids.length); | ||
} else if (!this._isCollapsed && hasVisible) { | ||
this._showExpanded(); | ||
} else { | ||
container.appendChild(e); | ||
this._hide(); | ||
} | ||
}; | ||
updateState(); | ||
} | ||
_proto._showCounter = function _showCounter(count) { | ||
this._toggle.innerText = "Show " + count + " accessibility error" + (count !== 1 ? 's' : ''); | ||
this._expanded.style.display = 'none'; | ||
this._container.style.display = 'flex'; | ||
}; | ||
function getError(id) { | ||
return elementByErrorId[id]; | ||
} | ||
_proto._showExpanded = function _showExpanded() { | ||
var _this3 = this; | ||
function dismissError(e, keepInDOM) { | ||
if (!keepInDOM && container.contains(e)) { | ||
container.removeChild(e); | ||
this._toggle.innerText = "Collapse errors"; | ||
Object.keys(_errors).forEach(function (id) { | ||
var meta = _errors[id]; | ||
if (meta.visible) { | ||
if (meta.shouldRerender) { | ||
delete meta.shouldRerender; | ||
_this3._removeErrorView(meta); | ||
} | ||
if (!meta.rendered) { | ||
meta.rendered = _this3._createErrorView(meta); | ||
} | ||
_this3._expanded.insertBefore(meta.rendered, _this3._expanded.firstChild || null); | ||
} | ||
}); | ||
this._expanded.style.display = null; | ||
this._container.style.display = 'flex'; | ||
}; | ||
_proto._hide = function _hide() { | ||
this._container.style.display = 'none'; | ||
}; | ||
_proto._createErrorView = function _createErrorView(meta) { | ||
var _this4 = this; | ||
var div = this._window.document.createElement('div'); | ||
div.className = 'aa-error-message'; | ||
var dismiss = this._window.document.createElement('button'); | ||
dismiss.className = 'aa-error-dismiss'; | ||
dismiss.setAttribute('aria-label', "Dismiss error " + meta.id); | ||
dismiss.innerText = 'X'; | ||
dismiss.addEventListener('click', function () { | ||
_this4.dismiss(meta.element); | ||
}); | ||
div.appendChild(dismiss); | ||
var text = this._window.document.createElement('span'); | ||
text.className = 'aa-error-text'; | ||
text.innerText = meta.error.message; | ||
div.appendChild(text); | ||
if (meta.locator) { | ||
var locator = this._window.document.createElement('div'); | ||
locator.className = 'aa-error-locator'; | ||
locator.innerText = meta.locator; | ||
div.appendChild(locator); | ||
} | ||
var prevId = e.getAttribute(ATTRIBUTE_NAME_ERROR_ID); | ||
div.addEventListener('dblclick', function () { | ||
_this4.dismiss(meta.element); | ||
}); | ||
return div; | ||
}; | ||
if (prevId) { | ||
delete elementByErrorId[prevId]; | ||
_proto._removeErrorView = function _removeErrorView(meta) { | ||
if (meta.rendered) { | ||
if (meta.rendered.parentNode) { | ||
meta.rendered.parentNode.removeChild(meta.rendered); | ||
} | ||
delete meta.rendered; | ||
} | ||
}; | ||
var index = elements.indexOf(e); | ||
return ErrorReporter; | ||
}(ErrorReporter); | ||
if (index >= 0) { | ||
elements.splice(index, 1); | ||
updateState(); | ||
} | ||
var ErrorCode; | ||
(function (ErrorCode) { | ||
ErrorCode[ErrorCode["AmbiguousAssumption"] = 1] = "AmbiguousAssumption"; | ||
ErrorCode[ErrorCode["IllegalTag"] = 2] = "IllegalTag"; | ||
ErrorCode[ErrorCode["UnknownParameter"] = 3] = "UnknownParameter"; | ||
ErrorCode[ErrorCode["ExcessiveParameter"] = 4] = "ExcessiveParameter"; | ||
ErrorCode[ErrorCode["IllegalParameterValue"] = 5] = "IllegalParameterValue"; | ||
ErrorCode[ErrorCode["MissingParameter"] = 6] = "MissingParameter"; | ||
ErrorCode[ErrorCode["SchemaNoAttributeValue"] = 7] = "SchemaNoAttributeValue"; | ||
ErrorCode[ErrorCode["SchemaIllegalAttributeValue"] = 8] = "SchemaIllegalAttributeValue"; | ||
ErrorCode[ErrorCode["ExcessiveAttribute"] = 9] = "ExcessiveAttribute"; | ||
ErrorCode[ErrorCode["InconsistentParameterValue"] = 10] = "InconsistentParameterValue"; | ||
ErrorCode[ErrorCode["IllegalAttributeValue"] = 11] = "IllegalAttributeValue"; | ||
ErrorCode[ErrorCode["MissingAttribute"] = 12] = "MissingAttribute"; | ||
ErrorCode[ErrorCode["IllegalTagAttribute"] = 13] = "IllegalTagAttribute"; | ||
ErrorCode[ErrorCode["UnknownClass"] = 14] = "UnknownClass"; | ||
ErrorCode[ErrorCode["ValidationFailed"] = 15] = "ValidationFailed"; | ||
ErrorCode[ErrorCode["NoClass"] = 16] = "NoClass"; | ||
ErrorCode[ErrorCode["ConstraintNotSatisfied"] = 17] = "ConstraintNotSatisfied"; | ||
ErrorCode[ErrorCode["XPathExpressionFailed"] = 18] = "XPathExpressionFailed"; | ||
})(ErrorCode || (ErrorCode = {})); | ||
var AmbiguousAssumptionError = | ||
/*#__PURE__*/ | ||
function (_AbilityAttributesErr) { | ||
_inheritsLoose(AmbiguousAssumptionError, _AbilityAttributesErr); | ||
function AmbiguousAssumptionError(className1, className2) { | ||
var _this; | ||
_this = _AbilityAttributesErr.call(this, "Ambiguous class assumption: '" + className1 + "' and '" + className2 + "'") || this; | ||
_this.code = ErrorCode.AmbiguousAssumption; | ||
return _this; | ||
} | ||
} | ||
function reportError(env, message, element, isRender) { | ||
if (!(process.env.NODE_ENV !== "production")) { | ||
return null; | ||
return AmbiguousAssumptionError; | ||
}(AbilityAttributesError); | ||
var UnknownClassError = | ||
/*#__PURE__*/ | ||
function (_AbilityAttributesErr2) { | ||
_inheritsLoose(UnknownClassError, _AbilityAttributesErr2); | ||
function UnknownClassError(className) { | ||
var _this2; | ||
_this2 = _AbilityAttributesErr2.call(this, "Unknown class '" + className + "'") || this; | ||
_this2.code = ErrorCode.UnknownClass; | ||
return _this2; | ||
} | ||
var errorContainer = env.errorContainer; | ||
return UnknownClassError; | ||
}(AbilityAttributesError); | ||
var ValidationFailedError = | ||
/*#__PURE__*/ | ||
function (_AbilityAttributesErr3) { | ||
_inheritsLoose(ValidationFailedError, _AbilityAttributesErr3); | ||
if (!errorContainer.__aaAddError || !errorContainer.__aaGetError || !errorContainer.__aaDismissError) { | ||
return null; | ||
function ValidationFailedError() { | ||
var _this3; | ||
_this3 = _AbilityAttributesErr3.call(this, 'Failed to validate element') || this; | ||
_this3.code = ErrorCode.ValidationFailed; | ||
return _this3; | ||
} | ||
var prevId = element ? element.getAttribute(ATTRIBUTE_NAME_ERROR_ID) : null; | ||
var errorElement; | ||
var errorText; | ||
var errorLocator; | ||
return ValidationFailedError; | ||
}(AbilityAttributesError); | ||
var ConstraintNotSatisfiedError = | ||
/*#__PURE__*/ | ||
function (_AbilityAttributesErr4) { | ||
_inheritsLoose(ConstraintNotSatisfiedError, _AbilityAttributesErr4); | ||
if (prevId) { | ||
errorElement = errorContainer.__aaGetError(prevId); | ||
function ConstraintNotSatisfiedError(description, constraint) { | ||
var _this4; | ||
_this4 = _AbilityAttributesErr4.call(this, function () { | ||
var errorMessage = description; | ||
if (constraint.param || constraint.name && constraint.value) { | ||
errorMessage += ' ('; | ||
if (constraint.param) { | ||
errorMessage += "when no " + constraint.param + " specified"; | ||
} | ||
if (constraint.name && constraint.value) { | ||
if (constraint.param) { | ||
errorMessage += ', '; | ||
} | ||
errorMessage += "parameter '" + constraint.name + "', value: '" + constraint.value + "'"; | ||
} | ||
errorMessage += ')'; | ||
} | ||
return errorMessage; | ||
}()) || this; | ||
_this4.code = ErrorCode.ConstraintNotSatisfied; | ||
return _this4; | ||
} | ||
if (!errorElement) { | ||
errorElement = document.createElement('div'); | ||
errorElement.className = 'aa-error-message' + (isRender ? ' aa-error-message_render' : ''); | ||
var dismiss = document.createElement('div'); | ||
dismiss.className = 'aa-error-dismiss'; | ||
errorElement.appendChild(dismiss); | ||
errorText = document.createElement('span'); | ||
errorElement.appendChild(errorText); | ||
errorLocator = document.createElement('div'); | ||
errorElement.appendChild(errorLocator); | ||
} else { | ||
var _dismiss = errorElement.firstChild; | ||
return ConstraintNotSatisfiedError; | ||
}(AbilityAttributesError); | ||
var XPathExpressionFailedError = | ||
/*#__PURE__*/ | ||
function (_AbilityAttributesErr5) { | ||
_inheritsLoose(XPathExpressionFailedError, _AbilityAttributesErr5); | ||
if (_dismiss) { | ||
errorText = _dismiss.nextSibling; | ||
} | ||
function XPathExpressionFailedError(xpath, message) { | ||
var _this5; | ||
if (errorText) { | ||
errorLocator = errorText.nextSibling; | ||
} | ||
_this5 = _AbilityAttributesErr5.call(this, "Failed to evaluate expression: " + xpath + ", " + message) || this; | ||
_this5.code = ErrorCode.XPathExpressionFailed; | ||
return _this5; | ||
} | ||
if (!errorText || !errorLocator) { | ||
return null; | ||
return XPathExpressionFailedError; | ||
}(AbilityAttributesError); | ||
var NoClassError = | ||
/*#__PURE__*/ | ||
function (_AbilityAttributesErr6) { | ||
_inheritsLoose(NoClassError, _AbilityAttributesErr6); | ||
function NoClassError() { | ||
var _this6; | ||
_this6 = _AbilityAttributesErr6.call(this, 'Accessible element must have accessibility class assigned') || this; | ||
_this6.code = ErrorCode.NoClass; | ||
return _this6; | ||
} | ||
if (!message) { | ||
if (prevId) { | ||
errorContainer.__aaDismissError(errorElement); | ||
return NoClassError; | ||
}(AbilityAttributesError); | ||
if (element) { | ||
element.removeAttribute(ATTRIBUTE_NAME_ERROR_ID); | ||
element.removeAttribute(ATTRIBUTE_NAME_ERROR_MESSAGE); | ||
} | ||
} | ||
var ClassError = | ||
/*#__PURE__*/ | ||
function (_AbilityAttributesErr7) { | ||
_inheritsLoose(ClassError, _AbilityAttributesErr7); | ||
return null; | ||
function ClassError(message, className) { | ||
return _AbilityAttributesErr7.call(this, message + " in class '" + className + "'") || this; | ||
} | ||
var errorId; | ||
var sameError = element ? element.getAttribute(ATTRIBUTE_NAME_ERROR_MESSAGE) === message : errorText.innerText === message; | ||
return ClassError; | ||
}(AbilityAttributesError); | ||
if (sameError && prevId) { | ||
if (_lastDismissAllId > parseInt(prevId, 10)) { | ||
return null; | ||
} | ||
var IllegalTagError = | ||
/*#__PURE__*/ | ||
function (_ClassError) { | ||
_inheritsLoose(IllegalTagError, _ClassError); | ||
errorId = prevId; | ||
} else { | ||
errorContainer.__aaDismissError(errorElement, true); | ||
function IllegalTagError(tagName, className) { | ||
var _this7; | ||
errorElement.className = 'aa-error-message' + (isRender ? ' aa-error-message_render' : ''); | ||
errorText.innerText = message; | ||
errorId = ++env.lastErrorId + ''; | ||
_this7 = _ClassError.call(this, "Illegal tag '" + tagName + "'", className) || this; | ||
_this7.code = ErrorCode.IllegalTag; | ||
return _this7; | ||
} | ||
var _locator = "$('[" + ATTRIBUTE_NAME_ERROR_ID + "=\"" + errorId + "\"]')"; | ||
return IllegalTagError; | ||
}(ClassError); | ||
var UnknownParameterError = | ||
/*#__PURE__*/ | ||
function (_ClassError2) { | ||
_inheritsLoose(UnknownParameterError, _ClassError2); | ||
errorLocator.innerText = _locator; | ||
errorElement.setAttribute(ATTRIBUTE_NAME_ERROR_ID, errorId); | ||
function UnknownParameterError(paramName, className) { | ||
var _this8; | ||
if (element) { | ||
element.setAttribute(ATTRIBUTE_NAME_ERROR_ID, errorId); | ||
element.setAttribute(ATTRIBUTE_NAME_ERROR_MESSAGE, message); | ||
} | ||
_this8 = _ClassError2.call(this, "Unknown parameter '" + paramName + "'", className) || this; | ||
_this8.code = ErrorCode.UnknownParameter; | ||
return _this8; | ||
} | ||
console.error(message + "\n\n" + _locator); | ||
return UnknownParameterError; | ||
}(ClassError); | ||
var ExcessiveParameterError = | ||
/*#__PURE__*/ | ||
function (_ClassError3) { | ||
_inheritsLoose(ExcessiveParameterError, _ClassError3); | ||
function ExcessiveParameterError(paramName1, paramName2, className) { | ||
var _this9; | ||
_this9 = _ClassError3.call(this, "Only one of '" + paramName1 + "' or '" + paramName2 + "' parameters can be present", className) || this; | ||
_this9.code = ErrorCode.ExcessiveParameter; | ||
return _this9; | ||
} | ||
errorText.innerText = message; | ||
var locator = "$('[" + ATTRIBUTE_NAME_ERROR_ID + "=\"" + errorId + "\"]')"; | ||
errorLocator.innerText = locator; | ||
errorElement.setAttribute(ATTRIBUTE_NAME_ERROR_ID, errorId); | ||
errorLocator.className = 'aa-error-locator' + (element ? ' aa-error-locator_available' : ''); | ||
return ExcessiveParameterError; | ||
}(ClassError); | ||
var IllegalParameterValueError = | ||
/*#__PURE__*/ | ||
function (_ClassError4) { | ||
_inheritsLoose(IllegalParameterValueError, _ClassError4); | ||
errorContainer.__aaAddError(errorId, errorElement); | ||
function IllegalParameterValueError(paramName, value, className) { | ||
var _this10; | ||
_lastId = env.lastErrorId; | ||
return errorId + ''; | ||
} | ||
_this10 = _ClassError4.call(this, "Illegal parameter value '" + value + "' of parameter '" + paramName + "'", className) || this; | ||
_this10.code = ErrorCode.IllegalParameterValue; | ||
return _this10; | ||
} | ||
return IllegalParameterValueError; | ||
}(ClassError); | ||
var MissingParameterError = | ||
/*#__PURE__*/ | ||
function (_ClassError5) { | ||
_inheritsLoose(MissingParameterError, _ClassError5); | ||
function MissingParameterError(paramName, className) { | ||
var _this11; | ||
_this11 = _ClassError5.call(this, "Missing mandatory parameter " + paramName, className) || this; | ||
_this11.code = ErrorCode.MissingParameter; | ||
return _this11; | ||
} | ||
return MissingParameterError; | ||
}(ClassError); | ||
var SchemaNoAttributeValueError = | ||
/*#__PURE__*/ | ||
function (_ClassError6) { | ||
_inheritsLoose(SchemaNoAttributeValueError, _ClassError6); | ||
function SchemaNoAttributeValueError(attrName, className) { | ||
var _this12; | ||
_this12 = _ClassError6.call(this, "Schema error, attribute '" + attrName + "' does not have a value", className) || this; | ||
_this12.code = ErrorCode.SchemaNoAttributeValue; | ||
return _this12; | ||
} | ||
return SchemaNoAttributeValueError; | ||
}(ClassError); | ||
var SchemaIllegalAttributeValueError = | ||
/*#__PURE__*/ | ||
function (_ClassError7) { | ||
_inheritsLoose(SchemaIllegalAttributeValueError, _ClassError7); | ||
function SchemaIllegalAttributeValueError(paramName, attrName, className) { | ||
var _this13; | ||
_this13 = _ClassError7.call(this, "Schema error, parameter '" + paramName + "' sets illegal value of attribute '" + attrName + "'", className) || this; | ||
_this13.code = ErrorCode.SchemaIllegalAttributeValue; | ||
return _this13; | ||
} | ||
return SchemaIllegalAttributeValueError; | ||
}(ClassError); | ||
var ExcessiveAttributeError = | ||
/*#__PURE__*/ | ||
function (_ClassError8) { | ||
_inheritsLoose(ExcessiveAttributeError, _ClassError8); | ||
function ExcessiveAttributeError(attrName1, attrName2, className) { | ||
var _this14; | ||
_this14 = _ClassError8.call(this, "Only one of '" + attrName1 + "' and '" + attrName2 + "' attributes can be present", className) || this; | ||
_this14.code = ErrorCode.ExcessiveAttribute; | ||
return _this14; | ||
} | ||
return ExcessiveAttributeError; | ||
}(ClassError); | ||
var InconsistentParameterValueError = | ||
/*#__PURE__*/ | ||
function (_ClassError9) { | ||
_inheritsLoose(InconsistentParameterValueError, _ClassError9); | ||
function InconsistentParameterValueError(paramName, value1, value2, className) { | ||
var _this15; | ||
_this15 = _ClassError9.call(this, "Inconsistent value of parameter '" + paramName + "': '" + value1 + "' != '" + value2 + "'", className) || this; | ||
_this15.code = ErrorCode.InconsistentParameterValue; | ||
return _this15; | ||
} | ||
return InconsistentParameterValueError; | ||
}(ClassError); | ||
var IllegalAttributeValueError = | ||
/*#__PURE__*/ | ||
function (_ClassError10) { | ||
_inheritsLoose(IllegalAttributeValueError, _ClassError10); | ||
function IllegalAttributeValueError(attrName, value, className) { | ||
var _this16; | ||
_this16 = _ClassError10.call(this, "Illegal attribute value '" + value + "' of attribute '" + attrName + "'", className) || this; | ||
_this16.code = ErrorCode.IllegalAttributeValue; | ||
return _this16; | ||
} | ||
return IllegalAttributeValueError; | ||
}(ClassError); | ||
var MissingAttributeError = | ||
/*#__PURE__*/ | ||
function (_ClassError11) { | ||
_inheritsLoose(MissingAttributeError, _ClassError11); | ||
function MissingAttributeError(attrName, className) { | ||
var _this17; | ||
_this17 = _ClassError11.call(this, "Missing mandatory attribute " + attrName, className) || this; | ||
_this17.code = ErrorCode.MissingAttribute; | ||
return _this17; | ||
} | ||
return MissingAttributeError; | ||
}(ClassError); | ||
var IllegalTagAttributeError = | ||
/*#__PURE__*/ | ||
function (_ClassError12) { | ||
_inheritsLoose(IllegalTagAttributeError, _ClassError12); | ||
function IllegalTagAttributeError(attrName, tagName, className) { | ||
var _this18; | ||
_this18 = _ClassError12.call(this, "Illegal attribute '" + attrName + "' for tag '" + tagName + "'", className) || this; | ||
_this18.code = ErrorCode.IllegalTagAttribute; | ||
return _this18; | ||
} | ||
return IllegalTagAttributeError; | ||
}(ClassError); | ||
/*! | ||
@@ -377,3 +864,3 @@ * Copyright (c) Microsoft Corporation. All rights reserved. | ||
var _reportError; | ||
var _error; | ||
@@ -423,3 +910,3 @@ var _getClass; | ||
var a; | ||
var errorMessage; | ||
var error; | ||
@@ -440,3 +927,3 @@ try { | ||
} else if (!_ignoreUnknownClasses) { | ||
errorMessage = "Unknown class '" + className + "'"; | ||
error = new UnknownClassError(className); | ||
} else { | ||
@@ -450,3 +937,3 @@ return; | ||
if (isAccessibleElement(tagName, attributes)) { | ||
var _Class = _assumeClass(tagName, attributes, element, false); | ||
var _Class = _assumeClass(tagName, attributes, element); | ||
@@ -456,3 +943,3 @@ if (_Class) { | ||
} else { | ||
errorMessage = 'Accessible element must have accessibility class assigned.'; | ||
error = new NoClassError(); | ||
} | ||
@@ -466,6 +953,6 @@ } else { | ||
} catch (e) { | ||
errorMessage = e.message || 'Failed to validate element'; | ||
error = e instanceof AbilityAttributesError ? e : new ValidationFailedError(); | ||
} | ||
if (!errorMessage && a && a.getConstraints) { | ||
if (!error && a && a.getConstraints) { | ||
var constraints = a.getConstraints(); | ||
@@ -476,3 +963,3 @@ constraints.every(function (constraint) { | ||
if (!checkConstraint(element, c)) { | ||
errorMessage = makeConstraintErrorMessage(c.description, constraint); | ||
error = new ConstraintNotSatisfiedError(c.description, constraint); | ||
return false; | ||
@@ -485,3 +972,3 @@ } | ||
if (!checkConstraint(element, constraint)) { | ||
errorMessage = makeConstraintErrorMessage(constraint.description, constraint); | ||
error = new ConstraintNotSatisfiedError(constraint.description, constraint); | ||
return false; | ||
@@ -495,27 +982,7 @@ } | ||
_reportError(errorMessage || null, element, false); | ||
} | ||
function makeConstraintErrorMessage(description, constraint) { | ||
var errorMessage = description; | ||
if (constraint.param || constraint.name && constraint.value) { | ||
errorMessage += ' ('; | ||
if (constraint.param) { | ||
errorMessage += "when no " + constraint.param + " specified"; | ||
} | ||
if (constraint.name && constraint.value) { | ||
if (constraint.param) { | ||
errorMessage += ', '; | ||
} | ||
errorMessage += "parameter '" + constraint.name + "', value: '" + constraint.value + "'"; | ||
} | ||
errorMessage += ')'; | ||
if (error) { | ||
_error.report(element, error); | ||
} else { | ||
_error.remove(element); | ||
} | ||
return errorMessage; | ||
} | ||
@@ -537,3 +1004,3 @@ | ||
} catch (e) { | ||
_reportError("Failed to evaluate expression: " + xpath + ", " + e.message, element, false); | ||
_error.report(element, new XPathExpressionFailedError(xpath, e.message)); | ||
@@ -559,3 +1026,3 @@ return true; | ||
function setup(win, reportError, getClass, enforceClasses, assumeClass, ignoreUnknownClasses) { | ||
function setup(win, error, getClass, enforceClasses, assumeClass, ignoreUnknownClasses) { | ||
if (!(process.env.NODE_ENV !== "production")) { | ||
@@ -569,3 +1036,3 @@ return; | ||
_reportError = reportError; | ||
_error = error; | ||
_getClass = getClass; | ||
@@ -632,4 +1099,4 @@ _enforceClasses = enforceClasses; | ||
_validatorQueue = {}; | ||
toRemove.map(function (e) { | ||
return _reportError(null, e, false); | ||
toRemove.forEach(function (e) { | ||
return _error.remove(e); | ||
}); | ||
@@ -705,45 +1172,10 @@ toValidate.filter(function (e) { | ||
if (!w.__abilityAttributesDev) { | ||
var els = createElements(); | ||
if (els) { | ||
w.__abilityAttributesDev = { | ||
errorStyle: els.style, | ||
errorContainer: els.container, | ||
reportError: function reportError$1(message, element, isRender) { | ||
var env = getDevEnv(w); | ||
if (env) { | ||
if (env.errorStyle.parentNode !== w.document.body) { | ||
w.document.body.appendChild(env.errorStyle); | ||
} | ||
if (env.errorContainer.parentNode !== w.document.body) { | ||
w.document.body.appendChild(env.errorContainer); | ||
} | ||
return reportError(env, message, element, isRender); | ||
} | ||
return null; | ||
}, | ||
lastErrorId: 0 | ||
}; | ||
var enforceClasses = (settings && settings.enforceClasses) !== false; | ||
var ignoreUnknownClasses = !!(settings && settings.ignoreUnknownClasses); | ||
setup(w, w.__abilityAttributesDev.reportError, getClassByName, enforceClasses, assumeClass, ignoreUnknownClasses); | ||
} | ||
w.__abilityAttributesDev = { | ||
error: new ErrorReporter$1(w) | ||
}; | ||
var enforceClasses = (settings && settings.enforceClasses) !== false; | ||
var ignoreUnknownClasses = !!(settings && settings.ignoreUnknownClasses); | ||
setup(w, w.__abilityAttributesDev.error, getClassByName, enforceClasses, assumeClass, ignoreUnknownClasses); | ||
} | ||
} | ||
function getDevEnv(win) { | ||
return win.__abilityAttributesDev; | ||
} | ||
function reportError$1(win, message, element, isRender) { | ||
var env = getDevEnv(win); | ||
if (env) { | ||
return env.reportError(message, element, isRender); | ||
} | ||
return null; | ||
} | ||
function addClass(name, Class) { | ||
@@ -772,3 +1204,3 @@ if (process.env.NODE_ENV !== "production" && typeof window !== 'undefined') { | ||
} | ||
function assumeClass(tagName, attributes, element, isRender) { | ||
function assumeClass(tagName, attributes, element) { | ||
if (process.env.NODE_ENV !== "production" && typeof window !== 'undefined') { | ||
@@ -819,3 +1251,3 @@ var win = window; | ||
if (hasEqualAssumptions) { | ||
reportError$1(window, "Ambiguous class assumption: '" + hasEqualAssumptions[0].Class.className + "' and '" + hasEqualAssumptions[1].Class.className + "'", element, isRender); | ||
reportError(new AmbiguousAssumptionError(hasEqualAssumptions[0].Class.className, hasEqualAssumptions[1].Class.className), element); | ||
return undefined; | ||
@@ -831,13 +1263,31 @@ } | ||
function getDevEnv(win) { | ||
return win.__abilityAttributesDev; | ||
} | ||
function reportError(error, element, win) { | ||
var w = win || (typeof window !== 'undefined' ? window : undefined); | ||
if (!w) { | ||
return; | ||
} | ||
var env = getDevEnv(w); | ||
if (env) { | ||
env.error.report(element, error); | ||
} | ||
} | ||
var DevEnv = ({ | ||
setup: setup$1, | ||
getDevEnv: getDevEnv, | ||
reportError: reportError$1, | ||
addClass: addClass, | ||
getClassByName: getClassByName, | ||
assumeClass: assumeClass, | ||
ATTRIBUTE_NAME_CLASS: ATTRIBUTE_NAME_CLASS, | ||
ATTRIBUTE_NAME_ERROR_ID: ATTRIBUTE_NAME_ERROR_ID, | ||
ATTRIBUTE_NAME_ERROR_MESSAGE: ATTRIBUTE_NAME_ERROR_MESSAGE, | ||
ATTRIBUTE_NAME_PROPS: ATTRIBUTE_NAME_PROPS | ||
setup: setup$1, | ||
addClass: addClass, | ||
getClassByName: getClassByName, | ||
assumeClass: assumeClass, | ||
ATTRIBUTE_NAME_CLASS: ATTRIBUTE_NAME_CLASS, | ||
ATTRIBUTE_NAME_ERROR_ID: ATTRIBUTE_NAME_ERROR_ID, | ||
ATTRIBUTE_NAME_ERROR_MESSAGE: ATTRIBUTE_NAME_ERROR_MESSAGE, | ||
ATTRIBUTE_NAME_PROPS: ATTRIBUTE_NAME_PROPS, | ||
AbilityAttributesError: AbilityAttributesError, | ||
ErrorReporter: ErrorReporter | ||
}); | ||
@@ -860,4 +1310,4 @@ | ||
AttributeSchema._error = function _error(message, className) { | ||
throw new Error(message + " in class '" + className + "'"); | ||
AttributeSchema._error = function _error(error) { | ||
throw error; | ||
}; | ||
@@ -867,4 +1317,4 @@ | ||
_proto._error = function _error(message) { | ||
AttributeSchema._error(message, this._className); | ||
_proto._error = function _error(error) { | ||
AttributeSchema._error(error); | ||
}; | ||
@@ -876,8 +1326,21 @@ | ||
AttributeSchema._assignTagNames = function _assignTagNames(byTag, tagsByTag) { | ||
var tagNames = Object.keys(tagsByTag); | ||
var ret = {}; | ||
for (var _i = 0, _tagNames = tagNames; _i < _tagNames.length; _i++) { | ||
var tagName = _tagNames[_i]; | ||
ret[tagName] = byTag[tagsByTag[tagName]]; | ||
} | ||
return ret; | ||
}; | ||
_proto.getAttributes = function getAttributes() { | ||
var params = this._params; | ||
var allParams = this._allParams; | ||
var allParams = this._allParamsByTag[this._tagName]; | ||
var classes = {}; | ||
var attrs = {}; | ||
var nonParamAttrs = this._nonParamAttrs[this._tagName]; | ||
var attrToParam = this._attrToParamByTag[this._tagName]; | ||
var nonParamAttrs = this._nonParamAttrsByTag[this._tagName]; | ||
@@ -888,5 +1351,5 @@ if (process.env.NODE_ENV !== "production") { | ||
if (!nonParamAttrs) { | ||
if (!allParams || !nonParamAttrs) { | ||
if (process.env.NODE_ENV !== "production") { | ||
this._error("Illegal tag '" + this._tagName + "'"); | ||
this._error(new IllegalTagError(this._tagName, this._className)); | ||
} | ||
@@ -897,12 +1360,12 @@ | ||
for (var _iterator = this._paramNames, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
for (var _iterator = this._paramNames, _isArray = Array.isArray(_iterator), _i2 = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref = _iterator[_i++]; | ||
if (_i2 >= _iterator.length) break; | ||
_ref = _iterator[_i2++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref = _i.value; | ||
_i2 = _iterator.next(); | ||
if (_i2.done) break; | ||
_ref = _i2.value; | ||
} | ||
@@ -915,3 +1378,3 @@ | ||
if (process.env.NODE_ENV !== "production") { | ||
this._error("Unknown param '" + paramName + "'"); | ||
this._error(new UnknownParameterError(paramName, this._className)); | ||
} | ||
@@ -924,3 +1387,3 @@ | ||
if (process.env.NODE_ENV !== "production") { | ||
this._error("Only one of '" + paramName + "' or '" + classes[paramDef["class"]] + "' parameters can be present"); | ||
this._error(new ExcessiveParameterError(paramName, classes[paramDef["class"]], this._className)); | ||
} | ||
@@ -932,33 +1395,53 @@ | ||
classes[paramDef["class"]] = paramName; | ||
var values = paramDef.param.value; | ||
if (values) { | ||
var illegalValue = true; | ||
for (var _iterator2 = paramDef.param.attributes, _isArray2 = Array.isArray(_iterator2), _i5 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { | ||
var _ref2; | ||
for (var _iterator2 = values, _isArray2 = Array.isArray(_iterator2), _i4 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { | ||
var _ref2; | ||
if (_isArray2) { | ||
if (_i5 >= _iterator2.length) break; | ||
_ref2 = _iterator2[_i5++]; | ||
} else { | ||
_i5 = _iterator2.next(); | ||
if (_i5.done) break; | ||
_ref2 = _i5.value; | ||
} | ||
if (_isArray2) { | ||
if (_i4 >= _iterator2.length) break; | ||
_ref2 = _iterator2[_i4++]; | ||
} else { | ||
_i4 = _iterator2.next(); | ||
if (_i4.done) break; | ||
_ref2 = _i4.value; | ||
} | ||
var a = _ref2; | ||
var value = _ref2; | ||
if (a.optional) { | ||
continue; | ||
} | ||
if (value.parameter === params[paramName]) { | ||
attrs[paramDef.param.attribute] = value.attribute; | ||
illegalValue = false; | ||
break; | ||
var values = a.value; | ||
if (values) { | ||
var illegalValue = true; | ||
for (var _iterator3 = values, _isArray3 = Array.isArray(_iterator3), _i6 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) { | ||
var _ref3; | ||
if (_isArray3) { | ||
if (_i6 >= _iterator3.length) break; | ||
_ref3 = _iterator3[_i6++]; | ||
} else { | ||
_i6 = _iterator3.next(); | ||
if (_i6.done) break; | ||
_ref3 = _i6.value; | ||
} | ||
var value = _ref3; | ||
if (value.parameter === params[paramName]) { | ||
attrs[a.name] = typeof value.attribute === 'boolean' ? '' : value.attribute; | ||
illegalValue = false; | ||
break; | ||
} | ||
} | ||
} | ||
if (process.env.NODE_ENV !== "production" && illegalValue) { | ||
this._error("Illegal parameter value '" + params[paramName] + "' of parameter '" + paramName + "'"); | ||
if (process.env.NODE_ENV !== "production" && illegalValue) { | ||
this._error(new IllegalParameterValueError(paramName, params[paramName], this._className)); | ||
} | ||
} else { | ||
attrs[a.name] = params[paramName]; | ||
} | ||
} else { | ||
attrs[paramDef.param.attribute] = params[paramName]; | ||
} | ||
@@ -968,9 +1451,9 @@ } | ||
if (process.env.NODE_ENV !== "production") { | ||
for (var _i2 = 0, _Object$keys = Object.keys(this._mandatoryParams); _i2 < _Object$keys.length; _i2++) { | ||
var c = _Object$keys[_i2]; | ||
for (var _i3 = 0, _Object$keys = Object.keys(this._mandatoryParams); _i3 < _Object$keys.length; _i3++) { | ||
var c = _Object$keys[_i3]; | ||
if (!(c in classes)) { | ||
this._error("Missing mandatory parameter " + this._mandatoryParams[c].map(function (p) { | ||
this._error(new MissingParameterError(this._mandatoryParams[c].map(function (p) { | ||
return "'" + p + "'"; | ||
}).join(' or ')); | ||
}).join(' or '), this._className)); | ||
} | ||
@@ -980,16 +1463,18 @@ } | ||
for (var _i3 = 0, _Object$keys2 = Object.keys(nonParamAttrs); _i3 < _Object$keys2.length; _i3++) { | ||
var a = _Object$keys2[_i3]; | ||
var attr = nonParamAttrs[a].attr; | ||
for (var _i4 = 0, _Object$keys2 = Object.keys(nonParamAttrs); _i4 < _Object$keys2.length; _i4++) { | ||
var _a = _Object$keys2[_i4]; | ||
var attr = nonParamAttrs[_a].attr; | ||
if (!(a in attrs)) { | ||
var v = this._defaults && a in this._defaults ? this._defaults[a] : attr["default"]; | ||
if (v) { | ||
attrs[a] = v; | ||
if (!(_a in attrs)) { | ||
if (this._defaults && _a in this._defaults) { | ||
attrs[_a] = this._defaults[_a]; | ||
} else if (attr["default"] !== undefined) { | ||
if (!attr.optional) { | ||
attrs[_a] = attr["default"]; | ||
} | ||
} else if (process.env.NODE_ENV !== "production") { | ||
this._error("Schema error, attribute '" + a + "' does not have a value"); | ||
this._error(new SchemaNoAttributeValueError(_a, this._className)); | ||
} | ||
} else if (process.env.NODE_ENV !== "production" && (!attr.value || !(attrs[a] in attr.value))) { | ||
this._error("Schema error, parameter '" + this._attrToParam[a] + "' sets illegal value of attribute '" + a + "'"); | ||
} else if (process.env.NODE_ENV !== "production" && (!attr.value || !(attrs[_a] in attr.value))) { | ||
this._error(new SchemaIllegalAttributeValueError(attrToParam[_a], _a, this._className)); | ||
} | ||
@@ -1001,7 +1486,10 @@ } | ||
AttributeSchema._getParamsFromAttributes = function _getParamsFromAttributes(tagName, attributes, className, allParams, attrToParam, paramToAttr, mandatoryParams, nonParamAttrs) { | ||
AttributeSchema._getParamsFromAttributes = function _getParamsFromAttributes(tagName, attributes, className, allParamsByTag, attrToParamByTag, paramToAttrByTag, mandatoryParams, nonParamAttrs) { | ||
var allParams = allParamsByTag[tagName]; | ||
var attrToParam = attrToParamByTag[tagName]; | ||
var paramToAttr = paramToAttrByTag[tagName]; | ||
var nonParamAttrsForTag = nonParamAttrs[tagName]; | ||
if (process.env.NODE_ENV !== "production" && !nonParamAttrsForTag) { | ||
AttributeSchema._error("Illegal tag '" + tagName + "'", className); | ||
AttributeSchema._error(new IllegalTagError(tagName, className)); | ||
} | ||
@@ -1015,6 +1503,6 @@ | ||
for (var _i5 = 0, _attrNames = attrNames; _i5 < _attrNames.length; _i5++) { | ||
var _attrName = _attrNames[_i5]; | ||
for (var _i7 = 0, _attrNames = attrNames; _i7 < _attrNames.length; _i7++) { | ||
var _attrName = _attrNames[_i7]; | ||
if (_attrName in attrToParam) { | ||
if (!attributesUsed[_attrName] && _attrName in attrToParam) { | ||
var paramName = attrToParam[_attrName]; | ||
@@ -1024,75 +1512,112 @@ var param = allParams[paramName]; | ||
if (process.env.NODE_ENV !== "production" && param["class"] in classes) { | ||
AttributeSchema._error("Only one of '" + _attrName + "' or '" + classes[param["class"]] + "' attributes can be present", className); | ||
AttributeSchema._error(new ExcessiveAttributeError(_attrName, classes[param["class"]], className)); | ||
} | ||
classes[param["class"]] = _attrName; | ||
var paramVal = void 0; | ||
if (param.param.value) { | ||
var illegalValue = true; | ||
for (var _iterator5 = param.param.attributes, _isArray5 = Array.isArray(_iterator5), _i11 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) { | ||
var _ref5; | ||
for (var _iterator3 = param.param.value, _isArray3 = Array.isArray(_iterator3), _i9 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) { | ||
var _ref3; | ||
if (_isArray5) { | ||
if (_i11 >= _iterator5.length) break; | ||
_ref5 = _iterator5[_i11++]; | ||
} else { | ||
_i11 = _iterator5.next(); | ||
if (_i11.done) break; | ||
_ref5 = _i11.value; | ||
} | ||
if (_isArray3) { | ||
if (_i9 >= _iterator3.length) break; | ||
_ref3 = _iterator3[_i9++]; | ||
} else { | ||
_i9 = _iterator3.next(); | ||
if (_i9.done) break; | ||
_ref3 = _i9.value; | ||
} | ||
var a = _ref5; | ||
var value = _ref3; | ||
if (a.value) { | ||
var illegalValue = true; | ||
if (value.attribute === attributes[_attrName]) { | ||
params[paramName] = value.parameter; | ||
illegalValue = false; | ||
break; | ||
for (var _iterator6 = a.value, _isArray6 = Array.isArray(_iterator6), _i12 = 0, _iterator6 = _isArray6 ? _iterator6 : _iterator6[Symbol.iterator]();;) { | ||
var _ref6; | ||
if (_isArray6) { | ||
if (_i12 >= _iterator6.length) break; | ||
_ref6 = _iterator6[_i12++]; | ||
} else { | ||
_i12 = _iterator6.next(); | ||
if (_i12.done) break; | ||
_ref6 = _i12.value; | ||
} | ||
var value = _ref6; | ||
var expected = value.attribute; | ||
var attrVal = attributes[a.name]; | ||
var valueMatched = !a.optional && expected === false && attrVal === undefined || expected === true && (attrVal === '' || attrVal === _attrName) || expected === attrVal; | ||
if (valueMatched || paramVal === value.parameter) { | ||
if (process.env.NODE_ENV !== "production" && paramVal !== undefined && paramVal !== value.parameter) { | ||
AttributeSchema._error(new InconsistentParameterValueError(param.param.name, paramVal, value.parameter, className)); | ||
} | ||
if (valueMatched || attrVal === undefined && a.optional) { | ||
illegalValue = false; | ||
} | ||
if (paramVal === undefined) { | ||
paramVal = value.parameter; | ||
break; | ||
} | ||
} | ||
} | ||
if (process.env.NODE_ENV !== "production" && illegalValue) { | ||
AttributeSchema._error(new IllegalAttributeValueError(a.name, attributes[a.name], className)); | ||
} | ||
} else { | ||
paramVal = attributes[_attrName]; | ||
} | ||
if (process.env.NODE_ENV !== "production" && illegalValue) { | ||
AttributeSchema._error("Illegal attribute value '" + attributes[_attrName] + "' of attribute '" + _attrName + "'", className); | ||
} | ||
} else { | ||
params[paramName] = attributes[_attrName]; | ||
attributesUsed[a.name] = true; | ||
} | ||
attributesUsed[_attrName] = true; | ||
if (paramVal !== undefined) { | ||
params[paramName] = paramVal; | ||
} | ||
} | ||
} | ||
for (var _i6 = 0, _Object$keys3 = Object.keys(mandatoryParams); _i6 < _Object$keys3.length; _i6++) { | ||
var c = _Object$keys3[_i6]; | ||
for (var _i8 = 0, _Object$keys3 = Object.keys(mandatoryParams); _i8 < _Object$keys3.length; _i8++) { | ||
var c = _Object$keys3[_i8]; | ||
if (process.env.NODE_ENV !== "production" && !(c in classes)) { | ||
AttributeSchema._error("Missing mandatory attribute " + mandatoryParams[c].map(function (p) { | ||
AttributeSchema._error(new MissingAttributeError(mandatoryParams[c].map(function (p) { | ||
return "'" + paramToAttr[p] + "'"; | ||
}).join(' or '), className); | ||
}).join(' or '), className)); | ||
} | ||
} | ||
for (var _i7 = 0, _Object$keys4 = Object.keys(nonParamAttrsForTag); _i7 < _Object$keys4.length; _i7++) { | ||
var a = _Object$keys4[_i7]; | ||
for (var _i9 = 0, _Object$keys4 = Object.keys(nonParamAttrsForTag); _i9 < _Object$keys4.length; _i9++) { | ||
var _a2 = _Object$keys4[_i9]; | ||
if (a in attributesUsed) { | ||
if (_a2 in attributesUsed) { | ||
continue; | ||
} | ||
if (process.env.NODE_ENV !== "production" && !(a in attributes)) { | ||
AttributeSchema._error("Missing mandatory attribute '" + a + "'", className); | ||
var attr = nonParamAttrsForTag[_a2].attr; | ||
var v = attributes[_a2]; | ||
if (process.env.NODE_ENV !== "production" && !(_a2 in attributes) && !(v === undefined && attr.optional)) { | ||
AttributeSchema._error(new MissingAttributeError(_a2, className)); | ||
} | ||
attributesUsed[a] = true; | ||
var attr = nonParamAttrsForTag[a].attr; | ||
var v = attributes[a]; | ||
attributesUsed[_a2] = true; | ||
if (v === undefined && attr.optional) { | ||
continue; | ||
} | ||
if (attr.value) { | ||
if (v in attr.value) { | ||
defaults[a] = v; | ||
defaults[_a2] = v; | ||
} else if (process.env.NODE_ENV !== "production") { | ||
AttributeSchema._error("Illegal attribute value '" + v + "' of attribute '" + a + "'", className); | ||
AttributeSchema._error(new IllegalAttributeValueError(_a2, v, className)); | ||
} | ||
} else { | ||
defaults[a] = v; | ||
defaults[_a2] = v; | ||
} | ||
@@ -1102,7 +1627,18 @@ } | ||
if (process.env.NODE_ENV !== "production") { | ||
for (var _i8 = 0, _attrNames2 = attrNames; _i8 < _attrNames2.length; _i8++) { | ||
var attrName = _attrNames2[_i8]; | ||
for (var _iterator4 = attrNames, _isArray4 = Array.isArray(_iterator4), _i10 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) { | ||
var _ref4; | ||
if (_isArray4) { | ||
if (_i10 >= _iterator4.length) break; | ||
_ref4 = _iterator4[_i10++]; | ||
} else { | ||
_i10 = _iterator4.next(); | ||
if (_i10.done) break; | ||
_ref4 = _i10.value; | ||
} | ||
var attrName = _ref4; | ||
if (!(attrName in attributesUsed) && attrName in AccessibilityAttributes) { | ||
AttributeSchema._error("Illegal attribute '" + attrName + "' for tag '" + tagName + "'", className); | ||
AttributeSchema._error(new IllegalTagAttributeError(attrName, tagName, className)); | ||
} | ||
@@ -1122,3 +1658,3 @@ } | ||
var Schema = ({ | ||
AttributeSchema: AttributeSchema | ||
AttributeSchema: AttributeSchema | ||
}); | ||
@@ -1125,0 +1661,0 @@ |
@@ -5,10 +5,8 @@ /*! | ||
*/ | ||
import { AttributeSchemaClass, DevEnv, DevEnvSettings } from './DevEnvTypes'; | ||
import { AttributeSchemaClass, DevEnvSettings } from './DevEnvTypes'; | ||
import { HTMLElementAttributes } from './HTML'; | ||
export * from './DevEnvTypes'; | ||
export declare function setup(settings?: DevEnvSettings): void; | ||
export declare function getDevEnv(win: Window): DevEnv | undefined; | ||
export declare function reportError(win: Window, message: string | null, element: HTMLElement | null, isRender: boolean): string | null; | ||
export declare function addClass(name: string, Class: AttributeSchemaClass): void; | ||
export declare function getClassByName(name: string): AttributeSchemaClass | undefined; | ||
export declare function assumeClass(tagName: string, attributes: HTMLElementAttributes, element: HTMLElement | null, isRender: boolean): AttributeSchemaClass | undefined; | ||
export declare function assumeClass(tagName: string, attributes: HTMLElementAttributes, element: HTMLElement): AttributeSchemaClass | undefined; |
@@ -11,3 +11,11 @@ /*! | ||
export declare const ATTRIBUTE_NAME_PROPS = "data-aa-props"; | ||
export declare type ErrorReporter = (message: string | null, element: HTMLElement | null, isRender: boolean) => string | null; | ||
export declare abstract class AbilityAttributesError extends Error { | ||
abstract readonly code: number; | ||
} | ||
export declare abstract class ErrorReporter { | ||
abstract report(element: HTMLElement, error: AbilityAttributesError): void; | ||
abstract remove(element: HTMLElement): void; | ||
abstract dismiss(element: HTMLElement): void; | ||
abstract toggle(): void; | ||
} | ||
export declare type AssumptionSpecificity = { | ||
@@ -17,3 +25,3 @@ tag: boolean; | ||
}; | ||
export declare type AssumeClass = (tagName: string, attributes: HTMLElementAttributes, element: HTMLElement | null, isRender: boolean) => AttributeSchemaClass | undefined; | ||
export declare type AssumeClass = (tagName: string, attributes: HTMLElementAttributes, element: HTMLElement | null) => AttributeSchemaClass | undefined; | ||
export interface AttributeSchemaClass<P = any> { | ||
@@ -26,7 +34,3 @@ new (tagName: string, params?: P): AttributeSchema<P>; | ||
export interface DevEnv { | ||
errorStyle: HTMLStyleElement; | ||
errorContainer: HTMLDivElement; | ||
reportError: ErrorReporter; | ||
lastErrorId: number; | ||
lastDismissAllId?: number; | ||
error: ErrorReporter; | ||
} | ||
@@ -33,0 +37,0 @@ export interface WindowWithDevEnv extends Window { |
@@ -5,8 +5,24 @@ /*! | ||
*/ | ||
import { DevEnv } from './DevEnvTypes'; | ||
export interface ErrorReporterUI { | ||
style: HTMLStyleElement; | ||
container: HTMLDivElement; | ||
import { AbilityAttributesError, ErrorReporter as ErrorReporterBase } from './DevEnvTypes'; | ||
export declare class ErrorReporter extends ErrorReporterBase { | ||
private _window; | ||
private _renderTimer; | ||
private _isCollapsed; | ||
private _styles; | ||
private _container; | ||
private _toggle; | ||
private _expanded; | ||
constructor(w: Window); | ||
report(element: HTMLElement, error: AbilityAttributesError): void; | ||
remove(element: HTMLElement): void; | ||
dismiss(element: HTMLElement): void; | ||
toggle: () => void; | ||
private _initUI; | ||
private _render; | ||
private _reallyRender; | ||
private _showCounter; | ||
private _showExpanded; | ||
private _hide; | ||
private _createErrorView; | ||
private _removeErrorView; | ||
} | ||
export declare function createElements(): ErrorReporterUI | undefined; | ||
export declare function reportError(env: DevEnv, message: string | null, element: HTMLElement | null, isRender: boolean): string | null; |
@@ -10,11 +10,15 @@ /*! | ||
parameter: string | number | boolean | null; | ||
attribute: string; | ||
attribute: string | boolean; | ||
} | ||
export interface ParameterEntry { | ||
export interface AttributeInParameter { | ||
name: string; | ||
attribute: string; | ||
value?: ParameterValue[]; | ||
constraints?: (Constraint | ConstraintRef)[]; | ||
optional?: boolean; | ||
} | ||
export interface Parameters { | ||
export interface ParameterEntry { | ||
name: string; | ||
attributes: AttributeInParameter[]; | ||
} | ||
export interface TagRuntimeParameters { | ||
[name: string]: { | ||
@@ -25,5 +29,11 @@ class: string; | ||
} | ||
export interface RuntimeParameters { | ||
[tagName: string]: TagRuntimeParameters; | ||
} | ||
export interface AttributeToParameter { | ||
[name: string]: string; | ||
} | ||
export interface AttributeToParameterByTag { | ||
[tagName: string]: AttributeToParameter; | ||
} | ||
export interface MandatoryParameters { | ||
@@ -41,2 +51,3 @@ [paramClass: string]: string[]; | ||
}; | ||
optional?: boolean; | ||
} | ||
@@ -49,3 +60,3 @@ export interface NonParameterAttribute { | ||
} | ||
export interface NonParameterAttributes { | ||
export interface NonParameterAttributesByTag { | ||
[tagName: string]: NonParameterAttribute; | ||
@@ -91,2 +102,5 @@ } | ||
}; | ||
export interface TagsByTag { | ||
[tagName: string]: string; | ||
} | ||
export declare abstract class AttributeSchema<P extends { | ||
@@ -96,6 +110,6 @@ [name: string]: any; | ||
protected abstract _className: string; | ||
protected abstract _allParams: Parameters; | ||
protected abstract _attrToParam: AttributeToParameter; | ||
protected abstract _allParamsByTag: RuntimeParameters; | ||
protected abstract _attrToParamByTag: AttributeToParameterByTag; | ||
protected abstract _mandatoryParams: MandatoryParameters; | ||
protected abstract _nonParamAttrs: NonParameterAttributes; | ||
protected abstract _nonParamAttrsByTag: NonParameterAttributesByTag; | ||
protected _tagName: string; | ||
@@ -111,6 +125,11 @@ protected _params: P; | ||
protected _setDefaults(defaults: AttributeDefaults): void; | ||
protected static _assignTagNames(byTag: { | ||
[tagsName: string]: any; | ||
}, tagsByTag: TagsByTag): { | ||
[tagName: string]: any; | ||
}; | ||
getAttributes(): HTMLElementAttributes; | ||
protected static _getParamsFromAttributes<P extends { | ||
[name: string]: any; | ||
}>(tagName: string, attributes: HTMLElementAttributes, className: string, allParams: Parameters, attrToParam: AttributeToParameter, paramToAttr: AttributeToParameter, mandatoryParams: MandatoryParameters, nonParamAttrs: NonParameterAttributes): { | ||
}>(tagName: string, attributes: HTMLElementAttributes, className: string, allParamsByTag: RuntimeParameters, attrToParamByTag: AttributeToParameterByTag, paramToAttrByTag: AttributeToParameterByTag, mandatoryParams: MandatoryParameters, nonParamAttrs: NonParameterAttributesByTag): { | ||
params: P; | ||
@@ -117,0 +136,0 @@ defaults: AttributeDefaults; |
@@ -7,3 +7,3 @@ /*! | ||
declare type GetClass = (name: string) => AttributeSchemaClass | undefined; | ||
export declare function setup(win: Window, reportError: ErrorReporter, getClass: GetClass, enforceClasses: boolean, assumeClass: AssumeClass, ignoreUnknownClasses: boolean): void; | ||
export declare function setup(win: Window, error: ErrorReporter, getClass: GetClass, enforceClasses: boolean, assumeClass: AssumeClass, ignoreUnknownClasses: boolean): void; | ||
export {}; |
{ | ||
"name": "ability-attributes", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "A base package for the accessibility attributes schema runtime", | ||
@@ -31,3 +31,3 @@ "author": "Marat Abdullin <marata@microsoft.com>", | ||
}, | ||
"gitHead": "4dfe2445b1fdc8fa248385fdb5281f37cd99c0fa" | ||
"gitHead": "f43aec3d71f0744b7637ef25b185877470b5a67c" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
321742
18
3139