@zajno/common 1.6.3 → 2.0.0-beta.2
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/.eslintrc.js +1 -1
- package/README.md +6 -1
- package/coverage/clover.xml +344 -1066
- package/coverage/coverage-final.json +31 -45
- package/coverage/lcov-report/__tests__/helpers/expect.ts.html +1 -1
- package/coverage/lcov-report/__tests__/helpers/index.html +1 -1
- package/coverage/lcov-report/__tests__/helpers/main.ts.html +1 -1
- package/coverage/lcov-report/async/arrays.ts.html +1 -1
- package/coverage/lcov-report/async/index.html +36 -21
- package/coverage/lcov-report/async/timeout.ts.html +59 -59
- package/coverage/lcov-report/dates/calc.ts.html +1 -1
- package/coverage/lcov-report/dates/convert.ts.html +1 -1
- package/coverage/lcov-report/dates/datex.ts.html +1 -1
- package/coverage/lcov-report/dates/format.ts.html +1 -1
- package/coverage/lcov-report/dates/index.html +1 -1
- package/coverage/lcov-report/dates/index.ts.html +1 -1
- package/coverage/lcov-report/dates/parse.ts.html +1 -1
- package/coverage/lcov-report/dates/period.ts.html +1 -1
- package/coverage/lcov-report/dates/shift.ts.html +1 -1
- package/coverage/lcov-report/dates/types.ts.html +1 -1
- package/coverage/lcov-report/dates/yearDate.ts.html +1 -1
- package/coverage/lcov-report/fields/index.html +1 -1
- package/coverage/lcov-report/fields/update.ts.html +1 -1
- package/coverage/lcov-report/functions/index.html +17 -17
- package/coverage/lcov-report/functions/safeCall.ts.html +13 -13
- package/coverage/lcov-report/index.html +119 -74
- package/coverage/lcov-report/lazy/index.html +1 -1
- package/coverage/lcov-report/lazy/promise.ts.html +1 -1
- package/coverage/lcov-report/lazy/singleton.ts.html +1 -1
- package/coverage/lcov-report/logger/batch.ts.html +1 -1
- package/coverage/lcov-report/logger/console.ts.html +1 -1
- package/coverage/lcov-report/logger/index.html +1 -1
- package/coverage/lcov-report/logger/index.ts.html +1 -1
- package/coverage/lcov-report/logger/named.ts.html +1 -1
- package/coverage/lcov-report/logger/proxy.ts.html +1 -1
- package/coverage/lcov-report/math/arrays.ts.html +1 -1
- package/coverage/lcov-report/math/calc.ts.html +1 -1
- package/coverage/lcov-report/math/distribution.ts.html +1 -1
- package/coverage/lcov-report/math/index.html +1 -1
- package/coverage/lcov-report/math/index.ts.html +1 -1
- package/coverage/lcov-report/observing/event.ts.html +1 -1
- package/coverage/lcov-report/observing/index.html +1 -1
- package/coverage/lcov-report/structures/helpers/enum.ts.html +1 -1
- package/coverage/lcov-report/structures/helpers/index.html +1 -1
- package/coverage/lcov-report/structures/index.html +1 -1
- package/coverage/lcov-report/structures/queue/index.html +24 -9
- package/coverage/lcov-report/structures/queue/parallel.ts.html +1 -1
- package/coverage/lcov-report/structures/queue/tasks.ts.html +358 -0
- package/coverage/lcov-report/structures/tempoCache.ts.html +1 -1
- package/coverage/lcov-report/types/comparator.ts.html +1 -1
- package/coverage/lcov-report/types/getter.ts.html +1 -1
- package/coverage/lcov-report/types/index.html +1 -1
- package/coverage/lcov-report/types/index.ts.html +1 -1
- package/coverage/lcov-report/validation/ValidationErrors.ts.html +1 -1
- package/coverage/lcov-report/validation/creditCard.ts.html +1 -1
- package/coverage/lcov-report/validation/helpers.ts.html +1 -1
- package/coverage/lcov-report/validation/index.html +1 -1
- package/coverage/lcov-report/validation/index.ts.html +1 -1
- package/coverage/lcov-report/validation/types.ts.html +1 -1
- package/coverage/lcov-report/validation/validators.ts.html +1 -1
- package/coverage/lcov-report/validation/wrappers.ts.html +1 -1
- package/coverage/lcov.info +863 -2381
- package/lib/fields/update.js +3 -3
- package/lib/fields/update.js.map +1 -1
- package/lib/{assert.d.ts → functions/assert.d.ts} +1 -1
- package/lib/functions/assert.d.ts.map +1 -0
- package/lib/{assert.js → functions/assert.js} +2 -2
- package/lib/functions/assert.js.map +1 -0
- package/lib/{disposer.d.ts → functions/disposer.d.ts} +0 -0
- package/lib/functions/disposer.d.ts.map +1 -0
- package/lib/{disposer.js → functions/disposer.js} +1 -1
- package/lib/functions/disposer.js.map +1 -0
- package/lib/functions/safeCall.d.ts +2 -0
- package/lib/functions/safeCall.d.ts.map +1 -0
- package/lib/{functions.js → functions/safeCall.js} +1 -1
- package/lib/functions/safeCall.js.map +1 -0
- package/lib/{throttle.d.ts → functions/throttle.d.ts} +0 -0
- package/lib/functions/throttle.d.ts.map +1 -0
- package/lib/{throttle.js → functions/throttle.js} +1 -1
- package/lib/functions/throttle.js.map +1 -0
- package/lib/lazy/light.d.ts +1 -1
- package/lib/lazy/light.d.ts.map +1 -1
- package/lib/lazy/promise.d.ts +1 -1
- package/lib/lazy/promise.d.ts.map +1 -1
- package/lib/lazy/singleton.d.ts +1 -1
- package/lib/lazy/singleton.d.ts.map +1 -1
- package/lib/math/arrays.d.ts +1 -0
- package/lib/math/arrays.d.ts.map +1 -1
- package/lib/math/arrays.js +13 -1
- package/lib/math/arrays.js.map +1 -1
- package/lib/{event.d.ts → observing/event.d.ts} +2 -3
- package/lib/observing/event.d.ts.map +1 -0
- package/lib/{event.js → observing/event.js} +2 -3
- package/lib/{event.js.map → observing/event.js.map} +1 -1
- package/lib/{throttledEvent.d.ts → observing/throttledEvent.d.ts} +0 -0
- package/lib/observing/throttledEvent.d.ts.map +1 -0
- package/lib/{throttledEvent.js → observing/throttledEvent.js} +1 -1
- package/lib/observing/throttledEvent.js.map +1 -0
- package/lib/{timer.d.ts → observing/timer.d.ts} +1 -1
- package/lib/observing/timer.d.ts.map +1 -0
- package/lib/{timer.js → observing/timer.js} +0 -0
- package/lib/observing/timer.js.map +1 -0
- package/lib/{abstractions/services/storage.d.ts → storage/abstractions.d.ts} +3 -2
- package/lib/storage/abstractions.d.ts.map +1 -0
- package/lib/{services/localization → storage}/abstractions.js +0 -0
- package/lib/storage/abstractions.js.map +1 -0
- package/lib/storage/asyncWrapper.d.ts +10 -0
- package/lib/storage/asyncWrapper.d.ts.map +1 -0
- package/lib/storage/asyncWrapper.js +24 -0
- package/lib/storage/asyncWrapper.js.map +1 -0
- package/lib/storage/index.d.ts +2 -0
- package/lib/storage/index.d.ts.map +1 -0
- package/lib/storage/index.js +5 -0
- package/lib/storage/index.js.map +1 -0
- package/lib/{services/storage/index.d.ts → storage/keyStorage.d.ts} +2 -10
- package/lib/storage/keyStorage.d.ts.map +1 -0
- package/lib/{services/storage/index.js → storage/keyStorage.js} +2 -22
- package/lib/storage/keyStorage.js.map +1 -0
- package/lib/{enumHelper.d.ts → structures/helpers/enum.d.ts} +1 -1
- package/lib/structures/helpers/enum.d.ts.map +1 -0
- package/lib/{enumHelper.js → structures/helpers/enum.js} +1 -1
- package/lib/structures/helpers/enum.js.map +1 -0
- package/lib/{nameHelper.d.ts → structures/helpers/name.d.ts} +5 -5
- package/lib/structures/helpers/name.d.ts.map +1 -0
- package/lib/{nameHelper.js → structures/helpers/name.js} +7 -6
- package/lib/structures/helpers/name.js.map +1 -0
- package/lib/structures/linkedList.d.ts +39 -0
- package/lib/structures/linkedList.d.ts.map +1 -0
- package/lib/structures/linkedList.js +82 -0
- package/lib/structures/linkedList.js.map +1 -0
- package/lib/{pool.d.ts → structures/pool.d.ts} +1 -1
- package/lib/structures/pool.d.ts.map +1 -0
- package/lib/{pool.js → structures/pool.js} +2 -2
- package/lib/structures/pool.js.map +1 -0
- package/lib/{queue → structures/queue}/parallel.d.ts +3 -3
- package/lib/structures/queue/parallel.d.ts.map +1 -0
- package/lib/{queue → structures/queue}/parallel.js +2 -2
- package/lib/structures/queue/parallel.js.map +1 -0
- package/lib/{queue → structures/queue}/tasks.d.ts +1 -1
- package/lib/structures/queue/tasks.d.ts.map +1 -0
- package/lib/{queue → structures/queue}/tasks.js +0 -0
- package/lib/structures/queue/tasks.js.map +1 -0
- package/lib/{tempoCache.d.ts → structures/tempoCache.d.ts} +0 -0
- package/lib/structures/tempoCache.d.ts.map +1 -0
- package/lib/{tempoCache.js → structures/tempoCache.js} +0 -0
- package/lib/structures/tempoCache.js.map +1 -0
- package/lib/types/comparator.d.ts +5 -0
- package/lib/types/comparator.d.ts.map +1 -0
- package/lib/types/comparator.js +8 -0
- package/lib/types/comparator.js.map +1 -0
- package/lib/types/deep.d.ts +9 -0
- package/lib/types/deep.d.ts.map +1 -0
- package/lib/{viewModels/types.js → types/deep.js} +1 -1
- package/lib/types/deep.js.map +1 -0
- package/lib/types/functions.d.ts +7 -0
- package/lib/types/functions.d.ts.map +1 -0
- package/lib/{abstractions/services/storage.js → types/functions.js} +1 -1
- package/lib/types/functions.js.map +1 -0
- package/lib/types/getter.d.ts +5 -0
- package/lib/types/getter.d.ts.map +1 -0
- package/lib/{types.js → types/getter.js} +2 -6
- package/lib/types/getter.js.map +1 -0
- package/lib/{ident.d.ts → types/ident.d.ts} +0 -0
- package/lib/types/ident.d.ts.map +1 -0
- package/lib/{ident.js → types/ident.js} +0 -0
- package/lib/types/ident.js.map +1 -0
- package/lib/types/index.d.ts +8 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +7 -0
- package/lib/types/index.js.map +1 -0
- package/lib/validation/ValidationErrors.d.ts +1 -1
- package/lib/validation/ValidationErrors.d.ts.map +1 -1
- package/lib/validation/ValidationErrors.js +2 -2
- package/lib/validation/ValidationErrors.js.map +1 -1
- package/lib/{emails.d.ts → validation/emails.d.ts} +0 -0
- package/lib/validation/emails.d.ts.map +1 -0
- package/lib/{emails.js → validation/emails.js} +0 -0
- package/lib/validation/emails.js.map +1 -0
- package/package.json +16 -16
- package/src/async/__tests__/timeout.test.ts +1 -1
- package/src/fields/update.ts +1 -1
- package/src/{assert.ts → functions/assert.ts} +2 -2
- package/src/{disposer.ts → functions/disposer.ts} +1 -1
- package/src/functions/safeCall.ts +6 -0
- package/src/{throttle.ts → functions/throttle.ts} +1 -1
- package/src/lazy/__tests__/lazy.test.ts +1 -48
- package/src/lazy/light.ts +1 -1
- package/src/lazy/promise.ts +1 -1
- package/src/lazy/singleton.ts +1 -1
- package/src/math/arrays.ts +13 -0
- package/src/{event.ts → observing/event.ts} +3 -4
- package/src/{throttledEvent.ts → observing/throttledEvent.ts} +1 -1
- package/src/{timer.ts → observing/timer.ts} +1 -1
- package/src/{abstractions/services/storage.ts → storage/abstractions.ts} +3 -1
- package/src/storage/asyncWrapper.ts +24 -0
- package/src/storage/index.ts +2 -0
- package/src/{services/storage/index.ts → storage/keyStorage.ts} +1 -24
- package/src/{__tests__ → structures/__tests__}/enumHelper.test.ts +1 -1
- package/src/{__tests__ → structures/__tests__}/tempoCache.test.ts +1 -1
- package/src/{enumHelper.ts → structures/helpers/enum.ts} +0 -0
- package/src/{nameHelper.ts → structures/helpers/name.ts} +4 -4
- package/src/structures/linkedList.ts +129 -0
- package/src/{pool.ts → structures/pool.ts} +2 -2
- package/src/{queue → structures/queue}/__tests__/parallel.test.ts +2 -2
- package/src/{queue → structures/queue}/__tests__/tasks.test.ts +2 -2
- package/src/{queue → structures/queue}/parallel.ts +2 -2
- package/src/{queue → structures/queue}/tasks.ts +1 -1
- package/src/{tempoCache.ts → structures/tempoCache.ts} +0 -0
- package/src/types/comparator.ts +6 -0
- package/src/types/deep.ts +18 -0
- package/src/types/functions.ts +8 -0
- package/src/types/getter.ts +14 -0
- package/src/{ident.ts → types/ident.ts} +0 -0
- package/src/types/index.ts +9 -0
- package/src/validation/ValidationErrors.ts +1 -1
- package/src/{emails.ts → validation/emails.ts} +0 -0
- package/tsconfig.build.json +10 -0
- package/tsconfig.json +0 -1
- package/yarn.lock +467 -370
- package/lib/abstractions/services/storage.d.ts.map +0 -1
- package/lib/abstractions/services/storage.js.map +0 -1
- package/lib/assert.d.ts.map +0 -1
- package/lib/assert.js.map +0 -1
- package/lib/cache.d.ts +0 -36
- package/lib/cache.d.ts.map +0 -1
- package/lib/cache.js +0 -165
- package/lib/cache.js.map +0 -1
- package/lib/deepPartial.d.ts +0 -4
- package/lib/deepPartial.d.ts.map +0 -1
- package/lib/deepPartial.js +0 -3
- package/lib/deepPartial.js.map +0 -1
- package/lib/disposer.d.ts.map +0 -1
- package/lib/disposer.js.map +0 -1
- package/lib/emails.d.ts.map +0 -1
- package/lib/emails.js.map +0 -1
- package/lib/enumHelper.d.ts.map +0 -1
- package/lib/enumHelper.js.map +0 -1
- package/lib/event.d.ts.map +0 -1
- package/lib/functions.d.ts +0 -9
- package/lib/functions.d.ts.map +0 -1
- package/lib/functions.js.map +0 -1
- package/lib/ident.d.ts.map +0 -1
- package/lib/ident.js.map +0 -1
- package/lib/lazy/index.d.ts +0 -10
- package/lib/lazy/index.d.ts.map +0 -1
- package/lib/lazy/index.js +0 -23
- package/lib/lazy/index.js.map +0 -1
- package/lib/lazy/observable.d.ts +0 -9
- package/lib/lazy/observable.d.ts.map +0 -1
- package/lib/lazy/observable.js +0 -31
- package/lib/lazy/observable.js.map +0 -1
- package/lib/lazy.light.d.ts +0 -2
- package/lib/lazy.light.d.ts.map +0 -1
- package/lib/lazy.light.js +0 -8
- package/lib/lazy.light.js.map +0 -1
- package/lib/nameHelper.d.ts.map +0 -1
- package/lib/nameHelper.js.map +0 -1
- package/lib/observersMap.d.ts +0 -22
- package/lib/observersMap.d.ts.map +0 -1
- package/lib/observersMap.js +0 -93
- package/lib/observersMap.js.map +0 -1
- package/lib/observingCache.d.ts +0 -32
- package/lib/observingCache.d.ts.map +0 -1
- package/lib/observingCache.js +0 -128
- package/lib/observingCache.js.map +0 -1
- package/lib/pool.d.ts.map +0 -1
- package/lib/pool.js.map +0 -1
- package/lib/queue/parallel.d.ts.map +0 -1
- package/lib/queue/parallel.js.map +0 -1
- package/lib/queue/tasks.d.ts.map +0 -1
- package/lib/queue/tasks.js.map +0 -1
- package/lib/services/localization/LocalaziedValidationErrors.d.ts +0 -9
- package/lib/services/localization/LocalaziedValidationErrors.d.ts.map +0 -1
- package/lib/services/localization/LocalaziedValidationErrors.js +0 -27
- package/lib/services/localization/LocalaziedValidationErrors.js.map +0 -1
- package/lib/services/localization/LocalizationManager.d.ts +0 -18
- package/lib/services/localization/LocalizationManager.d.ts.map +0 -1
- package/lib/services/localization/LocalizationManager.js +0 -58
- package/lib/services/localization/LocalizationManager.js.map +0 -1
- package/lib/services/localization/abstractions.d.ts +0 -12
- package/lib/services/localization/abstractions.d.ts.map +0 -1
- package/lib/services/localization/abstractions.js.map +0 -1
- package/lib/services/localization/defaultShape.d.ts +0 -26
- package/lib/services/localization/defaultShape.d.ts.map +0 -1
- package/lib/services/localization/defaultShape.js +0 -28
- package/lib/services/localization/defaultShape.js.map +0 -1
- package/lib/services/localization/index.d.ts +0 -5
- package/lib/services/localization/index.d.ts.map +0 -1
- package/lib/services/localization/index.js +0 -10
- package/lib/services/localization/index.js.map +0 -1
- package/lib/services/storage/index.d.ts.map +0 -1
- package/lib/services/storage/index.js.map +0 -1
- package/lib/services/storage/web/localStorage.d.ts +0 -13
- package/lib/services/storage/web/localStorage.d.ts.map +0 -1
- package/lib/services/storage/web/localStorage.js +0 -29
- package/lib/services/storage/web/localStorage.js.map +0 -1
- package/lib/services/storage/web/sessionStorage.d.ts +0 -13
- package/lib/services/storage/web/sessionStorage.d.ts.map +0 -1
- package/lib/services/storage/web/sessionStorage.js +0 -29
- package/lib/services/storage/web/sessionStorage.js.map +0 -1
- package/lib/services/storage/web/webStorage.d.ts +0 -9
- package/lib/services/storage/web/webStorage.d.ts.map +0 -1
- package/lib/services/storage/web/webStorage.js +0 -24
- package/lib/services/storage/web/webStorage.js.map +0 -1
- package/lib/tempoCache.d.ts.map +0 -1
- package/lib/tempoCache.js.map +0 -1
- package/lib/throttle.d.ts.map +0 -1
- package/lib/throttle.js.map +0 -1
- package/lib/throttledEvent.d.ts.map +0 -1
- package/lib/throttledEvent.js.map +0 -1
- package/lib/timeHelper.d.ts +0 -7
- package/lib/timeHelper.d.ts.map +0 -1
- package/lib/timeHelper.js +0 -37
- package/lib/timeHelper.js.map +0 -1
- package/lib/timer.d.ts.map +0 -1
- package/lib/timer.js.map +0 -1
- package/lib/transitionObserver.d.ts +0 -36
- package/lib/transitionObserver.d.ts.map +0 -1
- package/lib/transitionObserver.js +0 -153
- package/lib/transitionObserver.js.map +0 -1
- package/lib/types.d.ts +0 -17
- package/lib/types.d.ts.map +0 -1
- package/lib/types.js.map +0 -1
- package/lib/unsubscriber.d.ts +0 -2
- package/lib/unsubscriber.d.ts.map +0 -1
- package/lib/unsubscriber.js +0 -12
- package/lib/unsubscriber.js.map +0 -1
- package/lib/validation/ValidationErrorsLocalization.d.ts +0 -27
- package/lib/validation/ValidationErrorsLocalization.d.ts.map +0 -1
- package/lib/validation/ValidationErrorsLocalization.js +0 -26
- package/lib/validation/ValidationErrorsLocalization.js.map +0 -1
- package/lib/viewModels/CommonModel.d.ts +0 -13
- package/lib/viewModels/CommonModel.d.ts.map +0 -1
- package/lib/viewModels/CommonModel.js +0 -38
- package/lib/viewModels/CommonModel.js.map +0 -1
- package/lib/viewModels/FlagModel.d.ts +0 -22
- package/lib/viewModels/FlagModel.d.ts.map +0 -1
- package/lib/viewModels/FlagModel.js +0 -52
- package/lib/viewModels/FlagModel.js.map +0 -1
- package/lib/viewModels/InitializableModel.d.ts +0 -6
- package/lib/viewModels/InitializableModel.d.ts.map +0 -1
- package/lib/viewModels/InitializableModel.js +0 -23
- package/lib/viewModels/InitializableModel.js.map +0 -1
- package/lib/viewModels/LoadingModel.d.ts +0 -17
- package/lib/viewModels/LoadingModel.d.ts.map +0 -1
- package/lib/viewModels/LoadingModel.js +0 -42
- package/lib/viewModels/LoadingModel.js.map +0 -1
- package/lib/viewModels/MultiSelectModel.d.ts +0 -47
- package/lib/viewModels/MultiSelectModel.d.ts.map +0 -1
- package/lib/viewModels/MultiSelectModel.js +0 -144
- package/lib/viewModels/MultiSelectModel.js.map +0 -1
- package/lib/viewModels/NumberModel.d.ts +0 -19
- package/lib/viewModels/NumberModel.d.ts.map +0 -1
- package/lib/viewModels/NumberModel.js +0 -38
- package/lib/viewModels/NumberModel.js.map +0 -1
- package/lib/viewModels/PromptModal.d.ts +0 -31
- package/lib/viewModels/PromptModal.d.ts.map +0 -1
- package/lib/viewModels/PromptModal.js +0 -57
- package/lib/viewModels/PromptModal.js.map +0 -1
- package/lib/viewModels/SelectModel.d.ts +0 -35
- package/lib/viewModels/SelectModel.d.ts.map +0 -1
- package/lib/viewModels/SelectModel.js +0 -118
- package/lib/viewModels/SelectModel.js.map +0 -1
- package/lib/viewModels/TextModel.d.ts +0 -41
- package/lib/viewModels/TextModel.d.ts.map +0 -1
- package/lib/viewModels/TextModel.js +0 -98
- package/lib/viewModels/TextModel.js.map +0 -1
- package/lib/viewModels/Validatable.d.ts +0 -26
- package/lib/viewModels/Validatable.d.ts.map +0 -1
- package/lib/viewModels/Validatable.js +0 -81
- package/lib/viewModels/Validatable.js.map +0 -1
- package/lib/viewModels/ValueModel.d.ts +0 -12
- package/lib/viewModels/ValueModel.d.ts.map +0 -1
- package/lib/viewModels/ValueModel.js +0 -29
- package/lib/viewModels/ValueModel.js.map +0 -1
- package/lib/viewModels/ValuesCollector.d.ts +0 -26
- package/lib/viewModels/ValuesCollector.d.ts.map +0 -1
- package/lib/viewModels/ValuesCollector.js +0 -51
- package/lib/viewModels/ValuesCollector.js.map +0 -1
- package/lib/viewModels/index.d.ts +0 -12
- package/lib/viewModels/index.d.ts.map +0 -1
- package/lib/viewModels/index.js +0 -15
- package/lib/viewModels/index.js.map +0 -1
- package/lib/viewModels/types.d.ts +0 -19
- package/lib/viewModels/types.d.ts.map +0 -1
- package/lib/viewModels/types.js.map +0 -1
- package/lib/viewModels/wrappers.d.ts +0 -12
- package/lib/viewModels/wrappers.d.ts.map +0 -1
- package/lib/viewModels/wrappers.js +0 -43
- package/lib/viewModels/wrappers.js.map +0 -1
- package/src/__tests__/observingCache.test.ts +0 -127
- package/src/__tests__/transitionObserver.test.ts +0 -219
- package/src/cache.ts +0 -181
- package/src/deepPartial.ts +0 -4
- package/src/functions.ts +0 -14
- package/src/lazy/index.ts +0 -33
- package/src/lazy/observable.ts +0 -37
- package/src/lazy.light.ts +0 -8
- package/src/observersMap.ts +0 -105
- package/src/observingCache.ts +0 -160
- package/src/services/localization/LocalaziedValidationErrors.ts +0 -18
- package/src/services/localization/LocalizationManager.ts +0 -53
- package/src/services/localization/abstractions.ts +0 -16
- package/src/services/localization/defaultShape.ts +0 -26
- package/src/services/localization/index.ts +0 -6
- package/src/services/storage/web/localStorage.ts +0 -35
- package/src/services/storage/web/sessionStorage.ts +0 -35
- package/src/services/storage/web/webStorage.ts +0 -29
- package/src/timeHelper.ts +0 -39
- package/src/transitionObserver.ts +0 -183
- package/src/types.ts +0 -30
- package/src/unsubscriber.ts +0 -14
- package/src/validation/ValidationErrorsLocalization.ts +0 -27
- package/src/viewModels/CommonModel.ts +0 -45
- package/src/viewModels/FlagModel.ts +0 -70
- package/src/viewModels/InitializableModel.ts +0 -17
- package/src/viewModels/LoadingModel.ts +0 -52
- package/src/viewModels/MultiSelectModel.ts +0 -178
- package/src/viewModels/NumberModel.ts +0 -50
- package/src/viewModels/PromptModal.ts +0 -65
- package/src/viewModels/SelectModel.ts +0 -152
- package/src/viewModels/TextModel.ts +0 -127
- package/src/viewModels/Validatable.ts +0 -102
- package/src/viewModels/ValueModel.ts +0 -34
- package/src/viewModels/ValuesCollector.ts +0 -81
- package/src/viewModels/__tests__/common.test.ts +0 -107
- package/src/viewModels/__tests__/multiSelect.test.ts +0 -138
- package/src/viewModels/__tests__/select.test.ts +0 -71
- package/src/viewModels/__tests__/wrappers.test.ts +0 -79
- package/src/viewModels/index.ts +0 -15
- package/src/viewModels/types.ts +0 -23
- package/src/viewModels/wrappers.ts +0 -49
- package/tsconfig.eslint.json +0 -9
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { action, makeObservable, observable } from 'mobx';
|
|
2
|
-
import { Getter } from '../types';
|
|
3
|
-
import { ValidatableModel } from './Validatable';
|
|
4
|
-
|
|
5
|
-
export class CommonModel<T = any> extends ValidatableModel<T> {
|
|
6
|
-
|
|
7
|
-
// observable[.ref]
|
|
8
|
-
private _value: T;
|
|
9
|
-
|
|
10
|
-
private _defaultValue: Getter<T> = null;
|
|
11
|
-
|
|
12
|
-
constructor(v: Getter<T> = null, useRefObservable = true) {
|
|
13
|
-
super();
|
|
14
|
-
this._value = Getter.getValue(v) || null;
|
|
15
|
-
this._defaultValue = v;
|
|
16
|
-
|
|
17
|
-
makeObservable<CommonModel<T>, '_value'>(this, {
|
|
18
|
-
_value: useRefObservable ? observable.ref : observable,
|
|
19
|
-
setValue: action,
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
protected get valueToValidate(): Readonly<T> {
|
|
24
|
-
return this._value;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
public get value() { return this._value; }
|
|
28
|
-
public set value(v: T) {
|
|
29
|
-
this.setValue(v);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// action
|
|
33
|
-
public readonly setValue = (value: T) => {
|
|
34
|
-
this._value = value;
|
|
35
|
-
|
|
36
|
-
if (this._validateOnChange) {
|
|
37
|
-
this.validate();
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
reset = () => {
|
|
42
|
-
this._value = Getter.getValue(this._defaultValue);
|
|
43
|
-
super.reset();
|
|
44
|
-
};
|
|
45
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { action, makeObservable, observable } from 'mobx';
|
|
2
|
-
import { IResetableModel } from 'viewModels';
|
|
3
|
-
import { ILabel, IValueModel } from './types';
|
|
4
|
-
|
|
5
|
-
export interface IFlagModel extends IValueModel<boolean>, IResetableModel {
|
|
6
|
-
toggle(): void;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export type IFlagModelReadonly = {
|
|
10
|
-
readonly value: boolean;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export type ILabeledFlagModel = IFlagModel & ILabel<string>;
|
|
14
|
-
|
|
15
|
-
export class FlagModel implements IFlagModel, IFlagModelReadonly {
|
|
16
|
-
|
|
17
|
-
// @observable
|
|
18
|
-
private _value: boolean = false;
|
|
19
|
-
|
|
20
|
-
constructor(initial = false) {
|
|
21
|
-
makeObservable<FlagModel, '_value'>(this, {
|
|
22
|
-
_value: observable,
|
|
23
|
-
setValue: action,
|
|
24
|
-
setTrue: action,
|
|
25
|
-
setFalse: action,
|
|
26
|
-
toggle: action,
|
|
27
|
-
reset: action,
|
|
28
|
-
});
|
|
29
|
-
this._value = initial;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
get value() {
|
|
33
|
-
return this._value;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
set value(value: boolean) {
|
|
37
|
-
this.setValue(value);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// @action
|
|
41
|
-
public readonly setValue = (value: boolean) => {
|
|
42
|
-
this._value = value;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
get isDefault() { return this._value === false; }
|
|
46
|
-
|
|
47
|
-
// @action
|
|
48
|
-
setTrue = () => {
|
|
49
|
-
const v = this.value;
|
|
50
|
-
this.value = true;
|
|
51
|
-
return !v;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
// @action
|
|
55
|
-
setFalse = () => {
|
|
56
|
-
const v = this.value;
|
|
57
|
-
this.value = false;
|
|
58
|
-
return v;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
// @action
|
|
62
|
-
toggle = () => {
|
|
63
|
-
this._value = !this._value;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
// @action
|
|
67
|
-
reset = () => {
|
|
68
|
-
this._value = false;
|
|
69
|
-
};
|
|
70
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import NumberModel from './NumberModel';
|
|
2
|
-
|
|
3
|
-
export class InitializableModel {
|
|
4
|
-
private readonly _counter = new NumberModel(0);
|
|
5
|
-
|
|
6
|
-
public get initializing() { return this._counter.value > 0; }
|
|
7
|
-
|
|
8
|
-
protected async runOperation<T>(operation: () => Promise<T> | T): Promise<T> {
|
|
9
|
-
try {
|
|
10
|
-
this._counter.increment();
|
|
11
|
-
const res = await operation();
|
|
12
|
-
return res;
|
|
13
|
-
} finally {
|
|
14
|
-
this._counter.decrement();
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { NumberModel } from './NumberModel';
|
|
2
|
-
import { IResetableModel, IValueModel } from './types';
|
|
3
|
-
|
|
4
|
-
export class LoadingModel implements IValueModel<boolean>, IResetableModel {
|
|
5
|
-
|
|
6
|
-
private readonly _number = new NumberModel(0);
|
|
7
|
-
|
|
8
|
-
public get isLoading() { return this._number.value > 0; }
|
|
9
|
-
|
|
10
|
-
public get value(): boolean { return this.isLoading; }
|
|
11
|
-
public set value(v: boolean) {
|
|
12
|
-
if (v) {
|
|
13
|
-
this._number.increment();
|
|
14
|
-
} else {
|
|
15
|
-
this._number.decrement();
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
public async useLoading<T>(cb: () => (T | Promise<T>)): Promise<T>;
|
|
20
|
-
public async useLoading<T>(cb: () => (T | Promise<T>), exclusive: false): Promise<T>;
|
|
21
|
-
public async useLoading<T>(cb: () => (T | Promise<T>), exclusive: true): Promise<T | false>;
|
|
22
|
-
public async useLoading<T>(cb: () => (T | Promise<T>), exclusive: 'throw'): Promise<T>;
|
|
23
|
-
|
|
24
|
-
public useLoading<T>(cb: () => (T | Promise<T>), exclusive: boolean | 'throw' = false): Promise<T | false> {
|
|
25
|
-
return withLoading(this, cb, exclusive as any);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
public reset = () => this._number.reset();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function withLoading<T>(model: IValueModel<boolean>, cb: () => (T | Promise<T>)): Promise<T>;
|
|
32
|
-
export function withLoading<T>(model: IValueModel<boolean>, cb: () => (T | Promise<T>), exclusive: false): Promise<T>;
|
|
33
|
-
export function withLoading<T>(model: IValueModel<boolean>, cb: () => (T | Promise<T>), exclusive: true): Promise<T | false>;
|
|
34
|
-
export function withLoading<T>(model: IValueModel<boolean>, cb: () => (T | Promise<T>), exclusive: 'throw'): Promise<T>;
|
|
35
|
-
|
|
36
|
-
export async function withLoading<T>(this: void, model: IValueModel<boolean>, cb: () => (T | Promise<T>), exclusive: boolean | 'throw' = false): Promise<T | false> {
|
|
37
|
-
if (exclusive && model.value) {
|
|
38
|
-
if (exclusive === 'throw') {
|
|
39
|
-
throw new Error('Operation cannot be started because another one is in progress already.');
|
|
40
|
-
}
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
model.value = true;
|
|
45
|
-
|
|
46
|
-
try {
|
|
47
|
-
const res = await cb();
|
|
48
|
-
return res;
|
|
49
|
-
} finally {
|
|
50
|
-
model.value = false;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import { createLazy } from '../lazy/light';
|
|
2
|
-
import { action, computed, makeObservable, observable, reaction } from 'mobx';
|
|
3
|
-
import { FlagModel, ILabeledFlagModel } from './FlagModel';
|
|
4
|
-
import { ValidatableModel } from './Validatable';
|
|
5
|
-
import { IValueModel } from './types';
|
|
6
|
-
import { withLabel } from './wrappers';
|
|
7
|
-
import { ICountableModel, IResetableModel } from 'viewModels';
|
|
8
|
-
import { arraysCompareDistinct } from '../math';
|
|
9
|
-
|
|
10
|
-
export class MultiSelect<T = any> extends ValidatableModel<ReadonlyArray<T>> implements IValueModel<readonly string[]>, IResetableModel, ICountableModel {
|
|
11
|
-
|
|
12
|
-
// @observable
|
|
13
|
-
private readonly _indexes = new Set<number>();
|
|
14
|
-
|
|
15
|
-
public readonly opened = new FlagModel();
|
|
16
|
-
private readonly _initial: number[] = null;
|
|
17
|
-
|
|
18
|
-
private readonly _flags = createLazy(() => this.createFlags());
|
|
19
|
-
private _indexesLocked = false;
|
|
20
|
-
|
|
21
|
-
constructor(
|
|
22
|
-
private readonly _items: readonly T[],
|
|
23
|
-
private readonly _accessor: (item: T) => string,
|
|
24
|
-
...selected: number[]
|
|
25
|
-
) {
|
|
26
|
-
super();
|
|
27
|
-
makeObservable<MultiSelect<T>, '_indexes'>(this, {
|
|
28
|
-
'_indexes': observable,
|
|
29
|
-
selectedIndexes: computed,
|
|
30
|
-
values: computed,
|
|
31
|
-
selectedItems: computed,
|
|
32
|
-
selectedValues: computed,
|
|
33
|
-
isDefault: computed,
|
|
34
|
-
selectItems: action,
|
|
35
|
-
selectValues: action,
|
|
36
|
-
setIndexSelected: action,
|
|
37
|
-
});
|
|
38
|
-
this._initial = selected;
|
|
39
|
-
this.setInitialIndexes();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// @computed
|
|
43
|
-
get selectedIndexes(): ReadonlyArray<number> { return Array.from(this._indexes); }
|
|
44
|
-
|
|
45
|
-
get items(): ReadonlyArray<T> { return this._items; }
|
|
46
|
-
|
|
47
|
-
get flags() { return this._flags.value; }
|
|
48
|
-
|
|
49
|
-
// @computed
|
|
50
|
-
get values(): ReadonlyArray<string> {
|
|
51
|
-
return this._items.map(i => this._accessor(i));
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// @computed
|
|
55
|
-
get selectedItems(): ReadonlyArray<T> {
|
|
56
|
-
return this.selectedIndexes.map(i => this._items[i]);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// @computed
|
|
60
|
-
get selectedValues(): ReadonlyArray<string> {
|
|
61
|
-
const values = this.values;
|
|
62
|
-
return this.selectedIndexes.map(i => values[i]);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
get value() { return this.selectedValues; }
|
|
66
|
-
set value(v: readonly string[]) { this.selectValues(v); }
|
|
67
|
-
|
|
68
|
-
isIndexSelected(index: number) { return this._indexes.has(index); }
|
|
69
|
-
isValueSelected(value: string) { return this.selectedValues.includes(value); }
|
|
70
|
-
|
|
71
|
-
get count() { return this._items.length; }
|
|
72
|
-
get selectedCount() { return this._indexes.size; }
|
|
73
|
-
get isEmpty() { return this.selectedCount === 0; }
|
|
74
|
-
|
|
75
|
-
// @computed
|
|
76
|
-
get isDefault() { return arraysCompareDistinct(this.selectedIndexes, this._initial)?.diff === 0; }
|
|
77
|
-
|
|
78
|
-
protected get valueToValidate() { return this.selectedItems; }
|
|
79
|
-
|
|
80
|
-
setItemSelected = (item: T, selected: boolean) => {
|
|
81
|
-
const i = this.items.indexOf(item);
|
|
82
|
-
if (i >= 0) {
|
|
83
|
-
this.setIndexSelected(i, selected);
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
selectItem = (item: T) => this.setItemSelected(item, true);
|
|
88
|
-
deSelectItem = (item: T) => this.setItemSelected(item, false);
|
|
89
|
-
|
|
90
|
-
// @action
|
|
91
|
-
selectItems = (items: readonly T[]) => {
|
|
92
|
-
items.forEach(this.selectItem);
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
setValueSelected = (value: string, selected: boolean) => {
|
|
96
|
-
const i = this.values.indexOf(value);
|
|
97
|
-
if (i >= 0) {
|
|
98
|
-
this.setIndexSelected(i, selected);
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
selectValue = (value: string) => this.setValueSelected(value, true);
|
|
103
|
-
deSelectValue = (value: string) => this.setValueSelected(value, false);
|
|
104
|
-
|
|
105
|
-
// @action
|
|
106
|
-
selectValues = (values: readonly string[]) => {
|
|
107
|
-
values.forEach(this.selectValue);
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
// @action
|
|
111
|
-
setIndexSelected = (index: number, selected: boolean) => {
|
|
112
|
-
if (this._indexesLocked) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (selected) {
|
|
117
|
-
this._indexes.add(index);
|
|
118
|
-
} else {
|
|
119
|
-
this._indexes.delete(index);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (this._validateOnChange) {
|
|
123
|
-
this.validate();
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (!this._flags.hasValue) {
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
try {
|
|
131
|
-
this._indexesLocked = true;
|
|
132
|
-
this._flags.value[index].value = selected;
|
|
133
|
-
} finally {
|
|
134
|
-
this._indexesLocked = false;
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
selectIndex = (index: number) => this.setIndexSelected(index, true);
|
|
139
|
-
deSelectIndex = (index: number) => this.setIndexSelected(index, false);
|
|
140
|
-
|
|
141
|
-
reset = () => {
|
|
142
|
-
super.reset();
|
|
143
|
-
this.setInitialIndexes();
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
private setInitialIndexes() {
|
|
147
|
-
this._indexes.clear();
|
|
148
|
-
this._initial.forEach(i => this._indexes.add(i));
|
|
149
|
-
|
|
150
|
-
if (this._flags.hasValue) {
|
|
151
|
-
this._flags.value.forEach((flag, index) => flag.value = this._indexes.has(index));
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
private createFlags() {
|
|
156
|
-
const flags: ReadonlyArray<ILabeledFlagModel> = this._items
|
|
157
|
-
.map((item, index) => {
|
|
158
|
-
const flag = withLabel(
|
|
159
|
-
new FlagModel(this._indexes.has(index)),
|
|
160
|
-
() => this._accessor(item),
|
|
161
|
-
);
|
|
162
|
-
|
|
163
|
-
// react on every flag is changed directly
|
|
164
|
-
reaction(() => flag.value, isSelected => {
|
|
165
|
-
this.setIndexSelected(index, isSelected);
|
|
166
|
-
});
|
|
167
|
-
return flag;
|
|
168
|
-
});
|
|
169
|
-
return flags;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
export class MultiSelectString<T extends string = string> extends MultiSelect<T> {
|
|
174
|
-
|
|
175
|
-
constructor(items: ReadonlyArray<T>, ...selected: number[]) {
|
|
176
|
-
super(items, v => v, ...selected);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { action, makeObservable, observable } from 'mobx';
|
|
2
|
-
import { IResetableModel } from 'viewModels';
|
|
3
|
-
import { IValueModel } from './types';
|
|
4
|
-
|
|
5
|
-
export interface INumberModel extends IResetableModel {
|
|
6
|
-
value: number;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export class NumberModel implements INumberModel, IValueModel<number> {
|
|
10
|
-
|
|
11
|
-
// @observable
|
|
12
|
-
private _value: number = 0;
|
|
13
|
-
|
|
14
|
-
private _initial: number = 0;
|
|
15
|
-
|
|
16
|
-
constructor(initial: number = 0) {
|
|
17
|
-
makeObservable<NumberModel, '_value'>(this, {
|
|
18
|
-
_value: observable,
|
|
19
|
-
setValue: action,
|
|
20
|
-
reset: action,
|
|
21
|
-
increment: action,
|
|
22
|
-
decrement: action,
|
|
23
|
-
});
|
|
24
|
-
this._initial = initial;
|
|
25
|
-
this._value = this._initial;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
get value() { return this._value; }
|
|
29
|
-
set value(v: number) { this.setValue(v); }
|
|
30
|
-
|
|
31
|
-
// @action
|
|
32
|
-
public readonly setValue = (v: number) => {
|
|
33
|
-
this._value = v;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
get isDefault() { return this._value === this._initial; }
|
|
37
|
-
|
|
38
|
-
// @action
|
|
39
|
-
reset = () => {
|
|
40
|
-
this._value = this._initial;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
// @action
|
|
44
|
-
increment = (d = 1) => this.value += d;
|
|
45
|
-
|
|
46
|
-
// @action
|
|
47
|
-
decrement = (d = 1) => this.value -= d;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export default NumberModel;
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { observable, makeObservable, action } from 'mobx';
|
|
2
|
-
import { FlagModel } from './FlagModel';
|
|
3
|
-
|
|
4
|
-
export type BaseModalAction = {
|
|
5
|
-
title?: string;
|
|
6
|
-
message?: string;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export class ModalActionModel<T extends BaseModalAction = BaseModalAction> {
|
|
10
|
-
public readonly isActive = new FlagModel();
|
|
11
|
-
|
|
12
|
-
@observable.ref
|
|
13
|
-
private _currentAction: T = null;
|
|
14
|
-
|
|
15
|
-
constructor() {
|
|
16
|
-
makeObservable(this);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
get currentAction() { return this._currentAction; }
|
|
20
|
-
|
|
21
|
-
@action
|
|
22
|
-
public openModal = (action: T) => {
|
|
23
|
-
this._currentAction = action;
|
|
24
|
-
this.isActive.value = true;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
@action
|
|
28
|
-
public closeModal = () => {
|
|
29
|
-
this.isActive.value = false;
|
|
30
|
-
this._currentAction = null;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
protected runAction = async (cb: () => Promise<void> | void, close = true, awaitAction = false) => {
|
|
34
|
-
if (cb) {
|
|
35
|
-
const promise = cb();
|
|
36
|
-
if (awaitAction) {
|
|
37
|
-
await promise;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (close) {
|
|
42
|
-
this.closeModal();
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export type PromptModalAction = BaseModalAction & {
|
|
48
|
-
confirmText?: string;
|
|
49
|
-
rejectText?: string;
|
|
50
|
-
onConfirm?: () => Promise<void> | void;
|
|
51
|
-
onReject?: () => Promise<void> | void;
|
|
52
|
-
awaitActions?: boolean;
|
|
53
|
-
modalImage?: any;
|
|
54
|
-
confirmColor?: string;
|
|
55
|
-
rejectColor?: string;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export class PromptModalViewModel extends ModalActionModel<PromptModalAction> {
|
|
59
|
-
get confirmColor() { return this.currentAction.confirmColor; }
|
|
60
|
-
|
|
61
|
-
get rejectColor() { return this.currentAction.rejectColor; }
|
|
62
|
-
|
|
63
|
-
onConfirm = () => this.runAction(this.currentAction.onConfirm, true, this.currentAction.awaitActions);
|
|
64
|
-
onReject = () => this.runAction(this.currentAction.onReject, true, this.currentAction.awaitActions);
|
|
65
|
-
}
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import { observable, computed, makeObservable, reaction, action } from 'mobx';
|
|
2
|
-
import { createLazy } from '../lazy/light';
|
|
3
|
-
import { FlagModel, ILabeledFlagModel } from './FlagModel';
|
|
4
|
-
import { ValidatableModel } from './Validatable';
|
|
5
|
-
import { IValueModel } from './types';
|
|
6
|
-
import { withLabel } from './wrappers';
|
|
7
|
-
import { IResetableModel } from './types';
|
|
8
|
-
import { Getter } from '../types';
|
|
9
|
-
|
|
10
|
-
export class Select<T = any> extends ValidatableModel<T> implements IValueModel<string>, IResetableModel {
|
|
11
|
-
// @observable
|
|
12
|
-
private _index: number = undefined;
|
|
13
|
-
|
|
14
|
-
private readonly _items: Getter<readonly T[]>;
|
|
15
|
-
|
|
16
|
-
private _indexLocked = false;
|
|
17
|
-
private _initialIndex: number = null;
|
|
18
|
-
|
|
19
|
-
private readonly _flags = createLazy(() => this.createFlags());
|
|
20
|
-
|
|
21
|
-
public readonly opened = new FlagModel();
|
|
22
|
-
|
|
23
|
-
constructor(
|
|
24
|
-
items: Getter<readonly T[]>,
|
|
25
|
-
private readonly _accessor: (item: T) => string,
|
|
26
|
-
initialIndex: number = 0,
|
|
27
|
-
) {
|
|
28
|
-
super();
|
|
29
|
-
|
|
30
|
-
this._items = items;
|
|
31
|
-
|
|
32
|
-
makeObservable<Select<T>, '_index' | '_items'>(this, {
|
|
33
|
-
'_index': observable,
|
|
34
|
-
'_items': observable.ref,
|
|
35
|
-
values: computed,
|
|
36
|
-
items: computed,
|
|
37
|
-
setIndex: action,
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
this._initialIndex = initialIndex;
|
|
41
|
-
this._index = initialIndex;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
protected get valueToValidate() { return this.selectedItem; }
|
|
45
|
-
|
|
46
|
-
// @computed
|
|
47
|
-
get values(): readonly string[] {
|
|
48
|
-
return this.items.map(i => this._accessor(i));
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
get flags() {
|
|
52
|
-
return this._flags.value;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// @computed
|
|
56
|
-
get items(): readonly T[] {
|
|
57
|
-
return Getter.getValue(this._items);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
get value() { return this.selectedValue; }
|
|
61
|
-
get selectedValue() {
|
|
62
|
-
const vs = this.values;
|
|
63
|
-
return vs.length ? vs[this._index] : null;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
set value(v: string) { this.selectedValue = v; }
|
|
67
|
-
set selectedValue(value: string) {
|
|
68
|
-
const index = this.values.indexOf(value);
|
|
69
|
-
if (index >= 0) {
|
|
70
|
-
this.index = index;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
get selectedItem(): T {
|
|
75
|
-
const items = this.items;
|
|
76
|
-
return items.length ? items[this._index] : null;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
set selectedItem(item: T) {
|
|
80
|
-
const index = this.items.indexOf(item);
|
|
81
|
-
if (index >= 0) {
|
|
82
|
-
this.index = index;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
get isDefault() { return this._index === this._initialIndex; }
|
|
87
|
-
|
|
88
|
-
get index() {
|
|
89
|
-
return this._index;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
set index(val: number) {
|
|
93
|
-
this.setIndex(val);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// @action
|
|
97
|
-
public setIndex = (val: number) => {
|
|
98
|
-
if (this._indexLocked) {
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
this._index = val;
|
|
103
|
-
|
|
104
|
-
if (this._validateOnChange) {
|
|
105
|
-
this.validate();
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// update all flags to be properly selected
|
|
109
|
-
try {
|
|
110
|
-
this._indexLocked = true;
|
|
111
|
-
|
|
112
|
-
if (this._flags.hasValue) {
|
|
113
|
-
this._flags.value.forEach((f, i) => f.value = (i === this._index));
|
|
114
|
-
}
|
|
115
|
-
} finally {
|
|
116
|
-
this._indexLocked = false;
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
public reset = () => {
|
|
121
|
-
super.reset();
|
|
122
|
-
this.index = this._initialIndex;
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
private createFlags() {
|
|
126
|
-
const flags: ReadonlyArray<ILabeledFlagModel> = this.items
|
|
127
|
-
.map((item, index) => {
|
|
128
|
-
const flag: ILabeledFlagModel = withLabel(
|
|
129
|
-
new FlagModel(index === this.index),
|
|
130
|
-
() => this._accessor(item),
|
|
131
|
-
);
|
|
132
|
-
|
|
133
|
-
// react on every flag is changed directly
|
|
134
|
-
reaction(() => flag.value, isSelected => {
|
|
135
|
-
if (isSelected) {
|
|
136
|
-
this.index = index;
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
return flag;
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
return flags;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
export class SelectString<T extends string = string> extends Select<T> {
|
|
149
|
-
constructor(items: readonly T[], initialIndex: number = 0) {
|
|
150
|
-
super(items, v => v, initialIndex);
|
|
151
|
-
}
|
|
152
|
-
}
|