@anglr/datetime 5.0.0-beta.20221017112052 → 5.0.0-beta.20221018102923
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/changelog.md +46 -8
- package/es2015/src/index.js +0 -3
- package/es2015/src/index.js.map +1 -1
- package/es2015/src/interfaces/dateTimeInput/dateTimeInput.interface.js.map +1 -1
- package/es2015/src/legacy/selector/components/inputDateTime/inputDateTime.component.js +4 -6
- package/es2015/src/legacy/selector/components/inputDateTime/inputDateTime.component.js.map +1 -1
- package/es2015/src/legacy/selector/components/selector/selector.component.js +2 -2
- package/es2015/src/legacy/selector/components/selector/selector.component.js.map +1 -1
- package/es2015/src/legacy/selector/components/simpleInputDateTime/simpleInputDateTime.component.js +2 -2
- package/es2015/src/legacy/selector/components/simpleInputDateTime/simpleInputDateTime.component.js.map +1 -1
- package/es2015/src/misc/enums.js +1 -1
- package/es2015/src/misc/enums.js.map +1 -1
- package/es2015/src/misc/types.js.map +1 -1
- package/es2015/src/misc/utils.js +10 -0
- package/es2015/src/misc/utils.js.map +1 -1
- package/es2015/src/misc/validators.js +79 -2
- package/es2015/src/misc/validators.js.map +1 -1
- package/es2015/src/modules/dateTime/directives/dateTimeBase.js +77 -0
- package/es2015/src/modules/dateTime/directives/dateTimeBase.js.map +1 -0
- package/es2015/src/modules/dateTime/directives/dateTimeInput/dateTimeInput.directive.js +12 -59
- package/es2015/src/modules/dateTime/directives/dateTimeInput/dateTimeInput.directive.js.map +1 -1
- package/es2015/src/modules/dateTime/directives/dateTimeMaxValidator/dateTimeMaxValidator.directive.js +72 -0
- package/es2015/src/modules/dateTime/directives/dateTimeMaxValidator/dateTimeMaxValidator.directive.js.map +1 -0
- package/es2015/src/modules/dateTime/directives/dateTimeMinValidator/dateTimeMinValidator.directive.js +71 -0
- package/es2015/src/modules/dateTime/directives/dateTimeMinValidator/dateTimeMinValidator.directive.js.map +1 -0
- package/es2015/src/modules/dateTime/directives/dateTimeRestrictedBase.js +152 -0
- package/es2015/src/modules/dateTime/directives/dateTimeRestrictedBase.js.map +1 -0
- package/es2015/src/modules/dateTime/directives/dateTimeValidator/dateTimeValidator.directive.js +17 -6
- package/es2015/src/modules/dateTime/directives/dateTimeValidator/dateTimeValidator.directive.js.map +1 -1
- package/es2015/src/modules/dateTime/directives/index.js +4 -0
- package/es2015/src/modules/dateTime/directives/index.js.map +1 -1
- package/es2015/src/modules/dateTime/modules/dateTime.module.js +9 -1
- package/es2015/src/modules/dateTime/modules/dateTime.module.js.map +1 -1
- package/es2015/src/services/{datePositionParser.interface.js → datePositionParser/datePositionParser.interface.js} +0 -0
- package/es2015/src/services/datePositionParser/datePositionParser.interface.js.map +1 -0
- package/es2015/src/services/{datePositionParser.service.js → datePositionParser/datePositionParser.service.js} +0 -0
- package/es2015/src/services/datePositionParser/datePositionParser.service.js.map +1 -0
- package/es2015/src/services/{dateTimeRelativeParser.service.js → dateTimeRelativeParser/dateTimeRelativeParser.service.js} +8 -8
- package/es2015/src/services/dateTimeRelativeParser/dateTimeRelativeParser.service.js.map +1 -0
- package/es2015/src/services/{dateValueProvider.service.js → dateValueProvider/dateValueProvider.service.js} +1 -1
- package/es2015/src/services/dateValueProvider/dateValueProvider.service.js.map +1 -0
- package/es2015/src/services/index.js +4 -1
- package/es2015/src/services/index.js.map +1 -1
- package/es2020/src/index.js +0 -3
- package/es2020/src/index.js.map +1 -1
- package/es2020/src/interfaces/dateTimeInput/dateTimeInput.interface.js.map +1 -1
- package/es2020/src/legacy/selector/components/inputDateTime/inputDateTime.component.js +4 -6
- package/es2020/src/legacy/selector/components/inputDateTime/inputDateTime.component.js.map +1 -1
- package/es2020/src/legacy/selector/components/selector/selector.component.js +2 -2
- package/es2020/src/legacy/selector/components/selector/selector.component.js.map +1 -1
- package/es2020/src/legacy/selector/components/simpleInputDateTime/simpleInputDateTime.component.js +2 -2
- package/es2020/src/legacy/selector/components/simpleInputDateTime/simpleInputDateTime.component.js.map +1 -1
- package/es2020/src/misc/enums.js +1 -1
- package/es2020/src/misc/enums.js.map +1 -1
- package/es2020/src/misc/types.js.map +1 -1
- package/es2020/src/misc/utils.js +10 -0
- package/es2020/src/misc/utils.js.map +1 -1
- package/es2020/src/misc/validators.js +79 -2
- package/es2020/src/misc/validators.js.map +1 -1
- package/es2020/src/modules/dateTime/directives/dateTimeBase.js +77 -0
- package/es2020/src/modules/dateTime/directives/dateTimeBase.js.map +1 -0
- package/es2020/src/modules/dateTime/directives/dateTimeInput/dateTimeInput.directive.js +12 -59
- package/es2020/src/modules/dateTime/directives/dateTimeInput/dateTimeInput.directive.js.map +1 -1
- package/es2020/src/modules/dateTime/directives/dateTimeMaxValidator/dateTimeMaxValidator.directive.js +72 -0
- package/es2020/src/modules/dateTime/directives/dateTimeMaxValidator/dateTimeMaxValidator.directive.js.map +1 -0
- package/es2020/src/modules/dateTime/directives/dateTimeMinValidator/dateTimeMinValidator.directive.js +71 -0
- package/es2020/src/modules/dateTime/directives/dateTimeMinValidator/dateTimeMinValidator.directive.js.map +1 -0
- package/es2020/src/modules/dateTime/directives/dateTimeRestrictedBase.js +149 -0
- package/es2020/src/modules/dateTime/directives/dateTimeRestrictedBase.js.map +1 -0
- package/es2020/src/modules/dateTime/directives/dateTimeValidator/dateTimeValidator.directive.js +17 -6
- package/es2020/src/modules/dateTime/directives/dateTimeValidator/dateTimeValidator.directive.js.map +1 -1
- package/es2020/src/modules/dateTime/directives/index.js +4 -0
- package/es2020/src/modules/dateTime/directives/index.js.map +1 -1
- package/es2020/src/modules/dateTime/modules/dateTime.module.js +9 -1
- package/es2020/src/modules/dateTime/modules/dateTime.module.js.map +1 -1
- package/es2020/src/services/{datePositionParser.interface.js → datePositionParser/datePositionParser.interface.js} +0 -0
- package/es2020/src/services/datePositionParser/datePositionParser.interface.js.map +1 -0
- package/es2020/src/services/{datePositionParser.service.js → datePositionParser/datePositionParser.service.js} +0 -0
- package/es2020/src/services/datePositionParser/datePositionParser.service.js.map +1 -0
- package/es2020/src/services/{dateTimeRelativeParser.service.js → dateTimeRelativeParser/dateTimeRelativeParser.service.js} +8 -8
- package/es2020/src/services/dateTimeRelativeParser/dateTimeRelativeParser.service.js.map +1 -0
- package/es2020/src/services/{dateValueProvider.service.js → dateValueProvider/dateValueProvider.service.js} +1 -1
- package/es2020/src/services/dateValueProvider/dateValueProvider.service.js.map +1 -0
- package/es2020/src/services/index.js +4 -1
- package/es2020/src/services/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.d.ts +0 -3
- package/src/index.d.ts.map +1 -1
- package/src/interfaces/dateTimeInput/dateTimeInput.interface.d.ts +14 -9
- package/src/interfaces/dateTimeInput/dateTimeInput.interface.d.ts.map +1 -1
- package/src/legacy/selector/components/inputDateTime/inputDateTime.component.d.ts +1 -3
- package/src/legacy/selector/components/inputDateTime/inputDateTime.component.d.ts.map +1 -1
- package/src/legacy/selector/components/selector/selector.component.d.ts +1 -2
- package/src/legacy/selector/components/selector/selector.component.d.ts.map +1 -1
- package/src/legacy/selector/components/simpleInputDateTime/simpleInputDateTime.component.d.ts +1 -2
- package/src/legacy/selector/components/simpleInputDateTime/simpleInputDateTime.component.d.ts.map +1 -1
- package/src/misc/enums.d.ts +1 -1
- package/src/misc/types.d.ts +1 -1
- package/src/misc/types.d.ts.map +1 -1
- package/src/misc/utils.d.ts +5 -0
- package/src/misc/utils.d.ts.map +1 -1
- package/src/misc/validators.d.ts +17 -0
- package/src/misc/validators.d.ts.map +1 -1
- package/src/modules/dateTime/directives/dateTimeBase.d.ts +56 -0
- package/src/modules/dateTime/directives/dateTimeBase.d.ts.map +1 -0
- package/src/modules/dateTime/directives/dateTimeInput/dateTimeInput.directive.d.ts +3 -39
- package/src/modules/dateTime/directives/dateTimeInput/dateTimeInput.directive.d.ts.map +1 -1
- package/src/modules/dateTime/directives/dateTimeMaxValidator/dateTimeMaxValidator.directive.d.ts +33 -0
- package/src/modules/dateTime/directives/dateTimeMaxValidator/dateTimeMaxValidator.directive.d.ts.map +1 -0
- package/src/modules/dateTime/directives/dateTimeMinValidator/dateTimeMinValidator.directive.d.ts +33 -0
- package/src/modules/dateTime/directives/dateTimeMinValidator/dateTimeMinValidator.directive.d.ts.map +1 -0
- package/src/modules/dateTime/directives/dateTimeRestrictedBase.d.ts +74 -0
- package/src/modules/dateTime/directives/dateTimeRestrictedBase.d.ts.map +1 -0
- package/src/modules/dateTime/directives/dateTimeValidator/dateTimeValidator.directive.d.ts +9 -2
- package/src/modules/dateTime/directives/dateTimeValidator/dateTimeValidator.directive.d.ts.map +1 -1
- package/src/modules/dateTime/directives/index.d.ts +4 -0
- package/src/modules/dateTime/directives/index.d.ts.map +1 -1
- package/src/modules/dateTime/modules/dateTime.module.d.ts +4 -2
- package/src/modules/dateTime/modules/dateTime.module.d.ts.map +1 -1
- package/src/services/{datePositionParser.interface.d.ts → datePositionParser/datePositionParser.interface.d.ts} +0 -0
- package/src/services/{datePositionParser.interface.d.ts.map → datePositionParser/datePositionParser.interface.d.ts.map} +0 -0
- package/src/services/{datePositionParser.service.d.ts → datePositionParser/datePositionParser.service.d.ts} +0 -0
- package/src/services/{datePositionParser.service.d.ts.map → datePositionParser/datePositionParser.service.d.ts.map} +0 -0
- package/src/services/{dateTimeRelativeParser.service.d.ts → dateTimeRelativeParser/dateTimeRelativeParser.service.d.ts} +3 -3
- package/src/services/{dateTimeRelativeParser.service.d.ts.map → dateTimeRelativeParser/dateTimeRelativeParser.service.d.ts.map} +1 -1
- package/src/services/{dateValueProvider.service.d.ts → dateValueProvider/dateValueProvider.service.d.ts} +2 -2
- package/src/services/{dateValueProvider.service.d.ts.map → dateValueProvider/dateValueProvider.service.d.ts.map} +1 -1
- package/src/services/index.d.ts +4 -1
- package/src/services/index.d.ts.map +1 -1
- package/version.bak +1 -1
- package/es2015/src/services/datePositionParser.interface.js.map +0 -1
- package/es2015/src/services/datePositionParser.service.js.map +0 -1
- package/es2015/src/services/dateTimeRelativeParser.service.js.map +0 -1
- package/es2015/src/services/dateValueProvider.service.js.map +0 -1
- package/es2020/src/services/datePositionParser.interface.js.map +0 -1
- package/es2020/src/services/datePositionParser.service.js.map +0 -1
- package/es2020/src/services/dateTimeRelativeParser.service.js.map +0 -1
- package/es2020/src/services/dateValueProvider.service.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/misc/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAC,MAAM,gBAAgB,CAAC;AAIhF,OAAO,EAAC,mBAAmB,EAAC,MAAM,SAAS,CAAC;AAG5C;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAkB,KAAqD,EACrD,OAAuB,EACvB,cAAkD,EAClD,YAAmC;IAE9E,IAAG,OAAO,CAAC,KAAK,CAAC,EACjB;QACI,OAAO,KAAK,CAAC;KAChB;IAED,qBAAqB;IACrB,IAAG,SAAS,CAAC,cAAc,CAAC,EAC5B;QACI,4DAA4D;QAC5D,IAAG,cAAc,IAAI,mBAAmB,CAAC,eAAe,IAAI,OAAO,CAAC,YAAY,CAAC,EACjF;YACI,MAAM,IAAI,KAAK,CAAC,mEAAmE,CAAC,CAAC;SACxF;QAED,gBAAgB;QAChB,IAAG,eAAe,CAAC,KAAK,CAAC,EACzB;YACI,iCAAiC;YACjC,IAAG,cAAc,IAAI,mBAAmB,CAAC,oBAAoB,EAC7D;gBACI,MAAM,IAAI,KAAK,CAAC,uEAAuE,CAAC,CAAC;aAC5F;YAED,OAAO;gBACH,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,mBAAmB,CAAC,YAAY,EAAE,IAAI,CAAyB;gBAC/H,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,aAAa,CAA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AK,CAAC,EACjB;QACI,OAAO,KAAK,CAAC;KAChB;IAED,gBAAgB;IAChB,IAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EACvB;QACI,mBAAmB;QACnB,IAAG,cAAc,IAAI,mBAAmB,CAAC,oBAAoB,EAC7D;YACI,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAC;SACnF;QAED,OAAO;YACH,IAAI,EAAE,MAAA,MAAA,KAAK,CAAC,CAAC,CAAC,0CAAE,KAAK,mCAAI,IAAI;YAC7B,EAAE,EAAE,MAAA,MAAA,KAAK,CAAC,CAAC,CAAC,0CAAE,KAAK,mCAAI,IAAI;SAC9B,CAAC;KACL;IAED,uBAAuB;IACvB,IAAG,cAAc,IAAI,mBAAmB,CAAC,oBAAoB,EAC7D;QACI,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAC;KACnF;IAED,kBAAkB;IAClB,IAAG,cAAc,IAAI,mBAAmB,CAAC,eAAe,EACxD;QACI,+CAA+C;QAC/C,IAAG,OAAO,CAAC,YAAY,CAAC,EACxB;YACI,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;SAC5E;QAED,OAAO,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;KACrC;IAED,IAAG,cAAc,IAAI,mBAAmB,CAAC,aAAa,EACtD;QACI,KAAK,CAAC,aAAa,EAAE,CAAC;KACzB;IAED,OAAO,KAAK,CAAC,KAAK,CAAC;AACvB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAkB,KAAc;IAE3D,OAAO,UAAU,CAAC,KAAK,CAAC;QACjB,MAAM,CAAgB,MAAM,CAAC,IAAI,KAAK;QACtC,MAAM,CAAgB,IAAI,CAAC,IAAI,KAAK,CAAC;AAChD,CAAC","sourcesContent":["import {isBlank, isJsObject, isPresent, isString, nameof} from '@jscrpt/common';\n\nimport {DateTimeValue} from '../interfaces';\nimport {DateApi, DateApiObject} from '../services';\nimport {DateTimeValueFormat} from './enums';\nimport {DateTimeInputOutputValue, DateTimeObjectValue} from './types';\n\n/**\n * Parses date time input output value\n * @param value - Value to be parsed\n * @param dateApi - Date api used for obtaining result\n * @param dateTimeFormat - Date time format type, optional, if not specified autodetection of format will be used\n * @param stringFormat - String format for parsing string dates, required only for string dates\n */\nexport function parseDateTime<TDate = unknown>(value: DateTimeInputOutputValue<TDate>|undefined|null,\n dateApi: DateApi<TDate>,\n dateTimeFormat: DateTimeValueFormat|undefined|null,\n stringFormat: string|undefined|null,): DateTimeObjectValue<TDate>|undefined|null\n{\n if(isBlank(value))\n {\n return value;\n }\n\n //format is specified\n if(isPresent(dateTimeFormat))\n {\n //string format required, but format string was not provided\n if(dateTimeFormat == DateTimeValueFormat.FormattedString && isBlank(stringFormat))\n {\n throw new Error('DateTime: unable to parse string date, because format is missing!');\n }\n\n //value is range\n if(isDateTimeValue(value))\n {\n //requirested format is different\n if(dateTimeFormat != DateTimeValueFormat.RangeOfDateInstances)\n {\n throw new Error('DateTime: requested datetime format is not range, but value is range!');\n }\n\n return [\n isBlank(value.from) ? null : parseDateTime(value.from, dateApi, DateTimeValueFormat.DateInstance, null) as DateApiObject<TDate>,\n isBlank(value.to) ? null : parseDateTime(value.to, dateApi, DateTimeValueFormat.DateInstance, null) as DateApiObject<TDate>,\n ];\n }\n\n //value should be date instance, or number, or string, but it is not\n if(dateTimeFormat != DateTimeValueFormat.DateInstance &&\n dateTimeFormat != DateTimeValueFormat.FormattedString &&\n dateTimeFormat != DateTimeValueFormat.UnixTimestamp)\n {\n throw new Error('DateTime: unable to get date time value, should be date instance, or string, or number!');\n }\n\n //value is string, instance of date or unix timestamp\n return dateApi.getValue(value, stringFormat ?? undefined);\n }\n\n //value is range\n if(isDateTimeValue(value))\n {\n return [\n isBlank(value.from) ? null : parseDateTime(value.from, dateApi, DateTimeValueFormat.DateInstance, null) as DateApiObject<TDate>,\n isBlank(value.to) ? null : parseDateTime(value.to, dateApi, DateTimeValueFormat.DateInstance , null) as DateApiObject<TDate>,\n ];\n }\n\n //string format, but format string was not provided\n if(isString(value) && isBlank(stringFormat))\n {\n throw new Error('DateTime: unable to parse string date, because format is missing!');\n }\n\n //value is string, instance of date or unix timestamp\n return dateApi.getValue(value, stringFormat ?? undefined);\n}\n\n/**\n * Formats value into specified format of date time\n * @param value - Value that should be converted to input output date time value\n * @param dateTimeFormat - Date time format type\n * @param stringFormat - String format for parsing string dates, required only for string dates\n */\nexport function formatDateTime<TDate = unknown>(value: DateTimeObjectValue<TDate>|undefined|null,\n dateTimeFormat: DateTimeValueFormat,\n stringFormat: string|undefined|null): DateTimeInputOutputValue<TDate>|undefined|null\n{\n if(isBlank(value))\n {\n return value;\n }\n\n //value is range\n if(Array.isArray(value))\n {\n //range is expected\n if(dateTimeFormat != DateTimeValueFormat.RangeOfDateInstances)\n {\n throw new Error('DateTime: value is array of values, but format is not range!');\n }\n\n return {\n from: value[0]?.value ?? null,\n to: value[1]?.value ?? null,\n };\n }\n\n //range is not expected\n if(dateTimeFormat == DateTimeValueFormat.RangeOfDateInstances)\n {\n throw new Error('DateTime: value is not array of values, but format is range!');\n }\n\n //string date time\n if(dateTimeFormat == DateTimeValueFormat.FormattedString)\n {\n //string format is missing for string date time\n if(isBlank(stringFormat))\n {\n throw new Error('DateTime: missing string format for string date time!');\n }\n\n return value.format(stringFormat);\n }\n\n if(dateTimeFormat == DateTimeValueFormat.UnixTimestamp)\n {\n value.unixTimestamp();\n }\n\n return value.value;\n}\n\n/**\n * Tests whether value is `DateTimeValue`\n * @param value - Value that is tested\n */\nexport function isDateTimeValue<TDate = unknown>(value: unknown): value is DateTimeValue<TDate>\n{\n return isJsObject(value) &&\n nameof<DateTimeValue>('from') in value &&\n nameof<DateTimeValue>('to') in value;\n}"]}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/misc/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE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mCAAI,IAAI;YAC7B,EAAE,EAAE,MAAA,MAAA,KAAK,CAAC,CAAC,CAAC,0CAAE,KAAK,mCAAI,IAAI;SAC9B,CAAC;KACL;IAED,uBAAuB;IACvB,IAAG,cAAc,IAAI,mBAAmB,CAAC,oBAAoB,EAC7D;QACI,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAC;KACnF;IAED,kBAAkB;IAClB,IAAG,cAAc,IAAI,mBAAmB,CAAC,eAAe,EACxD;QACI,+CAA+C;QAC/C,IAAG,OAAO,CAAC,YAAY,CAAC,EACxB;YACI,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;SAC5E;QAED,OAAO,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;KACrC;IAED,IAAG,cAAc,IAAI,mBAAmB,CAAC,aAAa,EACtD;QACI,KAAK,CAAC,aAAa,EAAE,CAAC;KACzB;IAED,OAAO,KAAK,CAAC,KAAK,CAAC;AACvB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAkB,KAAc;IAE3D,OAAO,UAAU,CAAC,KAAK,CAAC;QACjB,MAAM,CAAgB,MAAM,CAAC,IAAI,KAAK;QACtC,MAAM,CAAgB,IAAI,CAAC,IAAI,KAAK,CAAC;AAChD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CAAQ,KAAqD;IAE/F,IAAG,eAAe,CAAC,KAAK,CAAC,EACzB;QACI,MAAM,IAAI,KAAK,CAAC,wEAAwE,CAAC,CAAC;KAC7F;IAED,OAAO,KAAK,CAAC;AACjB,CAAC","sourcesContent":["import {isBlank, isJsObject, isPresent, isString, nameof} from '@jscrpt/common';\n\nimport {DateTimeValue} from '../interfaces';\nimport {DateApi, DateApiObject} from '../services';\nimport {DateTimeValueFormat} from './enums';\nimport {DateTimeInputOutputValue, DateTimeObjectValue} from './types';\n\n/**\n * Parses date time input output value\n * @param value - Value to be parsed\n * @param dateApi - Date api used for obtaining result\n * @param dateTimeFormat - Date time format type, optional, if not specified autodetection of format will be used\n * @param stringFormat - String format for parsing string dates, required only for string dates\n */\nexport function parseDateTime<TDate = unknown>(value: DateTimeInputOutputValue<TDate>|undefined|null,\n dateApi: DateApi<TDate>,\n dateTimeFormat: DateTimeValueFormat|undefined|null,\n stringFormat: string|undefined|null,): DateTimeObjectValue<TDate>|undefined|null\n{\n if(isBlank(value))\n {\n return value;\n }\n\n //format is specified\n if(isPresent(dateTimeFormat))\n {\n //string format required, but format string was not provided\n if(dateTimeFormat == DateTimeValueFormat.FormattedString && isBlank(stringFormat))\n {\n throw new Error('DateTime: unable to parse string date, because format is missing!');\n }\n\n //value is range\n if(isDateTimeValue(value))\n {\n //requirested format is different\n if(dateTimeFormat != DateTimeValueFormat.RangeOfDateInstances)\n {\n throw new Error('DateTime: requested datetime format is not range, but value is range!');\n }\n\n return [\n isBlank(value.from) ? null : parseDateTime(value.from, dateApi, DateTimeValueFormat.DateInstance, null) as DateApiObject<TDate>,\n isBlank(value.to) ? null : parseDateTime(value.to, dateApi, DateTimeValueFormat.DateInstance, null) as DateApiObject<TDate>,\n ];\n }\n\n //value should be date instance, or number, or string, but it is not\n if(dateTimeFormat != DateTimeValueFormat.DateInstance &&\n dateTimeFormat != DateTimeValueFormat.FormattedString &&\n dateTimeFormat != DateTimeValueFormat.UnixTimestamp)\n {\n throw new Error('DateTime: unable to get date time value, should be date instance, or string, or number!');\n }\n\n //value is string, instance of date or unix timestamp\n return dateApi.getValue(value, stringFormat ?? undefined);\n }\n\n //value is range\n if(isDateTimeValue(value))\n {\n return [\n isBlank(value.from) ? null : parseDateTime(value.from, dateApi, DateTimeValueFormat.DateInstance, null) as DateApiObject<TDate>,\n isBlank(value.to) ? null : parseDateTime(value.to, dateApi, DateTimeValueFormat.DateInstance , null) as DateApiObject<TDate>,\n ];\n }\n\n //string format, but format string was not provided\n if(isString(value) && isBlank(stringFormat))\n {\n throw new Error('DateTime: unable to parse string date, because format is missing!');\n }\n\n //value is string, instance of date or unix timestamp\n return dateApi.getValue(value, stringFormat ?? undefined);\n}\n\n/**\n * Formats value into specified format of date time\n * @param value - Value that should be converted to input output date time value\n * @param dateTimeFormat - Date time format type\n * @param stringFormat - String format for parsing string dates, required only for string dates\n */\nexport function formatDateTime<TDate = unknown>(value: DateTimeObjectValue<TDate>|undefined|null,\n dateTimeFormat: DateTimeValueFormat,\n stringFormat: string|undefined|null): DateTimeInputOutputValue<TDate>|undefined|null\n{\n if(isBlank(value))\n {\n return value;\n }\n\n //value is range\n if(Array.isArray(value))\n {\n //range is expected\n if(dateTimeFormat != DateTimeValueFormat.RangeOfDateInstances)\n {\n throw new Error('DateTime: value is array of values, but format is not range!');\n }\n\n return {\n from: value[0]?.value ?? null,\n to: value[1]?.value ?? null,\n };\n }\n\n //range is not expected\n if(dateTimeFormat == DateTimeValueFormat.RangeOfDateInstances)\n {\n throw new Error('DateTime: value is not array of values, but format is range!');\n }\n\n //string date time\n if(dateTimeFormat == DateTimeValueFormat.FormattedString)\n {\n //string format is missing for string date time\n if(isBlank(stringFormat))\n {\n throw new Error('DateTime: missing string format for string date time!');\n }\n\n return value.format(stringFormat);\n }\n\n if(dateTimeFormat == DateTimeValueFormat.UnixTimestamp)\n {\n value.unixTimestamp();\n }\n\n return value.value;\n}\n\n/**\n * Tests whether value is `DateTimeValue`\n * @param value - Value that is tested\n */\nexport function isDateTimeValue<TDate = unknown>(value: unknown): value is DateTimeValue<TDate>\n{\n return isJsObject(value) &&\n nameof<DateTimeValue>('from') in value &&\n nameof<DateTimeValue>('to') in value;\n}\n\n/**\n * Gets single date time value, use in places where ranged date time can not be used\n * @param value - Value to be examined\n */\nexport function getSingleDateTimeValue<TDate>(value: DateTimeInputOutputValue<TDate>|undefined|null): string|number|Date|TDate|null|undefined\n{\n if(isDateTimeValue(value))\n {\n throw new Error('DateTime: Unable to apply ranged date time input as value restriction!');\n }\n\n return value;\n}"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isBlank } from '@jscrpt/common';
|
|
2
|
-
import { parseDateTime } from './utils';
|
|
2
|
+
import { getSingleDateTimeValue, parseDateTime } from './utils';
|
|
3
|
+
import { DateTimeBase } from '../modules/dateTime/directives/dateTimeBase';
|
|
3
4
|
/**
|
|
4
5
|
* Date time validator factory function, creates validator for checking validity of datetime
|
|
5
6
|
* @param dateApi - Date api used for parsing date time
|
|
@@ -18,7 +19,83 @@ export function datetimeValidator(dateApi, valueFormat, stringFormat) {
|
|
|
18
19
|
if (!Array.isArray(parsedValue)) {
|
|
19
20
|
if (!parsedValue.isValid()) {
|
|
20
21
|
return {
|
|
21
|
-
'datetime':
|
|
22
|
+
'datetime': stringFormat
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
//TODO: support for ranges
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Date time validator factory function, creates validator for checking validity of datetime max value
|
|
34
|
+
* @param dateApi - Date api used for parsing date time
|
|
35
|
+
* @param maxValue - Maximal date time value that should be used for validation against
|
|
36
|
+
* @param valueFormat - Optional required format
|
|
37
|
+
* @param stringFormat - Optional string format of value
|
|
38
|
+
*/
|
|
39
|
+
export function datetimeMaxValidator(dateApi, maxValue, valueFormat, stringFormat) {
|
|
40
|
+
return (control) => {
|
|
41
|
+
if (isBlank(control.value) || isBlank(maxValue)) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
if (maxValue instanceof (DateTimeBase)) {
|
|
45
|
+
const value = getSingleDateTimeValue(maxValue.value);
|
|
46
|
+
//no validation
|
|
47
|
+
if (isBlank(value)) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
maxValue = value;
|
|
51
|
+
}
|
|
52
|
+
const parsedValue = parseDateTime(control.value, dateApi, valueFormat, stringFormat);
|
|
53
|
+
if (!parsedValue) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
const maxDateTime = dateApi.getValue(maxValue, stringFormat !== null && stringFormat !== void 0 ? stringFormat : undefined);
|
|
57
|
+
if (!Array.isArray(parsedValue)) {
|
|
58
|
+
if (parsedValue.isValid() && !parsedValue.isBefore(maxDateTime.value)) {
|
|
59
|
+
return {
|
|
60
|
+
'datetimemax': maxDateTime.value
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
//TODO: support for ranges
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Date time validator factory function, creates validator for checking validity of datetime min value
|
|
72
|
+
* @param dateApi - Date api used for parsing date time
|
|
73
|
+
* @param minValue - Minimal date time value that should be used for validation against
|
|
74
|
+
* @param valueFormat - Optional required format
|
|
75
|
+
* @param stringFormat - Optional string format of value
|
|
76
|
+
*/
|
|
77
|
+
export function datetimeMinValidator(dateApi, minValue, valueFormat, stringFormat) {
|
|
78
|
+
return (control) => {
|
|
79
|
+
if (isBlank(control.value) || isBlank(minValue)) {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
if (minValue instanceof (DateTimeBase)) {
|
|
83
|
+
const value = getSingleDateTimeValue(minValue.value);
|
|
84
|
+
//no validation
|
|
85
|
+
if (isBlank(value)) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
minValue = value;
|
|
89
|
+
}
|
|
90
|
+
const parsedValue = parseDateTime(control.value, dateApi, valueFormat, stringFormat);
|
|
91
|
+
if (!parsedValue) {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
const minDateTime = dateApi.getValue(minValue, stringFormat !== null && stringFormat !== void 0 ? stringFormat : undefined);
|
|
95
|
+
if (!Array.isArray(parsedValue)) {
|
|
96
|
+
if (parsedValue.isValid() && !parsedValue.isAfter(minDateTime.value)) {
|
|
97
|
+
return {
|
|
98
|
+
'datetimemin': minDateTime.value
|
|
22
99
|
};
|
|
23
100
|
}
|
|
24
101
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../../../src/misc/validators.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAC,MAAM,gBAAgB,CAAC;AAIvC,OAAO,EAAC,aAAa,EAAC,MAAM,SAAS,CAAC;AAItC;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAkB,OAAuB,EACvB,WAA+C,EAC/C,YAAmC;IAElF,OAAO,CAAC,OAAyD,EAAyB,EAAE;QAExF,IAAG,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,EACzB;YACI,OAAO,IAAI,CAAC;SACf;QAED,MAAM,WAAW,GAAG,aAAa,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,YAAY,CAAC,CAAC;QAErF,IAAG,CAAC,WAAW,EACf;YACI,OAAO,IAAI,CAAC;SACf;QAED,IAAG,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,EAC9B;YACI,IAAG,CAAC,WAAW,CAAC,OAAO,EAAE,EACzB;gBACI,OAAO;oBACH,UAAU,EAAE,IAAI;iBACnB,CAAC;aACL;SACJ;aAED;YACI,0BAA0B;SAC7B;QAED,OAAO,IAAI,CAAC;IAChB,CAAC,CAAC;AACN,CAAC;AAED;;GAEG;AACH,MAAM,OAAO,UAAU;IAEnB;;;OAGG;IACI,MAAM,CAAC,QAAQ,CAAc,QAAoC;QAEpE,OAAO,GAA0B,EAAE;YAE/B,IAAG,CAAC,QAAQ,CAAC,KAAK,EAClB;gBACI,OAAO;oBACH,UAAU,EAAE,IAAI;iBACnB,CAAC;aACL;YAED,OAAO,IAAI,CAAC;QAChB,CAAC,CAAC;IACN,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,WAAW,CAAc,QAAoC,EAAE,OAAuB;QAEhG,OAAO,CAAC,OAAwB,EAAyB,EAAE;YAEvD,IAAG,CAAC,CAAC,OAAO,CAAC,KAAK;gBACf,QAAQ,CAAC,KAAK;gBACd,QAAQ,CAAC,QAAQ;gBACjB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAC9D;gBACI,OAAO;oBACH,aAAa,EAAE,QAAQ,CAAC,QAAQ;oBAChC,aAAa,EAAE,OAAO,CAAC,KAAK;iBAC/B,CAAC;aACL;YAED,OAAO,IAAI,CAAC;QAChB,CAAC,CAAC;IACN,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,WAAW,CAAc,QAAoC,EAAE,OAAuB;QAEhG,OAAO,CAAC,OAAwB,EAAyB,EAAE;YAEvD,IAAG,CAAC,CAAC,OAAO,CAAC,KAAK;gBACf,QAAQ,CAAC,KAAK;gBACd,QAAQ,CAAC,QAAQ;gBACjB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAC7D;gBACI,OAAO;oBACH,aAAa,EAAE,QAAQ,CAAC,QAAQ;oBAChC,aAAa,EAAE,OAAO,CAAC,KAAK;iBAC/B,CAAC;aACL;YAED,OAAO,IAAI,CAAC;QAChB,CAAC,CAAC;IACN,CAAC;CACJ","sourcesContent":["import {AbstractControl, ValidationErrors, ValidatorFn} from '@angular/forms';\nimport {isBlank} from '@jscrpt/common';\n\nimport {DateApi} from '../services';\nimport {DateTimeValueObject} from '../interfaces/dateTime/datetime.interface';\nimport {parseDateTime} from './utils';\nimport {DateTimeValueFormat} from './enums';\nimport {DateTimeInputOutputValue} from './types';\n\n/**\n * Date time validator factory function, creates validator for checking validity of datetime\n * @param dateApi - Date api used for parsing date time\n * @param valueFormat - Optional required format\n * @param stringFormat - Optional string format of value\n */\nexport function datetimeValidator<TDate = unknown>(dateApi: DateApi<TDate>,\n valueFormat: DateTimeValueFormat|undefined|null,\n stringFormat: string|undefined|null,): ValidatorFn\n{\n return (control: AbstractControl<DateTimeInputOutputValue<TDate>>): ValidationErrors|null =>\n {\n if(isBlank(control.value))\n {\n return null;\n }\n\n const parsedValue = parseDateTime(control.value, dateApi, valueFormat, stringFormat);\n\n if(!parsedValue)\n {\n return null;\n }\n\n if(!Array.isArray(parsedValue))\n {\n if(!parsedValue.isValid())\n {\n return {\n 'datetime': true\n };\n }\n }\n else\n {\n //TODO: support for ranges\n }\n\n return null;\n };\n}\n\n/**\n * Validations functions for datetime\n */\nexport class Validators\n{\n /**\n * Creates validator function that validates control if its value is valid datetime value\n * @param datetime - Object storing information about datetime value\n */\n public static datetime<TDate = any>(datetime: DateTimeValueObject<TDate>): ValidatorFn\n {\n return (): ValidationErrors|null =>\n {\n if(!datetime.valid)\n {\n return {\n 'datetime': true\n };\n }\n\n return null;\n };\n }\n\n /**\n * Creates validator function that validates control if its value is withing range of minimal datetime value\n * @param datetime - Object storing information about datetime value\n * @param dateApi - Date api object\n */\n public static minDatetime<TDate = any>(datetime: DateTimeValueObject<TDate>, dateApi: DateApi<TDate>): ValidatorFn\n {\n return (control: AbstractControl): ValidationErrors|null =>\n {\n if(!!control.value &&\n datetime.valid &&\n datetime.minValue &&\n dateApi.getValue(control.value).isBefore(datetime.minValue))\n {\n return {\n 'minDatetime': datetime.minValue,\n 'actualValue': control.value\n };\n }\n\n return null;\n };\n }\n\n /**\n * Creates validator function that validates control if its value is withing range of maximal datetime value\n * @param datetime - Object storing information about datetime value\n * @param dateApi - Date api object\n */\n public static maxDatetime<TDate = any>(datetime: DateTimeValueObject<TDate>, dateApi: DateApi<TDate>): ValidatorFn\n {\n return (control: AbstractControl): ValidationErrors|null =>\n {\n if(!!control.value &&\n datetime.valid &&\n datetime.maxValue &&\n dateApi.getValue(control.value).isAfter(datetime.maxValue))\n {\n return {\n 'maxDatetime': datetime.maxValue,\n 'actualValue': control.value\n };\n }\n\n return null;\n };\n }\n}"]}
|
|
1
|
+
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../../../src/misc/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C,WAAW,CAAc,QAAoC,EAAE,OAAuB;QAEhG,OAAO,CAAC,OAAwB,EAAyB,EAAE;YAEvD,IAAG,CAAC,CAAC,OAAO,CAAC,KAAK;gBACf,QAAQ,CAAC,KAAK;gBACd,QAAQ,CAAC,QAAQ;gBACjB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAC7D;gBACI,OAAO;oBACH,aAAa,EAAE,QAAQ,CAAC,QAAQ;oBAChC,aAAa,EAAE,OAAO,CAAC,KAAK;iBAC/B,CAAC;aACL;YAED,OAAO,IAAI,CAAC;QAChB,CAAC,CAAC;IACN,CAAC;CACJ","sourcesContent":["import {AbstractControl, ValidationErrors, ValidatorFn} from '@angular/forms';\nimport {isBlank} from '@jscrpt/common';\n\nimport {DateApi} from '../services';\nimport {DateTimeValueObject} from '../interfaces/dateTime/datetime.interface';\nimport {getSingleDateTimeValue, parseDateTime} from './utils';\nimport {DateTimeValueFormat} from './enums';\nimport {DateTimeInputOutputValue} from './types';\nimport {DateTimeBase} from '../modules/dateTime/directives/dateTimeBase';\n\n/**\n * Date time validator factory function, creates validator for checking validity of datetime\n * @param dateApi - Date api used for parsing date time\n * @param valueFormat - Optional required format\n * @param stringFormat - Optional string format of value\n */\nexport function datetimeValidator<TDate = unknown>(dateApi: DateApi<TDate>,\n valueFormat: DateTimeValueFormat|undefined|null,\n stringFormat: string|undefined|null,): ValidatorFn\n{\n return (control: AbstractControl<DateTimeInputOutputValue<TDate>>): ValidationErrors|null =>\n {\n if(isBlank(control.value))\n {\n return null;\n }\n\n const parsedValue = parseDateTime(control.value, dateApi, valueFormat, stringFormat);\n\n if(!parsedValue)\n {\n return null;\n }\n\n if(!Array.isArray(parsedValue))\n {\n if(!parsedValue.isValid())\n {\n return {\n 'datetime': stringFormat\n };\n }\n }\n else\n {\n //TODO: support for ranges\n }\n\n return null;\n };\n}\n\n/**\n * Date time validator factory function, creates validator for checking validity of datetime max value\n * @param dateApi - Date api used for parsing date time\n * @param maxValue - Maximal date time value that should be used for validation against\n * @param valueFormat - Optional required format\n * @param stringFormat - Optional string format of value\n */\nexport function datetimeMaxValidator<TDate = unknown>(dateApi: DateApi<TDate>,\n maxValue: string|number|TDate|Date|DateTimeBase<TDate>,\n valueFormat: DateTimeValueFormat|undefined|null,\n stringFormat: string|undefined|null,): ValidatorFn\n{\n return (control: AbstractControl<DateTimeInputOutputValue<TDate>>): ValidationErrors|null =>\n {\n if(isBlank(control.value) || isBlank(maxValue))\n {\n return null;\n }\n\n if(maxValue instanceof DateTimeBase<TDate>)\n {\n const value = getSingleDateTimeValue(maxValue.value);\n\n //no validation\n if(isBlank(value))\n {\n return null;\n }\n\n maxValue = value;\n }\n \n const parsedValue = parseDateTime(control.value, dateApi, valueFormat, stringFormat);\n\n if(!parsedValue)\n {\n return null;\n }\n\n const maxDateTime = dateApi.getValue(maxValue as string|number|TDate, stringFormat ?? undefined);\n\n if(!Array.isArray(parsedValue))\n {\n if(parsedValue.isValid() && !parsedValue.isBefore(maxDateTime.value))\n {\n return {\n 'datetimemax': maxDateTime.value\n };\n }\n }\n else\n {\n //TODO: support for ranges\n }\n\n return null;\n };\n}\n\n/**\n * Date time validator factory function, creates validator for checking validity of datetime min value\n * @param dateApi - Date api used for parsing date time\n * @param minValue - Minimal date time value that should be used for validation against\n * @param valueFormat - Optional required format\n * @param stringFormat - Optional string format of value\n */\nexport function datetimeMinValidator<TDate = unknown>(dateApi: DateApi<TDate>,\n minValue: string|number|TDate|Date|DateTimeBase<TDate>,\n valueFormat: DateTimeValueFormat|undefined|null,\n stringFormat: string|undefined|null,): ValidatorFn\n{\n return (control: AbstractControl<DateTimeInputOutputValue<TDate>>): ValidationErrors|null =>\n {\n if(isBlank(control.value) || isBlank(minValue))\n {\n return null;\n }\n\n if(minValue instanceof DateTimeBase<TDate>)\n {\n const value = getSingleDateTimeValue(minValue.value);\n\n //no validation\n if(isBlank(value))\n {\n return null;\n }\n\n minValue = value;\n }\n \n const parsedValue = parseDateTime(control.value, dateApi, valueFormat, stringFormat);\n\n if(!parsedValue)\n {\n return null;\n }\n\n const minDateTime = dateApi.getValue(minValue as string|number|TDate, stringFormat ?? undefined);\n\n if(!Array.isArray(parsedValue))\n {\n if(parsedValue.isValid() && !parsedValue.isAfter(minDateTime.value))\n {\n return {\n 'datetimemin': minDateTime.value\n };\n }\n }\n else\n {\n //TODO: support for ranges\n }\n\n return null;\n };\n}\n\n/**\n * Validations functions for datetime\n */\nexport class Validators\n{\n /**\n * Creates validator function that validates control if its value is valid datetime value\n * @param datetime - Object storing information about datetime value\n */\n public static datetime<TDate = any>(datetime: DateTimeValueObject<TDate>): ValidatorFn\n {\n return (): ValidationErrors|null =>\n {\n if(!datetime.valid)\n {\n return {\n 'datetime': true\n };\n }\n\n return null;\n };\n }\n\n /**\n * Creates validator function that validates control if its value is withing range of minimal datetime value\n * @param datetime - Object storing information about datetime value\n * @param dateApi - Date api object\n */\n public static minDatetime<TDate = any>(datetime: DateTimeValueObject<TDate>, dateApi: DateApi<TDate>): ValidatorFn\n {\n return (control: AbstractControl): ValidationErrors|null =>\n {\n if(!!control.value &&\n datetime.valid &&\n datetime.minValue &&\n dateApi.getValue(control.value).isBefore(datetime.minValue))\n {\n return {\n 'minDatetime': datetime.minValue,\n 'actualValue': control.value\n };\n }\n\n return null;\n };\n }\n\n /**\n * Creates validator function that validates control if its value is withing range of maximal datetime value\n * @param datetime - Object storing information about datetime value\n * @param dateApi - Date api object\n */\n public static maxDatetime<TDate = any>(datetime: DateTimeValueObject<TDate>, dateApi: DateApi<TDate>): ValidatorFn\n {\n return (control: AbstractControl): ValidationErrors|null =>\n {\n if(!!control.value &&\n datetime.valid &&\n datetime.maxValue &&\n dateApi.getValue(control.value).isAfter(datetime.maxValue))\n {\n return {\n 'maxDatetime': datetime.maxValue,\n 'actualValue': control.value\n };\n }\n\n return null;\n };\n }\n}"]}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Directive, EventEmitter, Input } from '@angular/core';
|
|
2
|
+
import { isString } from '@jscrpt/common';
|
|
3
|
+
import { DateTimeValueFormat } from '../../../misc/enums';
|
|
4
|
+
import * as i0 from "@angular/core";
|
|
5
|
+
/**
|
|
6
|
+
* Base class for date time directives, contains basic shared data
|
|
7
|
+
*/
|
|
8
|
+
export class DateTimeBase {
|
|
9
|
+
//######################### constructors #########################
|
|
10
|
+
constructor(dateApi, formatProvider) {
|
|
11
|
+
this.dateApi = dateApi;
|
|
12
|
+
this.formatProvider = formatProvider;
|
|
13
|
+
//######################### protected properties #########################
|
|
14
|
+
/**
|
|
15
|
+
* Date time value format which is being worked with in this date time
|
|
16
|
+
*/
|
|
17
|
+
this.ɵValueFormat = DateTimeValueFormat.DateInstance;
|
|
18
|
+
/**
|
|
19
|
+
* Format of string representation of date
|
|
20
|
+
*/
|
|
21
|
+
this.ɵFormat = 'date';
|
|
22
|
+
/**
|
|
23
|
+
* @inheritdoc
|
|
24
|
+
*/
|
|
25
|
+
this.valueChange = new EventEmitter();
|
|
26
|
+
/**
|
|
27
|
+
* Custom format string representation of date
|
|
28
|
+
*/
|
|
29
|
+
this.customFormat = this.dateApi.getFormat(this.formatProvider[this.ɵFormat]);
|
|
30
|
+
}
|
|
31
|
+
//######################### public properties - implementation of DateTimeInputValue #########################
|
|
32
|
+
/**
|
|
33
|
+
* @inheritdoc
|
|
34
|
+
*/
|
|
35
|
+
get value() {
|
|
36
|
+
return this.ɵValue;
|
|
37
|
+
}
|
|
38
|
+
set value(value) {
|
|
39
|
+
this.ɵValue = value;
|
|
40
|
+
}
|
|
41
|
+
//######################### public properties - inputs #########################
|
|
42
|
+
/**
|
|
43
|
+
* Gets or sets date time value format which is being worked with in this date time
|
|
44
|
+
*/
|
|
45
|
+
get valueFormat() {
|
|
46
|
+
return this.ɵValueFormat;
|
|
47
|
+
}
|
|
48
|
+
set valueFormat(value) {
|
|
49
|
+
if (isString(value)) {
|
|
50
|
+
this.ɵValueFormat = DateTimeValueFormat[value];
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
this.ɵValueFormat = value;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Gets or sets format of string representation of date
|
|
57
|
+
*/
|
|
58
|
+
get format() {
|
|
59
|
+
return this.ɵFormat;
|
|
60
|
+
}
|
|
61
|
+
set format(value) {
|
|
62
|
+
this.ɵFormat = value;
|
|
63
|
+
this.customFormat = this.dateApi.getFormat(this.formatProvider[value]);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
DateTimeBase.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: DateTimeBase, deps: "invalid", target: i0.ɵɵFactoryTarget.Directive });
|
|
67
|
+
DateTimeBase.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.6", type: DateTimeBase, inputs: { valueFormat: "valueFormat", format: "format", customFormat: "customFormat" }, ngImport: i0 });
|
|
68
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: DateTimeBase, decorators: [{
|
|
69
|
+
type: Directive
|
|
70
|
+
}], ctorParameters: function () { return [{ type: undefined }, { type: undefined }]; }, propDecorators: { valueFormat: [{
|
|
71
|
+
type: Input
|
|
72
|
+
}], format: [{
|
|
73
|
+
type: Input
|
|
74
|
+
}], customFormat: [{
|
|
75
|
+
type: Input
|
|
76
|
+
}] } });
|
|
77
|
+
//# sourceMappingURL=dateTimeBase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dateTimeBase.js","sourceRoot":"","sources":["../../../../../src/modules/dateTime/directives/dateTimeBase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,YAAY,EAAE,KAAK,EAAC,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAC,QAAQ,EAAC,MAAM,gBAAgB,CAAC;AAGxC,OAAO,EAAC,mBAA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KAAK,CAAC,CAAC,CAAC;IAC3E,CAAC;;yGAxEQ,YAAY;6FAAZ,YAAY;2FAAZ,YAAY;kBADxB,SAAS;kHA6CK,WAAW;sBADrB,KAAK;gBAqBK,MAAM;sBADhB,KAAK;gBAeC,YAAY;sBADlB,KAAK","sourcesContent":["import {Directive, EventEmitter, Input} from '@angular/core';\nimport {isString} from '@jscrpt/common';\n\nimport {DateTimeInputValue, FormatProvider} from '../../../interfaces';\nimport {DateTimeValueFormat} from '../../../misc/enums';\nimport {DateTimeInputOutputValue} from '../../../misc/types';\nimport {DateApi} from '../../../services';\n\n/**\n * Base class for date time directives, contains basic shared data\n */\n@Directive()\nexport class DateTimeBase<TDate = unknown> implements DateTimeInputValue<TDate>\n{\n //######################### protected properties #########################\n\n /**\n * Date time value format which is being worked with in this date time\n */\n protected ɵValueFormat: DateTimeValueFormat = DateTimeValueFormat.DateInstance;\n\n /**\n * Format of string representation of date\n */\n protected ɵFormat: keyof FormatProvider = 'date';\n\n /**\n * Current value of date time, could be string, unix timestamp, Date, TDate object, or ranged DateTimeValue\n */\n protected ɵValue: DateTimeInputOutputValue<TDate>|undefined|null;\n\n //######################### public properties - implementation of DateTimeInputValue #########################\n\n /**\n * @inheritdoc\n */\n public get value(): DateTimeInputOutputValue<TDate>|undefined|null\n {\n return this.ɵValue;\n }\n public set value(value: DateTimeInputOutputValue<TDate>|undefined|null)\n {\n this.ɵValue = value;\n }\n\n /**\n * @inheritdoc\n */\n public valueChange: EventEmitter<void> = new EventEmitter<void>();\n\n //######################### public properties - inputs #########################\n\n /**\n * Gets or sets date time value format which is being worked with in this date time\n */\n @Input()\n public get valueFormat(): DateTimeValueFormat\n {\n return this.ɵValueFormat;\n }\n public set valueFormat(value: DateTimeValueFormat)\n {\n if(isString(value))\n {\n this.ɵValueFormat = DateTimeValueFormat[value] as unknown as DateTimeValueFormat;\n\n return;\n }\n\n this.ɵValueFormat = value;\n }\n\n /**\n * Gets or sets format of string representation of date\n */\n @Input()\n public get format(): keyof FormatProvider\n {\n return this.ɵFormat;\n }\n public set format(value: keyof FormatProvider)\n {\n this.ɵFormat = value;\n this.customFormat = this.dateApi.getFormat(this.formatProvider[value]);\n }\n\n /**\n * Custom format string representation of date\n */\n @Input()\n public customFormat: string = this.dateApi.getFormat(this.formatProvider[this.ɵFormat]);\n\n //######################### constructors #########################\n constructor(protected dateApi: DateApi<TDate>,\n protected formatProvider: FormatProvider,)\n {\n }\n\n //######################### ng language server #########################\n \n /**\n * Custom input type for `valueFormat` input\n */\n public static ngAcceptInputType_valueFormat: keyof typeof DateTimeValueFormat|DateTimeValueFormat;\n}\n"]}
|
|
@@ -1,33 +1,19 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
|
-
import { Directive, ElementRef, EventEmitter, forwardRef, Inject
|
|
3
|
-
import { BindThis
|
|
4
|
-
import { DateTimeValueFormat } from '../../../../misc/enums';
|
|
2
|
+
import { Directive, ElementRef, EventEmitter, forwardRef, Inject } from '@angular/core';
|
|
3
|
+
import { BindThis } from '@jscrpt/common';
|
|
5
4
|
import { DATE_API, DATE_TIME_INPUT, FORMAT_PROVIDER } from '../../../../misc/tokens';
|
|
6
5
|
import { formatDateTime, parseDateTime } from '../../../../misc/utils';
|
|
6
|
+
import { DateTimeBase } from '../dateTimeBase';
|
|
7
7
|
import * as i0 from "@angular/core";
|
|
8
8
|
//TODO: range is unimplemented
|
|
9
9
|
/**
|
|
10
10
|
* Directive that is used for setting up date time input
|
|
11
11
|
*/
|
|
12
|
-
export class DateTimeInputDirective {
|
|
12
|
+
export class DateTimeInputDirective extends DateTimeBase {
|
|
13
13
|
//######################### constructors #########################
|
|
14
14
|
constructor(element, dateApi, formatProvider) {
|
|
15
|
+
super(dateApi, formatProvider);
|
|
15
16
|
this.element = element;
|
|
16
|
-
this.dateApi = dateApi;
|
|
17
|
-
this.formatProvider = formatProvider;
|
|
18
|
-
//######################### private fields #########################
|
|
19
|
-
/**
|
|
20
|
-
* Date time value format which is being worked with in this date time
|
|
21
|
-
*/
|
|
22
|
-
this._valueFormat = DateTimeValueFormat.DateInstance;
|
|
23
|
-
/**
|
|
24
|
-
* Format of string representation of date
|
|
25
|
-
*/
|
|
26
|
-
this._format = 'date';
|
|
27
|
-
/**
|
|
28
|
-
* @inheritdoc
|
|
29
|
-
*/
|
|
30
|
-
this.valueChange = new EventEmitter();
|
|
31
17
|
/**
|
|
32
18
|
* @inheritdoc
|
|
33
19
|
*/
|
|
@@ -36,10 +22,6 @@ export class DateTimeInputDirective {
|
|
|
36
22
|
* @inheritdoc
|
|
37
23
|
*/
|
|
38
24
|
this.blur = new EventEmitter();
|
|
39
|
-
/**
|
|
40
|
-
* Custom format string representation of date
|
|
41
|
-
*/
|
|
42
|
-
this.customFormat = this.dateApi.getFormat(this.formatProvider[this._format]);
|
|
43
25
|
this.element.nativeElement.addEventListener('input', this.handleInput);
|
|
44
26
|
this.element.nativeElement.addEventListener('focus', this.handleFocus);
|
|
45
27
|
this.element.nativeElement.addEventListener('blur', this.handleBlur);
|
|
@@ -58,11 +40,11 @@ export class DateTimeInputDirective {
|
|
|
58
40
|
* @inheritdoc
|
|
59
41
|
*/
|
|
60
42
|
get value() {
|
|
61
|
-
return this
|
|
43
|
+
return this.ɵValue;
|
|
62
44
|
}
|
|
63
45
|
set value(value) {
|
|
64
46
|
var _a;
|
|
65
|
-
this
|
|
47
|
+
this.ɵValue = value;
|
|
66
48
|
//accepts all available formats
|
|
67
49
|
this.internalValue = parseDateTime(value, this.dateApi, null, this.customFormat);
|
|
68
50
|
//not range value
|
|
@@ -82,30 +64,6 @@ export class DateTimeInputDirective {
|
|
|
82
64
|
set disabled(value) {
|
|
83
65
|
this.element.nativeElement.disabled = value;
|
|
84
66
|
}
|
|
85
|
-
//######################### public properties - inputs #########################
|
|
86
|
-
/**
|
|
87
|
-
* Gets or sets date time value format which is being worked with in this date time
|
|
88
|
-
*/
|
|
89
|
-
get valueFormat() {
|
|
90
|
-
return this._valueFormat;
|
|
91
|
-
}
|
|
92
|
-
set valueFormat(value) {
|
|
93
|
-
if (isString(value)) {
|
|
94
|
-
this._valueFormat = DateTimeValueFormat[value];
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
this._valueFormat = value;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Gets or sets format of string representation of date
|
|
101
|
-
*/
|
|
102
|
-
get format() {
|
|
103
|
-
return this._format;
|
|
104
|
-
}
|
|
105
|
-
set format(value) {
|
|
106
|
-
this._format = value;
|
|
107
|
-
this.customFormat = this.dateApi.getFormat(this.formatProvider[value]);
|
|
108
|
-
}
|
|
109
67
|
//######################### public methods - implementation of OnDestroy #########################
|
|
110
68
|
/**
|
|
111
69
|
* Called when component is destroyed
|
|
@@ -121,7 +79,7 @@ export class DateTimeInputDirective {
|
|
|
121
79
|
*/
|
|
122
80
|
handleInput() {
|
|
123
81
|
this.internalValue = parseDateTime(this.rawValue, this.dateApi, this.valueFormat, this.customFormat);
|
|
124
|
-
this
|
|
82
|
+
this.ɵValue = formatDateTime(this.internalValue, this.valueFormat, this.customFormat);
|
|
125
83
|
this.valueChange.next();
|
|
126
84
|
}
|
|
127
85
|
/**
|
|
@@ -140,12 +98,12 @@ export class DateTimeInputDirective {
|
|
|
140
98
|
}
|
|
141
99
|
}
|
|
142
100
|
DateTimeInputDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: DateTimeInputDirective, deps: [{ token: i0.ElementRef }, { token: DATE_API }, { token: FORMAT_PROVIDER }], target: i0.ɵɵFactoryTarget.Directive });
|
|
143
|
-
DateTimeInputDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.6", type: DateTimeInputDirective, selector: "input[dateTime][dateTimeInput]",
|
|
101
|
+
DateTimeInputDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.6", type: DateTimeInputDirective, selector: "input[dateTime][dateTimeInput]", providers: [
|
|
144
102
|
{
|
|
145
103
|
provide: DATE_TIME_INPUT,
|
|
146
104
|
useExisting: forwardRef(() => DateTimeInputDirective),
|
|
147
105
|
},
|
|
148
|
-
], ngImport: i0 });
|
|
106
|
+
], exportAs: ["dateTime"], usesInheritance: true, ngImport: i0 });
|
|
149
107
|
__decorate([
|
|
150
108
|
BindThis,
|
|
151
109
|
__metadata("design:type", Function),
|
|
@@ -174,6 +132,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.6", ngImpor
|
|
|
174
132
|
useExisting: forwardRef(() => DateTimeInputDirective),
|
|
175
133
|
},
|
|
176
134
|
],
|
|
135
|
+
exportAs: 'dateTime',
|
|
177
136
|
}]
|
|
178
137
|
}], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: undefined, decorators: [{
|
|
179
138
|
type: Inject,
|
|
@@ -181,11 +140,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.6", ngImpor
|
|
|
181
140
|
}] }, { type: undefined, decorators: [{
|
|
182
141
|
type: Inject,
|
|
183
142
|
args: [FORMAT_PROVIDER]
|
|
184
|
-
}] }]; }, propDecorators: {
|
|
185
|
-
type: Input
|
|
186
|
-
}], format: [{
|
|
187
|
-
type: Input
|
|
188
|
-
}], customFormat: [{
|
|
189
|
-
type: Input
|
|
190
|
-
}], handleInput: [], handleFocus: [], handleBlur: [] } });
|
|
143
|
+
}] }]; }, propDecorators: { handleInput: [], handleFocus: [], handleBlur: [] } });
|
|
191
144
|
//# sourceMappingURL=dateTimeInput.directive.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dateTimeInput.directive.js","sourceRoot":"","sources":["../../../../../../src/modules/dateTime/directives/dateTimeInput/dateTimeInput.directive.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,SAAS,EAAE,UAAU,EAAE,YAAY,EAAoB,UAAU,EAAE,MAAM,EAAE,KAAK,EAAY,MAAM,eAAe,CAAC;AAC1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AI,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;;mHA5LQ,sBAAsB,4CAwIX,QAAQ,aACR,eAAe;uGAzI1B,sBAAsB,iJAR/B;QAEI;YACI,OAAO,EAAE,eAAe;YACxB,WAAW,EAAE,UAAU,CAAC,GAAG,EAAE,CAAC,sBAAsB,CAAC;SACxD;KACJ;;IAmKA,QAAQ;;;;yDAOR;;IAMA,QAAQ;;qCACoB,UAAU;;yDAGtC;;IAMA,QAAQ;;qCACmB,UAAU;;wDAGrC;2FA5LQ,sBAAsB;kBAZlC,SAAS;mBACV;oBACI,QAAQ,EAAE,gCAAgC;oBAC1C,SAAS,EACT;wBAEI;4BACI,OAAO,EAAE,eAAe;4BACxB,WAAW,EAAE,UAAU,CAAC,GAAG,EAAE,uBAAuB,CAAC;yBACxD;qBACJ;iBACJ;;0BAyIgB,MAAM;2BAAC,QAAQ;;0BACf,MAAM;2BAAC,eAAe;4CAvCxB,WAAW;sBADrB,KAAK;gBAqBK,MAAM;sBADhB,KAAK;gBAeC,YAAY;sBADlB,KAAK;gBA+BI,WAAW,MAaX,WAAW,MAUX,UAAU","sourcesContent":["import {Directive, ElementRef, EventEmitter, ExistingProvider, forwardRef, Inject, Input, OnDestroy} from '@angular/core';\nimport {BindThis, isString} from '@jscrpt/common';\n\nimport {DateTimeInput, FormatProvider} from '../../../../interfaces';\nimport {DateTimeValueFormat} from '../../../../misc/enums';\nimport {DATE_API, DATE_TIME_INPUT, FORMAT_PROVIDER} from '../../../../misc/tokens';\nimport {DateTimeInputOutputValue, DateTimeObjectValue} from '../../../../misc/types';\nimport {formatDateTime, parseDateTime} from '../../../../misc/utils';\nimport {DateApi} from '../../../../services';\n\n//TODO: range is unimplemented\n\n/**\n * Directive that is used for setting up date time input\n */\n@Directive(\n{\n selector: 'input[dateTime][dateTimeInput]',\n providers:\n [\n <ExistingProvider>\n {\n provide: DATE_TIME_INPUT,\n useExisting: forwardRef(() => DateTimeInputDirective),\n },\n ],\n})\nexport class DateTimeInputDirective<TDate = unknown> implements DateTimeInput, OnDestroy\n{\n //######################### private fields #########################\n\n /**\n * Date time value format which is being worked with in this date time\n */\n private _valueFormat: DateTimeValueFormat = DateTimeValueFormat.DateInstance;\n\n /**\n * Value of date time\n */\n private _value: DateTimeInputOutputValue<TDate>|undefined|null;\n\n /**\n * Format of string representation of date\n */\n private _format: keyof FormatProvider = 'date';\n\n //######################### protected properties #########################\n\n /**\n * Internal representation of current date time value\n */\n protected internalValue: DateTimeObjectValue<TDate>|undefined|null;\n\n //######################### public properties - implementation of DateTimeInput #########################\n\n /**\n * @inheritdoc\n */\n public get rawValue(): string|undefined|null\n {\n return this.element.nativeElement.value;\n }\n public set rawValue(value: string|undefined|null)\n {\n this.element.nativeElement.value = value ?? '';\n }\n\n /**\n * @inheritdoc\n */\n public get value(): DateTimeInputOutputValue<TDate>|undefined|null\n {\n return this._value;\n }\n public set value(value: DateTimeInputOutputValue<TDate>|undefined|null)\n {\n this._value = value;\n\n //accepts all available formats\n this.internalValue = parseDateTime(value, this.dateApi, null, this.customFormat);\n \n //not range value\n if(!Array.isArray(this.internalValue))\n {\n this.rawValue = this.internalValue?.format(this.customFormat);\n }\n else\n {\n //TODO: add support for ranges\n }\n }\n\n /**\n * @inheritdoc\n */\n public get disabled(): boolean\n {\n return this.element.nativeElement.disabled;\n }\n public set disabled(value: boolean)\n {\n this.element.nativeElement.disabled = value;\n }\n\n /**\n * @inheritdoc\n */\n public valueChange: EventEmitter<void> = new EventEmitter<void>();\n\n /**\n * @inheritdoc\n */\n public focus: EventEmitter<FocusEvent> = new EventEmitter<FocusEvent>();\n\n /**\n * @inheritdoc\n */\n public blur: EventEmitter<FocusEvent> = new EventEmitter<FocusEvent>();\n\n //######################### public properties - inputs #########################\n\n /**\n * Gets or sets date time value format which is being worked with in this date time\n */\n @Input()\n public get valueFormat(): DateTimeValueFormat\n {\n return this._valueFormat;\n }\n public set valueFormat(value: DateTimeValueFormat)\n {\n if(isString(value))\n {\n this._valueFormat = DateTimeValueFormat[value] as unknown as DateTimeValueFormat;\n\n return;\n }\n\n this._valueFormat = value;\n }\n\n /**\n * Gets or sets format of string representation of date\n */\n @Input()\n public get format(): keyof FormatProvider\n {\n return this._format;\n }\n public set format(value: keyof FormatProvider)\n {\n this._format = value;\n this.customFormat = this.dateApi.getFormat(this.formatProvider[value]);\n }\n\n /**\n * Custom format string representation of date\n */\n @Input()\n public customFormat: string = this.dateApi.getFormat(this.formatProvider[this._format]);\n\n //######################### constructors #########################\n constructor(protected element: ElementRef<HTMLInputElement>,\n @Inject(DATE_API) protected dateApi: DateApi<TDate>,\n @Inject(FORMAT_PROVIDER) protected formatProvider: FormatProvider,)\n {\n this.element.nativeElement.addEventListener('input', this.handleInput);\n this.element.nativeElement.addEventListener('focus', this.handleFocus);\n this.element.nativeElement.addEventListener('blur', this.handleBlur);\n }\n\n //######################### public methods - implementation of OnDestroy #########################\n \n /**\n * Called when component is destroyed\n */\n public ngOnDestroy(): void\n {\n this.element.nativeElement.removeEventListener('input', this.handleInput);\n this.element.nativeElement.removeEventListener('focus', this.handleFocus);\n this.element.nativeElement.removeEventListener('blur', this.handleBlur);\n }\n\n //######################### protected methods #########################\n\n /**\n * Handles input event on input\n */\n @BindThis\n protected handleInput(): void\n {\n this.internalValue = parseDateTime(this.rawValue, this.dateApi, this.valueFormat, this.customFormat);\n this._value = formatDateTime(this.internalValue, this.valueFormat, this.customFormat);\n\n this.valueChange.next();\n }\n\n /**\n * Handles focus event on input\n * @param event - Event that occured\n */\n @BindThis\n protected handleFocus(event: FocusEvent): void\n {\n this.focus.emit(event);\n }\n\n /**\n * Handles blur event on input\n * @param event - Event that occured\n */\n @BindThis\n protected handleBlur(event: FocusEvent): void\n {\n this.blur.emit(event);\n }\n\n //######################### ng language server #########################\n \n /**\n * Custom input type for `valueFormat` input\n */\n public static ngAcceptInputType_valueFormat: keyof typeof DateTimeValueFormat|DateTimeValueFormat;\n}"]}
|
|
1
|
+
{"version":3,"file":"dateTimeInput.directive.js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scrpt/common';\n\nimport {DateTimeInput, FormatProvider} from '../../../../interfaces';\nimport {DATE_API, DATE_TIME_INPUT, FORMAT_PROVIDER} from '../../../../misc/tokens';\nimport {DateTimeInputOutputValue, DateTimeObjectValue} from '../../../../misc/types';\nimport {formatDateTime, parseDateTime} from '../../../../misc/utils';\nimport {DateApi} from '../../../../services';\nimport {DateTimeBase} from '../dateTimeBase';\n\n//TODO: range is unimplemented\n\n/**\n * Directive that is used for setting up date time input\n */\n@Directive(\n{\n selector: 'input[dateTime][dateTimeInput]',\n providers:\n [\n <ExistingProvider>\n {\n provide: DATE_TIME_INPUT,\n useExisting: forwardRef(() => DateTimeInputDirective),\n },\n ],\n exportAs: 'dateTime',\n})\nexport class DateTimeInputDirective<TDate = unknown> extends DateTimeBase<TDate> implements DateTimeInput, OnDestroy\n{\n //######################### protected properties #########################\n\n /**\n * Internal representation of current date time value\n */\n protected internalValue: DateTimeObjectValue<TDate>|undefined|null;\n\n //######################### public properties - implementation of DateTimeInput #########################\n\n /**\n * @inheritdoc\n */\n public get rawValue(): string|undefined|null\n {\n return this.element.nativeElement.value;\n }\n public set rawValue(value: string|undefined|null)\n {\n this.element.nativeElement.value = value ?? '';\n }\n\n /**\n * @inheritdoc\n */\n public override get value(): DateTimeInputOutputValue<TDate>|undefined|null\n {\n return this.ɵValue;\n }\n public override set value(value: DateTimeInputOutputValue<TDate>|undefined|null)\n {\n this.ɵValue = value;\n\n //accepts all available formats\n this.internalValue = parseDateTime(value, this.dateApi, null, this.customFormat);\n \n //not range value\n if(!Array.isArray(this.internalValue))\n {\n this.rawValue = this.internalValue?.format(this.customFormat);\n }\n else\n {\n //TODO: add support for ranges\n }\n }\n\n /**\n * @inheritdoc\n */\n public get disabled(): boolean\n {\n return this.element.nativeElement.disabled;\n }\n public set disabled(value: boolean)\n {\n this.element.nativeElement.disabled = value;\n }\n\n /**\n * @inheritdoc\n */\n public focus: EventEmitter<FocusEvent> = new EventEmitter<FocusEvent>();\n\n /**\n * @inheritdoc\n */\n public blur: EventEmitter<FocusEvent> = new EventEmitter<FocusEvent>();\n\n //######################### constructors #########################\n constructor(protected element: ElementRef<HTMLInputElement>,\n @Inject(DATE_API) dateApi: DateApi<TDate>,\n @Inject(FORMAT_PROVIDER) formatProvider: FormatProvider,)\n {\n super(dateApi, formatProvider);\n\n this.element.nativeElement.addEventListener('input', this.handleInput);\n this.element.nativeElement.addEventListener('focus', this.handleFocus);\n this.element.nativeElement.addEventListener('blur', this.handleBlur);\n }\n\n //######################### public methods - implementation of OnDestroy #########################\n \n /**\n * Called when component is destroyed\n */\n public ngOnDestroy(): void\n {\n this.element.nativeElement.removeEventListener('input', this.handleInput);\n this.element.nativeElement.removeEventListener('focus', this.handleFocus);\n this.element.nativeElement.removeEventListener('blur', this.handleBlur);\n }\n\n //######################### protected methods #########################\n\n /**\n * Handles input event on input\n */\n @BindThis\n protected handleInput(): void\n {\n this.internalValue = parseDateTime(this.rawValue, this.dateApi, this.valueFormat, this.customFormat);\n this.ɵValue = formatDateTime(this.internalValue, this.valueFormat, this.customFormat);\n\n this.valueChange.next();\n }\n\n /**\n * Handles focus event on input\n * @param event - Event that occured\n */\n @BindThis\n protected handleFocus(event: FocusEvent): void\n {\n this.focus.emit(event);\n }\n\n /**\n * Handles blur event on input\n * @param event - Event that occured\n */\n @BindThis\n protected handleBlur(event: FocusEvent): void\n {\n this.blur.emit(event);\n }\n}"]}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Directive, forwardRef, Inject } from '@angular/core';
|
|
2
|
+
import { NG_VALIDATORS } from '@angular/forms';
|
|
3
|
+
import { DATE_API, FORMAT_PROVIDER } from '../../../../misc/tokens';
|
|
4
|
+
import { datetimeMaxValidator, datetimeValidator } from '../../../../misc/validators';
|
|
5
|
+
import { DateTimeRestrictedBase } from '../dateTimeRestrictedBase';
|
|
6
|
+
import * as i0 from "@angular/core";
|
|
7
|
+
/**
|
|
8
|
+
* Applies validator for date time max value
|
|
9
|
+
*/
|
|
10
|
+
export class DateTimeMaxValidatorDirective extends DateTimeRestrictedBase {
|
|
11
|
+
//######################### constructor #########################
|
|
12
|
+
constructor(dateApi, formatProvider) {
|
|
13
|
+
super(dateApi, formatProvider);
|
|
14
|
+
//######################### private fields #########################
|
|
15
|
+
/**
|
|
16
|
+
* Function used for validations
|
|
17
|
+
*/
|
|
18
|
+
this._validator = () => null;
|
|
19
|
+
this._validator = datetimeValidator(dateApi, null, null);
|
|
20
|
+
}
|
|
21
|
+
//######################### public methods - implementation of OnInit #########################
|
|
22
|
+
/**
|
|
23
|
+
* Initialize component
|
|
24
|
+
*/
|
|
25
|
+
ngOnInit() {
|
|
26
|
+
this._validator = datetimeMaxValidator(this.dateApi, this.maxDateTime, this.valueFormat, this.customFormat);
|
|
27
|
+
}
|
|
28
|
+
//######################### public methods - implementation of Validator #########################
|
|
29
|
+
/**
|
|
30
|
+
* Validates input and returns validation result
|
|
31
|
+
* @param control - Control that is being validated
|
|
32
|
+
* @returns validation results
|
|
33
|
+
*/
|
|
34
|
+
validate(control) {
|
|
35
|
+
return this._validator(control);
|
|
36
|
+
}
|
|
37
|
+
//######################### protected methods - overrides #########################
|
|
38
|
+
/**
|
|
39
|
+
* @inheritdoc
|
|
40
|
+
*/
|
|
41
|
+
onMaxDateTimeChange() {
|
|
42
|
+
this._validator = datetimeMaxValidator(this.dateApi, this.maxDateTime, this.valueFormat, this.customFormat);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
DateTimeMaxValidatorDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: DateTimeMaxValidatorDirective, deps: [{ token: DATE_API }, { token: FORMAT_PROVIDER }], target: i0.ɵɵFactoryTarget.Directive });
|
|
46
|
+
DateTimeMaxValidatorDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.6", type: DateTimeMaxValidatorDirective, selector: "[dateTime][maxDateTime][validate]", providers: [
|
|
47
|
+
{
|
|
48
|
+
provide: NG_VALIDATORS,
|
|
49
|
+
useExisting: forwardRef(() => DateTimeMaxValidatorDirective),
|
|
50
|
+
multi: true
|
|
51
|
+
},
|
|
52
|
+
], usesInheritance: true, ngImport: i0 });
|
|
53
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: DateTimeMaxValidatorDirective, decorators: [{
|
|
54
|
+
type: Directive,
|
|
55
|
+
args: [{
|
|
56
|
+
selector: '[dateTime][maxDateTime][validate]',
|
|
57
|
+
providers: [
|
|
58
|
+
{
|
|
59
|
+
provide: NG_VALIDATORS,
|
|
60
|
+
useExisting: forwardRef(() => DateTimeMaxValidatorDirective),
|
|
61
|
+
multi: true
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
}]
|
|
65
|
+
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
66
|
+
type: Inject,
|
|
67
|
+
args: [DATE_API]
|
|
68
|
+
}] }, { type: undefined, decorators: [{
|
|
69
|
+
type: Inject,
|
|
70
|
+
args: [FORMAT_PROVIDER]
|
|
71
|
+
}] }]; } });
|
|
72
|
+
//# sourceMappingURL=dateTimeMaxValidator.directive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dateTimeMaxValidator.directive.js","sourceRoot":"","sources":["../../../../../../src/modules/dateTime/directives/dateTimeMaxValidator/dateTimeMaxValidator.directive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAoB,UAAU,EAAE,MAAM,EAAS,MAAM,eAAe,CAAC;AACtF,OAAO,EAAkB,aAAa,EAA2C,MAAM,gBAAgB,CAAC;AAGxG,OAAO,EAAC,QAAQ,EAAE,eAAe,EAAC,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAC,oBAAoB,EAAE,iBAAiB,EAAC,MAAM,6BAA6B,CAAC;AAEpF,OAAO,EAAC,sBAAsB,EAAC,MAAM,2BAA2B,CAAC;;AAEjE;;GAEG;A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AAI;yBACd;qBACJ;iBACJ;;0BAWgB,MAAM;2BAAC,QAAQ;;0BACf,MAAM;2BAAC,eAAe","sourcesContent":["import {Directive, ExistingProvider, forwardRef, Inject, OnInit} from '@angular/core';\nimport {AbstractControl, NG_VALIDATORS, ValidationErrors, Validator, ValidatorFn} from '@angular/forms';\n\nimport {FormatProvider} from '../../../../interfaces';\nimport {DATE_API, FORMAT_PROVIDER} from '../../../../misc/tokens';\nimport {datetimeMaxValidator, datetimeValidator} from '../../../../misc/validators';\nimport {DateApi} from '../../../../services';\nimport {DateTimeRestrictedBase} from '../dateTimeRestrictedBase';\n\n/**\n * Applies validator for date time max value\n */\n@Directive(\n{\n selector: '[dateTime][maxDateTime][validate]',\n providers:\n [\n <ExistingProvider>\n {\n provide: NG_VALIDATORS,\n useExisting: forwardRef(() => DateTimeMaxValidatorDirective),\n multi: true\n },\n ],\n})\nexport class DateTimeMaxValidatorDirective<TDate = unknown> extends DateTimeRestrictedBase<TDate> implements Validator, OnInit\n{\n //######################### private fields #########################\n\n /**\n * Function used for validations\n */\n private _validator: ValidatorFn = () => null;\n\n //######################### constructor #########################\n constructor(@Inject(DATE_API) dateApi: DateApi<TDate>,\n @Inject(FORMAT_PROVIDER) formatProvider: FormatProvider,)\n {\n super(dateApi, formatProvider);\n this._validator = datetimeValidator(dateApi, null, null);\n }\n\n //######################### public methods - implementation of OnInit #########################\n \n /**\n * Initialize component\n */\n public ngOnInit(): void\n {\n this._validator = datetimeMaxValidator(this.dateApi, this.maxDateTime, this.valueFormat, this.customFormat);\n }\n\n //######################### public methods - implementation of Validator #########################\n\n /**\n * Validates input and returns validation result\n * @param control - Control that is being validated\n * @returns validation results\n */\n public validate(control: AbstractControl): ValidationErrors|null\n {\n return this._validator(control);\n }\n\n //######################### protected methods - overrides #########################\n\n /**\n * @inheritdoc\n */\n protected override onMaxDateTimeChange(): void\n {\n this._validator = datetimeMaxValidator(this.dateApi, this.maxDateTime, this.valueFormat, this.customFormat);\n }\n}"]}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Directive, forwardRef, Inject } from '@angular/core';
|
|
2
|
+
import { NG_VALIDATORS } from '@angular/forms';
|
|
3
|
+
import { DATE_API, FORMAT_PROVIDER } from '../../../../misc/tokens';
|
|
4
|
+
import { datetimeMinValidator } from '../../../../misc/validators';
|
|
5
|
+
import { DateTimeRestrictedBase } from '../dateTimeRestrictedBase';
|
|
6
|
+
import * as i0 from "@angular/core";
|
|
7
|
+
/**
|
|
8
|
+
* Applies validator for date time min value
|
|
9
|
+
*/
|
|
10
|
+
export class DateTimeMinValidatorDirective extends DateTimeRestrictedBase {
|
|
11
|
+
//######################### constructor #########################
|
|
12
|
+
constructor(dateApi, formatProvider) {
|
|
13
|
+
super(dateApi, formatProvider);
|
|
14
|
+
//######################### private fields #########################
|
|
15
|
+
/**
|
|
16
|
+
* Function used for validations
|
|
17
|
+
*/
|
|
18
|
+
this._validator = () => null;
|
|
19
|
+
}
|
|
20
|
+
//######################### public methods - implementation of OnInit #########################
|
|
21
|
+
/**
|
|
22
|
+
* Initialize component
|
|
23
|
+
*/
|
|
24
|
+
ngOnInit() {
|
|
25
|
+
this._validator = datetimeMinValidator(this.dateApi, this.minDateTime, this.valueFormat, this.customFormat);
|
|
26
|
+
}
|
|
27
|
+
//######################### public methods - implementation of Validator #########################
|
|
28
|
+
/**
|
|
29
|
+
* Validates input and returns validation result
|
|
30
|
+
* @param control - Control that is being validated
|
|
31
|
+
* @returns validation results
|
|
32
|
+
*/
|
|
33
|
+
validate(control) {
|
|
34
|
+
return this._validator(control);
|
|
35
|
+
}
|
|
36
|
+
//######################### protected methods - overrides #########################
|
|
37
|
+
/**
|
|
38
|
+
* @inheritdoc
|
|
39
|
+
*/
|
|
40
|
+
onMinDateTimeChange() {
|
|
41
|
+
this._validator = datetimeMinValidator(this.dateApi, this.minDateTime, this.valueFormat, this.customFormat);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
DateTimeMinValidatorDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: DateTimeMinValidatorDirective, deps: [{ token: DATE_API }, { token: FORMAT_PROVIDER }], target: i0.ɵɵFactoryTarget.Directive });
|
|
45
|
+
DateTimeMinValidatorDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.6", type: DateTimeMinValidatorDirective, selector: "[dateTime][minDateTime][validate]", providers: [
|
|
46
|
+
{
|
|
47
|
+
provide: NG_VALIDATORS,
|
|
48
|
+
useExisting: forwardRef(() => DateTimeMinValidatorDirective),
|
|
49
|
+
multi: true
|
|
50
|
+
},
|
|
51
|
+
], usesInheritance: true, ngImport: i0 });
|
|
52
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: DateTimeMinValidatorDirective, decorators: [{
|
|
53
|
+
type: Directive,
|
|
54
|
+
args: [{
|
|
55
|
+
selector: '[dateTime][minDateTime][validate]',
|
|
56
|
+
providers: [
|
|
57
|
+
{
|
|
58
|
+
provide: NG_VALIDATORS,
|
|
59
|
+
useExisting: forwardRef(() => DateTimeMinValidatorDirective),
|
|
60
|
+
multi: true
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
}]
|
|
64
|
+
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
65
|
+
type: Inject,
|
|
66
|
+
args: [DATE_API]
|
|
67
|
+
}] }, { type: undefined, decorators: [{
|
|
68
|
+
type: Inject,
|
|
69
|
+
args: [FORMAT_PROVIDER]
|
|
70
|
+
}] }]; } });
|
|
71
|
+
//# sourceMappingURL=dateTimeMinValidator.directive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dateTimeMinValidator.directive.js","sourceRoot":"","sources":["../../../../../../src/modules/dateTime/directives/dateTimeMinValidator/dateTimeMinValidator.directive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAoB,UAAU,EAAE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BAA6B;kBAbzC,SAAS;mBACV;oBACI,QAAQ,EAAE,mCAAmC;oBAC7C,SAAS,EACT;wBAEI;4BACI,OAAO,EAAE,aAAa;4BACtB,WAAW,EAAE,UAAU,CAAC,GAAG,EAAE,8BAA8B,CAAC;4BAC5D,KAAK,EAAE,IAAI;yBACd;qBACJ;iBACJ;;0BAWgB,MAAM;2BAAC,QAAQ;;0BACf,MAAM;2BAAC,eAAe","sourcesContent":["import {Directive, ExistingProvider, forwardRef, Inject, OnInit} from '@angular/core';\nimport {AbstractControl, NG_VALIDATORS, ValidationErrors, Validator, ValidatorFn} from '@angular/forms';\n\nimport {FormatProvider} from '../../../../interfaces';\nimport {DATE_API, FORMAT_PROVIDER} from '../../../../misc/tokens';\nimport {datetimeMinValidator} from '../../../../misc/validators';\nimport {DateApi} from '../../../../services';\nimport {DateTimeRestrictedBase} from '../dateTimeRestrictedBase';\n\n/**\n * Applies validator for date time min value\n */\n@Directive(\n{\n selector: '[dateTime][minDateTime][validate]',\n providers:\n [\n <ExistingProvider>\n {\n provide: NG_VALIDATORS,\n useExisting: forwardRef(() => DateTimeMinValidatorDirective),\n multi: true\n },\n ],\n})\nexport class DateTimeMinValidatorDirective<TDate = unknown> extends DateTimeRestrictedBase<TDate> implements Validator, OnInit\n{\n //######################### private fields #########################\n\n /**\n * Function used for validations\n */\n private _validator: ValidatorFn = () => null;\n\n //######################### constructor #########################\n constructor(@Inject(DATE_API) dateApi: DateApi<TDate>,\n @Inject(FORMAT_PROVIDER) formatProvider: FormatProvider,)\n {\n super(dateApi, formatProvider);\n }\n\n //######################### public methods - implementation of OnInit #########################\n \n /**\n * Initialize component\n */\n public ngOnInit(): void\n {\n this._validator = datetimeMinValidator(this.dateApi, this.minDateTime, this.valueFormat, this.customFormat);\n }\n\n //######################### public methods - implementation of Validator #########################\n\n /**\n * Validates input and returns validation result\n * @param control - Control that is being validated\n * @returns validation results\n */\n public validate(control: AbstractControl): ValidationErrors|null\n {\n return this._validator(control);\n }\n\n //######################### protected methods - overrides #########################\n\n /**\n * @inheritdoc\n */\n protected override onMinDateTimeChange(): void\n {\n this._validator = datetimeMinValidator(this.dateApi, this.minDateTime, this.valueFormat, this.customFormat);\n }\n}"]}
|