@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
package/src/devise.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import Deserializer from "./deserializer"
|
|
2
|
+
import events from "./events"
|
|
3
|
+
import * as inflection from "inflection"
|
|
4
|
+
import modelClassRequire from "./model-class-require"
|
|
5
|
+
import Services from "./services"
|
|
6
|
+
|
|
7
|
+
if (!globalThis.ApiMakerDevise) globalThis.ApiMakerDevise = {scopes: {}}
|
|
8
|
+
|
|
9
|
+
const shared = globalThis.ApiMakerDevise
|
|
10
|
+
|
|
11
|
+
export default class ApiMakerDevise {
|
|
12
|
+
static callSignOutEvent(args) {
|
|
13
|
+
events.emit("onDeviseSignOut", {args})
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static current() {
|
|
17
|
+
if (!shared.currentApiMakerDevise) {
|
|
18
|
+
shared.currentApiMakerDevise = new ApiMakerDevise()
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return shared.currentApiMakerDevise
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static events() {
|
|
25
|
+
return events
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
static addUserScope(scope, args = {}) {
|
|
29
|
+
const currentMethodName = `current${inflection.camelize(scope)}`
|
|
30
|
+
const isSignedInMethodName = `is${inflection.camelize(scope)}SignedIn`
|
|
31
|
+
const getArgsMethodName = `get${inflection.camelize(scope)}Args`
|
|
32
|
+
|
|
33
|
+
ApiMakerDevise[currentMethodName] = () => ApiMakerDevise.current().getCurrentScope(scope)
|
|
34
|
+
ApiMakerDevise[isSignedInMethodName] = () => Boolean(ApiMakerDevise.current().getCurrentScope(scope))
|
|
35
|
+
ApiMakerDevise[getArgsMethodName] = () => args
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static async signIn(username, password, args = {}) {
|
|
39
|
+
if (!args.scope) args.scope = "user"
|
|
40
|
+
|
|
41
|
+
const postData = {username, password, args}
|
|
42
|
+
const response = await Services.current().sendRequest("Devise::SignIn", postData)
|
|
43
|
+
|
|
44
|
+
let model = response.model
|
|
45
|
+
|
|
46
|
+
if (Array.isArray(model)) model = model[0]
|
|
47
|
+
|
|
48
|
+
ApiMakerDevise.updateSession(model)
|
|
49
|
+
events.emit("onDeviseSignIn", Object.assign({username}, args))
|
|
50
|
+
|
|
51
|
+
return {model, response}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static updateSession(model, args = {}) {
|
|
55
|
+
if (!args.scope) args.scope = "user"
|
|
56
|
+
|
|
57
|
+
const camelizedScopeName = inflection.camelize(args.scope, true)
|
|
58
|
+
|
|
59
|
+
ApiMakerDevise.current().currents[camelizedScopeName] = model
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
hasCurrentScope(scope) {
|
|
63
|
+
const camelizedScopeName = inflection.camelize(scope, true)
|
|
64
|
+
|
|
65
|
+
return camelizedScopeName in ApiMakerDevise.current().currents
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
static setSignedOut(args) {
|
|
69
|
+
ApiMakerDevise.current().currents[inflection.camelize(args.scope, true)] = null
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
static async signOut(args = {}) {
|
|
73
|
+
if (!args.scope) {
|
|
74
|
+
args.scope = "user"
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const response = await Services.current().sendRequest("Devise::SignOut", {args})
|
|
78
|
+
|
|
79
|
+
// Cannot use the class because they would both import each other
|
|
80
|
+
if (shared.apiMakerSessionStatusUpdater) {
|
|
81
|
+
shared.apiMakerSessionStatusUpdater.updateSessionStatus()
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
ApiMakerDevise.setSignedOut(args)
|
|
85
|
+
ApiMakerDevise.callSignOutEvent(args)
|
|
86
|
+
|
|
87
|
+
return response
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
constructor() {
|
|
91
|
+
this.currents = {}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
getCurrentScope(scope) {
|
|
95
|
+
if (!(scope in this.currents)) {
|
|
96
|
+
this.currents[scope] = this.loadCurrentScope(scope)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return this.currents[scope]
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
hasGlobalCurrentScope(scope) {
|
|
103
|
+
if (globalThis.apiMakerDeviseCurrent && scope in globalThis.apiMakerDeviseCurrent) {
|
|
104
|
+
return true
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return false
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
loadCurrentScope(scope) {
|
|
111
|
+
if (!this.hasGlobalCurrentScope(scope)) {
|
|
112
|
+
return null
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const scopeData = globalThis.apiMakerDeviseCurrent[scope]
|
|
116
|
+
|
|
117
|
+
if (!scopeData) return null
|
|
118
|
+
|
|
119
|
+
const parsedScopeData = Deserializer.parse(scopeData)
|
|
120
|
+
|
|
121
|
+
// Might be a collection with preloaded relationships
|
|
122
|
+
if (Array.isArray(parsedScopeData)) return parsedScopeData[0]
|
|
123
|
+
|
|
124
|
+
const ModelClass = modelClassRequire(scope)
|
|
125
|
+
const modelInstance = new ModelClass({data: parsedScopeData})
|
|
126
|
+
|
|
127
|
+
return modelInstance
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import {digg} from "diggerize"
|
|
2
|
+
import EventEmitter from "events"
|
|
3
|
+
|
|
4
|
+
export default class DraggableSortController {
|
|
5
|
+
constructor({data, events, keyExtractor}) {
|
|
6
|
+
this.data = data
|
|
7
|
+
this.currentOrder = [...data]
|
|
8
|
+
this.events = events || new EventEmitter()
|
|
9
|
+
this.keyExtractor = keyExtractor
|
|
10
|
+
|
|
11
|
+
this.draggedItem = null
|
|
12
|
+
this.draggedItemData = null
|
|
13
|
+
this.draggedItemNewPosition = null
|
|
14
|
+
|
|
15
|
+
this.draggedOverItem = null
|
|
16
|
+
this.draggedOverItemData = null
|
|
17
|
+
|
|
18
|
+
this.itemData = {}
|
|
19
|
+
|
|
20
|
+
for (const itemIndex in data) {
|
|
21
|
+
this.itemData[itemIndex] = {
|
|
22
|
+
index: itemIndex,
|
|
23
|
+
item: data[itemIndex],
|
|
24
|
+
position: itemIndex
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
getEvents = () => this.events
|
|
30
|
+
getItemDataForItem = (item) => this.getItemDataForIndex(this.data.indexOf(item))
|
|
31
|
+
getItemDataForKey = (key) => this.itemData.find((itemDataI) => digg(itemDataI, "key") == key)
|
|
32
|
+
getItemDataForIndex = (index) => digg(this, "itemData", index)
|
|
33
|
+
|
|
34
|
+
onDragStart = ({item, itemIndex}) => {
|
|
35
|
+
if (item) {
|
|
36
|
+
this.draggedItem = item
|
|
37
|
+
this.draggedItemData = this.getItemDataForIndex(itemIndex)
|
|
38
|
+
this.draggedItemIndex = itemIndex
|
|
39
|
+
this.draggedItemPosition = this.draggedItemData.position
|
|
40
|
+
this.events.emit("onDragStart", {item, itemData: this.draggedItemData})
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
onDragEnd = () => {
|
|
45
|
+
const itemData = this.draggedItemData
|
|
46
|
+
const fromIndex = itemData.index
|
|
47
|
+
const fromPosition = digg(this, "draggedItemPosition")
|
|
48
|
+
const toPosition = this.draggedItemNewPosition
|
|
49
|
+
const fromItem = this.draggedItem
|
|
50
|
+
const toItem = this.draggedOverItem
|
|
51
|
+
const callbackArgs = {item: itemData.item, itemData, fromIndex, fromItem, fromPosition, toItem, toPosition}
|
|
52
|
+
|
|
53
|
+
this.draggedItemData.events.emit("resetPosition", {
|
|
54
|
+
callback: () => {
|
|
55
|
+
this.events.emit("onDragEndAnimation", callbackArgs)
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
this.draggedItem = null
|
|
60
|
+
this.draggedItemData = null
|
|
61
|
+
this.draggedItemNewPosition = null
|
|
62
|
+
|
|
63
|
+
this.draggedOverItem = null
|
|
64
|
+
this.draggedOverItemData = null
|
|
65
|
+
|
|
66
|
+
this.events.emit("onDragEnd", callbackArgs)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
onItemLayout = ({events, index, item, layout}) => {
|
|
70
|
+
if (!(index in this.itemData)) throw new Error(`Item not found for index ${index}`)
|
|
71
|
+
|
|
72
|
+
const itemData = this.itemData[index]
|
|
73
|
+
|
|
74
|
+
itemData.layout = layout
|
|
75
|
+
|
|
76
|
+
if (!itemData.initialLayout) {
|
|
77
|
+
itemData.baseX = layout.x
|
|
78
|
+
itemData.events = events
|
|
79
|
+
itemData.initialLayout = layout
|
|
80
|
+
itemData.key = this.keyExtractor(item)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
onMove = ({gestate}) => {
|
|
85
|
+
// Send move-event to the item being dragged so it will actually move around
|
|
86
|
+
this.draggedItemData?.events?.emit("move", {gestate})
|
|
87
|
+
|
|
88
|
+
const moveX = gestate.dx + this.initialDragPosition.x
|
|
89
|
+
|
|
90
|
+
for (const itemIndex in this.itemData) {
|
|
91
|
+
const itemData = this.getItemDataForIndex(itemIndex)
|
|
92
|
+
const baseX = digg(itemData, "baseX")
|
|
93
|
+
let smallestWidth = this.draggedItemData.layout.width
|
|
94
|
+
|
|
95
|
+
if (itemData.layout.width < smallestWidth) smallestWidth = itemData.layout.width
|
|
96
|
+
|
|
97
|
+
if (moveX > baseX && moveX < (baseX + smallestWidth) && itemIndex != this.draggedItemData.index) {
|
|
98
|
+
this.draggedOverItem = itemData.item
|
|
99
|
+
this.draggedOverItemData = itemData
|
|
100
|
+
|
|
101
|
+
const positionOfDraggedItem = this.currentOrder.indexOf(this.draggedItemData.item)
|
|
102
|
+
const positionOfOverItem = this.currentOrder.indexOf(this.draggedOverItemData.item)
|
|
103
|
+
|
|
104
|
+
this.currentOrder[positionOfDraggedItem] = this.draggedOverItemData.item
|
|
105
|
+
this.currentOrder[positionOfOverItem] = this.draggedItemData.item
|
|
106
|
+
|
|
107
|
+
this.draggedItemData.position = positionOfOverItem
|
|
108
|
+
this.draggedOverItemData.position = positionOfDraggedItem
|
|
109
|
+
|
|
110
|
+
this.updatePositionOfItems()
|
|
111
|
+
this.draggedItemNewPosition = positionOfOverItem
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
setInitialDragPosition = (initialDragPosition) => {
|
|
117
|
+
this.initialDragPosition = initialDragPosition
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
updatePositionOfItems() {
|
|
121
|
+
let currentPosition = 0
|
|
122
|
+
|
|
123
|
+
for (const item of this.currentOrder) {
|
|
124
|
+
const itemData = this.getItemDataForItem(item)
|
|
125
|
+
|
|
126
|
+
if (digg(itemData, "index") != digg(this, "draggedItemData", "index")) { // Dont animate dragged element to a new position because it is currently being dragged
|
|
127
|
+
itemData.events.emit("moveToPosition", {
|
|
128
|
+
x: currentPosition,
|
|
129
|
+
y: 0
|
|
130
|
+
})
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
itemData.baseX = currentPosition
|
|
134
|
+
currentPosition += digg(itemData, "layout", "width")
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import React, {useMemo} from "react"
|
|
2
|
+
import {Animated, PanResponder} from "react-native"
|
|
3
|
+
import {shapeComponent, ShapeComponent} from "set-state-compare/src/shape-component"
|
|
4
|
+
import Controller from "./controller"
|
|
5
|
+
import DraggableSortItem from "./item"
|
|
6
|
+
import EventEmitter from "events"
|
|
7
|
+
import memo from "set-state-compare/src/memo"
|
|
8
|
+
import PropTypes from "prop-types"
|
|
9
|
+
import propTypesExact from "prop-types-exact"
|
|
10
|
+
import useEventEmitter from "../use-event-emitter"
|
|
11
|
+
|
|
12
|
+
export default memo(shapeComponent(class DraggableSort extends ShapeComponent {
|
|
13
|
+
static defaultProps = {
|
|
14
|
+
horizontal: false
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static propTypes = propTypesExact({
|
|
18
|
+
cacheKeyExtractor: PropTypes.func,
|
|
19
|
+
data: PropTypes.array.isRequired,
|
|
20
|
+
dataSet: PropTypes.object,
|
|
21
|
+
events: PropTypes.instanceOf(EventEmitter),
|
|
22
|
+
horizontal: PropTypes.bool.isRequired,
|
|
23
|
+
keyExtractor: PropTypes.func.isRequired,
|
|
24
|
+
onDragItemEnd: PropTypes.func,
|
|
25
|
+
onDragItemStart: PropTypes.func,
|
|
26
|
+
onItemMoved: PropTypes.func,
|
|
27
|
+
onReordered: PropTypes.func.isRequired,
|
|
28
|
+
renderItem: PropTypes.func.isRequired
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
setup() {
|
|
32
|
+
const {data, keyExtractor} = this.p
|
|
33
|
+
const {events} = this.props
|
|
34
|
+
|
|
35
|
+
this.controller = useMemo(() => new Controller({data, events, keyExtractor}), [])
|
|
36
|
+
this.panResponder = useMemo(
|
|
37
|
+
() => PanResponder.create({
|
|
38
|
+
onStartShouldSetPanResponder: (e) => {
|
|
39
|
+
const initialDragPosition = {x: e.nativeEvent.locationX, y: e.nativeEvent.locationY}
|
|
40
|
+
|
|
41
|
+
this.controller.setInitialDragPosition(initialDragPosition)
|
|
42
|
+
|
|
43
|
+
if (this.controller.draggedItemData) {
|
|
44
|
+
return true
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
onPanResponderMove: (e, gestate) => {
|
|
48
|
+
this.tt.controller.onMove({gestate})
|
|
49
|
+
},
|
|
50
|
+
onPanResponderRelease: (e, gestate) => {
|
|
51
|
+
if (this.controller.draggedItem) {
|
|
52
|
+
this.tt.controller.onDragEnd()
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}),
|
|
56
|
+
[]
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
useEventEmitter(this.controller.getEvents(), "onDragStart", this.tt.onDragItemStart)
|
|
60
|
+
useEventEmitter(this.controller.getEvents(), "onDragEnd", this.tt.onDragItemEnd)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
render() {
|
|
64
|
+
const {data, horizontal, keyExtractor, renderItem} = this.p
|
|
65
|
+
const {cacheKeyExtractor, dataSet} = this.props
|
|
66
|
+
const actualDataSet = useMemo(
|
|
67
|
+
() => Object.assign(
|
|
68
|
+
{
|
|
69
|
+
component: "draggable-sort"
|
|
70
|
+
},
|
|
71
|
+
dataSet
|
|
72
|
+
),
|
|
73
|
+
[dataSet]
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<Animated.View dataSet={actualDataSet} style={{flexDirection: horizontal ? "row" : "column"}} {...this.tt.panResponder.panHandlers}>
|
|
78
|
+
{data.map((item, itemIndex) =>
|
|
79
|
+
<DraggableSortItem
|
|
80
|
+
cacheKey={cacheKeyExtractor ? cacheKeyExtractor(item) : undefined}
|
|
81
|
+
controller={this.tt.controller}
|
|
82
|
+
item={item}
|
|
83
|
+
itemIndex={itemIndex}
|
|
84
|
+
key={keyExtractor(item)}
|
|
85
|
+
onItemMoved={this.props.onItemMoved}
|
|
86
|
+
renderItem={renderItem}
|
|
87
|
+
/>
|
|
88
|
+
)}
|
|
89
|
+
</Animated.View>
|
|
90
|
+
)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
onDragItemStart = ({itemData}) => {
|
|
94
|
+
if (this.props.onDragItemStart) {
|
|
95
|
+
this.p.onDragItemStart({itemData})
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
onDragItemEnd = (args) => {
|
|
100
|
+
if (args.toPosition !== null) {
|
|
101
|
+
this.p.onReordered(args)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (this.props.onDragItemEnd) {
|
|
105
|
+
this.p.onDragItemEnd(args)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}))
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import React, {useMemo} from "react"
|
|
2
|
+
import {Animated, Easing, PanResponder} from "react-native"
|
|
3
|
+
import {shapeComponent, ShapeComponent} from "set-state-compare/src/shape-component"
|
|
4
|
+
import EventEmitter from "events"
|
|
5
|
+
import memo from "set-state-compare/src/memo"
|
|
6
|
+
import PropTypes from "prop-types"
|
|
7
|
+
import propTypesExact from "prop-types-exact"
|
|
8
|
+
import useEventEmitter from "../use-event-emitter"
|
|
9
|
+
|
|
10
|
+
export default memo(shapeComponent(class DraggableSortItem extends ShapeComponent {
|
|
11
|
+
static propTypes = propTypesExact({
|
|
12
|
+
cacheKey: PropTypes.string,
|
|
13
|
+
controller: PropTypes.object.isRequired,
|
|
14
|
+
item: PropTypes.any.isRequired,
|
|
15
|
+
itemIndex: PropTypes.number.isRequired,
|
|
16
|
+
onItemMoved: PropTypes.func,
|
|
17
|
+
renderItem: PropTypes.func.isRequired
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
initialLayout = null
|
|
21
|
+
|
|
22
|
+
setup() {
|
|
23
|
+
this.useStates({
|
|
24
|
+
active: false,
|
|
25
|
+
dragging: false
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
this.events = useMemo(() => new EventEmitter(), [])
|
|
29
|
+
this.position = useMemo(() => new Animated.ValueXY(), [])
|
|
30
|
+
this.panResponder = useMemo(
|
|
31
|
+
() => PanResponder.create({
|
|
32
|
+
onStartShouldSetPanResponder: (e, ) => {
|
|
33
|
+
this.setState({dragging: true})
|
|
34
|
+
this.p.controller.onDragStart({item: this.p.item, itemIndex: this.p.itemIndex})
|
|
35
|
+
|
|
36
|
+
return false
|
|
37
|
+
}
|
|
38
|
+
}),
|
|
39
|
+
[]
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
useEventEmitter(this.p.controller.getEvents(), "onDragStart", this.tt.onDragStart)
|
|
43
|
+
useEventEmitter(this.p.controller.getEvents(), "onDragEndAnimation", this.tt.onDragEndAnimation)
|
|
44
|
+
useEventEmitter(this.tt.events, "move", this.tt.onMove)
|
|
45
|
+
useEventEmitter(this.tt.events, "moveToPosition", this.tt.onMoveToPosition)
|
|
46
|
+
useEventEmitter(this.tt.events, "resetPosition", this.tt.onResetPosition)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
render() {
|
|
50
|
+
const {item, renderItem} = this.p
|
|
51
|
+
const {active} = this.s
|
|
52
|
+
const style = useMemo(
|
|
53
|
+
() => {
|
|
54
|
+
const style = {
|
|
55
|
+
transform: this.tt.position.getTranslateTransform()
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (active) {
|
|
59
|
+
style.backgroundColor = "#fff"
|
|
60
|
+
style.elevation = 2
|
|
61
|
+
style.zIndex = 99999
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return style
|
|
65
|
+
},
|
|
66
|
+
[active]
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<Animated.View dataSet={{component: "draggable-sort/item"}} onLayout={this.tt.onLayout} style={style}>
|
|
71
|
+
{renderItem({isActive: active, item, touchProps: this.tt.panResponder.panHandlers})}
|
|
72
|
+
</Animated.View>
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
onDragStart = ({itemData}) => {
|
|
77
|
+
const newState = {dragging: true}
|
|
78
|
+
|
|
79
|
+
if (itemData.index == this.p.itemIndex) {
|
|
80
|
+
newState.active = true
|
|
81
|
+
this.baseXAtStartedDragging = this.getBaseX()
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
this.setState(newState)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
onDragEndAnimation = () => this.setState({active: false, dragging: false})
|
|
88
|
+
|
|
89
|
+
onLayout = (e) => {
|
|
90
|
+
const {controller, item, itemIndex} = this.p
|
|
91
|
+
|
|
92
|
+
controller.onItemLayout({events: this.tt.events, index: itemIndex, item, layout: e.nativeEvent.layout})
|
|
93
|
+
|
|
94
|
+
if (!this.tt.initialLayout) {
|
|
95
|
+
this.initialLayout = e.nativeEvent.layout
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
onMove = ({gestate}) => {
|
|
100
|
+
const x = gestate.dx + this.tt.baseXAtStartedDragging - this.tt.initialLayout.x
|
|
101
|
+
const y = this.tt.initialLayout.y
|
|
102
|
+
|
|
103
|
+
this.tt.position.setValue({x, y})
|
|
104
|
+
|
|
105
|
+
if (this.props.onItemMoved) {
|
|
106
|
+
this.p.onItemMoved({itemIndex: this.p.itemIndex, x, y})
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
onMoveToPosition = ({x, y}) => {
|
|
111
|
+
const calculatedXFromStartingPosition = x - this.tt.initialLayout.x
|
|
112
|
+
const animationArgs = {
|
|
113
|
+
duration: 200,
|
|
114
|
+
easing: Easing.inOut(Easing.linear),
|
|
115
|
+
toValue: {
|
|
116
|
+
x: calculatedXFromStartingPosition,
|
|
117
|
+
y
|
|
118
|
+
},
|
|
119
|
+
useNativeDriver: true,
|
|
120
|
+
}
|
|
121
|
+
const animationEventArgs = {animationArgs, animationType: "moveToPosition", item: this.p.item}
|
|
122
|
+
|
|
123
|
+
this.p.controller.events.emit("onAnimationStart", animationEventArgs)
|
|
124
|
+
|
|
125
|
+
Animated
|
|
126
|
+
.timing(this.tt.position, animationArgs)
|
|
127
|
+
.start(() => {
|
|
128
|
+
this.p.controller.events.emit("onAnimationEnd", animationEventArgs)
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
if (this.props.onItemMoved) {
|
|
132
|
+
this.p.onItemMoved({
|
|
133
|
+
animationArgs,
|
|
134
|
+
itemIndex: this.p.itemIndex,
|
|
135
|
+
x: calculatedXFromStartingPosition,
|
|
136
|
+
y
|
|
137
|
+
})
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
getBaseX = () => this.p.controller.getItemDataForIndex(this.p.itemIndex).baseX
|
|
142
|
+
|
|
143
|
+
onResetPosition = (args) => {
|
|
144
|
+
const baseX = this.getBaseX() - this.tt.initialLayout.x
|
|
145
|
+
const animationArgs = {
|
|
146
|
+
duration: 200,
|
|
147
|
+
easing: Easing.inOut(Easing.linear),
|
|
148
|
+
toValue: {
|
|
149
|
+
x: baseX,
|
|
150
|
+
y: 0
|
|
151
|
+
},
|
|
152
|
+
useNativeDriver: true,
|
|
153
|
+
}
|
|
154
|
+
const animationEventArgs = {animationArgs, animationType: "resetPosition", item: this.p.item}
|
|
155
|
+
|
|
156
|
+
this.p.controller.events.emit("onAnimationStart", animationEventArgs)
|
|
157
|
+
|
|
158
|
+
Animated
|
|
159
|
+
.timing(this.tt.position, animationArgs)
|
|
160
|
+
.start(() => {
|
|
161
|
+
this.p.controller.events.emit("onAnimationEnd", animationEventArgs)
|
|
162
|
+
if (args?.callback) args.callback()
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
if (this.props.onItemMoved) {
|
|
166
|
+
this.p.onItemMoved({
|
|
167
|
+
animationArgs,
|
|
168
|
+
itemIndex: this.p.itemIndex,
|
|
169
|
+
x: baseX,
|
|
170
|
+
y: 0
|
|
171
|
+
})
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}))
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {digg} from "diggerize"
|
|
2
|
-
import SourceMapsLoader from "./source-maps-loader
|
|
2
|
+
import SourceMapsLoader from "./source-maps-loader"
|
|
3
3
|
|
|
4
4
|
export default class ErrorLogger {
|
|
5
5
|
constructor () {
|
|
6
|
-
this.
|
|
6
|
+
this.debugging = false
|
|
7
7
|
this.errorOccurred = false
|
|
8
8
|
this.errors = []
|
|
9
9
|
this.isHandlingError = false
|
|
@@ -18,14 +18,17 @@ export default class ErrorLogger {
|
|
|
18
18
|
})
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
debug(...output) {
|
|
22
|
+
if (this.debugging) console.error(`ApiMaker ErrorLogger:`, ...output)
|
|
23
|
+
}
|
|
24
|
+
|
|
21
25
|
enable () {
|
|
26
|
+
this.debug("Enable called")
|
|
22
27
|
this.connectOnError()
|
|
23
28
|
this.connectUnhandledRejection()
|
|
24
29
|
}
|
|
25
30
|
|
|
26
|
-
getErrors ()
|
|
27
|
-
return this.errors
|
|
28
|
-
}
|
|
31
|
+
getErrors = () => this.errors
|
|
29
32
|
|
|
30
33
|
hasErrorOccurred() {
|
|
31
34
|
return digg(this, "errorOccurred")
|
|
@@ -40,7 +43,8 @@ export default class ErrorLogger {
|
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
connectOnError () {
|
|
43
|
-
|
|
46
|
+
window.addEventListener("error", (event) => {
|
|
47
|
+
if (this.debugging) this.debug(`Error:`, event.message)
|
|
44
48
|
this.errorOccurred = true
|
|
45
49
|
|
|
46
50
|
if (!this.isHandlingError) {
|
|
@@ -53,7 +57,8 @@ export default class ErrorLogger {
|
|
|
53
57
|
}
|
|
54
58
|
|
|
55
59
|
connectUnhandledRejection () {
|
|
56
|
-
|
|
60
|
+
window.addEventListener("unhandledrejection", (event) => {
|
|
61
|
+
if (this.debugging) this.debug(`Unhandled rejection:`, event.reason.message)
|
|
57
62
|
this.errorOccurred = true
|
|
58
63
|
|
|
59
64
|
if (!this.isHandlingError) {
|
package/src/event-connection.jsx
CHANGED
|
@@ -1,32 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import PropTypes from "prop-types"
|
|
3
|
-
import React from "react"
|
|
1
|
+
import useEventEmitter from "./use-event-emitter"
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
event: PropTypes.string.isRequired,
|
|
8
|
-
events: PropTypes.instanceOf(EventEmitter).isRequired,
|
|
9
|
-
onCalled: PropTypes.func.isRequired
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
constructor (props) {
|
|
13
|
-
super(props)
|
|
14
|
-
this.onCalled = this.onCalled.bind(this)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
componentDidMount () {
|
|
18
|
-
this.props.events.addListener(this.props.event, this.onCalled)
|
|
19
|
-
}
|
|
3
|
+
const EventEmitterListener = ({event, events, onCalled, ...restProps}) => {
|
|
4
|
+
const restPropsKeys = Object.keys(restProps)
|
|
20
5
|
|
|
21
|
-
|
|
22
|
-
|
|
6
|
+
if (restPropsKeys.length > 0) {
|
|
7
|
+
throw new Error(`Unexpected props: ${restPropsKeys}`)
|
|
23
8
|
}
|
|
24
9
|
|
|
25
|
-
onCalled
|
|
26
|
-
this.props.onCalled.apply(null, ...args)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
render () {
|
|
30
|
-
return null
|
|
31
|
-
}
|
|
10
|
+
useEventEmitter(events, event, onCalled)
|
|
32
11
|
}
|
|
12
|
+
|
|
13
|
+
export default EventEmitterListener
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import ModelEvents from "./model-events
|
|
1
|
+
import ModelEvents from "./model-events"
|
|
2
2
|
import PropTypes from "prop-types"
|
|
3
3
|
import propTypesExact from "prop-types-exact"
|
|
4
4
|
import React from "react"
|
|
@@ -24,7 +24,5 @@ export default class ApiMakerEventModelClass extends React.PureComponent {
|
|
|
24
24
|
this.connection = ModelEvents.connectModelClass(this.props.modelClass, this.props.event, this.props.onCall)
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
render ()
|
|
28
|
-
return null
|
|
29
|
-
}
|
|
27
|
+
render = () => null
|
|
30
28
|
}
|