@asteby/metacore-runtime-react 4.0.0

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.
Files changed (81) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/LICENSE +201 -0
  3. package/README.md +59 -0
  4. package/dist/action-modal-dispatcher.d.ts +4 -0
  5. package/dist/action-modal-dispatcher.d.ts.map +1 -0
  6. package/dist/action-modal-dispatcher.js +123 -0
  7. package/dist/addon-loader.d.ts +27 -0
  8. package/dist/addon-loader.d.ts.map +1 -0
  9. package/dist/addon-loader.js +73 -0
  10. package/dist/api-context.d.ts +40 -0
  11. package/dist/api-context.d.ts.map +1 -0
  12. package/dist/api-context.js +25 -0
  13. package/dist/capability-gate.d.ts +29 -0
  14. package/dist/capability-gate.d.ts.map +1 -0
  15. package/dist/capability-gate.js +43 -0
  16. package/dist/dialogs/_primitives.d.ts +29 -0
  17. package/dist/dialogs/_primitives.d.ts.map +1 -0
  18. package/dist/dialogs/_primitives.js +35 -0
  19. package/dist/dialogs/dynamic-record.d.ts +11 -0
  20. package/dist/dialogs/dynamic-record.d.ts.map +1 -0
  21. package/dist/dialogs/dynamic-record.js +377 -0
  22. package/dist/dialogs/export.d.ts +12 -0
  23. package/dist/dialogs/export.d.ts.map +1 -0
  24. package/dist/dialogs/export.js +146 -0
  25. package/dist/dialogs/import.d.ts +11 -0
  26. package/dist/dialogs/import.d.ts.map +1 -0
  27. package/dist/dialogs/import.js +128 -0
  28. package/dist/dynamic-columns-shim.d.ts +25 -0
  29. package/dist/dynamic-columns-shim.d.ts.map +1 -0
  30. package/dist/dynamic-columns-shim.js +1 -0
  31. package/dist/dynamic-form.d.ts +12 -0
  32. package/dist/dynamic-form.d.ts.map +1 -0
  33. package/dist/dynamic-form.js +51 -0
  34. package/dist/dynamic-icon.d.ts +6 -0
  35. package/dist/dynamic-icon.d.ts.map +1 -0
  36. package/dist/dynamic-icon.js +11 -0
  37. package/dist/dynamic-table.d.ts +22 -0
  38. package/dist/dynamic-table.d.ts.map +1 -0
  39. package/dist/dynamic-table.js +516 -0
  40. package/dist/i18n-provider.d.ts +16 -0
  41. package/dist/i18n-provider.d.ts.map +1 -0
  42. package/dist/i18n-provider.js +16 -0
  43. package/dist/index.d.ts +18 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +21 -0
  46. package/dist/metadata-cache.d.ts +42 -0
  47. package/dist/metadata-cache.d.ts.map +1 -0
  48. package/dist/metadata-cache.js +71 -0
  49. package/dist/navigation-builder.d.ts +34 -0
  50. package/dist/navigation-builder.d.ts.map +1 -0
  51. package/dist/navigation-builder.js +45 -0
  52. package/dist/options-context.d.ts +8 -0
  53. package/dist/options-context.d.ts.map +1 -0
  54. package/dist/options-context.js +5 -0
  55. package/dist/slot.d.ts +32 -0
  56. package/dist/slot.d.ts.map +1 -0
  57. package/dist/slot.js +45 -0
  58. package/dist/types.d.ts +114 -0
  59. package/dist/types.d.ts.map +1 -0
  60. package/dist/types.js +1 -0
  61. package/package.json +67 -0
  62. package/src/action-modal-dispatcher.tsx +275 -0
  63. package/src/addon-loader.tsx +111 -0
  64. package/src/api-context.tsx +55 -0
  65. package/src/capability-gate.tsx +69 -0
  66. package/src/dialogs/_primitives.tsx +114 -0
  67. package/src/dialogs/dynamic-record.tsx +770 -0
  68. package/src/dialogs/export.tsx +339 -0
  69. package/src/dialogs/import.tsx +404 -0
  70. package/src/dynamic-columns-shim.ts +36 -0
  71. package/src/dynamic-form.tsx +108 -0
  72. package/src/dynamic-icon.tsx +15 -0
  73. package/src/dynamic-table.tsx +766 -0
  74. package/src/i18n-provider.tsx +33 -0
  75. package/src/index.ts +30 -0
  76. package/src/metadata-cache.ts +103 -0
  77. package/src/navigation-builder.tsx +77 -0
  78. package/src/options-context.tsx +11 -0
  79. package/src/slot.tsx +77 -0
  80. package/src/types.ts +112 -0
  81. package/tsconfig.json +16 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,31 @@
1
+ # @asteby/metacore-runtime-react
2
+
3
+ ## 4.0.0
4
+
5
+ ### Minor Changes
6
+
7
+ - e23eede: Publicación inicial a npm del ecosistema metacore.
8
+
9
+ Propaga los 13 paquetes del SDK al registry público para que apps consumidoras (ops, link) migren de `file:` a semver y Renovate pueda propagar updates.
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [e23eede]
14
+ - @asteby/metacore-sdk@2.2.0
15
+ - @asteby/metacore-ui@0.3.0
16
+
17
+ ## 3.0.0
18
+
19
+ ### Minor Changes
20
+
21
+ - 6d243b0: Initial release of the metacore frontend ecosystem.
22
+
23
+ 11 packages extracted from ops/link frontends into a publishable monorepo with auto-propagation via Changesets + Renovate.
24
+
25
+ ### Patch Changes
26
+
27
+ - Updated dependencies
28
+ - Updated dependencies
29
+ - Updated dependencies [6d243b0]
30
+ - @asteby/metacore-sdk@2.1.0
31
+ - @asteby/metacore-ui@0.2.0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Asteby, Inc.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # @asteby/metacore-runtime-react
2
+
3
+ React runtime for [metacore](https://github.com/asteby/metacore-sdk) hosts. This
4
+ package bundles the generic components a host (`ops`, `link`, `hub`) renders
5
+ when showing addon contributions — dynamic tables, forms, action dispatchers,
6
+ slot extension points and the federated addon loader.
7
+
8
+ It is a *runtime*, not a UI kit: the actual visual primitives (buttons,
9
+ dialogs, tables…) are resolved through the host's bundler aliases. The host
10
+ must provide the following modules at build time:
11
+
12
+ | Alias | Purpose |
13
+ | ---------------------------------- | ------------------------------------- |
14
+ | `@/components/ui/*` | shadcn primitives |
15
+ | `@/components/data-table` | DataTableToolbar / Pagination / etc. |
16
+ | `@/components/dynamic/dynamic-columns` | column renderers (`DynamicIcon`, etc) |
17
+ | `@/components/dynamic/dynamic-record-dialog` | CRUD dialog (still host-owned) |
18
+ | `@/components/dynamic/export-dialog` | Export dialog |
19
+ | `@/components/dynamic/import-dialog` | Import dialog |
20
+ | `@/lib/api` | axios instance |
21
+ | `@/lib/utils` | `cn()` helper |
22
+ | `@/stores/metadata-cache` | zustand store |
23
+ | `@/stores/branch-store` | zustand store (optional) |
24
+
25
+ ## Exports
26
+
27
+ - `DynamicTable` – CRUD-capable table driven by `manifest.model_definition`.
28
+ - `DynamicForm` – renders a form from `fields[]`.
29
+ - `ActionModalDispatcher` – routes a custom action to its registered component
30
+ (falls back to confirm dialog / generic form).
31
+ - `AddonLoader` – injects a federated `remoteEntry.js` and calls `register(api)`.
32
+ - `Slot` / `slotRegistry` – named extension points (`dashboard.widgets`, …).
33
+ - `CapabilityGate` / `CapabilityProvider` – conditional UI by capability.
34
+ - `NavigationBuilder` / `mergeNavigation` – merges host sidebar with addon nav.
35
+ - `I18nProvider` – injects `manifest.i18n` namespaces into the host's i18next.
36
+
37
+ ## Minimal usage
38
+
39
+ ```tsx
40
+ import { DynamicTable, Slot, CapabilityGate, AddonLoader } from '@asteby/metacore-runtime-react'
41
+
42
+ <AddonLoader scope="billing" url="/addons/billing/remoteEntry.js" api={api}>
43
+ <CapabilityGate require="invoice.read">
44
+ <DynamicTable model="invoice" />
45
+ <Slot name="invoice.footer" />
46
+ </CapabilityGate>
47
+ </AddonLoader>
48
+ ```
49
+
50
+ ## Installation
51
+
52
+ `@asteby/metacore-runtime-react` depends on `@asteby/metacore-sdk` for the
53
+ canonical action registry and `AddonAPI` contract. Build order:
54
+
55
+ ```
56
+ pnpm --filter @asteby/metacore-sdk build
57
+ pnpm --filter @asteby/metacore-runtime-react build
58
+ pnpm --filter <host> install
59
+ ```
@@ -0,0 +1,4 @@
1
+ import { type ActionMetadata, type ActionModalProps } from '@asteby/metacore-sdk';
2
+ export type { ActionMetadata, ActionModalProps };
3
+ export declare function ActionModalDispatcher({ open, onOpenChange, action, model, record, endpoint, onSuccess, }: ActionModalProps): import("react/jsx-runtime").JSX.Element | null;
4
+ //# sourceMappingURL=action-modal-dispatcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action-modal-dispatcher.d.ts","sourceRoot":"","sources":["../src/action-modal-dispatcher.tsx"],"names":[],"mappings":"AAyCA,OAAO,EACH,KAAK,cAAc,EACnB,KAAK,gBAAgB,EAExB,MAAM,sBAAsB,CAAA;AAE7B,YAAY,EAAE,cAAc,EAAE,gBAAgB,EAAE,CAAA;AAEhD,wBAAgB,qBAAqB,CAAC,EAClC,IAAI,EACJ,YAAY,EACZ,MAAM,EACN,KAAK,EACL,MAAM,EACN,QAAQ,EACR,SAAS,GACZ,EAAE,gBAAgB,kDAiDlB"}
@@ -0,0 +1,123 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // ActionModalDispatcher — renders the right modal for a custom action:
3
+ // 1) Custom component from the SDK registry → use it
4
+ // 2) action.fields[] → GenericActionModal (form)
5
+ // 3) action.confirm → ConfirmActionDialog
6
+ // 4) otherwise → nothing (caller executes immediately)
7
+ //
8
+ // The host injects its axios-like client via <ApiProvider>; we no longer
9
+ // depend on a bundler alias to `@/lib/api`.
10
+ import { useState, useEffect, useMemo } from 'react';
11
+ import { useTranslation } from 'react-i18next';
12
+ import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter, AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, Button, Input, Textarea, Label, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, Switch, } from '@asteby/metacore-ui/primitives';
13
+ import { Loader2 } from 'lucide-react';
14
+ import { toast } from 'sonner';
15
+ import { useApi } from './api-context';
16
+ import { DynamicIcon } from './dynamic-icon';
17
+ // Canonical registry lives in @asteby/metacore-sdk
18
+ import { getActionComponent, } from '@asteby/metacore-sdk';
19
+ export function ActionModalDispatcher({ open, onOpenChange, action, model, record, endpoint, onSuccess, }) {
20
+ const CustomComponent = useMemo(() => getActionComponent(model, action.key), [model, action.key]);
21
+ if (CustomComponent) {
22
+ return (_jsx(CustomComponent, { open: open, onOpenChange: onOpenChange, action: action, model: model, record: record, endpoint: endpoint, onSuccess: onSuccess }));
23
+ }
24
+ if (action.fields && action.fields.length > 0) {
25
+ return (_jsx(GenericActionModal, { open: open, onOpenChange: onOpenChange, action: action, model: model, record: record, endpoint: endpoint, onSuccess: onSuccess }));
26
+ }
27
+ if (action.confirm) {
28
+ return (_jsx(ConfirmActionDialog, { open: open, onOpenChange: onOpenChange, action: action, model: model, record: record, endpoint: endpoint, onSuccess: onSuccess }));
29
+ }
30
+ return null;
31
+ }
32
+ function buildActionUrl(endpoint, model, recordId, actionKey) {
33
+ return endpoint ? `${endpoint}/${recordId}/action/${actionKey}` : `/data/${model}/me/${recordId}/action/${actionKey}`;
34
+ }
35
+ function ConfirmActionDialog({ open, onOpenChange, action, model, record, endpoint, onSuccess }) {
36
+ const { t } = useTranslation();
37
+ const api = useApi();
38
+ const [executing, setExecuting] = useState(false);
39
+ const execute = async () => {
40
+ setExecuting(true);
41
+ try {
42
+ const url = buildActionUrl(endpoint, model, record.id, action.key);
43
+ const res = await api.post(url, {});
44
+ if (res.data.success) {
45
+ toast.success(res.data.message || t('common.success'));
46
+ onOpenChange(false);
47
+ onSuccess();
48
+ }
49
+ else {
50
+ toast.error(res.data.message || t('common.error'));
51
+ }
52
+ }
53
+ catch (err) {
54
+ toast.error(err?.response?.data?.message || t('common.error'));
55
+ }
56
+ finally {
57
+ setExecuting(false);
58
+ }
59
+ };
60
+ return (_jsx(AlertDialog, { open: open, onOpenChange: onOpenChange, children: _jsxs(AlertDialogContent, { children: [_jsxs(AlertDialogHeader, { children: [_jsxs(AlertDialogTitle, { className: "flex items-center gap-2", children: [_jsx(DynamicIcon, { name: action.icon, className: "h-5 w-5" }), action.label] }), _jsx(AlertDialogDescription, { children: action.confirmMessage || `${action.label}?` })] }), _jsxs(AlertDialogFooter, { children: [_jsx(AlertDialogCancel, { disabled: executing, children: t('common.cancel') }), _jsxs(AlertDialogAction, { onClick: (e) => { e.preventDefault(); execute(); }, disabled: executing, style: action.color ? { backgroundColor: action.color } : undefined, children: [executing ? _jsx(Loader2, { className: "mr-2 h-4 w-4 animate-spin" }) : _jsx(DynamicIcon, { name: action.icon, className: "mr-2 h-4 w-4" }), action.label] })] })] }) }));
61
+ }
62
+ function GenericActionModal({ open, onOpenChange, action, model, record, endpoint, onSuccess }) {
63
+ const { t } = useTranslation();
64
+ const api = useApi();
65
+ const [formData, setFormData] = useState({});
66
+ const [executing, setExecuting] = useState(false);
67
+ useEffect(() => {
68
+ if (open && action.fields) {
69
+ const defaults = {};
70
+ for (const field of action.fields) {
71
+ defaults[field.key] = field.defaultValue ?? (field.type === 'boolean' ? false : '');
72
+ }
73
+ setFormData(defaults);
74
+ }
75
+ }, [open, action.fields]);
76
+ const updateField = (key, value) => setFormData((prev) => ({ ...prev, [key]: value }));
77
+ const execute = async () => {
78
+ if (action.fields) {
79
+ for (const field of action.fields) {
80
+ if (field.required && !formData[field.key] && formData[field.key] !== false) {
81
+ toast.error(`${field.label} es requerido`);
82
+ return;
83
+ }
84
+ }
85
+ }
86
+ setExecuting(true);
87
+ try {
88
+ const url = buildActionUrl(endpoint, model, record.id, action.key);
89
+ const res = await api.post(url, formData);
90
+ if (res.data.success) {
91
+ toast.success(res.data.message || t('common.success'));
92
+ onOpenChange(false);
93
+ onSuccess();
94
+ }
95
+ else {
96
+ toast.error(res.data.message || t('common.error'));
97
+ }
98
+ }
99
+ catch (err) {
100
+ toast.error(err?.response?.data?.message || t('common.error'));
101
+ }
102
+ finally {
103
+ setExecuting(false);
104
+ }
105
+ };
106
+ return (_jsx(Dialog, { open: open, onOpenChange: onOpenChange, children: _jsxs(DialogContent, { className: "sm:max-w-lg", children: [_jsxs(DialogHeader, { children: [_jsxs(DialogTitle, { className: "flex items-center gap-2", children: [_jsx(DynamicIcon, { name: action.icon, className: "h-5 w-5" }), action.label] }), action.confirmMessage && _jsx(DialogDescription, { children: action.confirmMessage })] }), _jsx("div", { className: "grid gap-4 py-4", children: action.fields?.map((field) => (_jsxs("div", { className: "grid gap-2", children: [_jsxs(Label, { htmlFor: field.key, children: [field.label, field.required && _jsx("span", { className: "text-red-500 ml-1", children: "*" })] }), renderField(field, formData[field.key], (v) => updateField(field.key, v))] }, field.key))) }), _jsxs(DialogFooter, { children: [_jsx(Button, { variant: "outline", onClick: () => onOpenChange(false), disabled: executing, children: t('common.cancel') }), _jsxs(Button, { onClick: execute, disabled: executing, style: action.color ? { backgroundColor: action.color, color: 'white' } : undefined, children: [executing ? _jsx(Loader2, { className: "mr-2 h-4 w-4 animate-spin" }) : _jsx(DynamicIcon, { name: action.icon, className: "mr-2 h-4 w-4" }), action.label] })] })] }) }));
107
+ }
108
+ function renderField(field, value, onChange) {
109
+ switch (field.type) {
110
+ case 'textarea':
111
+ return _jsx(Textarea, { id: field.key, value: value || '', onChange: (e) => onChange(e.target.value), placeholder: field.placeholder });
112
+ case 'select':
113
+ return (_jsxs(Select, { value: value || '', onValueChange: onChange, children: [_jsx(SelectTrigger, { children: _jsx(SelectValue, { placeholder: field.placeholder || 'Seleccionar...' }) }), _jsx(SelectContent, { children: field.options?.map((opt) => _jsx(SelectItem, { value: opt.value, children: opt.label }, opt.value)) })] }));
114
+ case 'boolean':
115
+ return _jsx(Switch, { id: field.key, checked: !!value, onCheckedChange: onChange });
116
+ case 'number':
117
+ return _jsx(Input, { id: field.key, type: "number", value: value ?? '', onChange: (e) => onChange(e.target.valueAsNumber || ''), placeholder: field.placeholder });
118
+ case 'date':
119
+ return _jsx(Input, { id: field.key, type: "date", value: value || '', onChange: (e) => onChange(e.target.value) });
120
+ default:
121
+ return _jsx(Input, { id: field.key, type: field.type === 'email' ? 'email' : field.type === 'url' ? 'url' : 'text', value: value || '', onChange: (e) => onChange(e.target.value), placeholder: field.placeholder });
122
+ }
123
+ }
@@ -0,0 +1,27 @@
1
+ import type { AddonAPI } from '@asteby/metacore-sdk';
2
+ declare global {
3
+ interface Window {
4
+ [key: string]: any;
5
+ __webpack_init_sharing__?: (scope: string) => Promise<void>;
6
+ __webpack_share_scopes__?: Record<string, unknown>;
7
+ }
8
+ }
9
+ export interface AddonLoaderProps {
10
+ /** Unique key of the addon — maps to the federation container name. */
11
+ scope: string;
12
+ /** URL of the addon's remoteEntry.js bundle. */
13
+ url: string;
14
+ /** Exposed module to import from the remote (e.g. './register'). */
15
+ module?: string;
16
+ /** Host-provided API passed to the addon's register() call. */
17
+ api: AddonAPI;
18
+ /** Optional rendering while loading. */
19
+ fallback?: React.ReactNode;
20
+ /** Called once the addon has successfully registered. */
21
+ onReady?: () => void;
22
+ /** Called if loading fails. */
23
+ onError?: (err: Error) => void;
24
+ children?: React.ReactNode;
25
+ }
26
+ export declare function AddonLoader({ scope, url, module, api, fallback, onReady, onError, children, }: AddonLoaderProps): import("react/jsx-runtime").JSX.Element;
27
+ //# sourceMappingURL=addon-loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addon-loader.d.ts","sourceRoot":"","sources":["../src/addon-loader.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAEpD,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,MAAM;QACZ,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;QAClB,wBAAwB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;QAC3D,wBAAwB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KACrD;CACJ;AAED,MAAM,WAAW,gBAAgB;IAC7B,uEAAuE;IACvE,KAAK,EAAE,MAAM,CAAA;IACb,gDAAgD;IAChD,GAAG,EAAE,MAAM,CAAA;IACX,oEAAoE;IACpE,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,+DAA+D;IAC/D,GAAG,EAAE,QAAQ,CAAA;IACb,wCAAwC;IACxC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B,yDAAyD;IACzD,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,+BAA+B;IAC/B,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,IAAI,CAAA;IAC9B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAC7B;AAuCD,wBAAgB,WAAW,CAAC,EACxB,KAAK,EACL,GAAG,EACH,MAAqB,EACrB,GAAG,EACH,QAAe,EACf,OAAO,EACP,OAAO,EACP,QAAQ,GACX,EAAE,gBAAgB,2CAgClB"}
@@ -0,0 +1,73 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // Minimal federated-module addon loader. Injects a remoteEntry.js <script>,
3
+ // waits for the `window[scope]` container to initialize, then calls the
4
+ // addon's `register(api)` export with the AddonAPI injected by the host.
5
+ import { useEffect, useRef, useState } from 'react';
6
+ const loadedScripts = new Map();
7
+ function loadScript(url, scope) {
8
+ const key = `${scope}::${url}`;
9
+ const existing = loadedScripts.get(key);
10
+ if (existing)
11
+ return existing;
12
+ const promise = new Promise((resolve, reject) => {
13
+ const el = document.createElement('script');
14
+ el.src = url;
15
+ el.type = 'text/javascript';
16
+ el.async = true;
17
+ el.onload = () => resolve();
18
+ el.onerror = () => reject(new Error(`Failed to load addon script: ${url}`));
19
+ document.head.appendChild(el);
20
+ });
21
+ loadedScripts.set(key, promise);
22
+ return promise;
23
+ }
24
+ async function loadRemote(scope, module) {
25
+ if (typeof window.__webpack_init_sharing__ === 'function') {
26
+ await window.__webpack_init_sharing__('default');
27
+ }
28
+ const container = window[scope];
29
+ if (!container)
30
+ throw new Error(`Addon container "${scope}" not found on window`);
31
+ if (typeof container.init === 'function' && window.__webpack_share_scopes__) {
32
+ await container.init(window.__webpack_share_scopes__.default);
33
+ }
34
+ const factory = await container.get(module);
35
+ return factory();
36
+ }
37
+ export function AddonLoader({ scope, url, module = './register', api, fallback = null, onReady, onError, children, }) {
38
+ const [status, setStatus] = useState('loading');
39
+ const [error, setError] = useState(null);
40
+ const didRegister = useRef(false);
41
+ useEffect(() => {
42
+ let cancelled = false;
43
+ (async () => {
44
+ try {
45
+ await loadScript(url, scope);
46
+ if (cancelled)
47
+ return;
48
+ const mod = await loadRemote(scope, module);
49
+ if (cancelled)
50
+ return;
51
+ if (!didRegister.current && typeof mod?.register === 'function') {
52
+ didRegister.current = true;
53
+ await Promise.resolve(mod.register(api));
54
+ }
55
+ setStatus('ready');
56
+ onReady?.();
57
+ }
58
+ catch (e) {
59
+ if (cancelled)
60
+ return;
61
+ setError(e);
62
+ setStatus('error');
63
+ onError?.(e);
64
+ }
65
+ })();
66
+ return () => { cancelled = true; };
67
+ }, [scope, url, module]);
68
+ if (status === 'loading')
69
+ return _jsx(_Fragment, { children: fallback });
70
+ if (status === 'error')
71
+ return _jsxs("div", { className: "text-sm text-red-500", children: ["Addon load error: ", error?.message] });
72
+ return _jsx(_Fragment, { children: children });
73
+ }
@@ -0,0 +1,40 @@
1
+ import React from 'react';
2
+ /** Minimal axios-compatible client shape consumed by runtime-react. */
3
+ export interface ApiClient {
4
+ get: (url: string, config?: any) => Promise<{
5
+ data: any;
6
+ headers?: any;
7
+ }>;
8
+ post: (url: string, body?: any, config?: any) => Promise<{
9
+ data: any;
10
+ headers?: any;
11
+ }>;
12
+ put: (url: string, body?: any, config?: any) => Promise<{
13
+ data: any;
14
+ headers?: any;
15
+ }>;
16
+ delete: (url: string, config?: any) => Promise<{
17
+ data: any;
18
+ headers?: any;
19
+ }>;
20
+ }
21
+ export interface ApiProviderProps {
22
+ client: ApiClient;
23
+ children: React.ReactNode;
24
+ }
25
+ export declare function ApiProvider({ client, children }: ApiProviderProps): import("react/jsx-runtime").JSX.Element;
26
+ /** Returns the host-injected api client. Throws if no <ApiProvider> is mounted. */
27
+ export declare function useApi(): ApiClient;
28
+ /** Optional branch context — hosts that support tenant branches can supply
29
+ * a `currentBranch` so DynamicTable resets pagination/selection on branch
30
+ * switches. Hosts without branches can omit this provider entirely. */
31
+ export interface BranchState {
32
+ id: string | number | null | undefined;
33
+ }
34
+ export interface BranchProviderProps {
35
+ branch: BranchState;
36
+ children: React.ReactNode;
37
+ }
38
+ export declare function BranchProvider({ branch, children }: BranchProviderProps): import("react/jsx-runtime").JSX.Element;
39
+ export declare function useCurrentBranch(): BranchState;
40
+ //# sourceMappingURL=api-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-context.d.ts","sourceRoot":"","sources":["../src/api-context.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAoC,MAAM,OAAO,CAAA;AAExD,uEAAuE;AACvE,MAAM,WAAW,SAAS;IACtB,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,KAAK,OAAO,CAAC;QAAE,IAAI,EAAE,GAAG,CAAC;QAAC,OAAO,CAAC,EAAE,GAAG,CAAA;KAAE,CAAC,CAAA;IACzE,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,GAAG,KAAK,OAAO,CAAC;QAAE,IAAI,EAAE,GAAG,CAAC;QAAC,OAAO,CAAC,EAAE,GAAG,CAAA;KAAE,CAAC,CAAA;IACtF,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,GAAG,KAAK,OAAO,CAAC;QAAE,IAAI,EAAE,GAAG,CAAC;QAAC,OAAO,CAAC,EAAE,GAAG,CAAA;KAAE,CAAC,CAAA;IACrF,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,KAAK,OAAO,CAAC;QAAE,IAAI,EAAE,GAAG,CAAC;QAAC,OAAO,CAAC,EAAE,GAAG,CAAA;KAAE,CAAC,CAAA;CAC/E;AAID,MAAM,WAAW,gBAAgB;IAC7B,MAAM,EAAE,SAAS,CAAA;IACjB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC5B;AAED,wBAAgB,WAAW,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,gBAAgB,2CAEjE;AAED,mFAAmF;AACnF,wBAAgB,MAAM,IAAI,SAAS,CAMlC;AAED;;wEAEwE;AACxE,MAAM,WAAW,WAAW;IACxB,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;CACzC;AAID,MAAM,WAAW,mBAAmB;IAChC,MAAM,EAAE,WAAW,CAAA;IACnB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC5B;AAED,wBAAgB,cAAc,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,mBAAmB,2CAEvE;AAED,wBAAgB,gBAAgB,IAAI,WAAW,CAE9C"}
@@ -0,0 +1,25 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ // ApiContext — the host injects its HTTP client (axios-like interface) so
3
+ // runtime-react components (DynamicTable, dialogs, action dispatcher) can
4
+ // talk to the backend without a bundler alias to `@/lib/api`. Hosts wrap
5
+ // their app in <ApiProvider value={axiosInstance}> once at the root.
6
+ import { createContext, useContext } from 'react';
7
+ const ApiContext = createContext(null);
8
+ export function ApiProvider({ client, children }) {
9
+ return _jsx(ApiContext.Provider, { value: client, children: children });
10
+ }
11
+ /** Returns the host-injected api client. Throws if no <ApiProvider> is mounted. */
12
+ export function useApi() {
13
+ const ctx = useContext(ApiContext);
14
+ if (!ctx) {
15
+ throw new Error('useApi() requires an <ApiProvider> ancestor. Hosts must inject an axios-like client via runtime-react ApiProvider.');
16
+ }
17
+ return ctx;
18
+ }
19
+ const BranchContext = createContext({ id: undefined });
20
+ export function BranchProvider({ branch, children }) {
21
+ return _jsx(BranchContext.Provider, { value: branch, children: children });
22
+ }
23
+ export function useCurrentBranch() {
24
+ return useContext(BranchContext);
25
+ }
@@ -0,0 +1,29 @@
1
+ import React from 'react';
2
+ export type CapabilitySet = ReadonlySet<string> | string[] | Record<string, boolean>;
3
+ interface CapabilityContextValue {
4
+ has: (capability: string) => boolean;
5
+ all: (capabilities: string[]) => boolean;
6
+ any: (capabilities: string[]) => boolean;
7
+ }
8
+ export interface CapabilityProviderProps {
9
+ capabilities: CapabilitySet;
10
+ children: React.ReactNode;
11
+ }
12
+ export declare function CapabilityProvider({ capabilities, children }: CapabilityProviderProps): import("react/jsx-runtime").JSX.Element;
13
+ export declare function useCapabilities(): CapabilityContextValue;
14
+ export interface CapabilityGateProps {
15
+ /** Single capability required to render children. */
16
+ require?: string;
17
+ /** All of these capabilities must be present. */
18
+ all?: string[];
19
+ /** At least one of these capabilities must be present. */
20
+ any?: string[];
21
+ /** Content rendered when the user lacks the required capabilities. */
22
+ fallback?: React.ReactNode;
23
+ /** Optional negation: render children when capability is ABSENT. */
24
+ invert?: boolean;
25
+ children: React.ReactNode;
26
+ }
27
+ export declare function CapabilityGate({ require, all, any, fallback, invert, children }: CapabilityGateProps): import("react/jsx-runtime").JSX.Element;
28
+ export {};
29
+ //# sourceMappingURL=capability-gate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capability-gate.d.ts","sourceRoot":"","sources":["../src/capability-gate.tsx"],"names":[],"mappings":"AAGA,OAAO,KAA6C,MAAM,OAAO,CAAA;AAEjE,MAAM,MAAM,aAAa,GAAG,WAAW,CAAC,MAAM,CAAC,GAAG,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAEpF,UAAU,sBAAsB;IAC5B,GAAG,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAA;IACpC,GAAG,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,OAAO,CAAA;IACxC,GAAG,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,OAAO,CAAA;CAC3C;AAQD,MAAM,WAAW,uBAAuB;IACpC,YAAY,EAAE,aAAa,CAAA;IAC3B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC5B;AAQD,wBAAgB,kBAAkB,CAAC,EAAE,YAAY,EAAE,QAAQ,EAAE,EAAE,uBAAuB,2CAUrF;AAED,wBAAgB,eAAe,2BAE9B;AAED,MAAM,WAAW,mBAAmB;IAChC,qDAAqD;IACrD,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,iDAAiD;IACjD,GAAG,CAAC,EAAE,MAAM,EAAE,CAAA;IACd,0DAA0D;IAC1D,GAAG,CAAC,EAAE,MAAM,EAAE,CAAA;IACd,sEAAsE;IACtE,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B,oEAAoE;IACpE,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC5B;AAED,wBAAgB,cAAc,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,QAAe,EAAE,MAAc,EAAE,QAAQ,EAAE,EAAE,mBAAmB,2CAQnH"}