@kaspernj/api-maker 1.0.2054 → 1.0.2055
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/build/api.js +64 -212
- package/build/api.js.map +1 -1
- package/build/attribute-not-loaded-error.js +2 -25
- package/build/attribute-not-loaded-error.js.map +1 -1
- package/build/base-component.js +3 -26
- package/build/base-component.js.map +1 -1
- package/build/base-error.js +20 -45
- package/build/base-error.js.map +1 -1
- package/build/base-model/attribute.js +14 -21
- package/build/base-model/attribute.js.map +1 -1
- package/build/base-model/column.js +4 -8
- package/build/base-model/column.js.map +1 -1
- package/build/base-model/reflection.js +11 -51
- package/build/base-model/reflection.js.map +1 -1
- package/build/base-model/scope.js +8 -45
- package/build/base-model/scope.js.map +1 -1
- package/build/base-model.js +583 -836
- package/build/base-model.js.map +1 -1
- package/build/bootstrap/attribute-row.js +87 -172
- package/build/bootstrap/attribute-row.js.map +1 -1
- package/build/bootstrap/attribute-rows.js +21 -50
- package/build/bootstrap/attribute-rows.js.map +1 -1
- package/build/bootstrap/card.js +76 -159
- package/build/bootstrap/card.js.map +1 -1
- package/build/bootstrap/checkbox.js +53 -102
- package/build/bootstrap/checkbox.js.map +1 -1
- package/build/bootstrap/checkboxes.js +116 -202
- package/build/bootstrap/checkboxes.js.map +1 -1
- package/build/bootstrap/input.js +80 -131
- package/build/bootstrap/input.js.map +1 -1
- package/build/bootstrap/invalid-feedback.js +18 -46
- package/build/bootstrap/invalid-feedback.js.map +1 -1
- package/build/bootstrap/paginate.js +99 -164
- package/build/bootstrap/paginate.js.map +1 -1
- package/build/bootstrap/radio-buttons.js +43 -80
- package/build/bootstrap/radio-buttons.js.map +1 -1
- package/build/bootstrap/select.js +43 -90
- package/build/bootstrap/select.js.map +1 -1
- package/build/bootstrap/sort-link.js +68 -151
- package/build/bootstrap/sort-link.js.map +1 -1
- package/build/cable-connection-pool.js +43 -65
- package/build/cable-connection-pool.js.map +1 -1
- package/build/cable-subscription-pool.js +104 -161
- package/build/cable-subscription-pool.js.map +1 -1
- package/build/cable-subscription.js +9 -16
- package/build/cable-subscription.js.map +1 -1
- package/build/cache-key-generator.js +27 -36
- package/build/cache-key-generator.js.map +1 -1
- package/build/can-can.js +80 -201
- package/build/can-can.js.map +1 -1
- package/build/channels-consumer.js +5 -10
- package/build/channels-consumer.js.map +1 -1
- package/build/collection-loader.js +35 -53
- package/build/collection-loader.js.map +1 -1
- package/build/collection.js +160 -307
- package/build/collection.js.map +1 -1
- package/build/command-submit-data.d.ts +1 -1
- package/build/command-submit-data.d.ts.map +1 -1
- package/build/command-submit-data.js +29 -38
- package/build/command-submit-data.js.map +1 -1
- package/build/commands-pool.js +139 -215
- package/build/commands-pool.js.map +1 -1
- package/build/compose.js +3 -11
- package/build/compose.js.map +1 -1
- package/build/config.js +20 -67
- package/build/config.js.map +1 -1
- package/build/custom-error.js +4 -29
- package/build/custom-error.js.map +1 -1
- package/build/data-set-to-attributes.js +5 -41
- package/build/data-set-to-attributes.js.map +1 -1
- package/build/deserializer.js +26 -79
- package/build/deserializer.js.map +1 -1
- package/build/destroy-error.js +4 -29
- package/build/destroy-error.js.map +1 -1
- package/build/devise.js +83 -187
- package/build/devise.js.map +1 -1
- package/build/draggable-sort/controller.js +87 -110
- package/build/draggable-sort/controller.js.map +1 -1
- package/build/draggable-sort/index.js +67 -144
- package/build/draggable-sort/index.js.map +1 -1
- package/build/draggable-sort/item.js +131 -197
- package/build/draggable-sort/item.js.map +1 -1
- package/build/error-logger.js +78 -163
- package/build/error-logger.js.map +1 -1
- package/build/error-messages.js +4 -7
- package/build/error-messages.js.map +1 -1
- package/build/event-connection.js +23 -61
- package/build/event-connection.js.map +1 -1
- package/build/event-emitter-listener.js +6 -23
- package/build/event-emitter-listener.js.map +1 -1
- package/build/event-model-class.js +19 -46
- package/build/event-model-class.js.map +1 -1
- package/build/events.js +3 -8
- package/build/events.js.map +1 -1
- package/build/form.js +65 -153
- package/build/form.js.map +1 -1
- package/build/history-expo.js +12 -24
- package/build/history-expo.js.map +1 -1
- package/build/history-react-native.js +14 -26
- package/build/history-react-native.js.map +1 -1
- package/build/history.js +2 -4
- package/build/history.js.map +1 -1
- package/build/index.js +2 -5
- package/build/index.js.map +1 -1
- package/build/inputs/attachment.js +71 -122
- package/build/inputs/attachment.js.map +1 -1
- package/build/inputs/auto-submit.js +15 -54
- package/build/inputs/auto-submit.js.map +1 -1
- package/build/inputs/checkbox.js +77 -166
- package/build/inputs/checkbox.js.map +1 -1
- package/build/inputs/checkboxes.js +75 -158
- package/build/inputs/checkboxes.js.map +1 -1
- package/build/inputs/id-for-component.js +4 -40
- package/build/inputs/id-for-component.js.map +1 -1
- package/build/inputs/input-wrapper.js +7 -26
- package/build/inputs/input-wrapper.js.map +1 -1
- package/build/inputs/input.js +158 -244
- package/build/inputs/input.js.map +1 -1
- package/build/inputs/money.js +123 -185
- package/build/inputs/money.js.map +1 -1
- package/build/inputs/name-for-component.js +4 -40
- package/build/inputs/name-for-component.js.map +1 -1
- package/build/inputs/select.js +68 -122
- package/build/inputs/select.js.map +1 -1
- package/build/instance-of-class-name.js +15 -20
- package/build/instance-of-class-name.js.map +1 -1
- package/build/is-expo.js +8 -10
- package/build/is-expo.js.map +1 -1
- package/build/key-value-store.js +51 -127
- package/build/key-value-store.js.map +1 -1
- package/build/link.js +51 -114
- package/build/link.js.map +1 -1
- package/build/logger.js +19 -25
- package/build/logger.js.map +1 -1
- package/build/merge-styles.js +5 -9
- package/build/merge-styles.js.map +1 -1
- package/build/modal.js +14 -61
- package/build/modal.js.map +1 -1
- package/build/model-class-require.js +8 -43
- package/build/model-class-require.js.map +1 -1
- package/build/model-events.js +24 -33
- package/build/model-events.js.map +1 -1
- package/build/model-name.js +15 -56
- package/build/model-name.js.map +1 -1
- package/build/model-prop-type.js +51 -62
- package/build/model-prop-type.js.map +1 -1
- package/build/model-recipes-loader.js +16 -24
- package/build/model-recipes-loader.js.map +1 -1
- package/build/model-recipes-model-loader.d.ts +1 -1
- package/build/model-recipes-model-loader.js +129 -207
- package/build/model-recipes-model-loader.js.map +1 -1
- package/build/models-response-reader.js +24 -65
- package/build/models-response-reader.js.map +1 -1
- package/build/models.js +5 -10
- package/build/models.js.map +1 -1
- package/build/money-formatter.d.ts +2 -2
- package/build/money-formatter.d.ts.map +1 -1
- package/build/money-formatter.js +45 -55
- package/build/money-formatter.js.map +1 -1
- package/build/not-loaded-error.js +2 -25
- package/build/not-loaded-error.js.map +1 -1
- package/build/params.js +31 -41
- package/build/params.js.map +1 -1
- package/build/preloaded.js +18 -58
- package/build/preloaded.js.map +1 -1
- package/build/resize-observer.js +5 -11
- package/build/resize-observer.js.map +1 -1
- package/build/rest-props-validator.js +4 -6
- package/build/rest-props-validator.js.map +1 -1
- package/build/result.js +10 -14
- package/build/result.js.map +1 -1
- package/build/router/route.js +178 -311
- package/build/router/route.js.map +1 -1
- package/build/router/switch.js +55 -129
- package/build/router/switch.js.map +1 -1
- package/build/router.js +33 -93
- package/build/router.js.map +1 -1
- package/build/routes-native.js +63 -147
- package/build/routes-native.js.map +1 -1
- package/build/routes.js +25 -79
- package/build/routes.js.map +1 -1
- package/build/run-last.js +19 -24
- package/build/run-last.js.map +1 -1
- package/build/serializer.js +28 -33
- package/build/serializer.js.map +1 -1
- package/build/services.js +9 -18
- package/build/services.js.map +1 -1
- package/build/session-status-updater.js +84 -183
- package/build/session-status-updater.js.map +1 -1
- package/build/source-maps-loader.d.ts +37 -0
- package/build/source-maps-loader.d.ts.map +1 -0
- package/build/source-maps-loader.js +102 -224
- package/build/source-maps-loader.js.map +1 -1
- package/build/super-admin/config-reader.d.ts +2 -2
- package/build/super-admin/config-reader.js +41 -82
- package/build/super-admin/config-reader.js.map +1 -1
- package/build/super-admin/edit-page/edit-attribute-checkbox.js +52 -114
- package/build/super-admin/edit-page/edit-attribute-checkbox.js.map +1 -1
- package/build/super-admin/edit-page/edit-attribute-content.js +46 -76
- package/build/super-admin/edit-page/edit-attribute-content.js.map +1 -1
- package/build/super-admin/edit-page/edit-attribute-input.js +56 -118
- package/build/super-admin/edit-page/edit-attribute-input.js.map +1 -1
- package/build/super-admin/edit-page/edit-attribute.js +39 -103
- package/build/super-admin/edit-page/edit-attribute.js.map +1 -1
- package/build/super-admin/edit-page.js +87 -200
- package/build/super-admin/edit-page.js.map +1 -1
- package/build/super-admin/has-edit-config.js +6 -12
- package/build/super-admin/has-edit-config.js.map +1 -1
- package/build/super-admin/index-page.js +16 -43
- package/build/super-admin/index-page.js.map +1 -1
- package/build/super-admin/index.js +86 -209
- package/build/super-admin/index.js.map +1 -1
- package/build/super-admin/layout/header/index.js +90 -151
- package/build/super-admin/layout/header/index.js.map +1 -1
- package/build/super-admin/layout/index.js +69 -152
- package/build/super-admin/layout/index.js.map +1 -1
- package/build/super-admin/layout/menu/index.js +84 -160
- package/build/super-admin/layout/menu/index.js.map +1 -1
- package/build/super-admin/layout/menu/menu-content.js +24 -84
- package/build/super-admin/layout/menu/menu-content.js.map +1 -1
- package/build/super-admin/layout/menu/menu-item.js +51 -101
- package/build/super-admin/layout/menu/menu-item.js.map +1 -1
- package/build/super-admin/layout/no-access.js +18 -44
- package/build/super-admin/layout/no-access.js.map +1 -1
- package/build/super-admin/model-class-table.js +44 -128
- package/build/super-admin/model-class-table.js.map +1 -1
- package/build/super-admin/models.js +5 -41
- package/build/super-admin/models.js.map +1 -1
- package/build/super-admin/show-nav.js +26 -88
- package/build/super-admin/show-nav.js.map +1 -1
- package/build/super-admin/show-page/belongs-to-attribute-row.js +17 -75
- package/build/super-admin/show-page/belongs-to-attribute-row.js.map +1 -1
- package/build/super-admin/show-page/index.js +100 -186
- package/build/super-admin/show-page/index.js.map +1 -1
- package/build/super-admin/show-reflection-actions.js +38 -99
- package/build/super-admin/show-reflection-actions.js.map +1 -1
- package/build/super-admin/show-reflection-link.js +26 -98
- package/build/super-admin/show-reflection-link.js.map +1 -1
- package/build/super-admin/show-reflection-page.js +33 -96
- package/build/super-admin/show-reflection-page.js.map +1 -1
- package/build/table/column-content.js +76 -120
- package/build/table/column-content.js.map +1 -1
- package/build/table/column-identifier.js +6 -10
- package/build/table/column-identifier.js.map +1 -1
- package/build/table/column-visible.js +1 -4
- package/build/table/column-visible.js.map +1 -1
- package/build/table/components/column.js +12 -59
- package/build/table/components/column.js.map +1 -1
- package/build/table/components/flat-list.js +12 -59
- package/build/table/components/flat-list.js.map +1 -1
- package/build/table/components/header.js +14 -61
- package/build/table/components/header.js.map +1 -1
- package/build/table/components/row.js +15 -62
- package/build/table/components/row.js.map +1 -1
- package/build/table/filters/attribute-element.js +33 -61
- package/build/table/filters/attribute-element.js.map +1 -1
- package/build/table/filters/filter-form.js +279 -482
- package/build/table/filters/filter-form.js.map +1 -1
- package/build/table/filters/filter.js +44 -72
- package/build/table/filters/filter.js.map +1 -1
- package/build/table/filters/index.js +94 -138
- package/build/table/filters/index.js.map +1 -1
- package/build/table/filters/load-search-modal.js +63 -211
- package/build/table/filters/load-search-modal.js.map +1 -1
- package/build/table/filters/reflection-element.js +26 -54
- package/build/table/filters/reflection-element.js.map +1 -1
- package/build/table/filters/save-search-modal.js +43 -139
- package/build/table/filters/save-search-modal.js.map +1 -1
- package/build/table/filters/scope-element.js +27 -55
- package/build/table/filters/scope-element.js.map +1 -1
- package/build/table/header-column-content.js +32 -70
- package/build/table/header-column-content.js.map +1 -1
- package/build/table/header-column.js +88 -217
- package/build/table/header-column.js.map +1 -1
- package/build/table/header-select.js +44 -76
- package/build/table/header-select.js.map +1 -1
- package/build/table/model-callback-args.js +4 -40
- package/build/table/model-callback-args.js.map +1 -1
- package/build/table/model-column.js +58 -143
- package/build/table/model-column.js.map +1 -1
- package/build/table/model-row.js +74 -186
- package/build/table/model-row.js.map +1 -1
- package/build/table/select-calculator.js +26 -85
- package/build/table/select-calculator.js.map +1 -1
- package/build/table/settings/column-row.js +65 -185
- package/build/table/settings/column-row.js.map +1 -1
- package/build/table/settings/download-action.js +37 -73
- package/build/table/settings/download-action.js.map +1 -1
- package/build/table/settings/index.js +37 -101
- package/build/table/settings/index.js.map +1 -1
- package/build/table/table-settings.js +184 -322
- package/build/table/table-settings.js.map +1 -1
- package/build/table/table.js +582 -780
- package/build/table/table.js.map +1 -1
- package/build/table/use-sorting.js +15 -34
- package/build/table/use-sorting.js.map +1 -1
- package/build/table/widths.js +31 -37
- package/build/table/widths.js.map +1 -1
- package/build/table/worker-plugins-check-all-checkbox.js +76 -224
- package/build/table/worker-plugins-check-all-checkbox.js.map +1 -1
- package/build/table/worker-plugins-checkbox.js +73 -184
- package/build/table/worker-plugins-checkbox.js.map +1 -1
- package/build/translated-attributes.js +5 -10
- package/build/translated-attributes.js.map +1 -1
- package/build/translated-collections.js +10 -19
- package/build/translated-collections.js.map +1 -1
- package/build/updated-attribute.js +46 -119
- package/build/updated-attribute.js.map +1 -1
- package/build/url-encode.js +5 -11
- package/build/url-encode.js.map +1 -1
- package/build/use-breakpoint.js +42 -94
- package/build/use-breakpoint.js.map +1 -1
- package/build/use-can-can.js +29 -91
- package/build/use-can-can.js.map +1 -1
- package/build/use-collection.js +118 -228
- package/build/use-collection.js.map +1 -1
- package/build/use-created-event.js +26 -43
- package/build/use-created-event.js.map +1 -1
- package/build/use-current-user-context.js +56 -150
- package/build/use-current-user-context.js.map +1 -1
- package/build/use-current-user.js +13 -31
- package/build/use-current-user.js.map +1 -1
- package/build/use-destroyed-event.js +21 -42
- package/build/use-destroyed-event.js.map +1 -1
- package/build/use-event-emitter.js +9 -14
- package/build/use-event-emitter.js.map +1 -1
- package/build/use-event-listener.js +12 -21
- package/build/use-event-listener.js.map +1 -1
- package/build/use-input.js +48 -68
- package/build/use-input.js.map +1 -1
- package/build/use-model-event.js +21 -42
- package/build/use-model-event.js.map +1 -1
- package/build/use-model.js +95 -198
- package/build/use-model.js.map +1 -1
- package/build/use-resize-observer.js +10 -20
- package/build/use-resize-observer.js.map +1 -1
- package/build/use-router.js +64 -106
- package/build/use-router.js.map +1 -1
- package/build/use-screen-layout.js +16 -18
- package/build/use-screen-layout.js.map +1 -1
- package/build/use-styles.js +23 -74
- package/build/use-styles.js.map +1 -1
- package/build/use-updated-event.js +21 -43
- package/build/use-updated-event.js.map +1 -1
- package/build/use-validation-errors.js +11 -17
- package/build/use-validation-errors.js.map +1 -1
- package/build/utils/button.js +85 -135
- package/build/utils/button.js.map +1 -1
- package/build/utils/card.js +30 -105
- package/build/utils/card.js.map +1 -1
- package/build/utils/checkbox.js +50 -111
- package/build/utils/checkbox.js.map +1 -1
- package/build/utils/checkboxes.js +108 -181
- package/build/utils/checkboxes.js.map +1 -1
- package/build/utils/default-style.js +28 -102
- package/build/utils/default-style.js.map +1 -1
- package/build/utils/header.js +7 -34
- package/build/utils/header.js.map +1 -1
- package/build/utils/icon.js +35 -116
- package/build/utils/icon.js.map +1 -1
- package/build/utils/invalid-feedback.js +15 -42
- package/build/utils/invalid-feedback.js.map +1 -1
- package/build/utils/modal.js +24 -107
- package/build/utils/modal.js.map +1 -1
- package/build/utils/text.js +9 -36
- package/build/utils/text.js.map +1 -1
- package/build/validation-error.js +30 -88
- package/build/validation-error.js.map +1 -1
- package/build/validation-errors.js +60 -110
- package/build/validation-errors.js.map +1 -1
- package/build/with-api-maker.js +14 -66
- package/build/with-api-maker.js.map +1 -1
- package/build/with-collection.js +13 -63
- package/build/with-collection.js.map +1 -1
- package/build/with-current-user.js +6 -22
- package/build/with-current-user.js.map +1 -1
- package/build/with-model.js +10 -26
- package/build/with-model.js.map +1 -1
- package/build/with-router.js +7 -34
- package/build/with-router.js.map +1 -1
- package/package.json +1 -1
package/build/use-can-can.js
CHANGED
|
@@ -1,110 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
-
};
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.default = useCanCan;
|
|
43
|
-
var can_can_js_1 = __importDefault(require("./can-can.js"));
|
|
44
|
-
var react_1 = require("react");
|
|
45
|
-
var use_current_user_js_1 = __importDefault(require("./use-current-user.js"));
|
|
46
|
-
var use_event_emitter_js_1 = __importDefault(require("./use-event-emitter.js"));
|
|
47
|
-
var use_shape_js_1 = __importDefault(require("set-state-compare/build/use-shape.js"));
|
|
1
|
+
import CanCan from "./can-can.js";
|
|
2
|
+
import { useCallback, useMemo } from "react";
|
|
3
|
+
import useCurrentUser from "./use-current-user.js";
|
|
4
|
+
import useEventEmitter from "./use-event-emitter.js";
|
|
5
|
+
import useShape from "set-state-compare/build/use-shape.js";
|
|
48
6
|
/**
|
|
49
7
|
* @param {function() : Array} abilitiesCallback
|
|
50
8
|
* @param {Array} dependencies
|
|
51
9
|
* @returns {CanCan}
|
|
52
10
|
*/
|
|
53
|
-
function useCanCan(abilitiesCallback, dependencies) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
var s = (0, use_shape_js_1.default)({ abilitiesCallback: abilitiesCallback });
|
|
11
|
+
export default function useCanCan(abilitiesCallback, dependencies) {
|
|
12
|
+
const currentUser = useCurrentUser();
|
|
13
|
+
const s = useShape({ abilitiesCallback });
|
|
57
14
|
s.useStates({
|
|
58
15
|
canCan: null,
|
|
59
|
-
lastUpdate:
|
|
16
|
+
lastUpdate: () => new Date()
|
|
60
17
|
});
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return [4 /*yield*/, canCan.loadAbilities(abilities)];
|
|
69
|
-
case 1:
|
|
70
|
-
_a.sent();
|
|
71
|
-
s.set({ canCan: canCan, lastUpdate: new Date() });
|
|
72
|
-
return [2 /*return*/];
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
}); }, []);
|
|
76
|
-
var onResetAbilities = (0, react_1.useCallback)(function () {
|
|
18
|
+
const loadAbilities = useCallback(async () => {
|
|
19
|
+
const canCan = CanCan.current();
|
|
20
|
+
const abilities = s.p.abilitiesCallback();
|
|
21
|
+
await canCan.loadAbilities(abilities);
|
|
22
|
+
s.set({ canCan, lastUpdate: new Date() });
|
|
23
|
+
}, []);
|
|
24
|
+
const onResetAbilities = useCallback(() => {
|
|
77
25
|
s.set({ canCan: null }, { silent: true });
|
|
78
26
|
loadAbilities();
|
|
79
27
|
}, []);
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
_a.sent();
|
|
91
|
-
return [3 /*break*/, 4];
|
|
92
|
-
case 2: return [4 /*yield*/, loadAbilities()];
|
|
93
|
-
case 3:
|
|
94
|
-
_a.sent();
|
|
95
|
-
_a.label = 4;
|
|
96
|
-
case 4: return [2 /*return*/];
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
}); }, []);
|
|
28
|
+
const loadAbilitiesOnNew = useCallback(async () => {
|
|
29
|
+
const canCan = s.s.canCan;
|
|
30
|
+
s.set({ canCan: null }, { silent: true });
|
|
31
|
+
if (canCan) {
|
|
32
|
+
await canCan?.resetAbilities();
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
await loadAbilities();
|
|
36
|
+
}
|
|
37
|
+
}, []);
|
|
100
38
|
if (!dependencies) {
|
|
101
39
|
// @ts-expect-error
|
|
102
|
-
dependencies = [currentUser
|
|
40
|
+
dependencies = [currentUser?.id()];
|
|
103
41
|
}
|
|
104
|
-
|
|
42
|
+
useMemo(() => {
|
|
105
43
|
loadAbilitiesOnNew();
|
|
106
44
|
}, dependencies);
|
|
107
|
-
(
|
|
45
|
+
useEventEmitter(CanCan.current().events, "onResetAbilities", onResetAbilities);
|
|
108
46
|
return s.s.canCan;
|
|
109
47
|
}
|
|
110
48
|
//# sourceMappingURL=use-can-can.js.map
|
package/build/use-can-can.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-can-can.js","sourceRoot":"/src/","sources":["use-can-can.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-can-can.js","sourceRoot":"/src/","sources":["use-can-can.js"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,cAAc,CAAA;AACjC,OAAO,EAAC,WAAW,EAAE,OAAO,EAAC,MAAM,OAAO,CAAA;AAC1C,OAAO,cAAc,MAAM,uBAAuB,CAAA;AAClD,OAAO,eAAe,MAAM,wBAAwB,CAAA;AACpD,OAAO,QAAQ,MAAM,sCAAsC,CAAA;AAE3D;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,iBAAiB,EAAE,YAAY;IAC/D,MAAM,WAAW,GAAG,cAAc,EAAE,CAAA;IACpC,MAAM,CAAC,GAAG,QAAQ,CAAC,EAAC,iBAAiB,EAAC,CAAC,CAAA;IAEvC,CAAC,CAAC,SAAS,CAAC;QACV,MAAM,EAAE,IAAI;QACZ,UAAU,EAAE,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE;KAC7B,CAAC,CAAA;IAEF,MAAM,aAAa,GAAG,WAAW,CAAC,KAAK,IAAI,EAAE;QAC3C,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,EAAE,CAAA;QAC/B,MAAM,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,iBAAiB,EAAE,CAAA;QAEzC,MAAM,MAAM,CAAC,aAAa,CAAC,SAAS,CAAC,CAAA;QAErC,CAAC,CAAC,GAAG,CAAC,EAAC,MAAM,EAAE,UAAU,EAAE,IAAI,IAAI,EAAE,EAAC,CAAC,CAAA;IACzC,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,MAAM,gBAAgB,GAAG,WAAW,CAAC,GAAG,EAAE;QACxC,CAAC,CAAC,GAAG,CAAC,EAAC,MAAM,EAAE,IAAI,EAAC,EAAE,EAAC,MAAM,EAAE,IAAI,EAAC,CAAC,CAAA;QACrC,aAAa,EAAE,CAAA;IACjB,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,MAAM,kBAAkB,GAAG,WAAW,CAAC,KAAK,IAAI,EAAE;QAChD,MAAM,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAA;QAEzB,CAAC,CAAC,GAAG,CAAC,EAAC,MAAM,EAAE,IAAI,EAAC,EAAE,EAAC,MAAM,EAAE,IAAI,EAAC,CAAC,CAAA;QAErC,IAAI,MAAM,EAAE,CAAC;YACX,MAAM,MAAM,EAAE,cAAc,EAAE,CAAA;QAChC,CAAC;aAAM,CAAC;YACN,MAAM,aAAa,EAAE,CAAA;QACvB,CAAC;IACH,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,mBAAmB;QACnB,YAAY,GAAG,CAAC,WAAW,EAAE,EAAE,EAAE,CAAC,CAAA;IACpC,CAAC;IAED,OAAO,CAAC,GAAG,EAAE;QACX,kBAAkB,EAAE,CAAA;IACtB,CAAC,EAAE,YAAY,CAAC,CAAA;IAEhB,eAAe,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,kBAAkB,EAAE,gBAAgB,CAAC,CAAA;IAE9E,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAA;AACnB,CAAC"}
|
package/build/use-collection.js
CHANGED
|
@@ -1,96 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
45
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
46
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
47
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
48
|
-
function step(op) {
|
|
49
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
50
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
51
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
52
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
53
|
-
switch (op[0]) {
|
|
54
|
-
case 0: case 1: t = op; break;
|
|
55
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
56
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
57
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
58
|
-
default:
|
|
59
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
60
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
61
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
62
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
63
|
-
if (t[2]) _.ops.pop();
|
|
64
|
-
_.trys.pop(); continue;
|
|
65
|
-
}
|
|
66
|
-
op = body.call(thisArg, _);
|
|
67
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
68
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
72
|
-
var t = {};
|
|
73
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
74
|
-
t[p] = s[p];
|
|
75
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
76
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
77
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
78
|
-
t[p[i]] = s[p[i]];
|
|
79
|
-
}
|
|
80
|
-
return t;
|
|
81
|
-
};
|
|
82
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
83
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
84
|
-
};
|
|
85
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
86
|
-
var debounce_1 = __importDefault(require("debounce"));
|
|
87
|
-
var diggerize_1 = require("diggerize");
|
|
88
|
-
var inflection = __importStar(require("inflection"));
|
|
89
|
-
var model_events_js_1 = __importDefault(require("./model-events.js"));
|
|
90
|
-
var react_1 = require("react");
|
|
91
|
-
var use_created_event_js_1 = __importDefault(require("./use-created-event.js"));
|
|
92
|
-
var use_shape_js_1 = __importDefault(require("set-state-compare/build/use-shape.js"));
|
|
93
|
-
var use_query_params_js_1 = __importDefault(require("on-location-changed/build/use-query-params.js"));
|
|
1
|
+
import debounce from "debounce";
|
|
2
|
+
import { digg } from "diggerize";
|
|
3
|
+
import * as inflection from "inflection";
|
|
4
|
+
import ModelEvents from "./model-events.js";
|
|
5
|
+
import { useCallback, useLayoutEffect, useMemo } from "react";
|
|
6
|
+
import useCreatedEvent from "./use-created-event.js";
|
|
7
|
+
import useShape from "set-state-compare/build/use-shape.js";
|
|
8
|
+
import useQueryParams from "on-location-changed/build/use-query-params.js";
|
|
94
9
|
/**
|
|
95
10
|
* @param {object} props
|
|
96
11
|
* @param {Record<string, string[]>} props.abilities
|
|
@@ -127,44 +42,42 @@ var use_query_params_js_1 = __importDefault(require("on-location-changed/build/u
|
|
|
127
42
|
* showNoRecordsFoundContent: false | import("react").ReactNode
|
|
128
43
|
* }}
|
|
129
44
|
*/
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
if (cacheKeys === void 0) { cacheKeys = []; }
|
|
133
|
-
var abilities = props.abilities, collection = props.collection, defaultParams = props.defaultParams, groupBy = props.groupBy, ifCondition = props.ifCondition, limit = props.limit, modelClass = props.modelClass, _b = props.noRecordsAvailableContent, noRecordsAvailableContent = _b === void 0 ? undefined : _b, _c = props.noRecordsFoundContent, noRecordsFoundContent = _c === void 0 ? undefined : _c, onModelsLoaded = props.onModelsLoaded, _d = props.pagination, pagination = _d === void 0 ? false : _d, _e = props.preloads, preloads = _e === void 0 ? [] : _e, queryMethod = props.queryMethod, initialQueryName = props.queryName, ransack = props.ransack, _f = props.select, select = _f === void 0 ? {} : _f, selectColumns = props.selectColumns, restProps = __rest(props, ["abilities", "collection", "defaultParams", "groupBy", "ifCondition", "limit", "modelClass", "noRecordsAvailableContent", "noRecordsFoundContent", "onModelsLoaded", "pagination", "preloads", "queryMethod", "queryName", "ransack", "select", "selectColumns"]);
|
|
45
|
+
const useCollection = (props, cacheKeys = []) => {
|
|
46
|
+
const { abilities, collection, defaultParams, groupBy, ifCondition, limit, modelClass, noRecordsAvailableContent = undefined, noRecordsFoundContent = undefined, onModelsLoaded, pagination = false, preloads = [], queryMethod, queryName: initialQueryName, ransack, select = {}, selectColumns, ...restProps } = props;
|
|
134
47
|
if (Object.keys(restProps).length > 0) {
|
|
135
|
-
throw new Error(
|
|
48
|
+
throw new Error(`Unknown props given to useCollection: ${Object.keys(restProps).join(", ")}`);
|
|
136
49
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
s.meta.queryParams = (
|
|
140
|
-
|
|
50
|
+
const s = useShape(props);
|
|
51
|
+
const queryName = initialQueryName || digg(modelClass.modelClassData(), "collectionKey");
|
|
52
|
+
s.meta.queryParams = useQueryParams();
|
|
53
|
+
const hasQParams = useCallback(() => {
|
|
141
54
|
if (s.s.queryQName in s.m.queryParams)
|
|
142
55
|
return true;
|
|
143
56
|
return false;
|
|
144
57
|
}, []);
|
|
145
|
-
|
|
58
|
+
const qParams = useCallback(() => {
|
|
146
59
|
if (hasQParams())
|
|
147
|
-
return JSON.parse(
|
|
60
|
+
return JSON.parse(digg(s.m.queryParams, s.s.queryQName));
|
|
148
61
|
return {};
|
|
149
62
|
}, []);
|
|
150
63
|
s.useStates({
|
|
151
64
|
models: undefined,
|
|
152
65
|
overallCount: undefined,
|
|
153
66
|
query: undefined,
|
|
154
|
-
queryName
|
|
155
|
-
queryPerKey:
|
|
156
|
-
queryQName:
|
|
157
|
-
querySName:
|
|
158
|
-
queryPageName:
|
|
67
|
+
queryName,
|
|
68
|
+
queryPerKey: `${queryName}_per`,
|
|
69
|
+
queryQName: `${queryName}_q`,
|
|
70
|
+
querySName: `${queryName}_s`,
|
|
71
|
+
queryPageName: `${queryName}_page`,
|
|
159
72
|
result: undefined,
|
|
160
73
|
searchParams: undefined,
|
|
161
74
|
showNoRecordsAvailableContent: false,
|
|
162
75
|
showNoRecordsFoundContent: false
|
|
163
76
|
});
|
|
164
77
|
s.useStates({
|
|
165
|
-
qParams:
|
|
78
|
+
qParams: () => qParams()
|
|
166
79
|
});
|
|
167
|
-
|
|
80
|
+
let modelIdsCacheString;
|
|
168
81
|
if (s.s.models === undefined) {
|
|
169
82
|
modelIdsCacheString = "models-undefined";
|
|
170
83
|
}
|
|
@@ -172,123 +85,102 @@ var useCollection = function (props, cacheKeys) {
|
|
|
172
85
|
modelIdsCacheString = "no-models";
|
|
173
86
|
}
|
|
174
87
|
else {
|
|
175
|
-
modelIdsCacheString =
|
|
88
|
+
modelIdsCacheString = s.s.models.map((model) => model.cacheKey())?.join("---");
|
|
176
89
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
case 1:
|
|
185
|
-
overallCount = _a.sent();
|
|
186
|
-
s.set({
|
|
187
|
-
overallCount: overallCount,
|
|
188
|
-
showNoRecordsAvailableContent: showNoRecordsAvailableContent({ overallCount: overallCount }),
|
|
189
|
-
showNoRecordsFoundContent: showNoRecordsFoundContent({ overallCount: overallCount })
|
|
190
|
-
});
|
|
191
|
-
return [2 /*return*/];
|
|
192
|
-
}
|
|
90
|
+
const loadOverallCount = useCallback(async () => {
|
|
91
|
+
const baseQuery = s.p.collection || s.p.modelClass.all();
|
|
92
|
+
const overallCount = await baseQuery.count();
|
|
93
|
+
s.set({
|
|
94
|
+
overallCount,
|
|
95
|
+
showNoRecordsAvailableContent: showNoRecordsAvailableContent({ overallCount }),
|
|
96
|
+
showNoRecordsFoundContent: showNoRecordsFoundContent({ overallCount })
|
|
193
97
|
});
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
98
|
+
}, []);
|
|
99
|
+
const loadQParams = useCallback(() => {
|
|
100
|
+
const qParamsToSet = hasQParams() ? qParams() : Object.assign({}, s.props.defaultParams);
|
|
101
|
+
const searchParams = [];
|
|
198
102
|
if (s.m.queryParams[s.s.querySName]) {
|
|
199
|
-
for (
|
|
200
|
-
|
|
201
|
-
var parsedSearchParam = JSON.parse(rawSearchParam);
|
|
103
|
+
for (const rawSearchParam of s.m.queryParams[s.s.querySName]) {
|
|
104
|
+
const parsedSearchParam = JSON.parse(rawSearchParam);
|
|
202
105
|
searchParams.push(parsedSearchParam);
|
|
203
106
|
}
|
|
204
107
|
}
|
|
205
108
|
s.set({
|
|
206
109
|
qParams: qParamsToSet,
|
|
207
|
-
searchParams
|
|
110
|
+
searchParams
|
|
208
111
|
});
|
|
209
112
|
}, []);
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
if (s.props.pagination) {
|
|
218
|
-
page = s.m.queryParams[s.s.queryPageName] || 1;
|
|
219
|
-
per = s.m.queryParams[s.s.queryPerKey] || 30;
|
|
220
|
-
if (per == "all") {
|
|
221
|
-
per = 999999999;
|
|
222
|
-
}
|
|
223
|
-
else {
|
|
224
|
-
per = Number(per);
|
|
225
|
-
}
|
|
226
|
-
query.page(page).per(per);
|
|
227
|
-
}
|
|
228
|
-
if (s.props.groupBy)
|
|
229
|
-
query = query.groupBy.apply(query, s.p.groupBy);
|
|
230
|
-
query = query
|
|
231
|
-
.ransack(s.s.qParams)
|
|
232
|
-
.search(s.s.searchParams)
|
|
233
|
-
.searchKey(s.s.queryQName)
|
|
234
|
-
.pageKey(s.s.queryPageName)
|
|
235
|
-
.perKey(s.s.queryPerKey);
|
|
236
|
-
if (s.props.abilities)
|
|
237
|
-
query.abilities(s.p.abilities);
|
|
238
|
-
if (s.props.limit !== undefined)
|
|
239
|
-
query.limit(s.p.limit);
|
|
240
|
-
if (s.props.preloads)
|
|
241
|
-
query.preload(s.p.preloads);
|
|
242
|
-
if (s.props.ransack)
|
|
243
|
-
query.ransack(s.props.ransack);
|
|
244
|
-
if (s.props.select)
|
|
245
|
-
query.select(s.p.select);
|
|
246
|
-
if (s.props.selectColumns)
|
|
247
|
-
query.selectColumns(s.p.selectColumns);
|
|
248
|
-
if (!s.props.queryMethod) return [3 /*break*/, 2];
|
|
249
|
-
return [4 /*yield*/, s.p.queryMethod({ query: query })];
|
|
250
|
-
case 1:
|
|
251
|
-
result = _b.sent();
|
|
252
|
-
return [3 /*break*/, 4];
|
|
253
|
-
case 2: return [4 /*yield*/, query.result()];
|
|
254
|
-
case 3:
|
|
255
|
-
result = _b.sent();
|
|
256
|
-
_b.label = 4;
|
|
257
|
-
case 4:
|
|
258
|
-
models = result.models();
|
|
259
|
-
if (s.props.onModelsLoaded) {
|
|
260
|
-
s.p.onModelsLoaded({
|
|
261
|
-
models: models,
|
|
262
|
-
qParams: s.s.qParams,
|
|
263
|
-
query: query,
|
|
264
|
-
result: result
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
s.set({
|
|
268
|
-
models: result.models(),
|
|
269
|
-
query: query,
|
|
270
|
-
result: result,
|
|
271
|
-
showNoRecordsAvailableContent: showNoRecordsAvailableContent({ models: models }),
|
|
272
|
-
showNoRecordsFoundContent: showNoRecordsFoundContent({ models: models })
|
|
273
|
-
});
|
|
274
|
-
return [2 /*return*/];
|
|
113
|
+
const loadModels = useCallback(async () => {
|
|
114
|
+
let query = s.props.collection?.clone() || s.p.modelClass.ransack();
|
|
115
|
+
if (s.props.pagination) {
|
|
116
|
+
const page = s.m.queryParams[s.s.queryPageName] || 1;
|
|
117
|
+
let per = s.m.queryParams[s.s.queryPerKey] || 30;
|
|
118
|
+
if (per == "all") {
|
|
119
|
+
per = 999_999_999;
|
|
275
120
|
}
|
|
121
|
+
else {
|
|
122
|
+
per = Number(per);
|
|
123
|
+
}
|
|
124
|
+
query.page(page).per(per);
|
|
125
|
+
}
|
|
126
|
+
if (s.props.groupBy)
|
|
127
|
+
query = query.groupBy(...s.p.groupBy);
|
|
128
|
+
query = query
|
|
129
|
+
.ransack(s.s.qParams)
|
|
130
|
+
.search(s.s.searchParams)
|
|
131
|
+
.searchKey(s.s.queryQName)
|
|
132
|
+
.pageKey(s.s.queryPageName)
|
|
133
|
+
.perKey(s.s.queryPerKey);
|
|
134
|
+
if (s.props.abilities)
|
|
135
|
+
query.abilities(s.p.abilities);
|
|
136
|
+
if (s.props.limit !== undefined)
|
|
137
|
+
query.limit(s.p.limit);
|
|
138
|
+
if (s.props.preloads)
|
|
139
|
+
query.preload(s.p.preloads);
|
|
140
|
+
if (s.props.ransack)
|
|
141
|
+
query.ransack(s.props.ransack);
|
|
142
|
+
if (s.props.select)
|
|
143
|
+
query.select(s.p.select);
|
|
144
|
+
if (s.props.selectColumns)
|
|
145
|
+
query.selectColumns(s.p.selectColumns);
|
|
146
|
+
let result;
|
|
147
|
+
if (s.props.queryMethod) {
|
|
148
|
+
result = await s.p.queryMethod({ query });
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
result = await query.result();
|
|
152
|
+
}
|
|
153
|
+
const models = result.models();
|
|
154
|
+
if (s.props.onModelsLoaded) {
|
|
155
|
+
s.p.onModelsLoaded({
|
|
156
|
+
models,
|
|
157
|
+
qParams: s.s.qParams,
|
|
158
|
+
query,
|
|
159
|
+
result
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
s.set({
|
|
163
|
+
models: result.models(),
|
|
164
|
+
query,
|
|
165
|
+
result,
|
|
166
|
+
showNoRecordsAvailableContent: showNoRecordsAvailableContent({ models }),
|
|
167
|
+
showNoRecordsFoundContent: showNoRecordsFoundContent({ models })
|
|
276
168
|
});
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
|
|
169
|
+
}, []);
|
|
170
|
+
const loadModelsDebounce = useCallback(debounce(loadModels), []);
|
|
171
|
+
const onModelDestroyed = useCallback((args) => {
|
|
280
172
|
s.set({
|
|
281
|
-
models: s.s.models.filter(
|
|
173
|
+
models: s.s.models.filter((model) => model.id() != args.model.id())
|
|
282
174
|
});
|
|
283
175
|
}, []);
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
176
|
+
const onModelUpdated = useCallback((args) => {
|
|
177
|
+
const updatedModel = digg(args, "model");
|
|
178
|
+
const foundModel = s.s.models.find((model) => model.id() == updatedModel.id());
|
|
287
179
|
if (foundModel)
|
|
288
180
|
loadModelsDebounce();
|
|
289
181
|
}, []);
|
|
290
|
-
|
|
291
|
-
|
|
182
|
+
const showNoRecordsAvailableContent = useCallback((args) => {
|
|
183
|
+
let models, overallCount;
|
|
292
184
|
if (args.models !== undefined) {
|
|
293
185
|
models = args.models;
|
|
294
186
|
}
|
|
@@ -306,8 +198,8 @@ var useCollection = function (props, cacheKeys) {
|
|
|
306
198
|
if (models.length === 0 && overallCount === 0 && s.p.noRecordsAvailableContent)
|
|
307
199
|
return true;
|
|
308
200
|
}, []);
|
|
309
|
-
|
|
310
|
-
|
|
201
|
+
const showNoRecordsFoundContent = useCallback((args) => {
|
|
202
|
+
let models, overallCount;
|
|
311
203
|
if (args.models !== undefined) {
|
|
312
204
|
models = args.models;
|
|
313
205
|
}
|
|
@@ -328,10 +220,10 @@ var useCollection = function (props, cacheKeys) {
|
|
|
328
220
|
if (models.length === 0 && s.props.noRecordsFoundContent)
|
|
329
221
|
return true;
|
|
330
222
|
}, []);
|
|
331
|
-
|
|
223
|
+
const onCreated = useCallback(() => {
|
|
332
224
|
loadModelsDebounce();
|
|
333
225
|
}, []);
|
|
334
|
-
|
|
226
|
+
useMemo(() => {
|
|
335
227
|
if (!("ifCondition" in s.props) || s.props.ifCondition) {
|
|
336
228
|
loadQParams();
|
|
337
229
|
loadModels();
|
|
@@ -344,33 +236,31 @@ var useCollection = function (props, cacheKeys) {
|
|
|
344
236
|
s.m.queryParams[s.s.querySName],
|
|
345
237
|
collection
|
|
346
238
|
].concat(cacheKeys));
|
|
347
|
-
|
|
239
|
+
useMemo(() => {
|
|
348
240
|
if (s.props.noRecordsAvailableContent) {
|
|
349
241
|
loadOverallCount();
|
|
350
242
|
}
|
|
351
243
|
}, []);
|
|
352
|
-
(
|
|
353
|
-
|
|
354
|
-
|
|
244
|
+
useCreatedEvent(s.p.modelClass, onCreated);
|
|
245
|
+
useLayoutEffect(() => {
|
|
246
|
+
const connections = [];
|
|
355
247
|
if (s.s.models) {
|
|
356
|
-
for (
|
|
357
|
-
|
|
358
|
-
connections.push(
|
|
359
|
-
connections.push(model_events_js_1.default.connectDestroyed(model, onModelDestroyed));
|
|
248
|
+
for (const model of s.s.models) {
|
|
249
|
+
connections.push(ModelEvents.connectUpdated(model, onModelUpdated));
|
|
250
|
+
connections.push(ModelEvents.connectDestroyed(model, onModelDestroyed));
|
|
360
251
|
}
|
|
361
252
|
}
|
|
362
|
-
return
|
|
363
|
-
for (
|
|
364
|
-
var connection = connections_1[_i];
|
|
253
|
+
return () => {
|
|
254
|
+
for (const connection of connections) {
|
|
365
255
|
connection.unsubscribe();
|
|
366
256
|
}
|
|
367
257
|
};
|
|
368
258
|
}, [modelIdsCacheString]);
|
|
369
|
-
|
|
370
|
-
|
|
259
|
+
const result = Object.assign({}, s.state);
|
|
260
|
+
const modelVariableName = inflection.pluralize(inflection.camelize(modelClass.modelClassData().name, true));
|
|
371
261
|
result.modelIdsCacheString = modelIdsCacheString;
|
|
372
262
|
result[modelVariableName] = s.s.models;
|
|
373
263
|
return result;
|
|
374
264
|
};
|
|
375
|
-
|
|
265
|
+
export default useCollection;
|
|
376
266
|
//# sourceMappingURL=use-collection.js.map
|