@bemaestro/views 0.0.2
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/LICENSE +193 -0
- package/README.md +45 -0
- package/package.json +55 -0
- package/src/ViewRenderer.vue +47 -0
- package/src/composables/use-view-data.ts +53 -0
- package/src/index.ts +29 -0
- package/src/lib/cn.ts +7 -0
- package/src/lib/format.ts +31 -0
- package/src/lib/view-binding.ts +40 -0
- package/src/primitives/Badge.vue +34 -0
- package/src/primitives/Card.vue +11 -0
- package/src/primitives/RichTextField.vue +485 -0
- package/src/primitives/StateMessage.vue +29 -0
- package/src/renderers/CalendarView.vue +118 -0
- package/src/renderers/DashboardView.vue +73 -0
- package/src/renderers/DetailView.vue +79 -0
- package/src/renderers/FormView.vue +160 -0
- package/src/renderers/GalleryView.vue +72 -0
- package/src/renderers/KanbanView.vue +87 -0
- package/src/renderers/TableView.vue +117 -0
- package/src/styles.css +5 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
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
|
|
44
|
+
purposes of this License, Derivative Works shall not include works
|
|
45
|
+
that remain separable from, or merely link (or bind by name) to the
|
|
46
|
+
interfaces of, the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including the
|
|
49
|
+
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
|
|
52
|
+
owner or by an individual or Legal Entity authorized to submit on
|
|
53
|
+
behalf of the copyright owner. For the purposes of this definition,
|
|
54
|
+
"submitted" means any form of electronic, verbal, or written
|
|
55
|
+
communication sent to the Licensor or its representatives, including
|
|
56
|
+
but not limited to communication on electronic mailing lists, source
|
|
57
|
+
code control systems, and issue tracking systems that are managed by,
|
|
58
|
+
or on behalf of, the Licensor for the purpose of discussing and
|
|
59
|
+
improving the Work, but excluding communication that is conspicuously
|
|
60
|
+
marked or otherwise designated in writing by the copyright owner as
|
|
61
|
+
"Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing
|
|
142
|
+
the origin of the Work and reproducing the content of the NOTICE
|
|
143
|
+
file.
|
|
144
|
+
|
|
145
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
146
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
147
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
148
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
149
|
+
implied, including, without limitation, any warranties or conditions
|
|
150
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
151
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
152
|
+
appropriateness of using or redistributing the Work and assume any
|
|
153
|
+
risks associated with Your exercise of permissions under this
|
|
154
|
+
License.
|
|
155
|
+
|
|
156
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
157
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
158
|
+
unless required by applicable law (such as deliberate and grossly
|
|
159
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
160
|
+
liable to You for damages, including any direct, indirect, special,
|
|
161
|
+
incidental, or consequential damages of any character arising as a
|
|
162
|
+
result of this License or out of the use or inability to use the
|
|
163
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
164
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
165
|
+
other commercial damages or losses), even if such Contributor
|
|
166
|
+
has been advised of the possibility of such damages.
|
|
167
|
+
|
|
168
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
169
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
170
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
171
|
+
or other liability obligations and/or rights consistent with this
|
|
172
|
+
License. However, in accepting such obligations, You may act only
|
|
173
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
174
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
175
|
+
defend, and hold each Contributor harmless for any liability
|
|
176
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
177
|
+
of your accepting any such warranty or additional liability.
|
|
178
|
+
|
|
179
|
+
END OF TERMS AND CONDITIONS
|
|
180
|
+
|
|
181
|
+
Copyright 2026 BeMaestro
|
|
182
|
+
|
|
183
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
184
|
+
you may not use this file except in compliance with the License.
|
|
185
|
+
You may obtain a copy of the License at
|
|
186
|
+
|
|
187
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
188
|
+
|
|
189
|
+
Unless required by applicable law or agreed to in writing, software
|
|
190
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
191
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
192
|
+
See the License for the specific language governing permissions and
|
|
193
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# @bemaestro/views
|
|
2
|
+
|
|
3
|
+
Vue 3 renderers that turn a Maestro Core `view` (table/detail/form/calendar/kanban/gallery/dashboard,
|
|
4
|
+
spec 17) into a working screen driven entirely by the meta-model — no per-app UI code required.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
npm install @bemaestro/views
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
This package ships raw `.vue`/`.ts` **source**, not a pre-built bundle — your bundler compiles it
|
|
13
|
+
like any workspace file. With Vite, exclude it from dependency pre-bundling so `@vitejs/plugin-vue`
|
|
14
|
+
processes its `.vue` files:
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
// vite.config.ts
|
|
18
|
+
export default defineConfig({
|
|
19
|
+
plugins: [vue()],
|
|
20
|
+
optimizeDeps: { exclude: ['@bemaestro/views'] },
|
|
21
|
+
});
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
(`create-maestro-app` scaffolds this automatically.)
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
```vue
|
|
29
|
+
<script setup lang="ts">
|
|
30
|
+
import { ViewRenderer } from '@bemaestro/views';
|
|
31
|
+
import '@bemaestro/views/styles.css';
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
<template>
|
|
35
|
+
<ViewRenderer :client="client" :view="view" />
|
|
36
|
+
</template>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Individual renderers (`TableView`, `DetailView`, `FormView`, `CalendarView`, `KanbanView`,
|
|
40
|
+
`GalleryView`, `DashboardView`) are exported directly for consumers that want to mount one without
|
|
41
|
+
the dispatcher. Peer deps: `vue`, `@lucide/vue`, `date-fns`.
|
|
42
|
+
|
|
43
|
+
## License
|
|
44
|
+
|
|
45
|
+
UNLICENSED — proprietary, part of the Maestro Core platform.
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bemaestro/views",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"src",
|
|
8
|
+
"!src/**/*.spec.ts",
|
|
9
|
+
"!src/**/*.test.ts"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": "./src/index.ts",
|
|
13
|
+
"./styles.css": "./src/styles.css"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@tiptap/core": "^3.28.0",
|
|
17
|
+
"@tiptap/extension-image": "^3.28.0",
|
|
18
|
+
"@tiptap/extension-placeholder": "^3.28.0",
|
|
19
|
+
"@tiptap/extension-table": "^3.28.0",
|
|
20
|
+
"@tiptap/pm": "^3.28.0",
|
|
21
|
+
"@tiptap/starter-kit": "^3.28.0",
|
|
22
|
+
"@tiptap/vue-3": "^3.28.0",
|
|
23
|
+
"clsx": "^2.1.1",
|
|
24
|
+
"tailwind-merge": "^3.5.0",
|
|
25
|
+
"@bemaestro/sdk": "0.1.0"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"@lucide/vue": "^1.23.0",
|
|
29
|
+
"date-fns": "^4.1.0",
|
|
30
|
+
"vue": "^3.5.25"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@eslint/js": "^10.0.1",
|
|
34
|
+
"@lucide/vue": "^1.23.0",
|
|
35
|
+
"@vitejs/plugin-vue": "^6.0.1",
|
|
36
|
+
"@vue/test-utils": "^2.4.11",
|
|
37
|
+
"@vue/tsconfig": "^0.8.1",
|
|
38
|
+
"date-fns": "^4.1.0",
|
|
39
|
+
"eslint": "^10.2.1",
|
|
40
|
+
"eslint-config-prettier": "^10.1.8",
|
|
41
|
+
"eslint-plugin-vue": "^10.6.0",
|
|
42
|
+
"globals": "^17.7.0",
|
|
43
|
+
"jsdom": "^29.1.1",
|
|
44
|
+
"typescript": "~5.8.3",
|
|
45
|
+
"typescript-eslint": "^8.62.1",
|
|
46
|
+
"vitest": "^4.1.9",
|
|
47
|
+
"vue": "^3.5.25",
|
|
48
|
+
"vue-tsc": "^3.1.1"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"typecheck": "vue-tsc --noEmit",
|
|
52
|
+
"lint": "eslint src",
|
|
53
|
+
"test": "vitest run"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed } from 'vue'
|
|
3
|
+
import type { MaestroClient, RuntimeView } from '@bemaestro/sdk/runtime'
|
|
4
|
+
import TableView from './renderers/TableView.vue'
|
|
5
|
+
import CalendarView from './renderers/CalendarView.vue'
|
|
6
|
+
import KanbanView from './renderers/KanbanView.vue'
|
|
7
|
+
import GalleryView from './renderers/GalleryView.vue'
|
|
8
|
+
import DetailView from './renderers/DetailView.vue'
|
|
9
|
+
import FormView from './renderers/FormView.vue'
|
|
10
|
+
import DashboardView from './renderers/DashboardView.vue'
|
|
11
|
+
import StateMessage from './primitives/StateMessage.vue'
|
|
12
|
+
|
|
13
|
+
const props = defineProps<{ view: RuntimeView; client: MaestroClient }>()
|
|
14
|
+
|
|
15
|
+
// Single dispatch point: a surface's nav entry maps to a view type, each with
|
|
16
|
+
// its own generic renderer (spec 17 — no per-app custom code).
|
|
17
|
+
const component = computed(() => {
|
|
18
|
+
switch (props.view.type) {
|
|
19
|
+
case 'table':
|
|
20
|
+
return TableView
|
|
21
|
+
case 'calendar':
|
|
22
|
+
return CalendarView
|
|
23
|
+
case 'kanban':
|
|
24
|
+
return KanbanView
|
|
25
|
+
case 'gallery':
|
|
26
|
+
return GalleryView
|
|
27
|
+
case 'detail':
|
|
28
|
+
return DetailView
|
|
29
|
+
case 'form':
|
|
30
|
+
return FormView
|
|
31
|
+
case 'dashboard':
|
|
32
|
+
return DashboardView
|
|
33
|
+
default:
|
|
34
|
+
return null
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
</script>
|
|
38
|
+
|
|
39
|
+
<template>
|
|
40
|
+
<component :is="component" v-if="component" :view="view" :client="client" />
|
|
41
|
+
<StateMessage
|
|
42
|
+
v-else
|
|
43
|
+
variant="error"
|
|
44
|
+
title="Unknown view type"
|
|
45
|
+
:description="`No renderer for '${view.type}'.`"
|
|
46
|
+
/>
|
|
47
|
+
</template>
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { ref, shallowRef, watch, type Ref } from 'vue';
|
|
2
|
+
import type { ListParams, MaestroClient } from '@bemaestro/sdk/runtime';
|
|
3
|
+
|
|
4
|
+
export type DataRecord = Record<string, unknown>;
|
|
5
|
+
|
|
6
|
+
export interface UseViewDataOptions {
|
|
7
|
+
/** Collection to read via the Data API; when null the view reads nothing. */
|
|
8
|
+
collectionKey: Ref<string | null | undefined>;
|
|
9
|
+
/** Query params (filter/sort/fields/search/window). Re-fetches on change. */
|
|
10
|
+
params: Ref<ListParams>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Reactive reader over the Data API for a view (spec 17): server-side paging
|
|
15
|
+
* only — the renderer passes the visible window/params, never loads a whole
|
|
16
|
+
* collection. Kept free of vue-query so the package has no data-layer peer.
|
|
17
|
+
*/
|
|
18
|
+
export function useViewData(client: MaestroClient, options: UseViewDataOptions) {
|
|
19
|
+
const rows = shallowRef<DataRecord[]>([]);
|
|
20
|
+
const total = ref<number | null>(null);
|
|
21
|
+
const loading = ref(false);
|
|
22
|
+
const error = ref<Error | null>(null);
|
|
23
|
+
let seq = 0;
|
|
24
|
+
|
|
25
|
+
async function reload() {
|
|
26
|
+
const collectionKey = options.collectionKey.value;
|
|
27
|
+
if (!collectionKey) {
|
|
28
|
+
rows.value = [];
|
|
29
|
+
total.value = null;
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const current = ++seq;
|
|
33
|
+
loading.value = true;
|
|
34
|
+
error.value = null;
|
|
35
|
+
try {
|
|
36
|
+
const res = await client.collection<DataRecord>(collectionKey).list(options.params.value);
|
|
37
|
+
// Drop a response that a newer request has superseded (avoids flicker).
|
|
38
|
+
if (current !== seq) return;
|
|
39
|
+
rows.value = res.data;
|
|
40
|
+
total.value = res.meta?.total ?? null;
|
|
41
|
+
} catch (err) {
|
|
42
|
+
if (current !== seq) return;
|
|
43
|
+
error.value = err instanceof Error ? err : new Error(String(err));
|
|
44
|
+
rows.value = [];
|
|
45
|
+
} finally {
|
|
46
|
+
if (current === seq) loading.value = false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
watch([options.collectionKey, options.params], reload, { immediate: true, deep: true });
|
|
51
|
+
|
|
52
|
+
return { rows, total, loading, error, reload };
|
|
53
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export { cn } from './lib/cn.js';
|
|
2
|
+
export { formatValue, humanizeKey, recordLabel } from './lib/format.js';
|
|
3
|
+
export { checkViewBinding, type BindingCheck } from './lib/view-binding.js';
|
|
4
|
+
export {
|
|
5
|
+
useViewData,
|
|
6
|
+
type DataRecord,
|
|
7
|
+
type UseViewDataOptions,
|
|
8
|
+
} from './composables/use-view-data.js';
|
|
9
|
+
|
|
10
|
+
// The dispatcher is the main entry point; individual renderers are exported for
|
|
11
|
+
// consumers that want to mount one directly (e.g. a detail page by id).
|
|
12
|
+
export { default as ViewRenderer } from './ViewRenderer.vue';
|
|
13
|
+
export { default as RichTextField } from './primitives/RichTextField.vue';
|
|
14
|
+
export { default as TableView } from './renderers/TableView.vue';
|
|
15
|
+
export { default as CalendarView } from './renderers/CalendarView.vue';
|
|
16
|
+
export { default as KanbanView } from './renderers/KanbanView.vue';
|
|
17
|
+
export { default as GalleryView } from './renderers/GalleryView.vue';
|
|
18
|
+
export { default as DetailView } from './renderers/DetailView.vue';
|
|
19
|
+
export { default as FormView } from './renderers/FormView.vue';
|
|
20
|
+
export { default as DashboardView } from './renderers/DashboardView.vue';
|
|
21
|
+
|
|
22
|
+
// Re-export the runtime view/surface contract so consumers get one import site.
|
|
23
|
+
export type {
|
|
24
|
+
RuntimeResponse,
|
|
25
|
+
RuntimeSurface,
|
|
26
|
+
RuntimeView,
|
|
27
|
+
SurfaceNavEntry,
|
|
28
|
+
ViewType,
|
|
29
|
+
} from '@bemaestro/sdk/runtime';
|
package/src/lib/cn.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** Human-friendly rendering of a raw Data API value (spec 17 renderers). */
|
|
2
|
+
export function formatValue(value: unknown): string {
|
|
3
|
+
if (value === null || value === undefined) return '—';
|
|
4
|
+
if (typeof value === 'boolean') return value ? 'Yes' : 'No';
|
|
5
|
+
if (value instanceof Date) return value.toLocaleString();
|
|
6
|
+
if (typeof value === 'string') {
|
|
7
|
+
// ISO date/datetime → locale string; leave other strings untouched.
|
|
8
|
+
if (/^\d{4}-\d{2}-\d{2}(T|\s)/.test(value)) {
|
|
9
|
+
const d = new Date(value);
|
|
10
|
+
if (!Number.isNaN(d.getTime())) return d.toLocaleString();
|
|
11
|
+
}
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
if (typeof value === 'number') return String(value);
|
|
15
|
+
return JSON.stringify(value);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Turn a field key into a readable label: `starts_at` → `Starts at`. */
|
|
19
|
+
export function humanizeKey(key: string): string {
|
|
20
|
+
const spaced = key.replace(/[_-]+/g, ' ').trim();
|
|
21
|
+
return spaced.charAt(0).toUpperCase() + spaced.slice(1);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Best-effort label for a record (title binding, else name/title/id field). */
|
|
25
|
+
export function recordLabel(record: Record<string, unknown>, titleField?: string): string {
|
|
26
|
+
if (titleField && record[titleField] != null) return formatValue(record[titleField]);
|
|
27
|
+
for (const k of ['name', 'title', 'label']) {
|
|
28
|
+
if (record[k] != null) return formatValue(record[k]);
|
|
29
|
+
}
|
|
30
|
+
return record.id != null ? String(record.id) : '—';
|
|
31
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { RuntimeView, ViewType } from '@bemaestro/sdk/runtime';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Config keys each view type needs to render (mirrors the server's
|
|
5
|
+
* VIEW_FIELD_BINDINGS, spec 17 US-17.1). The server validates types at write
|
|
6
|
+
* time; here we only guard against a dangling/misconfigured view at load so it
|
|
7
|
+
* renders a clear message instead of crashing (spec 17 edge cases).
|
|
8
|
+
*/
|
|
9
|
+
const REQUIRED_CONFIG: Partial<Record<ViewType, string[]>> = {
|
|
10
|
+
calendar: ['dateField', 'titleField'],
|
|
11
|
+
kanban: ['groupField', 'titleField'],
|
|
12
|
+
gallery: ['imageField', 'titleField'],
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const NEEDS_COLLECTION: ViewType[] = ['table', 'calendar', 'kanban', 'gallery', 'detail', 'form'];
|
|
16
|
+
|
|
17
|
+
export interface BindingCheck {
|
|
18
|
+
ok: boolean;
|
|
19
|
+
reason?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function checkViewBinding(view: RuntimeView): BindingCheck {
|
|
23
|
+
if (NEEDS_COLLECTION.includes(view.type) && !view.collectionKey) {
|
|
24
|
+
return { ok: false, reason: `${view.type} view is not bound to a collection` };
|
|
25
|
+
}
|
|
26
|
+
const required = REQUIRED_CONFIG[view.type] ?? [];
|
|
27
|
+
const missing = required.filter((k) => {
|
|
28
|
+
const v = (view.config as Record<string, unknown>)[k];
|
|
29
|
+
return v === undefined || v === null || v === '';
|
|
30
|
+
});
|
|
31
|
+
if (missing.length > 0) {
|
|
32
|
+
return { ok: false, reason: `missing config: ${missing.join(', ')}` };
|
|
33
|
+
}
|
|
34
|
+
return { ok: true };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function configString(view: RuntimeView, key: string): string | undefined {
|
|
38
|
+
const v = (view.config as Record<string, unknown>)[key];
|
|
39
|
+
return typeof v === 'string' ? v : undefined;
|
|
40
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed } from 'vue'
|
|
3
|
+
import { cn } from '../lib/cn.js'
|
|
4
|
+
|
|
5
|
+
const props = defineProps<{ class?: string; color?: string }>()
|
|
6
|
+
|
|
7
|
+
// Optional stable hue derived from an enum value (calendar/kanban color coding).
|
|
8
|
+
const style = computed(() =>
|
|
9
|
+
props.color
|
|
10
|
+
? { backgroundColor: `var(--maestro-badge-bg, hsl(${hashHue(props.color)} 70% 92%))` }
|
|
11
|
+
: undefined,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
function hashHue(value: string): number {
|
|
15
|
+
let h = 0
|
|
16
|
+
for (let i = 0; i < value.length; i++) h = (h * 31 + value.charCodeAt(i)) % 360
|
|
17
|
+
return h
|
|
18
|
+
}
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<template>
|
|
22
|
+
<span
|
|
23
|
+
:class="
|
|
24
|
+
cn(
|
|
25
|
+
'inline-flex items-center rounded-md border px-2 py-0.5 text-xs font-medium',
|
|
26
|
+
!props.color && 'bg-secondary text-secondary-foreground',
|
|
27
|
+
$props.class,
|
|
28
|
+
)
|
|
29
|
+
"
|
|
30
|
+
:style="style"
|
|
31
|
+
>
|
|
32
|
+
<slot />
|
|
33
|
+
</span>
|
|
34
|
+
</template>
|