@kaspernj/api-maker 1.0.2011 → 1.0.2012
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/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 +62 -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-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 +19 -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/link.sh +8 -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/{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 +76 -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-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 +16 -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,158 @@
|
|
|
1
|
+
import {shapeComponent, ShapeComponent} from "set-state-compare/src/shape-component"
|
|
2
|
+
import React, {useMemo} from "react"
|
|
3
|
+
import Checkbox from "./checkbox"
|
|
4
|
+
import {digs} from "diggerize"
|
|
5
|
+
import {useForm} from "../form"
|
|
6
|
+
import * as inflection from "inflection"
|
|
7
|
+
import InvalidFeedback from "./invalid-feedback"
|
|
8
|
+
import memo from "set-state-compare/src/memo"
|
|
9
|
+
import PropTypes from "prop-types"
|
|
10
|
+
import propTypesExact from "prop-types-exact"
|
|
11
|
+
import Text from "./text"
|
|
12
|
+
import useInput from "../use-input"
|
|
13
|
+
import {View} from "react-native"
|
|
14
|
+
|
|
15
|
+
const OptionElement = memo(shapeComponent(class OptionElement extends ShapeComponent {
|
|
16
|
+
static propTypes = propTypesExact({
|
|
17
|
+
checked: PropTypes.bool.isRequired,
|
|
18
|
+
inputName: PropTypes.string.isRequired,
|
|
19
|
+
onChange: PropTypes.func.isRequired,
|
|
20
|
+
option: PropTypes.array.isRequired
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
render() {
|
|
24
|
+
const {checked, inputName, option} = this.p
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<View >
|
|
28
|
+
<Checkbox
|
|
29
|
+
checked={checked}
|
|
30
|
+
dataSet={{
|
|
31
|
+
component: "api-maker/utils/checkboxes/option",
|
|
32
|
+
name: inputName,
|
|
33
|
+
value: option[1]
|
|
34
|
+
}}
|
|
35
|
+
label={option[0]}
|
|
36
|
+
onCheckedChange={this.tt.onChange}
|
|
37
|
+
/>
|
|
38
|
+
</View>
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
onChange = (checked) => this.p.onChange({checked, option: this.p.option})
|
|
43
|
+
}))
|
|
44
|
+
|
|
45
|
+
export default memo(shapeComponent(class ApiMakerUtilsCheckboxes extends ShapeComponent {
|
|
46
|
+
static propTypes = propTypesExact({
|
|
47
|
+
attribute: PropTypes.string,
|
|
48
|
+
defaultValue: PropTypes.array,
|
|
49
|
+
label: PropTypes.string,
|
|
50
|
+
labelClassName: PropTypes.string,
|
|
51
|
+
model: PropTypes.object,
|
|
52
|
+
name: PropTypes.string,
|
|
53
|
+
onChange: PropTypes.func,
|
|
54
|
+
options: PropTypes.array.isRequired
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
setup() {
|
|
58
|
+
const {inputProps, wrapperOpts} = useInput({props: this.props})
|
|
59
|
+
|
|
60
|
+
this.generatedId = useMemo(
|
|
61
|
+
() => Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15),
|
|
62
|
+
[]
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
this.setInstance({
|
|
66
|
+
form: useForm(),
|
|
67
|
+
inputProps,
|
|
68
|
+
wrapperOpts
|
|
69
|
+
})
|
|
70
|
+
this.useStates({
|
|
71
|
+
checkedOptions: () => {
|
|
72
|
+
if (Array.isArray(this.props.defaultValue)) return this.props.defaultValue
|
|
73
|
+
if (this.props.defaultValue) return [this.props.defaultValue]
|
|
74
|
+
|
|
75
|
+
return []
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
useMemo(() => {
|
|
80
|
+
if (this.form && inputProps.name) {
|
|
81
|
+
this.form.setValue(inputProps.name, this.s.checkedOptions)
|
|
82
|
+
}
|
|
83
|
+
}, [])
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
render () {
|
|
87
|
+
const {wrapperOpts} = this.tt
|
|
88
|
+
const {errors} = digs(wrapperOpts, "errors")
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<View dataSet={{component: "api-maker/utils/checkboxes"}}>
|
|
92
|
+
<Text style={{fontWeight: "bold"}}>
|
|
93
|
+
{this.tt.wrapperOpts.label}
|
|
94
|
+
</Text>
|
|
95
|
+
{this.props.options.map((option) =>
|
|
96
|
+
<OptionElement
|
|
97
|
+
checked={this.isChecked(option)}
|
|
98
|
+
inputName={this.inputName()}
|
|
99
|
+
key={option[1]}
|
|
100
|
+
onChange={this.tt.onOptionChecked}
|
|
101
|
+
option={option}
|
|
102
|
+
/>
|
|
103
|
+
)}
|
|
104
|
+
{errors.length > 0 &&
|
|
105
|
+
<InvalidFeedback errors={errors} />
|
|
106
|
+
}
|
|
107
|
+
</View>
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
inputDefaultValue () {
|
|
112
|
+
const {attribute, defaultValue, model} = this.props
|
|
113
|
+
|
|
114
|
+
if (defaultValue) {
|
|
115
|
+
return defaultValue
|
|
116
|
+
} else if (attribute && model) {
|
|
117
|
+
if (!model[attribute]) throw `No such attribute: ${attribute}`
|
|
118
|
+
|
|
119
|
+
return this.props.model[attribute]()
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
inputName () {
|
|
124
|
+
if (this.props.name) {
|
|
125
|
+
return `${this.props.name}[]`
|
|
126
|
+
} else if (this.props.model) {
|
|
127
|
+
return `${this.props.model.modelClassData().paramKey}[${inflection.underscore(this.props.attribute)}]`
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
isChecked = (option) => this.s.checkedOptions.includes(option[1])
|
|
132
|
+
|
|
133
|
+
onOptionChecked = ({checked, option}) => {
|
|
134
|
+
const {inputProps, form} = this.tt
|
|
135
|
+
const {name} = inputProps
|
|
136
|
+
let newOptions
|
|
137
|
+
|
|
138
|
+
if (checked) {
|
|
139
|
+
newOptions = this.s.checkedOptions.concat([option[1]])
|
|
140
|
+
|
|
141
|
+
this.setState({checkedOptions: newOptions})
|
|
142
|
+
} else {
|
|
143
|
+
newOptions = this.s.checkedOptions.filter((value) => value != option[1])
|
|
144
|
+
|
|
145
|
+
this.setState({checkedOptions: newOptions})
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
console.log({checkedOptions: this.s.checkedOptions})
|
|
149
|
+
|
|
150
|
+
if (this.props.onChange) {
|
|
151
|
+
this.p.onChange({checked, option})
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (form && name) {
|
|
155
|
+
form.setValue(name, newOptions)
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}))
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React, {createContext, useContext} from "react"
|
|
2
|
+
import memo from "set-state-compare/src/memo"
|
|
3
|
+
|
|
4
|
+
const DefaultStyleContext = createContext({
|
|
5
|
+
Text: {}
|
|
6
|
+
})
|
|
7
|
+
|
|
8
|
+
const useDefaultStyle = () => {
|
|
9
|
+
const defaultStyle = useContext(DefaultStyleContext)
|
|
10
|
+
|
|
11
|
+
return defaultStyle
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const WithDefaultStyle = memo((props) => {
|
|
15
|
+
const defaultStyle = useContext(DefaultStyleContext)
|
|
16
|
+
const newDefaultStyle = Object.assign({}, defaultStyle, props.style)
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<DefaultStyleContext.Provider value={newDefaultStyle}>
|
|
20
|
+
{props.children}
|
|
21
|
+
</DefaultStyleContext.Provider>
|
|
22
|
+
)
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
export {useDefaultStyle, WithDefaultStyle}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import BaseComponent from "../base-component"
|
|
2
|
+
import FontAwesomeIcon from "react-native-vector-icons/FontAwesome"
|
|
3
|
+
import memo from "set-state-compare/src/memo"
|
|
4
|
+
import React from "react"
|
|
5
|
+
import {shapeComponent} from "set-state-compare/src/shape-component"
|
|
6
|
+
import {useDefaultStyle} from "./default-style"
|
|
7
|
+
|
|
8
|
+
export default memo(shapeComponent(class ApiMakerUtilsIcon extends BaseComponent {
|
|
9
|
+
render() {
|
|
10
|
+
const defaultStyle = useDefaultStyle()
|
|
11
|
+
const {style, ...restProps} = this.props
|
|
12
|
+
const actualStyle = Object.assign(
|
|
13
|
+
{color: defaultStyle.Text.color},
|
|
14
|
+
style
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<FontAwesomeIcon style={actualStyle} {...restProps} />
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
}))
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {shapeComponent, ShapeComponent} from "set-state-compare/src/shape-component"
|
|
2
|
+
import memo from "set-state-compare/src/memo"
|
|
3
|
+
import PropTypes from "prop-types"
|
|
4
|
+
import propTypesExact from "prop-types-exact"
|
|
5
|
+
import React from "react"
|
|
6
|
+
import Text from "./text"
|
|
7
|
+
|
|
8
|
+
export default memo(shapeComponent(class ApiMakerUtilsInvalidFeedback extends ShapeComponent {
|
|
9
|
+
static propTypes = propTypesExact({
|
|
10
|
+
message: PropTypes.string.isRequired
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
render() {
|
|
14
|
+
return (
|
|
15
|
+
<Text style={{color: "red"}}>
|
|
16
|
+
{this.p.message}
|
|
17
|
+
</Text>
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
}))
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import {Modal, Pressable, View} from "react-native"
|
|
2
|
+
import BaseComponent from "../base-component"
|
|
3
|
+
import Card from "./card"
|
|
4
|
+
import Icon from "../utils/icon"
|
|
5
|
+
import memo from "set-state-compare/src/memo"
|
|
6
|
+
import React from "react"
|
|
7
|
+
import {shapeComponent} from "set-state-compare/src/shape-component"
|
|
8
|
+
import useBreakpoint from "../use-breakpoint"
|
|
9
|
+
|
|
10
|
+
export default memo(shapeComponent(class ApiMakerUtilsComponent extends BaseComponent {
|
|
11
|
+
render() {
|
|
12
|
+
const {xs, sm} = useBreakpoint()
|
|
13
|
+
const {children, dataSet, ...restProps} = this.props
|
|
14
|
+
const actualDataSet = Object.assign(
|
|
15
|
+
{
|
|
16
|
+
component: "api-maker/utils/modal"
|
|
17
|
+
},
|
|
18
|
+
dataSet
|
|
19
|
+
)
|
|
20
|
+
let width, maxWidth
|
|
21
|
+
|
|
22
|
+
if (xs || sm) {
|
|
23
|
+
width = "95%"
|
|
24
|
+
} else {
|
|
25
|
+
width = "80%"
|
|
26
|
+
maxWidth = 800
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<Modal dataSet={actualDataSet} {...restProps}>
|
|
31
|
+
<View
|
|
32
|
+
style={{
|
|
33
|
+
alignItems: "center",
|
|
34
|
+
justifyContent: "center",
|
|
35
|
+
width: "100%",
|
|
36
|
+
height: "100%",
|
|
37
|
+
backgroundColor: "rgba(0, 0, 0, 0.8)"
|
|
38
|
+
}}
|
|
39
|
+
>
|
|
40
|
+
<Card
|
|
41
|
+
controls={this.cardHeaderControls()}
|
|
42
|
+
style={{width, maxWidth}}
|
|
43
|
+
>
|
|
44
|
+
{children}
|
|
45
|
+
</Card>
|
|
46
|
+
</View>
|
|
47
|
+
</Modal>
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
cardHeaderControls() {
|
|
52
|
+
return (
|
|
53
|
+
<Pressable onPress={this.tt.onModalClosePress} style={{marginLeft: "auto", padding: 5}}>
|
|
54
|
+
<Icon name="remove" />
|
|
55
|
+
</Pressable>
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
onModalClosePress = () => this.props.onRequestClose && this.props.onRequestClose()
|
|
60
|
+
}))
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import memo from "set-state-compare/src/memo"
|
|
2
|
+
import React from "react"
|
|
3
|
+
import {Text} from "react-native"
|
|
4
|
+
import {useDefaultStyle, WithDefaultStyle} from "./default-style"
|
|
5
|
+
|
|
6
|
+
export default memo((props) => {
|
|
7
|
+
const {style, ...restProps} = props
|
|
8
|
+
const defaultStyle = useDefaultStyle()
|
|
9
|
+
const actualStyle = Object.assign({}, defaultStyle?.Text, style)
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<WithDefaultStyle style={actualStyle}>
|
|
13
|
+
<Text style={actualStyle} {...restProps} />
|
|
14
|
+
</WithDefaultStyle>
|
|
15
|
+
)
|
|
16
|
+
})
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import BaseError from "./base-error
|
|
2
|
-
import inflection from "inflection"
|
|
1
|
+
import BaseError from "./base-error"
|
|
2
|
+
import * as inflection from "inflection"
|
|
3
3
|
|
|
4
4
|
class ValidationError extends BaseError {
|
|
5
|
-
constructor
|
|
5
|
+
constructor(validationErrors, args) {
|
|
6
6
|
const errorMessage = validationErrors.getUnhandledErrorMessage() || validationErrors.getErrorMessage()
|
|
7
7
|
const forwardedArgs = {addResponseErrorsToErrorMessage: false}
|
|
8
8
|
const newArgs = Object.assign({}, args, forwardedArgs)
|
|
@@ -11,12 +11,16 @@ class ValidationError extends BaseError {
|
|
|
11
11
|
this.validationErrors = validationErrors
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
getUnhandledErrors = () => this.validationErrors.getValidationErrors().filter((validationError) => !validationError.getHandled())
|
|
15
|
+
getValidationErrors = () => digg(this, "validationErrors")
|
|
16
|
+
|
|
17
|
+
hasUnhandledErrors() {
|
|
15
18
|
const unhandledError = this.validationErrors.getValidationErrors().find((validationError) => !validationError.getHandled())
|
|
19
|
+
|
|
16
20
|
return Boolean(unhandledError)
|
|
17
21
|
}
|
|
18
22
|
|
|
19
|
-
hasValidationErrorForAttribute
|
|
23
|
+
hasValidationErrorForAttribute(attributeName) {
|
|
20
24
|
const underscoredAttributeName = inflection.underscore(attributeName)
|
|
21
25
|
const foundAttribute = this.validationErrors.getValidationErrors().find((validationError) => validationError.getAttributeName() == underscoredAttributeName)
|
|
22
26
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {digg, digs} from "diggerize"
|
|
2
|
-
import inflection from "inflection"
|
|
3
|
-
import modelClassRequire from "./model-class-require
|
|
2
|
+
import * as inflection from "inflection"
|
|
3
|
+
import modelClassRequire from "./model-class-require"
|
|
4
4
|
|
|
5
5
|
class ValidationError {
|
|
6
|
-
constructor
|
|
6
|
+
constructor(args) {
|
|
7
7
|
this.attributeName = digg(args, "attribute_name")
|
|
8
8
|
this.attributeType = digg(args, "attribute_type")
|
|
9
9
|
this.errorMessages = digg(args, "error_messages")
|
|
@@ -13,7 +13,7 @@ class ValidationError {
|
|
|
13
13
|
this.modelName = digg(args, "model_name")
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
matchesAttributeAndInputName
|
|
16
|
+
matchesAttributeAndInputName(attributeName, inputName) {
|
|
17
17
|
if (this.getInputName() == inputName) return true
|
|
18
18
|
if (!attributeName) return false
|
|
19
19
|
|
|
@@ -30,15 +30,10 @@ class ValidationError {
|
|
|
30
30
|
return false
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
getAttributeName ()
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
getErrorMessages () {
|
|
38
|
-
return digg(this, "errorMessages")
|
|
39
|
-
}
|
|
33
|
+
getAttributeName = () => digg(this, "attributeName")
|
|
34
|
+
getErrorMessages = () => digg(this, "errorMessages")
|
|
40
35
|
|
|
41
|
-
getFullErrorMessages
|
|
36
|
+
getFullErrorMessages() {
|
|
42
37
|
const {attributeType} = digs(this, "attributeType")
|
|
43
38
|
|
|
44
39
|
if (attributeType == "base") {
|
|
@@ -55,32 +50,27 @@ class ValidationError {
|
|
|
55
50
|
}
|
|
56
51
|
}
|
|
57
52
|
|
|
58
|
-
getHandled ()
|
|
59
|
-
|
|
60
|
-
}
|
|
53
|
+
getHandled = () => digg(this, "handled")
|
|
54
|
+
getInputName = () => digg(this, "inputName")
|
|
61
55
|
|
|
62
|
-
|
|
63
|
-
return digg(this, "inputName")
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
getModelClass () {
|
|
56
|
+
getModelClass() {
|
|
67
57
|
const modelName = inflection.classify(digg(this, "modelName"))
|
|
68
58
|
|
|
69
59
|
return modelClassRequire(modelName)
|
|
70
60
|
}
|
|
71
61
|
|
|
72
|
-
setHandled
|
|
62
|
+
setHandled() {
|
|
73
63
|
this.handled = true
|
|
74
64
|
}
|
|
75
65
|
}
|
|
76
66
|
|
|
77
67
|
class ValidationErrors {
|
|
78
|
-
constructor
|
|
68
|
+
constructor(args) {
|
|
79
69
|
this.rootModel = digg(args, "model")
|
|
80
70
|
this.validationErrors = digg(args, "validationErrors").map((validationError) => new ValidationError(validationError))
|
|
81
71
|
}
|
|
82
72
|
|
|
83
|
-
getErrorMessage
|
|
73
|
+
getErrorMessage() {
|
|
84
74
|
const fullErrorMessages = []
|
|
85
75
|
|
|
86
76
|
for (const validationError of this.validationErrors) {
|
|
@@ -92,16 +82,14 @@ class ValidationErrors {
|
|
|
92
82
|
return fullErrorMessages.join(". ")
|
|
93
83
|
}
|
|
94
84
|
|
|
95
|
-
getValidationErrors ()
|
|
96
|
-
return this.validationErrors
|
|
97
|
-
}
|
|
85
|
+
getValidationErrors = () => this.validationErrors
|
|
98
86
|
|
|
99
87
|
getValidationErrorsForInput ({attribute, inputName, onMatchValidationError}) {
|
|
100
88
|
const validationErrors = this.validationErrors.filter((validationError) => {
|
|
101
89
|
if (onMatchValidationError) {
|
|
102
90
|
return onMatchValidationError(validationError)
|
|
103
91
|
} else {
|
|
104
|
-
return validationError.matchesAttributeAndInputName(attribute, inputName
|
|
92
|
+
return validationError.matchesAttributeAndInputName(attribute, inputName)
|
|
105
93
|
}
|
|
106
94
|
})
|
|
107
95
|
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React, {createContext, useContext, useMemo} from "react"
|
|
2
|
+
import ApiMakerConfig from "./config"
|
|
3
|
+
import memo from "set-state-compare/src/memo"
|
|
4
|
+
|
|
5
|
+
const ApiMakerContext = createContext()
|
|
6
|
+
const useApiMaker = () => {
|
|
7
|
+
const apiMakerContext = useContext(ApiMakerContext)
|
|
8
|
+
|
|
9
|
+
if (apiMakerContext) {
|
|
10
|
+
return apiMakerContext
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return {
|
|
14
|
+
config: ApiMakerConfig
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const WithApiMaker = memo(({children, config, ...restProps}) => {
|
|
19
|
+
const restPropsKeys = Object.keys(restProps)
|
|
20
|
+
const value = useMemo(() => ({config}), [config])
|
|
21
|
+
|
|
22
|
+
if (restPropsKeys.length > 0) throw new Error(`Unhandled props: ${restPropsKeys.join(", ")}`)
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<ApiMakerContext.Provider value={value}>
|
|
26
|
+
{children}
|
|
27
|
+
</ApiMakerContext.Provider>
|
|
28
|
+
)
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
export {useApiMaker, WithApiMaker}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {digg} from "diggerize"
|
|
2
|
+
import memo from "set-state-compare/src/memo"
|
|
3
|
+
import React from "react"
|
|
4
|
+
import useCollection from "./use-collection"
|
|
5
|
+
|
|
6
|
+
export default (WrappedComponent, withCollectionArgs) => memo(() => {
|
|
7
|
+
const useCollectionResult = useCollection(withCollectionArgs)
|
|
8
|
+
const models = digg(useCollectionResult, "models")
|
|
9
|
+
const modelsArgName = inflection.camelize(digg(withCollectionArgs.modelClass.modelClassData(), "pluralName"), true)
|
|
10
|
+
const forwardArgs = {}
|
|
11
|
+
|
|
12
|
+
forwardArgs[modelsArgName] = models
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<WrappedComponent {...forwardArgs} {...this.props} />
|
|
16
|
+
)
|
|
17
|
+
})
|
|
@@ -1,28 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import PureComponent from "set-state-compare/src/pure-component"
|
|
1
|
+
import React from "react"
|
|
2
|
+
import useCurrentUser from "./use-current-user"
|
|
4
3
|
|
|
5
|
-
export default (WrappedComponent) =>
|
|
6
|
-
|
|
7
|
-
currentUser: Devise.currentUser()
|
|
8
|
-
}
|
|
4
|
+
export default (WrappedComponent) => (props) => {
|
|
5
|
+
const currentUser = useCurrentUser()
|
|
9
6
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return (
|
|
15
|
-
<>
|
|
16
|
-
<EventEmitterListener events={Devise.events()} event="onDeviseSignIn" onCalled={onDeviseSigned} />
|
|
17
|
-
<EventEmitterListener events={Devise.events()} event="onDeviseSignOut" onCalled={onDeviseSigned} />
|
|
18
|
-
<WrappedComponent {...this.props} currentUser={currentUser} />
|
|
19
|
-
</>
|
|
20
|
-
)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
onDeviseSigned = () => {
|
|
24
|
-
const currentUser = Devise.currentUser()
|
|
25
|
-
|
|
26
|
-
if (this.state.currentUser !== currentUser) this.setState({currentUser})
|
|
27
|
-
}
|
|
7
|
+
return (
|
|
8
|
+
<WrappedComponent {...props} currentUser={currentUser} />
|
|
9
|
+
)
|
|
28
10
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import memo from "set-state-compare/src/memo"
|
|
2
|
+
import React from "react"
|
|
3
|
+
import useModel from "./use-model"
|
|
4
|
+
|
|
5
|
+
export default (WrappedComponent, modelClass, givenArgs) => {
|
|
6
|
+
const ApiMakerWithModel = (props) => {
|
|
7
|
+
const args = Object.assign({match: props.match}, givenArgs)
|
|
8
|
+
const useModelResult = useModel(modelClass, args)
|
|
9
|
+
|
|
10
|
+
return (
|
|
11
|
+
<WrappedComponent {...useModelResult} {...props} />
|
|
12
|
+
)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return memo(ApiMakerWithModel)
|
|
16
|
+
}
|
package/src/with-router.jsx
CHANGED
|
@@ -1,133 +1,11 @@
|
|
|
1
|
-
import config from "./config.mjs"
|
|
2
|
-
import escapeStringRegexp from "escape-string-regexp"
|
|
3
|
-
import inflection from "inflection"
|
|
4
|
-
import PropTypes from "prop-types"
|
|
5
1
|
import React from "react"
|
|
6
|
-
import
|
|
2
|
+
import useRouter from "./use-router"
|
|
7
3
|
|
|
8
|
-
export default (WrapperComponent) =>
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
routeDefinitions: PropTypes.object,
|
|
12
|
-
routes: PropTypes.object
|
|
13
|
-
}
|
|
4
|
+
export default (WrapperComponent) => (props) => {
|
|
5
|
+
const {path, routes, routeDefinitions, ...restProps} = props
|
|
6
|
+
const {match} = useRouter({path, routes, routeDefinitions})
|
|
14
7
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return shouldComponentUpdate(this, nextProps, nextState)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
findRouteParams(routeDefinition) {
|
|
22
|
-
const result = []
|
|
23
|
-
const parts = routeDefinition.path.split("/")
|
|
24
|
-
|
|
25
|
-
for (const part of parts) {
|
|
26
|
-
if (part.match(/^:([a-z_]+)$/))
|
|
27
|
-
result.push(part)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return result
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
path() {
|
|
34
|
-
let path = this.props.path || window.location.pathname
|
|
35
|
-
|
|
36
|
-
path = path.replace(/[/]+$/, "")
|
|
37
|
-
|
|
38
|
-
return path
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
routeDefinitions() {
|
|
42
|
-
return this.props.routeDefinitions || config.getRouteDefinitions()
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
routes() {
|
|
46
|
-
return this.props.routes || config.getRoutes()
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
parseRouteDefinitions() {
|
|
50
|
-
const Locales = require("shared/locales").default
|
|
51
|
-
const routeDefinitions = this.routeDefinitions()
|
|
52
|
-
const routes = this.routes()
|
|
53
|
-
const regex = /:([A-z\d_]+)/
|
|
54
|
-
const parsedRouteDefinitions = []
|
|
55
|
-
|
|
56
|
-
for (const locale of Locales.availableLocales()) {
|
|
57
|
-
for (const routeDefinition of routeDefinitions.routes) {
|
|
58
|
-
const routePathName = `${inflection.camelize(routeDefinition.name, true)}Path`
|
|
59
|
-
const params = this.findRouteParams(routeDefinition)
|
|
60
|
-
|
|
61
|
-
params.push({locale})
|
|
62
|
-
|
|
63
|
-
if (!(routePathName in routes))
|
|
64
|
-
throw new Error(`${routePathName} not found in routes: ${Object.keys(routes, ", ")}`)
|
|
65
|
-
|
|
66
|
-
const routePath = routes[routePathName](...params).replace(/[/]+$/, "")
|
|
67
|
-
const groups = []
|
|
68
|
-
let pathRegexString = "^"
|
|
69
|
-
|
|
70
|
-
pathRegexString += escapeStringRegexp(routePath)
|
|
71
|
-
|
|
72
|
-
while (true) {
|
|
73
|
-
const match = pathRegexString.match(regex)
|
|
74
|
-
|
|
75
|
-
if (!match) break
|
|
76
|
-
|
|
77
|
-
const variableName = match[1]
|
|
78
|
-
|
|
79
|
-
groups.push(variableName)
|
|
80
|
-
|
|
81
|
-
pathRegexString = pathRegexString.replace(match[0], "([^/]+)")
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
pathRegexString += "$"
|
|
85
|
-
|
|
86
|
-
const pathRegex = new RegExp(pathRegexString)
|
|
87
|
-
|
|
88
|
-
parsedRouteDefinitions.push({groups, pathRegex, routeDefinition})
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return parsedRouteDefinitions
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
findMatchingRoute() {
|
|
96
|
-
const path = this.path()
|
|
97
|
-
|
|
98
|
-
for (const parsedRouteDefinition of this.parsedRouteDefinitions) {
|
|
99
|
-
const match = path.match(parsedRouteDefinition.pathRegex)
|
|
100
|
-
let matched, params
|
|
101
|
-
|
|
102
|
-
if (match) {
|
|
103
|
-
matched = true
|
|
104
|
-
params = {}
|
|
105
|
-
|
|
106
|
-
for (const groupKey in parsedRouteDefinition.groups) {
|
|
107
|
-
const groupName = parsedRouteDefinition.groups[groupKey]
|
|
108
|
-
|
|
109
|
-
params[groupName] = match[Number(groupKey) + 1]
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (path == "" && parsedRouteDefinition.routeDefinition.path == "/") matched = true
|
|
114
|
-
if (matched) {
|
|
115
|
-
return {params, parsedRouteDefinition}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
render() {
|
|
121
|
-
const {path, routes, routeDefinitions, ...restProps} = this.props
|
|
122
|
-
const matchingRoute = this.findMatchingRoute()
|
|
123
|
-
const params = matchingRoute?.params || {}
|
|
124
|
-
const match = {
|
|
125
|
-
matchingRoute,
|
|
126
|
-
params
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return (
|
|
130
|
-
<WrapperComponent match={match} {...restProps} />
|
|
131
|
-
)
|
|
132
|
-
}
|
|
8
|
+
return (
|
|
9
|
+
<WrapperComponent match={match} {...restProps} />
|
|
10
|
+
)
|
|
133
11
|
}
|