@kaspernj/api-maker 1.0.2011 → 1.0.2013
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.cjs → .eslintrc.js} +10 -1
- package/README.md +35 -0
- package/android/build.gradle +43 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/expo/modules/api_maker/ApiMakerModule.kt +50 -0
- package/android/src/main/java/expo/modules/api_maker/ApiMakerView.kt +30 -0
- package/build/api.js +120 -0
- package/build/attribute-not-loaded-error.js +2 -0
- package/build/base-component.js +5 -0
- package/build/base-error.js +33 -0
- package/build/base-model/attribute.js +25 -0
- package/build/base-model/column.js +11 -0
- package/build/base-model/reflection.js +14 -0
- package/build/base-model/scope.js +11 -0
- package/build/base-model.js +828 -0
- package/build/bootstrap/attribute-row.js +135 -0
- package/build/bootstrap/attribute-rows.js +31 -0
- package/build/bootstrap/card.js +138 -0
- package/build/bootstrap/checkbox.js +97 -0
- package/build/bootstrap/checkboxes.js +183 -0
- package/build/bootstrap/index.js +2 -0
- package/build/bootstrap/input.js +129 -0
- package/build/bootstrap/invalid-feedback.js +27 -0
- package/build/bootstrap/paginate.js +150 -0
- package/build/bootstrap/radio-buttons.js +72 -0
- package/build/bootstrap/select.js +88 -0
- package/build/bootstrap/sort-link.js +131 -0
- package/build/cable-connection-pool.js +128 -0
- package/build/cable-subscription-pool.js +207 -0
- package/build/cable-subscription.js +21 -0
- package/build/cache-key-generator.js +81 -0
- package/build/can-can.js +134 -0
- package/build/channels-consumer.js +9 -0
- package/build/collection-loader.js +48 -0
- package/build/collection.js +280 -0
- package/build/command-submit-data.js +81 -0
- package/build/commands-pool.js +195 -0
- package/build/compose.js +9 -0
- package/build/config.js +62 -0
- package/build/custom-error.js +5 -0
- package/build/data-set-to-attributes.js +10 -0
- package/build/deserializer.js +56 -0
- package/build/destroy-error.js +5 -0
- package/build/devise.js +112 -0
- package/build/draggable-sort/controller.js +136 -0
- package/build/draggable-sort/index.js +114 -0
- package/build/draggable-sort/item.js +188 -0
- package/build/error-logger.js +101 -0
- package/build/error-messages.js +13 -0
- package/build/event-connection.js +32 -0
- package/build/event-emitter-listener.js +15 -0
- package/build/event-model-class.js +24 -0
- package/build/events.js +5 -0
- package/build/flash-message.js +79 -0
- package/build/form.js +83 -0
- package/build/history-expo.js +20 -0
- package/build/history-react-native.js +20 -0
- package/build/history.js +3 -0
- package/build/index.js +3 -0
- package/build/inputs/attachment.js +133 -0
- package/build/inputs/auto-submit.js +36 -0
- package/build/inputs/checkbox.js +138 -0
- package/build/inputs/checkboxes.js +112 -0
- package/build/inputs/id-for-component.js +15 -0
- package/build/inputs/input-wrapper.js +19 -0
- package/build/inputs/input.js +243 -0
- package/build/inputs/money.js +179 -0
- package/build/inputs/name-for-component.js +13 -0
- package/build/inputs/select.js +93 -0
- package/build/instance-of-class-name.js +23 -0
- package/build/is-expo.js +22 -0
- package/build/key-value-store.js +53 -0
- package/build/link.js +73 -0
- package/build/logger.js +30 -0
- package/build/modal.js +38 -0
- package/build/model-class-require.js +13 -0
- package/build/model-events.js +30 -0
- package/build/model-name.js +28 -0
- package/build/model-prop-type.js +101 -0
- package/build/model-recipes-loader.js +32 -0
- package/build/model-recipes-model-loader.js +357 -0
- package/build/models-response-reader.js +40 -0
- package/build/models.js +8 -0
- package/build/money-formatter.js +78 -0
- package/build/not-loaded-error.js +2 -0
- package/build/params.js +61 -0
- package/build/preloaded.js +38 -0
- package/build/resize-observer.js +11 -0
- package/build/result.js +13 -0
- package/build/router/route.js +270 -0
- package/build/router/switch.js +72 -0
- package/build/router.js +59 -0
- package/build/routes-native.js +202 -0
- package/build/routes.js +50 -0
- package/build/run-last.js +35 -0
- package/build/serializer.js +63 -0
- package/build/services.js +20 -0
- package/build/session-status-updater.js +134 -0
- package/build/source-maps-loader.js +184 -0
- package/build/super-admin/config-reader.js +85 -0
- package/build/super-admin/edit-page/edit-attribute-checkbox.js +85 -0
- package/build/super-admin/edit-page/edit-attribute-content.js +55 -0
- package/build/super-admin/edit-page/edit-attribute-input.js +79 -0
- package/build/super-admin/edit-page/edit-attribute.js +77 -0
- package/build/super-admin/edit-page.js +123 -0
- package/build/super-admin/has-edit-config.js +12 -0
- package/build/super-admin/index-page.js +25 -0
- package/build/super-admin/index.js +181 -0
- package/build/super-admin/layout/header/index.js +161 -0
- package/build/super-admin/layout/index.js +164 -0
- package/build/super-admin/layout/menu/index.js +206 -0
- package/build/super-admin/layout/menu/menu-content.js +46 -0
- package/build/super-admin/layout/menu/menu-item.js +84 -0
- package/build/super-admin/layout/no-access.js +27 -0
- package/build/super-admin/model-class-table.js +61 -0
- package/build/super-admin/models.js +8 -0
- package/build/super-admin/show-nav.js +51 -0
- package/build/super-admin/show-page/belongs-to-attribute-row.js +29 -0
- package/build/super-admin/show-page/index.js +141 -0
- package/build/super-admin/show-reflection-actions.js +47 -0
- package/build/super-admin/show-reflection-link.js +48 -0
- package/build/super-admin/show-reflection-page.js +48 -0
- package/build/table/column-content.js +117 -0
- package/build/table/column-identifier.js +18 -0
- package/build/table/column-visible.js +7 -0
- package/build/table/components/column.js +21 -0
- package/build/table/components/flat-list.js +21 -0
- package/build/table/components/header.js +26 -0
- package/build/table/components/row.js +26 -0
- package/build/table/filters/attribute-element.js +44 -0
- package/build/table/filters/filter-form.js +402 -0
- package/build/table/filters/filter.js +90 -0
- package/build/table/filters/index.js +184 -0
- package/build/table/filters/load-search-modal.js +175 -0
- package/build/table/filters/reflection-element.js +37 -0
- package/build/table/filters/save-search-modal.js +88 -0
- package/build/table/filters/scope-element.js +42 -0
- package/build/table/header-column-content.js +68 -0
- package/build/table/header-column.js +144 -0
- package/build/table/header-select.js +105 -0
- package/build/table/model-callback-args.js +10 -0
- package/build/table/model-column.js +97 -0
- package/build/table/model-row.js +193 -0
- package/build/table/select-calculator.js +63 -0
- package/build/table/settings/column-row.js +97 -0
- package/build/table/settings/download-action.js +79 -0
- package/build/table/settings/index.js +92 -0
- package/build/table/table-settings.js +219 -0
- package/build/table/table.js +972 -0
- package/build/table/use-sorting.js +34 -0
- package/build/table/widths.js +75 -0
- package/build/table/worker-plugins-check-all-checkbox.js +125 -0
- package/build/table/worker-plugins-checkbox.js +115 -0
- package/build/translated-attributes.js +10 -0
- package/build/translated-collections.js +12 -0
- package/build/updated-attribute.js +76 -0
- package/build/url-encode.js +15 -0
- package/build/use-breakpoint.js +71 -0
- package/build/use-can-can.js +55 -0
- package/build/use-collection.js +225 -0
- package/build/use-created-event.js +52 -0
- package/build/use-current-user.js +76 -0
- package/build/use-destroyed-event.js +60 -0
- package/build/use-event-emitter.js +13 -0
- package/build/use-event-listener.js +16 -0
- package/build/use-input.js +137 -0
- package/build/use-model-event.js +60 -0
- package/build/use-model.js +169 -0
- package/build/use-resize-observer.js +23 -0
- package/build/use-router.js +104 -0
- package/build/use-screen-layout.js +39 -0
- package/build/use-styles.js +41 -0
- package/build/use-updated-event.js +60 -0
- package/build/use-validation-errors.js +30 -0
- package/build/utils/card.js +51 -0
- package/build/utils/checkbox.js +78 -0
- package/build/utils/checkboxes.js +163 -0
- package/build/utils/default-style.js +18 -0
- package/build/utils/icon.js +23 -0
- package/build/utils/invalid-feedback.js +19 -0
- package/build/utils/modal.js +62 -0
- package/build/utils/text.js +44 -0
- package/build/validation-error.js +28 -0
- package/build/validation-errors.js +98 -0
- package/build/with-api-maker.js +29 -0
- package/build/with-collection.js +14 -0
- package/build/with-current-user.js +10 -0
- package/build/with-model.js +15 -0
- package/build/with-router.js +22 -0
- package/expo-module.config.json +17 -0
- package/ios/ApiMaker.podspec +29 -0
- package/ios/ApiMakerModule.swift +48 -0
- package/ios/ApiMakerView.swift +38 -0
- package/package.json +49 -46
- package/src/{api.mjs → api.js} +38 -37
- package/src/base-component.jsx +5 -0
- package/src/{base-error.mjs → base-error.js} +4 -6
- package/src/base-model/attribute.js +33 -0
- package/src/base-model/column.js +13 -0
- package/src/base-model/reflection.js +15 -0
- package/src/base-model/scope.js +12 -0
- package/src/{base-model.mjs → base-model.js} +302 -144
- package/src/bootstrap/attribute-row.jsx +135 -0
- package/src/bootstrap/attribute-rows.jsx +27 -0
- package/src/bootstrap/card.jsx +149 -0
- package/src/bootstrap/checkbox.jsx +86 -0
- package/src/bootstrap/checkboxes.jsx +185 -0
- package/src/bootstrap/index.js +0 -0
- package/src/bootstrap/input.jsx +173 -0
- package/src/bootstrap/invalid-feedback.jsx +31 -0
- package/src/bootstrap/paginate.jsx +187 -0
- package/src/bootstrap/radio-buttons.jsx +87 -0
- package/src/bootstrap/select.jsx +110 -0
- package/src/bootstrap/sort-link.jsx +106 -0
- package/src/{cable-connection-pool.mjs → cable-connection-pool.js} +16 -36
- package/src/{cable-subscription-pool.mjs → cable-subscription-pool.js} +26 -21
- package/src/{cable-subscription.mjs → cable-subscription.js} +6 -4
- package/src/cache-key-generator.js +100 -0
- package/src/{can-can.mjs → can-can.js} +13 -12
- package/src/channels-consumer.js +10 -0
- package/src/collection-loader.jsx +58 -224
- package/src/{collection.mjs → collection.js} +98 -44
- package/src/{command-submit-data.mjs → command-submit-data.js} +2 -7
- package/src/{commands-pool.mjs → commands-pool.js} +57 -41
- package/src/compose.js +11 -0
- package/src/{config.mjs → config.js} +6 -2
- package/src/{custom-error.mjs → custom-error.js} +1 -1
- package/src/data-set-to-attributes.js +13 -0
- package/src/{deserializer.mjs → deserializer.js} +3 -3
- package/src/destroy-error.js +7 -0
- package/src/devise.js +129 -0
- package/src/draggable-sort/controller.js +137 -0
- package/src/draggable-sort/index.jsx +108 -0
- package/src/draggable-sort/item.jsx +174 -0
- package/src/{error-logger.mjs → error-logger.js} +12 -7
- package/src/{error-messages.mjs → error-messages.js} +1 -0
- package/src/event-connection.jsx +1 -1
- package/src/event-emitter-listener.jsx +8 -27
- package/src/event-model-class.jsx +2 -4
- package/src/events.js +7 -0
- package/src/flash-message.js +70 -0
- package/src/form.jsx +91 -0
- package/src/history-expo.js +23 -0
- package/src/history-react-native.js +25 -0
- package/src/history.js +3 -0
- package/src/index.js +3 -0
- package/src/inputs/attachment.jsx +108 -0
- package/src/inputs/auto-submit.js +37 -0
- package/src/inputs/checkbox.jsx +125 -0
- package/src/inputs/checkboxes.jsx +116 -0
- package/src/inputs/id-for-component.js +15 -0
- package/src/inputs/input-wrapper.jsx +16 -0
- package/src/inputs/input.jsx +260 -0
- package/src/inputs/money.jsx +187 -0
- package/src/inputs/name-for-component.js +15 -0
- package/src/inputs/select.jsx +104 -0
- package/src/is-expo.js +18 -0
- package/src/{key-value-store.mjs → key-value-store.js} +1 -1
- package/src/link.jsx +54 -9
- package/src/logger.js +38 -0
- package/src/modal.jsx +37 -0
- package/src/model-class-require.js +17 -0
- package/src/{model-events.mjs → model-events.js} +1 -1
- package/src/{model-name.mjs → model-name.js} +8 -8
- package/src/{model-recipes-loader.mjs → model-recipes-loader.js} +1 -1
- package/src/{model-recipes-model-loader.mjs → model-recipes-model-loader.js} +5 -5
- package/src/{models-response-reader.mjs → models-response-reader.js} +3 -4
- package/src/models.js +7 -0
- package/src/{models.mjs.erb → models.js.erb} +6 -3
- package/src/{money-formatter.mjs → money-formatter.js} +5 -4
- package/src/{params.mjs → params.js} +17 -7
- package/src/{preloaded.mjs → preloaded.js} +2 -2
- package/src/resize-observer.jsx +10 -0
- package/src/result.js +13 -0
- package/src/router/route.jsx +246 -0
- package/src/router/switch.jsx +76 -0
- package/src/router.jsx +23 -21
- package/src/{routes-native.mjs → routes-native.js} +12 -6
- package/src/{routes.mjs → routes.js} +1 -1
- package/src/run-last.js +39 -0
- package/src/{serializer.mjs → serializer.js} +2 -2
- package/src/{services.mjs → services.js} +1 -1
- package/src/session-status-updater.js +172 -0
- package/src/{source-maps-loader.mjs → source-maps-loader.js} +54 -28
- package/src/super-admin/config-reader.jsx +93 -0
- package/src/super-admin/edit-page/edit-attribute-checkbox.jsx +81 -0
- package/src/super-admin/edit-page/edit-attribute-content.jsx +57 -0
- package/src/super-admin/edit-page/edit-attribute-input.jsx +71 -0
- package/src/super-admin/edit-page/edit-attribute.jsx +81 -0
- package/src/super-admin/edit-page.jsx +117 -0
- package/src/super-admin/has-edit-config.js +15 -0
- package/src/super-admin/index-page.jsx +23 -0
- package/src/super-admin/index.jsx +197 -0
- package/src/super-admin/layout/header/index.jsx +144 -0
- package/src/super-admin/layout/header/style.scss +45 -0
- package/src/super-admin/layout/index.jsx +154 -0
- package/src/super-admin/layout/menu/index.jsx +171 -0
- package/src/super-admin/layout/menu/menu-content.jsx +43 -0
- package/src/super-admin/layout/menu/menu-item.jsx +70 -0
- package/src/super-admin/layout/menu/style.scss +11 -0
- package/src/super-admin/layout/no-access.jsx +26 -0
- package/src/super-admin/model-class-table.jsx +66 -0
- package/src/super-admin/models.js +11 -0
- package/src/super-admin/show-nav.jsx +44 -0
- package/src/super-admin/show-page/belongs-to-attribute-row.jsx +30 -0
- package/src/super-admin/show-page/index.jsx +141 -0
- package/src/super-admin/show-reflection-actions.jsx +49 -0
- package/src/super-admin/show-reflection-link.jsx +40 -0
- package/src/super-admin/show-reflection-page.jsx +47 -0
- package/src/super-admin/stylesheets/variables.scss +11 -0
- package/src/table/column-content.jsx +122 -0
- package/src/table/column-identifier.js +23 -0
- package/src/table/column-visible.js +7 -0
- package/src/table/components/column.jsx +19 -0
- package/src/table/components/flat-list.jsx +19 -0
- package/src/table/components/header.jsx +21 -0
- package/src/table/components/row.jsx +23 -0
- package/src/table/filters/attribute-element.jsx +47 -0
- package/src/table/filters/filter-form.jsx +407 -0
- package/src/table/filters/filter.jsx +70 -0
- package/src/table/filters/index.jsx +170 -0
- package/src/table/filters/load-search-modal.jsx +146 -0
- package/src/table/filters/reflection-element.jsx +38 -0
- package/src/table/filters/save-search-modal.jsx +74 -0
- package/src/table/filters/scope-element.jsx +44 -0
- package/src/table/header-column-content.jsx +55 -0
- package/src/table/header-column.jsx +129 -0
- package/src/table/header-select.jsx +73 -0
- package/src/table/model-callback-args.js +10 -0
- package/src/table/model-column.jsx +82 -0
- package/src/table/model-row.jsx +136 -0
- package/src/table/select-calculator.js +65 -0
- package/src/table/settings/column-row.jsx +93 -0
- package/src/table/settings/download-action.jsx +68 -0
- package/src/table/settings/index.jsx +65 -0
- package/src/table/table-settings.js +263 -0
- package/src/table/table.jsx +950 -0
- package/src/table/use-sorting.js +35 -0
- package/src/table/variables.scss +11 -0
- package/src/table/widths.jsx +87 -0
- package/src/table/worker-plugins-check-all-checkbox.jsx +112 -0
- package/src/table/worker-plugins-checkbox.jsx +104 -0
- package/src/translated-attributes.js +11 -0
- package/src/{translated-collections.mjs → translated-collections.js} +3 -2
- package/src/updated-attribute.jsx +1 -1
- package/src/url-encode.js +18 -0
- package/src/use-breakpoint.js +87 -0
- package/src/use-can-can.js +55 -0
- package/src/use-collection.js +280 -0
- package/src/use-created-event.js +55 -0
- package/src/use-current-user.js +88 -0
- package/src/use-destroyed-event.js +60 -0
- package/src/use-event-emitter.js +15 -0
- package/src/use-event-listener.js +19 -0
- package/src/use-input.js +157 -0
- package/src/use-model-event.js +60 -0
- package/src/use-model.js +189 -0
- package/src/use-resize-observer.js +24 -0
- package/src/use-router.jsx +128 -0
- package/src/use-screen-layout.js +49 -0
- package/src/use-styles.js +50 -0
- package/src/use-updated-event.js +60 -0
- package/src/use-validation-errors.js +33 -0
- package/src/utils/card.jsx +49 -0
- package/src/utils/checkbox.jsx +80 -0
- package/src/utils/checkboxes.jsx +158 -0
- package/src/utils/default-style.jsx +25 -0
- package/src/utils/icon.jsx +21 -0
- package/src/utils/invalid-feedback.jsx +20 -0
- package/src/utils/modal.jsx +60 -0
- package/src/utils/text.jsx +38 -0
- package/src/{validation-error.mjs → validation-error.js} +9 -5
- package/src/{validation-errors.mjs → validation-errors.js} +15 -27
- package/src/with-api-maker.jsx +31 -0
- package/src/with-collection.jsx +17 -0
- package/src/with-current-user.jsx +7 -25
- package/src/with-model.jsx +16 -0
- package/src/with-router.jsx +7 -129
- package/__tests__/base-model.test.js +0 -71
- package/__tests__/cable-connection-pool.test.js +0 -227
- package/__tests__/cable-subscription-pool.test.js +0 -26
- package/__tests__/can-can.test.js +0 -34
- package/__tests__/collection.test.js +0 -51
- package/__tests__/custom-error.test.js +0 -13
- package/__tests__/model-name.test.js +0 -34
- package/__tests__/model-prop-type.test.js +0 -113
- package/__tests__/params.test.js +0 -40
- package/__tests__/routes-native.test.js +0 -103
- package/__tests__/routes.test.js +0 -46
- package/__tests__/serializer.test.js +0 -30
- package/__tests__/support/task.js +0 -27
- package/__tests__/support/user.js +0 -32
- package/index.js +0 -1
- package/jest.config.js +0 -4
- package/src/can-can-loader.jsx +0 -54
- package/src/channels-consumer.mjs +0 -3
- package/src/destroy-error.mjs +0 -7
- package/src/devise.mjs +0 -122
- package/src/event-created.jsx +0 -65
- package/src/event-destroyed.jsx +0 -29
- package/src/event-listener.jsx +0 -38
- package/src/event-updated.jsx +0 -74
- package/src/logger.mjs +0 -25
- package/src/model-class-require.mjs +0 -10
- package/src/model-load-wrapper.jsx +0 -116
- package/src/result.mjs +0 -29
- package/src/session-status-updater.mjs +0 -116
- package/webpack.config.js +0 -15
- /package/src/{attribute-not-loaded-error.mjs → attribute-not-loaded-error.js} +0 -0
- /package/src/{instance-of-class-name.mjs → instance-of-class-name.js} +0 -0
- /package/src/{model-prop-type.mjs → model-prop-type.js} +0 -0
- /package/src/{not-loaded-error.mjs → not-loaded-error.js} +0 -0
- /package/src/{translated-collections-data.mjs.erb → translated-collections-data.js.erb} +0 -0
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import AutoSubmit from "./auto-submit"
|
|
2
|
+
import BaseComponent from "../base-component"
|
|
3
|
+
import {dig, digg, digs} from "diggerize"
|
|
4
|
+
import inputWrapper from "./input-wrapper"
|
|
5
|
+
import memo from "set-state-compare/src/memo"
|
|
6
|
+
import Money from "./money"
|
|
7
|
+
import PropTypes from "prop-types"
|
|
8
|
+
import React, {useMemo, useRef} from "react"
|
|
9
|
+
import replaceall from "replaceall"
|
|
10
|
+
import {shapeComponent} from "set-state-compare/src/shape-component"
|
|
11
|
+
import strftime from "strftime"
|
|
12
|
+
import {useForm} from "../form"
|
|
13
|
+
import useI18n from "i18n-on-steroids/src/use-i18n"
|
|
14
|
+
import useUpdatedEvent from "../use-updated-event"
|
|
15
|
+
|
|
16
|
+
const ApiMakerInputsInput = memo(shapeComponent(class ApiMakerInputsInput extends BaseComponent {
|
|
17
|
+
static defaultProps = {
|
|
18
|
+
autoRefresh: false,
|
|
19
|
+
autoSubmit: false,
|
|
20
|
+
model: null,
|
|
21
|
+
localizedNumber: false
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static propTypes = {
|
|
25
|
+
attribute: PropTypes.string,
|
|
26
|
+
autoRefresh: PropTypes.bool.isRequired,
|
|
27
|
+
autoSubmit: PropTypes.bool.isRequired,
|
|
28
|
+
className: PropTypes.string,
|
|
29
|
+
formatValue: PropTypes.func,
|
|
30
|
+
id: PropTypes.string,
|
|
31
|
+
localizedNumber: PropTypes.bool.isRequired,
|
|
32
|
+
model: PropTypes.object,
|
|
33
|
+
name: PropTypes.string,
|
|
34
|
+
onChange: PropTypes.func,
|
|
35
|
+
onMatchValidationError: PropTypes.func,
|
|
36
|
+
type: PropTypes.string
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
setup() {
|
|
40
|
+
const {t} = useI18n({namespace: "js.api_maker.inputs.input"})
|
|
41
|
+
const {autoRefresh, inputProps, model} = this.p
|
|
42
|
+
const {defaultValue, name} = inputProps
|
|
43
|
+
|
|
44
|
+
this.form = useForm()
|
|
45
|
+
this.visibleInputRef = useRef()
|
|
46
|
+
this.t = t
|
|
47
|
+
|
|
48
|
+
this.useStates({
|
|
49
|
+
blankInputName: digg(inputProps, "type") == "file"
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
useMemo(() => {
|
|
53
|
+
if (name) {
|
|
54
|
+
this.tt.form?.setValue(name, defaultValue)
|
|
55
|
+
}
|
|
56
|
+
}, [])
|
|
57
|
+
|
|
58
|
+
useUpdatedEvent(model, this.tt.onModelUpdated, {active: Boolean(autoRefresh && model)})
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
render () {
|
|
62
|
+
const {
|
|
63
|
+
attribute,
|
|
64
|
+
autoRefresh,
|
|
65
|
+
autoSubmit,
|
|
66
|
+
defaultValue,
|
|
67
|
+
formatValue,
|
|
68
|
+
id,
|
|
69
|
+
inputProps,
|
|
70
|
+
inputRef,
|
|
71
|
+
localizedNumber,
|
|
72
|
+
model,
|
|
73
|
+
name,
|
|
74
|
+
onChange,
|
|
75
|
+
onErrors,
|
|
76
|
+
onMatchValidationError,
|
|
77
|
+
type,
|
|
78
|
+
wrapperOpts,
|
|
79
|
+
...restProps
|
|
80
|
+
} = this.props
|
|
81
|
+
|
|
82
|
+
const sharedProps = {
|
|
83
|
+
id: localizedNumber ? null : inputProps.id,
|
|
84
|
+
name: localizedNumber ? null : inputProps.name,
|
|
85
|
+
}
|
|
86
|
+
const ref = localizedNumber ? this.visibleInputRef : this.inputReference()
|
|
87
|
+
const {ref: inputPropsRef, ...inputPropsWithoutRef} = inputProps
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<>
|
|
91
|
+
{localizedNumber &&
|
|
92
|
+
<input
|
|
93
|
+
defaultValue={defaultValue}
|
|
94
|
+
id={inputProps.id}
|
|
95
|
+
name={this.inputName()}
|
|
96
|
+
ref={this.inputReference()}
|
|
97
|
+
type="hidden"
|
|
98
|
+
/>
|
|
99
|
+
}
|
|
100
|
+
{type == "money" &&
|
|
101
|
+
<Money
|
|
102
|
+
attribute={attribute}
|
|
103
|
+
defaultValue={this.inputDefaultValueLocalized()}
|
|
104
|
+
inputRef={this.inputReference()}
|
|
105
|
+
model={model}
|
|
106
|
+
onChange={this.onInputChanged}
|
|
107
|
+
{...inputPropsWithoutRef}
|
|
108
|
+
{...sharedProps}
|
|
109
|
+
{...restProps}
|
|
110
|
+
/>
|
|
111
|
+
}
|
|
112
|
+
{type == "textarea" &&
|
|
113
|
+
<textarea
|
|
114
|
+
defaultValue={this.inputDefaultValueLocalized()}
|
|
115
|
+
onChange={this.onInputChanged}
|
|
116
|
+
ref={ref}
|
|
117
|
+
{...inputPropsWithoutRef}
|
|
118
|
+
{...sharedProps}
|
|
119
|
+
{...restProps}
|
|
120
|
+
/>
|
|
121
|
+
}
|
|
122
|
+
{type != "money" && type != "textarea" &&
|
|
123
|
+
<input
|
|
124
|
+
defaultValue={this.inputDefaultValueLocalized()}
|
|
125
|
+
onChange={this.onInputChanged}
|
|
126
|
+
ref={ref}
|
|
127
|
+
{...inputPropsWithoutRef}
|
|
128
|
+
{...sharedProps}
|
|
129
|
+
name={localizedNumber ? null : this.inputName()}
|
|
130
|
+
{...restProps}
|
|
131
|
+
/>
|
|
132
|
+
}
|
|
133
|
+
</>
|
|
134
|
+
)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
actualValue (visibleInput) {
|
|
138
|
+
const {t} = this.tt
|
|
139
|
+
const {localizedNumber} = digs(this.props, "localizedNumber")
|
|
140
|
+
const value = digg(visibleInput, "value")
|
|
141
|
+
|
|
142
|
+
if (localizedNumber) {
|
|
143
|
+
const decimal = t("number.currency.format.separator")
|
|
144
|
+
const integerSeparator = t("number.currency.format.delimiter")
|
|
145
|
+
|
|
146
|
+
let unformatted = replaceall(integerSeparator, "", value)
|
|
147
|
+
|
|
148
|
+
unformatted = replaceall(decimal, ".", unformatted)
|
|
149
|
+
|
|
150
|
+
return unformatted
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return value
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
autoSubmit = () => new AutoSubmit({component: this}).autoSubmit()
|
|
157
|
+
|
|
158
|
+
formatValue (value) {
|
|
159
|
+
const {formatValue, type} = this.props
|
|
160
|
+
|
|
161
|
+
if (formatValue) {
|
|
162
|
+
return formatValue(value)
|
|
163
|
+
} else if (value instanceof Date && !isNaN(value.getTime())) {
|
|
164
|
+
// We need to use a certain format for datetime-local
|
|
165
|
+
if (type == "datetime-local") {
|
|
166
|
+
return strftime("%Y-%m-%dT%H:%M:%S", value)
|
|
167
|
+
} else if (type == "date") {
|
|
168
|
+
return strftime("%Y-%m-%d", value)
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return value
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
inputDefaultValueLocalized () {
|
|
176
|
+
const {t} = this.tt
|
|
177
|
+
const {defaultValue} = this.props
|
|
178
|
+
const {localizedNumber} = digs(this.props, "localizedNumber")
|
|
179
|
+
|
|
180
|
+
if (localizedNumber && defaultValue !== null && defaultValue !== undefined) {
|
|
181
|
+
const separator = t("number.currency.format.separator")
|
|
182
|
+
const delimiter = t("number.currency.format.delimiter")
|
|
183
|
+
|
|
184
|
+
let formatted = `${defaultValue}`
|
|
185
|
+
|
|
186
|
+
formatted = replaceall(".", "{{separator}}", formatted)
|
|
187
|
+
formatted = replaceall(",", "{{delimiter}}", formatted)
|
|
188
|
+
formatted = replaceall("{{separator}}", separator, formatted)
|
|
189
|
+
formatted = replaceall("{{delimiter}}", delimiter, formatted)
|
|
190
|
+
|
|
191
|
+
return formatted
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return defaultValue
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
inputName () {
|
|
198
|
+
if (this.state.blankInputName) return ""
|
|
199
|
+
|
|
200
|
+
return this.props.inputProps.name
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
inputReference = () => digg(this, "props", "inputProps", "ref")
|
|
204
|
+
|
|
205
|
+
onModelUpdated = (args) => {
|
|
206
|
+
const inputRef = this.inputReference()
|
|
207
|
+
|
|
208
|
+
if (!inputRef.current) {
|
|
209
|
+
// This can happen if the component is being unmounted
|
|
210
|
+
return
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const {attribute} = digs(this.props, "attribute")
|
|
214
|
+
const newModel = digg(args, "model")
|
|
215
|
+
const currentValue = digg(inputRef, "current", "value")
|
|
216
|
+
const newValue = newModel.readAttribute(attribute)
|
|
217
|
+
const newFormattedValue = this.formatValue(newValue)
|
|
218
|
+
|
|
219
|
+
if (currentValue != newFormattedValue) {
|
|
220
|
+
inputRef.current.value = newFormattedValue
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
onInputChanged = (e) => {
|
|
225
|
+
const {form} = this.tt
|
|
226
|
+
const {attribute, autoSubmit, inputProps, model, onChange} = this.props
|
|
227
|
+
const {localizedNumber} = digs(this.props, "localizedNumber")
|
|
228
|
+
const {name} = inputProps
|
|
229
|
+
|
|
230
|
+
if (localizedNumber) this.inputReference().current.value = this.actualValue(digg(e, "target"))
|
|
231
|
+
|
|
232
|
+
if (attribute && autoSubmit && model) this.delayAutoSubmit()
|
|
233
|
+
if (digg(inputProps, "type") == "file") this.setState({blankInputName: this.getBlankInputName()})
|
|
234
|
+
|
|
235
|
+
if (form && name) {
|
|
236
|
+
form.setValue(name, e.target.value)
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if (onChange) onChange(e)
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
delayAutoSubmit () {
|
|
243
|
+
if (this.delayAutoSubmitTimeout) {
|
|
244
|
+
clearTimeout(this.delayAutoSubmitTimeout)
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
this.delayAutoSubmitTimeout = setTimeout(this.autoSubmit, 200)
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// This fixes an issue in Firefox and ActiveStorage, where uploads would be a blank string if a file wasn't chosen
|
|
251
|
+
getBlankInputName () {
|
|
252
|
+
const value = dig(this.inputReference(), "current", "value")
|
|
253
|
+
|
|
254
|
+
if (this.props.inputProps.type == "file" && value == "")
|
|
255
|
+
return true
|
|
256
|
+
}
|
|
257
|
+
}))
|
|
258
|
+
|
|
259
|
+
export {ApiMakerInputsInput as Input}
|
|
260
|
+
export default inputWrapper(ApiMakerInputsInput)
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import React, {useRef} from "react"
|
|
2
|
+
import {shapeComponent, ShapeComponent} from "set-state-compare/src/shape-component"
|
|
3
|
+
import classNames from "classnames"
|
|
4
|
+
import Config from "../config"
|
|
5
|
+
import {digg} from "diggerize"
|
|
6
|
+
import idForComponent from "./id-for-component"
|
|
7
|
+
import * as inflection from "inflection"
|
|
8
|
+
import memo from "set-state-compare/src/memo"
|
|
9
|
+
import MoneyFormatter from "../money-formatter"
|
|
10
|
+
import PropTypes from "prop-types"
|
|
11
|
+
import PropTypesExact from "prop-types-exact"
|
|
12
|
+
|
|
13
|
+
export default memo(shapeComponent(class ApiMakerInputsMoney extends ShapeComponent {
|
|
14
|
+
static defaultProps = {
|
|
15
|
+
disabled: false,
|
|
16
|
+
showCurrencyOptions: true
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
static propTypes = PropTypesExact({
|
|
20
|
+
attribute: PropTypes.string,
|
|
21
|
+
centsInputName: PropTypes.string,
|
|
22
|
+
className: PropTypes.string,
|
|
23
|
+
currenciesCollection: PropTypes.array,
|
|
24
|
+
currencyName: PropTypes.string,
|
|
25
|
+
currencyRef: PropTypes.object,
|
|
26
|
+
defaultValue: PropTypes.object,
|
|
27
|
+
disabled: PropTypes.bool.isRequired,
|
|
28
|
+
id: PropTypes.string,
|
|
29
|
+
inputRef: PropTypes.object,
|
|
30
|
+
label: PropTypes.node,
|
|
31
|
+
model: PropTypes.object,
|
|
32
|
+
name: PropTypes.string,
|
|
33
|
+
onChange: PropTypes.func,
|
|
34
|
+
placeholder: PropTypes.node,
|
|
35
|
+
showCurrencyOptions: PropTypes.bool,
|
|
36
|
+
small: PropTypes.bool,
|
|
37
|
+
type: PropTypes.string,
|
|
38
|
+
wholeRef: PropTypes.object
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
setup() {
|
|
42
|
+
this.inputRef = useRef()
|
|
43
|
+
this.currencyRefBackup = useRef()
|
|
44
|
+
this.currencyRef = this.props.currencyRef || this.currencyRefBackup
|
|
45
|
+
this.wholeRefBackup = useRef()
|
|
46
|
+
this.wholeRef = this.props.wholeRef || this.wholeRefBackup
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
getInputRef () {
|
|
50
|
+
return this.props.inputRef || this.inputRef
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
render () {
|
|
54
|
+
const {attribute, className, disabled, model, showCurrencyOptions} = this.props
|
|
55
|
+
let {currenciesCollection} = this.props
|
|
56
|
+
|
|
57
|
+
if (!currenciesCollection) currenciesCollection = Config.getCurrenciesCollection()
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<div className="api-maker-inputs-money" data-attribute={attribute} data-model-id={model?.id()}>
|
|
61
|
+
<input defaultValue={this.inputDefaultCentsValue()} id={this.inputCentsId()} name={this.inputCentsName()} ref={this.getInputRef()} type="hidden" />
|
|
62
|
+
<input
|
|
63
|
+
className={classNames("money-cents", className)}
|
|
64
|
+
defaultValue={this.inputDefaultValue()}
|
|
65
|
+
disabled={disabled}
|
|
66
|
+
id={this.inputId()}
|
|
67
|
+
onBlur={digg(this, "setAmount")}
|
|
68
|
+
onChange={digg(this, "setCents")}
|
|
69
|
+
onKeyUp={digg(this, "setCents")}
|
|
70
|
+
placeholder={this.props.placeholder}
|
|
71
|
+
ref={this.wholeRef}
|
|
72
|
+
type="text"
|
|
73
|
+
/>
|
|
74
|
+
{showCurrencyOptions &&
|
|
75
|
+
<select
|
|
76
|
+
className="money-currency"
|
|
77
|
+
defaultValue={this.inputCurrencyValue()}
|
|
78
|
+
disabled={disabled}
|
|
79
|
+
id={this.inputCurrencyId()}
|
|
80
|
+
name={this.inputCurrencyName()}
|
|
81
|
+
onChange={digg(this, "onCurrencyChanged")}
|
|
82
|
+
ref={this.currencyRef}
|
|
83
|
+
>
|
|
84
|
+
<option></option>
|
|
85
|
+
{currenciesCollection.map((option) => (
|
|
86
|
+
<option key={`select-option-${option[1]}`} value={option[1]}>
|
|
87
|
+
{this.props.small && option[1]}
|
|
88
|
+
{!this.props.small && option[0]}
|
|
89
|
+
</option>
|
|
90
|
+
))}
|
|
91
|
+
</select>
|
|
92
|
+
}
|
|
93
|
+
</div>
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
inputCurrencyId () {
|
|
98
|
+
return `${this.inputId()}_currency`
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
inputCurrencyName () {
|
|
102
|
+
if ("currencyName" in this.props)
|
|
103
|
+
return this.props.currencyName
|
|
104
|
+
|
|
105
|
+
return `${this.props.model.modelClassData().paramKey}[${inflection.underscore(this.props.attribute)}_currency]`
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
inputCurrencyValue () {
|
|
109
|
+
const {defaultValue} = this.props
|
|
110
|
+
|
|
111
|
+
if (defaultValue) {
|
|
112
|
+
return MoneyFormatter.currencyFromMoney(defaultValue).code
|
|
113
|
+
} else {
|
|
114
|
+
return "DKK"
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
inputDefaultValue () {
|
|
119
|
+
const {defaultValue} = this.props
|
|
120
|
+
|
|
121
|
+
if (defaultValue) {
|
|
122
|
+
return MoneyFormatter.fromMoney({amount: defaultValue.amount, currency: this.inputCurrencyValue()}, {decimals: 2, excludeCurrency: true}).toString()
|
|
123
|
+
} else {
|
|
124
|
+
return ""
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
inputDefaultCentsValue () {
|
|
129
|
+
const {defaultValue} = this.props
|
|
130
|
+
|
|
131
|
+
if (this.getInputRef().current) {
|
|
132
|
+
return digg(this.getInputRef(), "current", "value")
|
|
133
|
+
} else if (defaultValue) {
|
|
134
|
+
return MoneyFormatter.amountFromMoney(defaultValue)
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
inputCentsId () {
|
|
139
|
+
return `${this.inputId()}_cents`
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
inputCentsName () {
|
|
143
|
+
if ("name" in this.props)
|
|
144
|
+
return this.props.name
|
|
145
|
+
|
|
146
|
+
return `${this.props.model.modelClassData().paramKey}[${inflection.underscore(this.props.attribute)}_cents]`
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
inputId () {
|
|
150
|
+
return idForComponent(this)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
onCurrencyChanged = () => {
|
|
154
|
+
if (this.props.onChange)
|
|
155
|
+
this.props.onChange()
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
setAmount = () => {
|
|
159
|
+
const inputElement = this.getInputRef().current
|
|
160
|
+
|
|
161
|
+
if (!inputElement.value && inputElement.value == "") {
|
|
162
|
+
this.wholeRef.current.value = ""
|
|
163
|
+
} else {
|
|
164
|
+
const cents = parseFloat(inputElement.value)
|
|
165
|
+
const formatted = MoneyFormatter.fromMoney({amount: cents, currency: this.inputCurrencyValue()}, {decimals: 2, excludeCurrency: true}).toString()
|
|
166
|
+
|
|
167
|
+
this.wholeRef.current.value = formatted
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
setCents = () => {
|
|
172
|
+
const inputElement = this.getInputRef().current
|
|
173
|
+
|
|
174
|
+
let whole = MoneyFormatter.stringToFloat(this.wholeRef.current.value)
|
|
175
|
+
let cents = parseInt(whole * 100, 10)
|
|
176
|
+
let oldCents = parseInt(inputElement.value, 10)
|
|
177
|
+
|
|
178
|
+
if (typeof cents == "number") {
|
|
179
|
+
inputElement.value = cents
|
|
180
|
+
} else {
|
|
181
|
+
inputElement.value = ''
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (this.props.onChange && oldCents != cents)
|
|
185
|
+
this.props.onChange()
|
|
186
|
+
}
|
|
187
|
+
}))
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as inflection from "inflection"
|
|
2
|
+
|
|
3
|
+
export default function apiMakerNameForComponent (component) {
|
|
4
|
+
if ("name" in component.props) {
|
|
5
|
+
return component.props.name
|
|
6
|
+
} else if (component.props.attribute && component.props.model) {
|
|
7
|
+
let attributeName = inflection.underscore(component.props.attribute)
|
|
8
|
+
|
|
9
|
+
if (component.props.type == "money") {
|
|
10
|
+
attributeName += "_cents"
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return `${component.props.model.modelClassData().paramKey}[${attributeName}]`
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import BaseComponent from "../base-component"
|
|
2
|
+
import inputWrapper from "./input-wrapper"
|
|
3
|
+
import memo from "set-state-compare/src/memo"
|
|
4
|
+
import PropTypes from "prop-types"
|
|
5
|
+
import React from "react"
|
|
6
|
+
import {shapeComponent} from "set-state-compare/src/shape-component"
|
|
7
|
+
import {useForm} from "../form"
|
|
8
|
+
|
|
9
|
+
const ApiMakerInputsSelect = memo(shapeComponent(class ApiMakerInputsSelect extends BaseComponent {
|
|
10
|
+
static propTypes = {
|
|
11
|
+
attribute: PropTypes.string,
|
|
12
|
+
children: PropTypes.node,
|
|
13
|
+
defaultValue: PropTypes.oneOfType([PropTypes.array, PropTypes.number, PropTypes.string]),
|
|
14
|
+
id: PropTypes.string,
|
|
15
|
+
includeBlank: PropTypes.oneOfType([PropTypes.bool, PropTypes.node]),
|
|
16
|
+
inputProps: PropTypes.object.isRequired,
|
|
17
|
+
model: PropTypes.object,
|
|
18
|
+
name: PropTypes.string,
|
|
19
|
+
onChange: PropTypes.func,
|
|
20
|
+
options: PropTypes.array,
|
|
21
|
+
wrapperOpts: PropTypes.object.isRequired
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
setup() {
|
|
25
|
+
this.form = useForm()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
render () {
|
|
29
|
+
const {
|
|
30
|
+
attribute,
|
|
31
|
+
children,
|
|
32
|
+
defaultValue,
|
|
33
|
+
id,
|
|
34
|
+
includeBlank,
|
|
35
|
+
inputProps,
|
|
36
|
+
inputRef,
|
|
37
|
+
model,
|
|
38
|
+
name,
|
|
39
|
+
onChange,
|
|
40
|
+
options,
|
|
41
|
+
wrapperOpts,
|
|
42
|
+
...restProps
|
|
43
|
+
} = this.props
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<select onChange={this.tt.onChange} {...inputProps} {...restProps}>
|
|
47
|
+
{this.includeBlank() &&
|
|
48
|
+
<option data-include-blank="true">
|
|
49
|
+
{typeof includeBlank != "boolean" ? includeBlank : null}
|
|
50
|
+
</option>
|
|
51
|
+
}
|
|
52
|
+
{options && options.map((option) =>
|
|
53
|
+
<option key={this.optionKey(option)} value={this.optionValue(option)}>
|
|
54
|
+
{this.optionLabel(option)}
|
|
55
|
+
</option>
|
|
56
|
+
)}
|
|
57
|
+
{children}
|
|
58
|
+
</select>
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
onChange = (e) => {
|
|
63
|
+
const {form} = this.tt
|
|
64
|
+
const {name, onChange} = this.props
|
|
65
|
+
|
|
66
|
+
if (form && name) form.setValue(name, e.target.value)
|
|
67
|
+
if (onChange) onChange(e)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
optionKey (option) {
|
|
71
|
+
if (Array.isArray(option)) {
|
|
72
|
+
return `select-option-${option[1]}`
|
|
73
|
+
} else {
|
|
74
|
+
return `select-option-${option}`
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
optionLabel (option) {
|
|
79
|
+
if (Array.isArray(option)) {
|
|
80
|
+
return option[0]
|
|
81
|
+
} else {
|
|
82
|
+
return option
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
optionValue (option) {
|
|
87
|
+
if (Array.isArray(option)) {
|
|
88
|
+
return option[1]
|
|
89
|
+
} else {
|
|
90
|
+
return option
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
includeBlank () {
|
|
95
|
+
if (this.props.includeBlank && !this.props.multiple) {
|
|
96
|
+
return true
|
|
97
|
+
} else {
|
|
98
|
+
return false
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}))
|
|
102
|
+
|
|
103
|
+
export {ApiMakerInputsSelect as Select}
|
|
104
|
+
export default inputWrapper(ApiMakerInputsSelect)
|
package/src/is-expo.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {digg, digs} from "diggerize"
|
|
2
|
+
|
|
3
|
+
let isExpo = false
|
|
4
|
+
|
|
5
|
+
try {
|
|
6
|
+
const REQUIRE_TERMINATOR = ""
|
|
7
|
+
const Constants = require(`expo-constants${REQUIRE_TERMINATOR}`)
|
|
8
|
+
const executionEnvironment = digg(Constants, "default", "executionEnvironment")
|
|
9
|
+
const {ExecutionEnvironment} = digs(Constants, "ExecutionEnvironment")
|
|
10
|
+
const {Bare, Standalone, StoreClient} = digs(ExecutionEnvironment, "Bare", "Standalone", "StoreClient")
|
|
11
|
+
|
|
12
|
+
// True if the app is running in an `expo build` app or if it's running in Expo Go.
|
|
13
|
+
isExpo = executionEnvironment === Bare || executionEnvironment === Standalone || executionEnvironment === StoreClient
|
|
14
|
+
} catch (error) {
|
|
15
|
+
// Do nothing - failed to require expo-constants
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default isExpo
|
package/src/link.jsx
CHANGED
|
@@ -1,27 +1,72 @@
|
|
|
1
|
+
import {Platform, Pressable} from "react-native"
|
|
2
|
+
import BaseComponent from "./base-component"
|
|
3
|
+
import dataSetToAttributes from "./data-set-to-attributes"
|
|
4
|
+
import memo from "set-state-compare/src/memo"
|
|
5
|
+
import PropTypes from "prop-types"
|
|
1
6
|
import React from "react"
|
|
7
|
+
import {shapeComponent} from "set-state-compare/src/shape-component"
|
|
8
|
+
import {useApiMaker} from "@kaspernj/api-maker/build/with-api-maker"
|
|
9
|
+
|
|
10
|
+
export default memo(shapeComponent(class ApiMakerLink extends BaseComponent {
|
|
11
|
+
static propTypes = {
|
|
12
|
+
usePressable: PropTypes.bool
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
setup() {
|
|
16
|
+
this.apiMaker = useApiMaker()
|
|
17
|
+
}
|
|
2
18
|
|
|
3
|
-
export default class Link extends React.PureComponent {
|
|
4
19
|
render() {
|
|
5
|
-
const {to, onClick, ...restProps} = this.props
|
|
20
|
+
const {dataSet, to, onClick, onPress, usePressable, ...restProps} = this.props
|
|
21
|
+
|
|
22
|
+
if (Platform.OS == "web" && !usePressable) {
|
|
23
|
+
return (
|
|
24
|
+
<a {...dataSetToAttributes(dataSet)} href={to} {...restProps} onClick={this.tt.onLinkClicked} />
|
|
25
|
+
)
|
|
26
|
+
}
|
|
6
27
|
|
|
7
28
|
return (
|
|
8
|
-
<
|
|
29
|
+
<Pressable dataSet={dataSet} onPress={this.tt.onPress} {...restProps} />
|
|
9
30
|
)
|
|
10
31
|
}
|
|
11
32
|
|
|
12
33
|
onLinkClicked = (e, ...restArgs) => {
|
|
13
|
-
const {onClick} = this.props
|
|
34
|
+
const {onClick, onPress} = this.props
|
|
35
|
+
|
|
36
|
+
if (onClick) {
|
|
37
|
+
onClick(e, ...restArgs)
|
|
38
|
+
}
|
|
14
39
|
|
|
15
|
-
if (
|
|
40
|
+
if (onPress) {
|
|
41
|
+
onPress(e, ...restArgs)
|
|
42
|
+
}
|
|
16
43
|
|
|
17
44
|
if (!e.defaultPrevented && !e.ctrlKey && !e.metaKey) {
|
|
18
45
|
e.preventDefault()
|
|
19
46
|
|
|
20
|
-
|
|
47
|
+
this.redirect()
|
|
48
|
+
}
|
|
49
|
+
}
|
|
21
50
|
|
|
22
|
-
|
|
51
|
+
onPress = () => {
|
|
52
|
+
const {onClick, onPress} = this.props
|
|
23
53
|
|
|
24
|
-
|
|
54
|
+
if (onClick) {
|
|
55
|
+
onClick(e, ...restArgs)
|
|
25
56
|
}
|
|
57
|
+
|
|
58
|
+
if (onPress) {
|
|
59
|
+
onPress(e, ...restArgs)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
this.redirect()
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
redirect = () => {
|
|
66
|
+
const history = this.apiMaker.config.getHistory()
|
|
67
|
+
|
|
68
|
+
if (!history) throw new Error("History hasn't been set in the API maker configuration")
|
|
69
|
+
|
|
70
|
+
history.push(this.props.to)
|
|
26
71
|
}
|
|
27
|
-
}
|
|
72
|
+
}))
|