@mobile-reality/mdma-renderer-vue 0.2.0 → 0.4.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.
- package/README.md +2 -2
- package/dist/components/ChartRenderer.d.ts +0 -5
- package/dist/components/ChartRenderer.d.ts.map +1 -1
- package/dist/components/ChartRenderer.js +59 -15
- package/dist/components/ChartRenderer.js.map +1 -1
- package/dist/components/DataStateViews.d.ts +77 -0
- package/dist/components/DataStateViews.d.ts.map +1 -0
- package/dist/components/DataStateViews.js +41 -0
- package/dist/components/DataStateViews.js.map +1 -0
- package/dist/components/FormRenderer.d.ts.map +1 -1
- package/dist/components/FormRenderer.js +263 -10
- package/dist/components/FormRenderer.js.map +1 -1
- package/dist/components/TableRenderer.d.ts +2 -1
- package/dist/components/TableRenderer.d.ts.map +1 -1
- package/dist/components/TableRenderer.js +178 -41
- package/dist/components/TableRenderer.js.map +1 -1
- package/dist/composables/use-document-store.d.ts +2 -1
- package/dist/composables/use-document-store.d.ts.map +1 -1
- package/dist/composables/use-document-store.js +8 -0
- package/dist/composables/use-document-store.js.map +1 -1
- package/dist/context/ElementOverridesContext.d.ts +14 -0
- package/dist/context/ElementOverridesContext.d.ts.map +1 -1
- package/dist/context/ElementOverridesContext.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/styles.css +253 -0
package/README.md
CHANGED
|
@@ -46,8 +46,8 @@ as a `data-theme` attribute, a custom theme as inline `--mdma-*` CSS variables.
|
|
|
46
46
|
components rendered outside a `MdmaDocument` (a lone `MdmaBlock`, say), wrap them in
|
|
47
47
|
`MdmaThemeProvider`.
|
|
48
48
|
|
|
49
|
-
The `MdmaTheme` token shape is shared with the React and React
|
|
50
|
-
object is portable across all
|
|
49
|
+
The `MdmaTheme` token shape is shared with the React, [vanilla](../renderer-vanilla) and React
|
|
50
|
+
Native renderers, so a theme object is portable across all four. See the repo [Theming guide](../../docs/guides/theming.md)
|
|
51
51
|
for the full token reference.
|
|
52
52
|
|
|
53
53
|
### Customizations
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Basic built-in chart renderer.
|
|
3
|
-
* Renders chart data as a simple HTML table.
|
|
4
|
-
* Override with a richer renderer (e.g. a charting library) via customizations.
|
|
5
|
-
*/
|
|
6
1
|
export declare const ChartRenderer: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
7
2
|
component: {
|
|
8
3
|
type: import("vue").PropType<import("@mobile-reality/mdma-spec").MdmaComponent>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChartRenderer.d.ts","sourceRoot":"","sources":["../../src/components/ChartRenderer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ChartRenderer.d.ts","sourceRoot":"","sources":["../../src/components/ChartRenderer.ts"],"names":[],"mappings":"AAiGA,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4EAsCxB,CAAC"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { computed, defineComponent, h } from 'vue';
|
|
2
|
+
import { isDataSourceRef } from '@mobile-reality/mdma-spec';
|
|
2
3
|
import { blockRendererProps } from '../renderers/renderer-props.js';
|
|
4
|
+
import { useDataState, useDocumentStore } from '../composables/use-document-store.js';
|
|
5
|
+
import { useElementOverride } from '../context/ElementOverridesContext.js';
|
|
6
|
+
import { DefaultDataLoading, DefaultDataError, DefaultDataEmpty } from './DataStateViews.js';
|
|
3
7
|
function parseCsvData(raw) {
|
|
4
8
|
const lines = raw
|
|
5
9
|
.trim()
|
|
@@ -20,11 +24,55 @@ function parseCsvData(raw) {
|
|
|
20
24
|
});
|
|
21
25
|
return { headers, rows };
|
|
22
26
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
function rowsToChartData(rows) {
|
|
28
|
+
const headers = new Set();
|
|
29
|
+
for (const row of rows) {
|
|
30
|
+
for (const key of Object.keys(row))
|
|
31
|
+
headers.add(key);
|
|
32
|
+
}
|
|
33
|
+
return { headers: [...headers], rows: rows };
|
|
34
|
+
}
|
|
35
|
+
function renderChartTable(component, data) {
|
|
36
|
+
return h('div', { class: 'mdma-chart', 'data-component-id': component.id }, [
|
|
37
|
+
component.label ? h('div', { class: 'mdma-chart-label' }, component.label) : null,
|
|
38
|
+
h('div', { class: 'mdma-chart-variant' }, `${component.variant ?? 'line'} chart`),
|
|
39
|
+
h('table', { class: 'mdma-chart-data' }, [
|
|
40
|
+
h('thead', [h('tr', data.headers.map((header) => h('th', { key: header }, header)))]),
|
|
41
|
+
h('tbody', data.rows.map((row, i) => h('tr', { key: i }, data.headers.map((header) => h('td', { key: header }, String(row[header] ?? '')))))),
|
|
42
|
+
]),
|
|
43
|
+
]);
|
|
44
|
+
}
|
|
45
|
+
const DataDrivenChart = defineComponent({
|
|
46
|
+
name: 'MdmaDataDrivenChart',
|
|
47
|
+
props: {
|
|
48
|
+
component: { type: Object, required: true },
|
|
49
|
+
},
|
|
50
|
+
setup(props) {
|
|
51
|
+
const store = useDocumentStore();
|
|
52
|
+
const dataState = useDataState(() => props.component.id);
|
|
53
|
+
const DataLoading = useElementOverride('chart', 'dataLoading');
|
|
54
|
+
const DataError = useElementOverride('chart', 'dataError');
|
|
55
|
+
const DataEmpty = useElementOverride('chart', 'dataEmpty');
|
|
56
|
+
return () => {
|
|
57
|
+
const component = props.component;
|
|
58
|
+
const state = dataState.value;
|
|
59
|
+
if (!state || state.status === 'loading') {
|
|
60
|
+
return h(DataLoading.value ?? DefaultDataLoading, { componentId: component.id });
|
|
61
|
+
}
|
|
62
|
+
if (state.status === 'error') {
|
|
63
|
+
return h(DataError.value ?? DefaultDataError, {
|
|
64
|
+
componentId: component.id,
|
|
65
|
+
error: state.error ?? 'Failed to load chart data',
|
|
66
|
+
onRetry: () => store.value.retryData(component.id),
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
if (state.rows.length === 0) {
|
|
70
|
+
return h(DataEmpty.value ?? DefaultDataEmpty, { componentId: component.id });
|
|
71
|
+
}
|
|
72
|
+
return renderChartTable(component, rowsToChartData(state.rows));
|
|
73
|
+
};
|
|
74
|
+
},
|
|
75
|
+
});
|
|
28
76
|
export const ChartRenderer = defineComponent({
|
|
29
77
|
name: 'ChartRenderer',
|
|
30
78
|
props: blockRendererProps,
|
|
@@ -34,6 +82,8 @@ export const ChartRenderer = defineComponent({
|
|
|
34
82
|
if (component.type !== 'chart')
|
|
35
83
|
return { headers: [], rows: [] };
|
|
36
84
|
const raw = component.data;
|
|
85
|
+
if (isDataSourceRef(raw))
|
|
86
|
+
return { headers: [], rows: [] };
|
|
37
87
|
if (typeof raw === 'string' && raw.startsWith('{{')) {
|
|
38
88
|
const resolved = props.resolveBinding(raw);
|
|
39
89
|
return typeof resolved === 'string' ? parseCsvData(resolved) : { headers: [], rows: [] };
|
|
@@ -44,22 +94,16 @@ export const ChartRenderer = defineComponent({
|
|
|
44
94
|
const component = props.component;
|
|
45
95
|
if (component.type !== 'chart')
|
|
46
96
|
return null;
|
|
97
|
+
if (isDataSourceRef(component.data)) {
|
|
98
|
+
return h(DataDrivenChart, { component });
|
|
99
|
+
}
|
|
47
100
|
if (data.value.rows.length === 0) {
|
|
48
101
|
return h('div', { class: 'mdma-chart mdma-chart--empty', 'data-component-id': component.id }, [
|
|
49
102
|
component.label ? h('div', { class: 'mdma-chart-label' }, component.label) : null,
|
|
50
103
|
h('div', { class: 'mdma-chart-empty' }, 'No chart data'),
|
|
51
104
|
]);
|
|
52
105
|
}
|
|
53
|
-
return
|
|
54
|
-
component.label ? h('div', { class: 'mdma-chart-label' }, component.label) : null,
|
|
55
|
-
h('div', { class: 'mdma-chart-variant' }, `${component.variant ?? 'line'} chart`),
|
|
56
|
-
h('table', { class: 'mdma-chart-data' }, [
|
|
57
|
-
h('thead', [
|
|
58
|
-
h('tr', data.value.headers.map((header) => h('th', { key: header }, header))),
|
|
59
|
-
]),
|
|
60
|
-
h('tbody', data.value.rows.map((row, i) => h('tr', { key: i }, data.value.headers.map((header) => h('td', { key: header }, String(row[header] ?? '')))))),
|
|
61
|
-
]),
|
|
62
|
-
]);
|
|
106
|
+
return renderChartTable(component, data.value);
|
|
63
107
|
};
|
|
64
108
|
},
|
|
65
109
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChartRenderer.js","sourceRoot":"","sources":["../../src/components/ChartRenderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"ChartRenderer.js","sourceRoot":"","sources":["../../src/components/ChartRenderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACnD,OAAO,EAAE,eAAe,EAAuB,MAAM,2BAA2B,CAAC;AACjF,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AACtF,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAO7F,SAAS,YAAY,CAAC,GAAW;IAC/B,MAAM,KAAK,GAAG,GAAG;SACd,IAAI,EAAE;SACN,KAAK,CAAC,IAAI,CAAC;SACX,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAClC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE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GAAG,KAAK,CAAC,SAAS,CAAC;YAClC,IAAI,SAAS,CAAC,IAAI,KAAK,OAAO;gBAAE,OAAO,IAAI,CAAC;YAE5C,IAAI,eAAe,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;gBACpC,OAAO,CAAC,CAAC,eAAe,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;YAC3C,CAAC;YAED,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACjC,OAAO,CAAC,CACN,KAAK,EACL,EAAE,KAAK,EAAE,8BAA8B,EAAE,mBAAmB,EAAE,SAAS,CAAC,EAAE,EAAE,EAC5E;oBACE,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,kBAAkB,EAAE,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI;oBACjF,CAAC,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,kBAAkB,EAAE,EAAE,eAAe,CAAC;iBACzD,CACF,CAAC;YACJ,CAAC;YAED,OAAO,gBAAgB,CAAC,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QACjD,CAAC,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { type PropType } from 'vue';
|
|
2
|
+
export declare const DefaultDataLoading: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
3
|
+
componentId: {
|
|
4
|
+
type: StringConstructor;
|
|
5
|
+
required: true;
|
|
6
|
+
};
|
|
7
|
+
reloading: {
|
|
8
|
+
type: BooleanConstructor;
|
|
9
|
+
default: boolean;
|
|
10
|
+
};
|
|
11
|
+
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
14
|
+
componentId: {
|
|
15
|
+
type: StringConstructor;
|
|
16
|
+
required: true;
|
|
17
|
+
};
|
|
18
|
+
reloading: {
|
|
19
|
+
type: BooleanConstructor;
|
|
20
|
+
default: boolean;
|
|
21
|
+
};
|
|
22
|
+
}>> & Readonly<{}>, {
|
|
23
|
+
reloading: boolean;
|
|
24
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
25
|
+
export declare const DefaultDataError: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
26
|
+
componentId: {
|
|
27
|
+
type: StringConstructor;
|
|
28
|
+
required: true;
|
|
29
|
+
};
|
|
30
|
+
error: {
|
|
31
|
+
type: StringConstructor;
|
|
32
|
+
required: true;
|
|
33
|
+
};
|
|
34
|
+
onRetry: {
|
|
35
|
+
type: PropType<() => void>;
|
|
36
|
+
required: true;
|
|
37
|
+
};
|
|
38
|
+
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
39
|
+
[key: string]: any;
|
|
40
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
41
|
+
componentId: {
|
|
42
|
+
type: StringConstructor;
|
|
43
|
+
required: true;
|
|
44
|
+
};
|
|
45
|
+
error: {
|
|
46
|
+
type: StringConstructor;
|
|
47
|
+
required: true;
|
|
48
|
+
};
|
|
49
|
+
onRetry: {
|
|
50
|
+
type: PropType<() => void>;
|
|
51
|
+
required: true;
|
|
52
|
+
};
|
|
53
|
+
}>> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
54
|
+
export declare const DefaultDataEmpty: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
55
|
+
componentId: {
|
|
56
|
+
type: StringConstructor;
|
|
57
|
+
required: true;
|
|
58
|
+
};
|
|
59
|
+
label: {
|
|
60
|
+
type: StringConstructor;
|
|
61
|
+
default: undefined;
|
|
62
|
+
};
|
|
63
|
+
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
64
|
+
[key: string]: any;
|
|
65
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
66
|
+
componentId: {
|
|
67
|
+
type: StringConstructor;
|
|
68
|
+
required: true;
|
|
69
|
+
};
|
|
70
|
+
label: {
|
|
71
|
+
type: StringConstructor;
|
|
72
|
+
default: undefined;
|
|
73
|
+
};
|
|
74
|
+
}>> & Readonly<{}>, {
|
|
75
|
+
label: string;
|
|
76
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
77
|
+
//# sourceMappingURL=DataStateViews.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DataStateViews.d.ts","sourceRoot":"","sources":["../../src/components/DataStateViews.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,QAAQ,EAAE,MAAM,KAAK,CAAC;AAExD,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;4EAoB7B,CAAC;AAEH,eAAO,MAAM,gBAAgB;;;;;;;;;;cAKI,QAAQ,CAAC,MAAM,IAAI,CAAC;;;;;;;;;;;;;;;cAApB,QAAQ,CAAC,MAAM,IAAI,CAAC;;;iGASnD,CAAC;AAEH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;4EAa3B,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { defineComponent, h } from 'vue';
|
|
2
|
+
export const DefaultDataLoading = defineComponent({
|
|
3
|
+
name: 'MdmaDataLoading',
|
|
4
|
+
props: {
|
|
5
|
+
componentId: { type: String, required: true },
|
|
6
|
+
reloading: { type: Boolean, default: false },
|
|
7
|
+
},
|
|
8
|
+
setup(props) {
|
|
9
|
+
return () => props.reloading
|
|
10
|
+
? h('span', { class: 'mdma-table-loading-indicator', 'data-component-id': props.componentId }, 'Loading…')
|
|
11
|
+
: h('div', { class: 'mdma-data-loading', 'data-component-id': props.componentId }, 'Loading…');
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
export const DefaultDataError = defineComponent({
|
|
15
|
+
name: 'MdmaDataError',
|
|
16
|
+
props: {
|
|
17
|
+
componentId: { type: String, required: true },
|
|
18
|
+
error: { type: String, required: true },
|
|
19
|
+
onRetry: { type: Function, required: true },
|
|
20
|
+
},
|
|
21
|
+
setup(props) {
|
|
22
|
+
return () => h('div', { class: 'mdma-data-error', 'data-component-id': props.componentId }, [
|
|
23
|
+
h('span', props.error),
|
|
24
|
+
h('button', { type: 'button', onClick: props.onRetry }, 'Retry'),
|
|
25
|
+
]);
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
export const DefaultDataEmpty = defineComponent({
|
|
29
|
+
name: 'MdmaDataEmpty',
|
|
30
|
+
props: {
|
|
31
|
+
componentId: { type: String, required: true },
|
|
32
|
+
label: { type: String, default: undefined },
|
|
33
|
+
},
|
|
34
|
+
setup(props) {
|
|
35
|
+
return () => h('div', { class: 'mdma-data-empty', 'data-component-id': props.componentId }, [
|
|
36
|
+
props.label ? h('div', { class: 'mdma-chart-label' }, props.label) : null,
|
|
37
|
+
'No data',
|
|
38
|
+
]);
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
//# sourceMappingURL=DataStateViews.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DataStateViews.js","sourceRoot":"","sources":["../../src/components/DataStateViews.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,CAAC,EAAiB,MAAM,KAAK,CAAC;AAExD,MAAM,CAAC,MAAM,kBAAkB,GAAG,eAAe,CAAC;IAChD,IAAI,EAAE,iBAAiB;IACvB,KAAK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AAgB,GAAG,eAAe,CAAC;IAC9C,IAAI,EAAE,eAAe;IACrB,KAAK,EAAE;QACL,WAAW,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;QAC7C,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE;KAC5C;IACD,KAAK,CAAC,KAAK;QACT,OAAO,GAAG,EAAE,CACV,CAAC,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,KAAK,CAAC,WAAW,EAAE,EAAE;YAC7E,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,kBAAkB,EAAE,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI;YACzE,SAAS;SACV,CAAC,CAAC;IACP,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormRenderer.d.ts","sourceRoot":"","sources":["../../src/components/FormRenderer.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"FormRenderer.d.ts","sourceRoot":"","sources":["../../src/components/FormRenderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,QAAQ,EAEd,MAAM,KAAK,CAAC;AA4eb,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4EAkKvB,CAAC"}
|
|
@@ -1,7 +1,18 @@
|
|
|
1
|
-
import { defineComponent, h, ref } from 'vue';
|
|
1
|
+
import { computed, defineComponent, h, ref, watch, watchPostEffect, } from 'vue';
|
|
2
|
+
import { isDataDrivenOptions } from '@mobile-reality/mdma-runtime';
|
|
2
3
|
import { blockRendererProps } from '../renderers/renderer-props.js';
|
|
3
4
|
import { useMdmaContext } from '../context/MdmaProvider.js';
|
|
5
|
+
import { useDataState, useDocumentStore } from '../composables/use-document-store.js';
|
|
4
6
|
import { useElementOverride, } from '../context/ElementOverridesContext.js';
|
|
7
|
+
import { DefaultDataLoading, DefaultDataError } from './DataStateViews.js';
|
|
8
|
+
function inlineOptions(options, dataSources) {
|
|
9
|
+
if (typeof options === 'string')
|
|
10
|
+
return dataSources?.[options] ?? [];
|
|
11
|
+
return Array.isArray(options) ? options : [];
|
|
12
|
+
}
|
|
13
|
+
function matchesQuery(option, query) {
|
|
14
|
+
return option.label.toLowerCase().includes(query.trim().toLowerCase());
|
|
15
|
+
}
|
|
5
16
|
// ─── Sensitive field indicator ──────────────────────────────────────────────
|
|
6
17
|
const DefaultSensitiveIndicator = defineComponent({
|
|
7
18
|
name: 'MdmaSensitiveIndicator',
|
|
@@ -82,6 +93,132 @@ const DefaultSelect = defineComponent({
|
|
|
82
93
|
]);
|
|
83
94
|
},
|
|
84
95
|
});
|
|
96
|
+
const COMBOBOX_REQUIRED_MESSAGE = 'Select an option from the list.';
|
|
97
|
+
const DefaultCombobox = defineComponent({
|
|
98
|
+
name: 'MdmaCombobox',
|
|
99
|
+
props: {
|
|
100
|
+
...baseElementProps,
|
|
101
|
+
type: { type: String, required: true },
|
|
102
|
+
value: { type: String, required: true },
|
|
103
|
+
options: { type: Array, required: true },
|
|
104
|
+
query: { type: String, required: true },
|
|
105
|
+
onQueryChange: { type: Function, required: true },
|
|
106
|
+
loading: { type: Boolean, default: undefined },
|
|
107
|
+
error: { type: String, default: undefined },
|
|
108
|
+
onRetry: { type: Function, default: undefined },
|
|
109
|
+
},
|
|
110
|
+
setup(props) {
|
|
111
|
+
const open = ref(false);
|
|
112
|
+
// the highlight belongs to one result set; new results drop it
|
|
113
|
+
const resultsKey = computed(() => props.options.map((o) => o.value).join('\n'));
|
|
114
|
+
const highlight = ref({ resultsKey: resultsKey.value, index: -1 });
|
|
115
|
+
const active = computed(() => highlight.value.resultsKey === resultsKey.value ? highlight.value.index : -1);
|
|
116
|
+
const setActive = (index) => {
|
|
117
|
+
highlight.value = { resultsKey: resultsKey.value, index };
|
|
118
|
+
};
|
|
119
|
+
// the picked option may drop out of later search results; keep its label
|
|
120
|
+
const picked = ref(null);
|
|
121
|
+
const inputEl = ref(null);
|
|
122
|
+
// typed text is only a search query, so it never satisfies `required` on its own
|
|
123
|
+
watchPostEffect(() => {
|
|
124
|
+
inputEl.value?.setCustomValidity(props.required && !props.value ? COMBOBOX_REQUIRED_MESSAGE : '');
|
|
125
|
+
});
|
|
126
|
+
const choose = (option) => {
|
|
127
|
+
picked.value = option;
|
|
128
|
+
open.value = false;
|
|
129
|
+
setActive(-1);
|
|
130
|
+
props.onChange(option.value);
|
|
131
|
+
};
|
|
132
|
+
const handleKeyDown = (e) => {
|
|
133
|
+
if (e.key === 'ArrowDown') {
|
|
134
|
+
e.preventDefault();
|
|
135
|
+
open.value = true;
|
|
136
|
+
setActive(Math.min(active.value + 1, props.options.length - 1));
|
|
137
|
+
}
|
|
138
|
+
else if (e.key === 'ArrowUp') {
|
|
139
|
+
e.preventDefault();
|
|
140
|
+
setActive(Math.max(active.value - 1, 0));
|
|
141
|
+
}
|
|
142
|
+
else if (e.key === 'Enter' && open.value && props.error && props.onRetry) {
|
|
143
|
+
e.preventDefault();
|
|
144
|
+
props.onRetry();
|
|
145
|
+
}
|
|
146
|
+
else if (e.key === 'Enter' && open.value && props.options[active.value]) {
|
|
147
|
+
e.preventDefault();
|
|
148
|
+
choose(props.options[active.value]);
|
|
149
|
+
}
|
|
150
|
+
else if (e.key === 'Escape') {
|
|
151
|
+
open.value = false;
|
|
152
|
+
setActive(-1);
|
|
153
|
+
props.onQueryChange('');
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
return () => {
|
|
157
|
+
const listboxId = `${props.id}-listbox`;
|
|
158
|
+
const selectedLabel = props.options.find((o) => o.value === props.value)?.label ??
|
|
159
|
+
(picked.value?.value === props.value ? picked.value.label : props.value);
|
|
160
|
+
const status = props.error
|
|
161
|
+
? props.error
|
|
162
|
+
: props.loading && props.options.length === 0
|
|
163
|
+
? 'Searching...'
|
|
164
|
+
: props.options.length === 0
|
|
165
|
+
? 'No matches'
|
|
166
|
+
: '';
|
|
167
|
+
return h('span', { class: 'mdma-combobox' }, [
|
|
168
|
+
h('input', {
|
|
169
|
+
ref: inputEl,
|
|
170
|
+
id: props.id,
|
|
171
|
+
type: 'text',
|
|
172
|
+
role: 'combobox',
|
|
173
|
+
autocomplete: 'off',
|
|
174
|
+
'aria-autocomplete': 'list',
|
|
175
|
+
'aria-expanded': open.value && !status,
|
|
176
|
+
'aria-controls': listboxId,
|
|
177
|
+
'aria-activedescendant': open.value && active.value >= 0 ? `${props.id}-option-${active.value}` : undefined,
|
|
178
|
+
'aria-busy': props.loading || undefined,
|
|
179
|
+
required: props.required,
|
|
180
|
+
placeholder: 'Search...',
|
|
181
|
+
value: open.value ? props.query : selectedLabel,
|
|
182
|
+
onFocus: () => {
|
|
183
|
+
open.value = true;
|
|
184
|
+
},
|
|
185
|
+
onBlur: () => {
|
|
186
|
+
open.value = false;
|
|
187
|
+
setActive(-1);
|
|
188
|
+
props.onQueryChange('');
|
|
189
|
+
},
|
|
190
|
+
onInput: (e) => {
|
|
191
|
+
open.value = true;
|
|
192
|
+
setActive(-1);
|
|
193
|
+
props.onQueryChange(e.target.value);
|
|
194
|
+
},
|
|
195
|
+
onKeydown: handleKeyDown,
|
|
196
|
+
}),
|
|
197
|
+
h('div', { class: 'mdma-combobox-popup', hidden: !open.value }, [
|
|
198
|
+
h('ul', { id: listboxId, role: 'listbox', class: 'mdma-combobox-listbox', hidden: !!status }, props.options.map((opt, index) => h('li', {
|
|
199
|
+
key: opt.value,
|
|
200
|
+
id: `${props.id}-option-${index}`,
|
|
201
|
+
role: 'option',
|
|
202
|
+
'aria-selected': opt.value === props.value,
|
|
203
|
+
class: `mdma-combobox-option${index === active.value ? ' mdma-combobox-option--active' : ''}`,
|
|
204
|
+
onMousedown: (e) => e.preventDefault(),
|
|
205
|
+
onClick: () => choose(opt),
|
|
206
|
+
}, opt.label))),
|
|
207
|
+
h('output', { class: `mdma-combobox-status${props.error ? ' mdma-combobox-status--error' : ''}` }, [
|
|
208
|
+
open.value ? status : null,
|
|
209
|
+
open.value && props.error && props.onRetry
|
|
210
|
+
? h('button', {
|
|
211
|
+
type: 'button',
|
|
212
|
+
onMousedown: (e) => e.preventDefault(),
|
|
213
|
+
onClick: props.onRetry,
|
|
214
|
+
}, 'Retry')
|
|
215
|
+
: null,
|
|
216
|
+
]),
|
|
217
|
+
]),
|
|
218
|
+
]);
|
|
219
|
+
};
|
|
220
|
+
},
|
|
221
|
+
});
|
|
85
222
|
const DefaultCheckbox = defineComponent({
|
|
86
223
|
name: 'MdmaCheckbox',
|
|
87
224
|
props: {
|
|
@@ -163,6 +300,94 @@ const DefaultSubmitButton = defineComponent({
|
|
|
163
300
|
return () => h('button', { type: 'button', class: 'mdma-form-submit', onClick: props.onClick }, props.label);
|
|
164
301
|
},
|
|
165
302
|
});
|
|
303
|
+
const DataDrivenSelect = defineComponent({
|
|
304
|
+
name: 'MdmaDataDrivenSelect',
|
|
305
|
+
props: {
|
|
306
|
+
dataKey: { type: String, required: true },
|
|
307
|
+
select: { type: Object, required: true },
|
|
308
|
+
selectProps: { type: Object, required: true },
|
|
309
|
+
},
|
|
310
|
+
setup(props) {
|
|
311
|
+
const store = useDocumentStore();
|
|
312
|
+
const dataState = useDataState(() => props.dataKey);
|
|
313
|
+
const DataLoading = useElementOverride('form', 'dataLoading');
|
|
314
|
+
const DataError = useElementOverride('form', 'dataError');
|
|
315
|
+
return () => {
|
|
316
|
+
const state = dataState.value;
|
|
317
|
+
if (!state || state.status === 'loading') {
|
|
318
|
+
return h(DataLoading.value ?? DefaultDataLoading, { componentId: props.dataKey });
|
|
319
|
+
}
|
|
320
|
+
if (state.status === 'error') {
|
|
321
|
+
return h(DataError.value ?? DefaultDataError, {
|
|
322
|
+
componentId: props.dataKey,
|
|
323
|
+
error: state.error ?? 'Failed to load options',
|
|
324
|
+
onRetry: () => store.value.retryData(props.dataKey),
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
return h(props.select, {
|
|
328
|
+
...props.selectProps,
|
|
329
|
+
options: state.rows,
|
|
330
|
+
});
|
|
331
|
+
};
|
|
332
|
+
},
|
|
333
|
+
});
|
|
334
|
+
/**
|
|
335
|
+
* A `searchable: true` select. Inline options are filtered here; a data-source
|
|
336
|
+
* slot gets the typed text as its `filter`, so the resolver does the search.
|
|
337
|
+
*/
|
|
338
|
+
const SearchableSelect = defineComponent({
|
|
339
|
+
name: 'MdmaSearchableSelect',
|
|
340
|
+
props: {
|
|
341
|
+
combobox: { type: Object, required: true },
|
|
342
|
+
dataKey: { type: String, default: undefined },
|
|
343
|
+
staticOptions: { type: Array, required: true },
|
|
344
|
+
selectProps: { type: Object, required: true },
|
|
345
|
+
},
|
|
346
|
+
setup(props) {
|
|
347
|
+
const store = useDocumentStore();
|
|
348
|
+
const dataState = useDataState(() => props.dataKey ?? '');
|
|
349
|
+
const query = ref('');
|
|
350
|
+
// a filter left on the slot by an earlier mount would hide options behind an empty input
|
|
351
|
+
watch([() => props.dataKey, store], ([key, s]) => {
|
|
352
|
+
if (key && s.getDataState(key)?.filter)
|
|
353
|
+
s.setDataFilter(key, undefined);
|
|
354
|
+
}, { immediate: true, flush: 'post' });
|
|
355
|
+
const handleQueryChange = (next) => {
|
|
356
|
+
query.value = next;
|
|
357
|
+
if (props.dataKey)
|
|
358
|
+
store.value.setDataFilter(props.dataKey, next.trim() || undefined);
|
|
359
|
+
};
|
|
360
|
+
const handleChange = (value) => {
|
|
361
|
+
props.selectProps.onChange(value);
|
|
362
|
+
handleQueryChange('');
|
|
363
|
+
};
|
|
364
|
+
return () => {
|
|
365
|
+
const shared = {
|
|
366
|
+
...props.selectProps,
|
|
367
|
+
onChange: handleChange,
|
|
368
|
+
query: query.value,
|
|
369
|
+
onQueryChange: handleQueryChange,
|
|
370
|
+
};
|
|
371
|
+
const dataKey = props.dataKey;
|
|
372
|
+
if (!dataKey) {
|
|
373
|
+
return h(props.combobox, {
|
|
374
|
+
...shared,
|
|
375
|
+
options: query.value
|
|
376
|
+
? props.staticOptions.filter((o) => matchesQuery(o, query.value))
|
|
377
|
+
: props.staticOptions,
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
const state = dataState.value;
|
|
381
|
+
return h(props.combobox, {
|
|
382
|
+
...shared,
|
|
383
|
+
options: (state?.rows ?? []),
|
|
384
|
+
loading: !state || state.status === 'loading' || state.status === 'idle',
|
|
385
|
+
error: state?.status === 'error' ? (state.error ?? 'Failed to load options') : undefined,
|
|
386
|
+
onRetry: () => store.value.retryData(dataKey),
|
|
387
|
+
});
|
|
388
|
+
};
|
|
389
|
+
},
|
|
390
|
+
});
|
|
166
391
|
// ─── FormRenderer ────────────────────────────────────────────────────────────
|
|
167
392
|
export const FormRenderer = defineComponent({
|
|
168
393
|
name: 'FormRenderer',
|
|
@@ -173,6 +398,7 @@ export const FormRenderer = defineComponent({
|
|
|
173
398
|
// the sub-elements without remounting the form.
|
|
174
399
|
const Input = useElementOverride('form', 'input');
|
|
175
400
|
const Select = useElementOverride('form', 'select');
|
|
401
|
+
const Combobox = useElementOverride('form', 'combobox');
|
|
176
402
|
const Checkbox = useElementOverride('form', 'checkbox');
|
|
177
403
|
const Textarea = useElementOverride('form', 'textarea');
|
|
178
404
|
const FileInput = useElementOverride('form', 'file');
|
|
@@ -213,15 +439,42 @@ export const FormRenderer = defineComponent({
|
|
|
213
439
|
};
|
|
214
440
|
let control;
|
|
215
441
|
if (field.type === 'select') {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
:
|
|
224
|
-
|
|
442
|
+
const dataKey = `${component.id}.${field.name}`;
|
|
443
|
+
const isDataDriven = isDataDrivenOptions(field.options, dataKey, (key) => ctx.value.store.getDataState(key));
|
|
444
|
+
if (field.searchable) {
|
|
445
|
+
control = h(SearchableSelect, {
|
|
446
|
+
combobox: Combobox.value ?? DefaultCombobox,
|
|
447
|
+
dataKey: isDataDriven ? dataKey : undefined,
|
|
448
|
+
staticOptions: inlineOptions(field.options, ctx.value.dataSources),
|
|
449
|
+
selectProps: {
|
|
450
|
+
...shared,
|
|
451
|
+
type: 'select',
|
|
452
|
+
value: fieldValue,
|
|
453
|
+
onChange: handleChange,
|
|
454
|
+
},
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
else if (isDataDriven) {
|
|
458
|
+
control = h(DataDrivenSelect, {
|
|
459
|
+
dataKey,
|
|
460
|
+
select: Select.value ?? DefaultSelect,
|
|
461
|
+
selectProps: {
|
|
462
|
+
...shared,
|
|
463
|
+
type: 'select',
|
|
464
|
+
value: fieldValue,
|
|
465
|
+
onChange: handleChange,
|
|
466
|
+
},
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
else {
|
|
470
|
+
control = h(Select.value ?? DefaultSelect, {
|
|
471
|
+
...shared,
|
|
472
|
+
type: 'select',
|
|
473
|
+
value: fieldValue,
|
|
474
|
+
onChange: handleChange,
|
|
475
|
+
options: inlineOptions(field.options, ctx.value.dataSources),
|
|
476
|
+
});
|
|
477
|
+
}
|
|
225
478
|
}
|
|
226
479
|
else if (field.type === 'checkbox') {
|
|
227
480
|
control = h(Checkbox.value ?? DefaultCheckbox, {
|