@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
package/src/modal.jsx
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import BaseComponent from "./base-component"
|
|
2
|
+
import memo from "set-state-compare/src/memo"
|
|
3
|
+
import React from "react"
|
|
4
|
+
import {shapeComponent} from "set-state-compare/src/shape-component"
|
|
5
|
+
import {Modal, Pressable, View} from "react-native"
|
|
6
|
+
|
|
7
|
+
export default memo(shapeComponent(class ApiMakerModal extends BaseComponent {
|
|
8
|
+
render() {
|
|
9
|
+
const {children, onRequestClose, ...restProps} = this.props
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<Modal onRequestClose={onRequestClose} {...restProps}>
|
|
13
|
+
<View
|
|
14
|
+
style={{
|
|
15
|
+
alignItems: "center",
|
|
16
|
+
justifyContent: "center",
|
|
17
|
+
minWidth: "100%",
|
|
18
|
+
minHeight: "100%",
|
|
19
|
+
padding: 20,
|
|
20
|
+
}}
|
|
21
|
+
>
|
|
22
|
+
<Pressable
|
|
23
|
+
dataSet={{class: "modal-backdrop"}}
|
|
24
|
+
onPress={onRequestClose}
|
|
25
|
+
style={{
|
|
26
|
+
position: "absolute",
|
|
27
|
+
minWidth: "100%",
|
|
28
|
+
minHeight: "100%",
|
|
29
|
+
backgroundColor: "rgba(0, 0, 0, 0.5)"
|
|
30
|
+
}}
|
|
31
|
+
/>
|
|
32
|
+
{children}
|
|
33
|
+
</View>
|
|
34
|
+
</Modal>
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
}))
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as inflection from "inflection"
|
|
2
|
+
import * as models from "models"
|
|
3
|
+
|
|
4
|
+
const modelClassRequire = (modelName) => {
|
|
5
|
+
const requireName = inflection.camelize(modelName)
|
|
6
|
+
const ModelClass = models[requireName]
|
|
7
|
+
|
|
8
|
+
if (!ModelClass) {
|
|
9
|
+
const modelClasses = Object.keys(models).sort()
|
|
10
|
+
|
|
11
|
+
throw new Error(`No model called ${modelName} in ${modelClasses.join(", ")}`)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return ModelClass
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default modelClassRequire
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import Config from "
|
|
1
|
+
import Config from "./config"
|
|
2
|
+
import * as inflection from "inflection"
|
|
2
3
|
|
|
3
4
|
export default class ModelName {
|
|
4
5
|
constructor(data) {
|
|
5
6
|
this.data = data
|
|
6
7
|
}
|
|
7
8
|
|
|
8
|
-
camelizedLower()
|
|
9
|
-
return this.data.modelClassData.camelizedLower
|
|
10
|
-
}
|
|
9
|
+
camelizedLower = () => this.data.modelClassData.camelizedLower
|
|
11
10
|
|
|
12
11
|
human(args) {
|
|
13
12
|
let argsToUse = args
|
|
@@ -23,11 +22,12 @@ export default class ModelName {
|
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
const key = `activerecord.models.${this.data.modelClassData.i18nKey}.${countKey}`
|
|
25
|
+
let defaultModelName = this.data.modelClassData.name
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
}
|
|
27
|
+
if (args?.count > 1) defaultModelName = inflection.pluralize(defaultModelName)
|
|
29
28
|
|
|
30
|
-
|
|
31
|
-
return this.data.modelClassData.paramKey
|
|
29
|
+
return Config.getI18n().t(key, {defaultValue: defaultModelName})
|
|
32
30
|
}
|
|
31
|
+
|
|
32
|
+
paramKey = () => this.data.modelClassData.paramKey
|
|
33
33
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import BaseModel from "./base-model
|
|
2
|
-
import Collection from "./collection
|
|
1
|
+
import BaseModel from "./base-model"
|
|
2
|
+
import Collection from "./collection"
|
|
3
3
|
import {digg, digs} from "diggerize"
|
|
4
|
-
import inflection from "inflection"
|
|
4
|
+
import * as inflection from "inflection"
|
|
5
5
|
|
|
6
6
|
export default class ApiMakerModelRecipesModelLoader {
|
|
7
7
|
constructor ({modelRecipe, modelRecipesLoader}) {
|
|
@@ -36,7 +36,7 @@ export default class ApiMakerModelRecipesModelLoader {
|
|
|
36
36
|
|
|
37
37
|
this.addAttributeMethodsToModelClass(ModelClass, attributes)
|
|
38
38
|
this.addRelationshipsToModelClass(ModelClass, modelClassData, relationships)
|
|
39
|
-
this.
|
|
39
|
+
this.addQueryCommandsToModelClass(ModelClass, collectionCommands)
|
|
40
40
|
this.addMemberCommandsToModelClass(ModelClass, memberCommands)
|
|
41
41
|
|
|
42
42
|
return ModelClass
|
|
@@ -61,7 +61,7 @@ export default class ApiMakerModelRecipesModelLoader {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
addQueryCommandsToModelClass (ModelClass, collectionCommands) {
|
|
65
65
|
for (const collectionCommandName in collectionCommands) {
|
|
66
66
|
const methodName = inflection.camelize(collectionCommandName, true)
|
|
67
67
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import Preloaded from "./preloaded.mjs"
|
|
1
|
+
import * as inflection from "inflection"
|
|
2
|
+
import modelClassRequire from "./model-class-require"
|
|
3
|
+
import Preloaded from "./preloaded"
|
|
5
4
|
|
|
6
5
|
export default class ModelsResponseReader {
|
|
7
6
|
static first (response) {
|
package/src/models.js
ADDED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
/* rails-erb-loader-dependencies api_maker/resources/ models/ */
|
|
2
2
|
|
|
3
3
|
import {digg} from "diggerize"
|
|
4
|
-
import ModelRecipesLoader from "
|
|
4
|
+
import ModelRecipesLoader from "@kaspernj/api-maker/build/model-recipes-loader"
|
|
5
|
+
import modelRecipes from "./model-recipes.json"
|
|
5
6
|
|
|
6
|
-
const modelRecipes = <%= ApiMaker::ModelClassesJavaScriptGeneratorService.execute!.to_json %>
|
|
7
7
|
const loader = new ModelRecipesLoader({recipes: modelRecipes})
|
|
8
8
|
const result = loader.load()
|
|
9
9
|
|
|
10
10
|
<% model_class_names = [] %>
|
|
11
11
|
<% ApiMaker::ModelClassesJavaScriptGeneratorService.new.resources.each do |resource| %>
|
|
12
12
|
<% model_class_names << resource.short_name %>
|
|
13
|
-
|
|
13
|
+
|
|
14
|
+
const <%= resource.short_name %>ModelClass = digg(result, "<%= resource.short_name %>")
|
|
15
|
+
|
|
16
|
+
class <%= resource.short_name %> extends <%= resource.short_name %>ModelClass {}
|
|
14
17
|
<% end %>
|
|
15
18
|
|
|
16
19
|
export {<%= model_class_names.join(", ") %>}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import I18nOnSteroids from "i18n-on-steroids"
|
|
1
2
|
import Money from "js-money"
|
|
2
3
|
import formatNumber from "format-number"
|
|
3
4
|
import replaceall from "replaceall"
|
|
@@ -12,9 +13,9 @@ export default class MoneyFormatter {
|
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
static stringToFloat (moneyString) {
|
|
15
|
-
let unformatted = replaceall(
|
|
16
|
+
let unformatted = replaceall(I18nOnSteroids.getCurrent().t("number.currency.format.delimiter"), "", moneyString)
|
|
16
17
|
|
|
17
|
-
unformatted = replaceall(
|
|
18
|
+
unformatted = replaceall(I18nOnSteroids.getCurrent().t("number.currency.format.separator"), ".", unformatted)
|
|
18
19
|
const float = parseFloat(unformatted)
|
|
19
20
|
|
|
20
21
|
return float
|
|
@@ -74,8 +75,8 @@ export default class MoneyFormatter {
|
|
|
74
75
|
const amount = (this.amount / 100).toFixed(this.decimalDigits())
|
|
75
76
|
const formatOptions = {
|
|
76
77
|
prefix: this.prefix(),
|
|
77
|
-
decimal:
|
|
78
|
-
integerSeparator:
|
|
78
|
+
decimal: I18nOnSteroids.getCurrent().t("number.currency.format.separator"),
|
|
79
|
+
integerSeparator: I18nOnSteroids.getCurrent().t("number.currency.format.delimiter")
|
|
79
80
|
}
|
|
80
81
|
|
|
81
82
|
return formatNumber(formatOptions)(amount)
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
+
import config from "./config"
|
|
1
2
|
import formSerialize from "form-serialize"
|
|
2
3
|
import Incorporator from "incorporator"
|
|
3
4
|
import qs from "qs"
|
|
5
|
+
import urlEncode from "./url-encode"
|
|
4
6
|
|
|
5
7
|
export default class Params {
|
|
6
|
-
static parse
|
|
8
|
+
static parse() {
|
|
7
9
|
return qs.parse(globalThis.location.search.substr(1))
|
|
8
10
|
}
|
|
9
11
|
|
|
10
|
-
static change
|
|
12
|
+
static change(given) {
|
|
11
13
|
const incorporator = new Incorporator({objects: [Params.parse(), given]})
|
|
12
14
|
|
|
13
15
|
incorporator.replaceArrayIfExists(true)
|
|
@@ -15,23 +17,31 @@ export default class Params {
|
|
|
15
17
|
return incorporator.merge()
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
static
|
|
20
|
+
static withParams(params) {
|
|
21
|
+
const newParams = qs.stringify(params, {encoder: urlEncode})
|
|
22
|
+
const newPath = `${location.pathname}?${newParams}`
|
|
23
|
+
|
|
24
|
+
return newPath
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static changeParams(given, opts = {}) {
|
|
19
28
|
const params = Params.change(given)
|
|
20
|
-
const newParams = qs.stringify(params)
|
|
29
|
+
const newParams = qs.stringify(params, {encoder: urlEncode})
|
|
21
30
|
const newPath = `${location.pathname}?${newParams}`
|
|
31
|
+
const appHistory = opts.appHistory || config.getHistory()
|
|
22
32
|
|
|
23
|
-
|
|
33
|
+
if (!appHistory) throw new Error("AppHistory hasn't been set in the ApiMaker configuration")
|
|
24
34
|
|
|
25
35
|
appHistory.push(newPath)
|
|
26
36
|
}
|
|
27
37
|
|
|
28
|
-
static serializeForm
|
|
38
|
+
static serializeForm(form) {
|
|
29
39
|
const hash = formSerialize(form, {empty: true, hash: true})
|
|
30
40
|
return Params.setUndefined(hash)
|
|
31
41
|
}
|
|
32
42
|
|
|
33
43
|
// This is used to set all empty values to 'undefined' which makes qs removed those elements from the query string
|
|
34
|
-
static setUndefined
|
|
44
|
+
static setUndefined(given) {
|
|
35
45
|
if (Array.isArray(given)) {
|
|
36
46
|
if (given.length == 0)
|
|
37
47
|
return undefined
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import memo from "set-state-compare/src/memo"
|
|
2
|
+
import useResizeObserver from "./use-resize-observer"
|
|
3
|
+
|
|
4
|
+
const ApiMakerResizeObserver = memo(({element, onResize}) => {
|
|
5
|
+
useResizeObserver(element, onResize)
|
|
6
|
+
|
|
7
|
+
return null
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
export default ApiMakerResizeObserver
|
package/src/result.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export default class ApiMakerResult {
|
|
2
|
+
constructor (data) {
|
|
3
|
+
this.data = data
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
count = () => this.data.response.meta.count
|
|
7
|
+
currentPage = () => this.data.response.meta.currentPage
|
|
8
|
+
models = () => this.data.models
|
|
9
|
+
modelClass = () => this.data.collection.modelClass()
|
|
10
|
+
perPage = () => this.data.response.meta.perPage
|
|
11
|
+
totalCount = () => this.data.response.meta.totalCount
|
|
12
|
+
totalPages = () => this.data.response.meta.totalPages
|
|
13
|
+
}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import BaseComponent from "../base-component"
|
|
2
|
+
import React, {createContext, useContext, useMemo} from "react"
|
|
3
|
+
import memo from "set-state-compare/src/memo"
|
|
4
|
+
import PropTypes from "prop-types"
|
|
5
|
+
import propTypesExact from "prop-types-exact"
|
|
6
|
+
import {shapeComponent} from "set-state-compare/src/shape-component"
|
|
7
|
+
import Switch, {CurrentSwitchContext} from "./switch"
|
|
8
|
+
import useI18n from "i18n-on-steroids/src/use-i18n"
|
|
9
|
+
|
|
10
|
+
const CurrentPathContext = createContext([])
|
|
11
|
+
const ParamsContext = createContext({})
|
|
12
|
+
const RequireComponentContext = createContext(null)
|
|
13
|
+
const RouteContext = createContext(null)
|
|
14
|
+
const useParams = () => useContext(ParamsContext)
|
|
15
|
+
|
|
16
|
+
const Route = memo(shapeComponent(class Route extends BaseComponent {
|
|
17
|
+
static defaultProps = {
|
|
18
|
+
exact: false,
|
|
19
|
+
fallback: false,
|
|
20
|
+
includeInPath: true
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static propTypes = propTypesExact({
|
|
24
|
+
children: PropTypes.node,
|
|
25
|
+
component: PropTypes.string,
|
|
26
|
+
componentPath: PropTypes.string,
|
|
27
|
+
exact: PropTypes.bool.isRequired,
|
|
28
|
+
fallback: PropTypes.bool.isRequired,
|
|
29
|
+
includeInPath: PropTypes.bool.isRequired,
|
|
30
|
+
onMatch: PropTypes.func,
|
|
31
|
+
path: PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(RegExp)])
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
match = null
|
|
35
|
+
newParams = null
|
|
36
|
+
pathParts = null
|
|
37
|
+
|
|
38
|
+
setup() {
|
|
39
|
+
const {t} = useI18n({namespace: "js.api_maker.router.route"})
|
|
40
|
+
const {path} = this.props
|
|
41
|
+
const {pathsMatched, switchGroup} = useContext(CurrentSwitchContext)
|
|
42
|
+
const givenRoute = useContext(RouteContext)
|
|
43
|
+
const {pathShown} = switchGroup.s
|
|
44
|
+
|
|
45
|
+
this.debug = false
|
|
46
|
+
this.log(() => ({givenRoute}))
|
|
47
|
+
this.t = t
|
|
48
|
+
|
|
49
|
+
this.requireComponent = useContext(RequireComponentContext)
|
|
50
|
+
this.currentParams = useContext(ParamsContext)
|
|
51
|
+
this.currentPath = useContext(CurrentPathContext)
|
|
52
|
+
this.switchGroup = switchGroup
|
|
53
|
+
this.routeParts = useMemo(() => givenRoute?.split("/"), [path, givenRoute])
|
|
54
|
+
this.pathParts = useMemo(() => path?.split("/"), [path])
|
|
55
|
+
|
|
56
|
+
this.newRouteParts = useMemo(
|
|
57
|
+
() => {
|
|
58
|
+
if (!path) {
|
|
59
|
+
if (givenRoute == "") {
|
|
60
|
+
return []
|
|
61
|
+
} else {
|
|
62
|
+
return this.routeParts
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return this.routeParts.slice(this.pathParts.length, this.routeParts.length)
|
|
67
|
+
},
|
|
68
|
+
[givenRoute].concat(this.pathParts)
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
this.useStates({Component: null, componentNotFound: null, matches: false})
|
|
72
|
+
|
|
73
|
+
useMemo(() => {
|
|
74
|
+
this.loadMatches()
|
|
75
|
+
}, [givenRoute, path, pathsMatched])
|
|
76
|
+
|
|
77
|
+
useMemo(() => {
|
|
78
|
+
if (this.hasSwitchMatch() && !this.s.Component && this.s.matches) {
|
|
79
|
+
if (this.props.onMatch) {
|
|
80
|
+
this.props.onMatch()
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (!this.props.children && (this.props.path || this.props.component || this.props.componentPath)) {
|
|
84
|
+
this.loadComponent()
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}, [path, pathShown, this.s.matches])
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
hasSwitchMatch = () => this.switchGroup.s.pathShown && this.switchGroup.s.pathShown == this.pathId()
|
|
91
|
+
|
|
92
|
+
pathId() {
|
|
93
|
+
const {fallback} = this.p
|
|
94
|
+
const {path} = this.props
|
|
95
|
+
let pathId
|
|
96
|
+
|
|
97
|
+
if (fallback) {
|
|
98
|
+
pathId = "[FALLBACK]"
|
|
99
|
+
} else if (!path) {
|
|
100
|
+
pathId = "[PATH-EMPTY]"
|
|
101
|
+
} else {
|
|
102
|
+
pathId = path
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return pathId
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
loadMatches() {
|
|
109
|
+
const {newRouteParts, t} = this.tt
|
|
110
|
+
const {component, path} = this.props
|
|
111
|
+
const {exact, includeInPath, fallback} = this.p
|
|
112
|
+
|
|
113
|
+
let matches = true
|
|
114
|
+
const params = {}
|
|
115
|
+
const componentPathParts = [...this.currentPath]
|
|
116
|
+
|
|
117
|
+
this.log(() => [this.props.path, "Start generating component paths", JSON.stringify(componentPathParts)])
|
|
118
|
+
|
|
119
|
+
for (const pathPartIndex in this.pathParts) {
|
|
120
|
+
const pathPart = this.pathParts[pathPartIndex]
|
|
121
|
+
const translatedPathPart = t(`routes.${pathPart}`, {defaultValue: pathPart})
|
|
122
|
+
|
|
123
|
+
if (!(pathPartIndex in this.routeParts)) {
|
|
124
|
+
this.log(() => `No match for: ${pathPartIndex}`)
|
|
125
|
+
matches = false
|
|
126
|
+
break
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const routePart = decodeURIComponent(this.routeParts[pathPartIndex])
|
|
130
|
+
|
|
131
|
+
if (pathPart.startsWith(":") && routePart) {
|
|
132
|
+
const paramName = pathPart.slice(1, pathPart.length)
|
|
133
|
+
|
|
134
|
+
params[paramName] = routePart
|
|
135
|
+
} else if (translatedPathPart != routePart) {
|
|
136
|
+
matches = false
|
|
137
|
+
break
|
|
138
|
+
} else if (!component && includeInPath) {
|
|
139
|
+
componentPathParts.push(pathPart)
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (exact && newRouteParts.length > 0) {
|
|
144
|
+
this.log(() => ["Exact and more route parts", {newRouteParts, pathParts: this.pathParts, routeParts: this.routeParts}])
|
|
145
|
+
matches = false
|
|
146
|
+
} else if (matches && path) {
|
|
147
|
+
matches = true
|
|
148
|
+
} else if (this.routeParts.length == 0) {
|
|
149
|
+
matches = true
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const matchId = this.pathId()
|
|
153
|
+
|
|
154
|
+
if (!matches && fallback) {
|
|
155
|
+
matches = true
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
this.log(() => [this.props.path, "End generating component paths", JSON.stringify(componentPathParts), {matches}])
|
|
159
|
+
|
|
160
|
+
if (matches) {
|
|
161
|
+
if (component && includeInPath) {
|
|
162
|
+
componentPathParts.push(component)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const newParams = Object.assign({}, this.currentParams, params)
|
|
166
|
+
|
|
167
|
+
this.setInstance({componentPathParts, match: {params}, newParams})
|
|
168
|
+
this.setState({matches})
|
|
169
|
+
this.switchGroup?.setPathMatched(matchId, true)
|
|
170
|
+
} else {
|
|
171
|
+
this.setInstance({componentPathParts: null, match: null, newParams: null})
|
|
172
|
+
this.setState({matches})
|
|
173
|
+
this.switchGroup?.setPathMatched(matchId, false)
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
async loadComponent() {
|
|
178
|
+
const actualComponentPath = this.props.componentPath || this.tt.componentPathParts.join("/")
|
|
179
|
+
let Component
|
|
180
|
+
|
|
181
|
+
this.log(() => ["loadComponent", {componentPath: this.props.componentPath, componentPathParts: this.componentPathParts, actualComponentPath}])
|
|
182
|
+
|
|
183
|
+
try {
|
|
184
|
+
const componentImport = await this.tt.requireComponent({routeDefinition: {component: actualComponentPath}})
|
|
185
|
+
|
|
186
|
+
Component = componentImport
|
|
187
|
+
} catch (error) {
|
|
188
|
+
console.error(`Couldn't find component: ${actualComponentPath}`)
|
|
189
|
+
|
|
190
|
+
throw error
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
this.setState({Component, componentNotFound: !Component})
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
log(callbackArgs) {
|
|
197
|
+
if (this.debug) {
|
|
198
|
+
let args = callbackArgs()
|
|
199
|
+
|
|
200
|
+
if (!Array.isArray(args)) args = [args]
|
|
201
|
+
|
|
202
|
+
console.log(...args)
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
render() {
|
|
207
|
+
const {componentPathParts, match, newParams, newRouteParts} = this.tt
|
|
208
|
+
const {children, component, path} = this.props
|
|
209
|
+
const {Component, componentNotFound, matches} = this.s
|
|
210
|
+
|
|
211
|
+
if (!matches || !this.hasSwitchMatch()) {
|
|
212
|
+
// Route isn't matching and shouldn't be rendered at all.
|
|
213
|
+
return null
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (!Component && !children && !componentNotFound) {
|
|
217
|
+
// Route is matching but hasn't been loaded yet.
|
|
218
|
+
return (
|
|
219
|
+
<div>
|
|
220
|
+
Loading {component || this.props.componentPath || componentPathParts.join("/")}
|
|
221
|
+
</div>
|
|
222
|
+
)
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (!Component && !children && componentNotFound) {
|
|
226
|
+
// Don't render anything if the component couldn't be found.
|
|
227
|
+
return null
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return (
|
|
231
|
+
<CurrentPathContext.Provider value={componentPathParts}>
|
|
232
|
+
<RouteContext.Provider value={newRouteParts.join("/")}>
|
|
233
|
+
<ParamsContext.Provider value={newParams}>
|
|
234
|
+
<Switch name={`route-group-${path}`} single={false}>
|
|
235
|
+
{Component && <Component match={match} />}
|
|
236
|
+
{children}
|
|
237
|
+
</Switch>
|
|
238
|
+
</ParamsContext.Provider>
|
|
239
|
+
</RouteContext.Provider>
|
|
240
|
+
</CurrentPathContext.Provider>
|
|
241
|
+
)
|
|
242
|
+
}
|
|
243
|
+
}))
|
|
244
|
+
|
|
245
|
+
export {RequireComponentContext, RouteContext, Switch, useParams}
|
|
246
|
+
export default Route
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import BaseComponent from "../base-component"
|
|
2
|
+
import React, {createContext} from "react"
|
|
3
|
+
import memo from "set-state-compare/src/memo"
|
|
4
|
+
import PropTypes from "prop-types"
|
|
5
|
+
import propTypesExact from "prop-types-exact"
|
|
6
|
+
import {shapeComponent} from "set-state-compare/src/shape-component"
|
|
7
|
+
|
|
8
|
+
const CurrentSwitchContext = createContext([])
|
|
9
|
+
|
|
10
|
+
const Switch = memo(shapeComponent(class Switch extends BaseComponent {
|
|
11
|
+
static defaultProps = {
|
|
12
|
+
name: "[no name]",
|
|
13
|
+
single: true
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static propTypes = propTypesExact({
|
|
17
|
+
children: PropTypes.node,
|
|
18
|
+
name: PropTypes.string,
|
|
19
|
+
single: PropTypes.bool
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
pathsMatchedKeys = []
|
|
23
|
+
|
|
24
|
+
setup() {
|
|
25
|
+
this.useStates({
|
|
26
|
+
lastUpdate: new Date(),
|
|
27
|
+
pathShown: undefined,
|
|
28
|
+
pathsMatched: {}
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
render() {
|
|
33
|
+
const {pathShown, pathsMatched} = this.s
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<CurrentSwitchContext.Provider value={{pathShown, pathsMatched, switchGroup: this}}>
|
|
37
|
+
{this.props.children}
|
|
38
|
+
</CurrentSwitchContext.Provider>
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
pathShown(pathsMatched) {
|
|
43
|
+
for (const pathMatched of this.tt.pathsMatchedKeys) {
|
|
44
|
+
const isPathMatched = pathsMatched[pathMatched]
|
|
45
|
+
|
|
46
|
+
if (isPathMatched) {
|
|
47
|
+
return pathMatched
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
setPathMatched(path, matched) {
|
|
53
|
+
const {pathsMatchedKeys} = this.tt
|
|
54
|
+
const {pathsMatched} = this.s
|
|
55
|
+
|
|
56
|
+
if (!path) throw new Error("No 'path' given")
|
|
57
|
+
if (pathsMatched[path] == matched) return
|
|
58
|
+
|
|
59
|
+
if (!pathsMatchedKeys.includes(path)) {
|
|
60
|
+
pathsMatchedKeys.push(path)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const newPathsMatched = {...this.s.pathsMatched}
|
|
64
|
+
|
|
65
|
+
newPathsMatched[path] = matched
|
|
66
|
+
|
|
67
|
+
this.setState({
|
|
68
|
+
lastUpdate: Math.random() + new Date().getTime(),
|
|
69
|
+
pathShown: this.pathShown(newPathsMatched),
|
|
70
|
+
pathsMatched: newPathsMatched
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
}))
|
|
74
|
+
|
|
75
|
+
export {CurrentSwitchContext}
|
|
76
|
+
export default Switch
|