@cocoar/vue-ui 3.4.0-beta.34 → 3.4.0-beta.38
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/dist/components/date-time/plain-date-picker/CoarPlainDatePicker.vue.d.ts +11 -1
- package/dist/components/date-time/plain-date-picker/CoarPlainDatePicker.vue.d.ts.map +1 -1
- package/dist/components/date-time/plain-date-time-picker/CoarPlainDateTimePicker.vue.d.ts +11 -1
- package/dist/components/date-time/plain-date-time-picker/CoarPlainDateTimePicker.vue.d.ts.map +1 -1
- package/dist/components/date-time/zoned-date-time-picker/CoarZonedDateTimePicker.vue.d.ts +11 -1
- package/dist/components/date-time/zoned-date-time-picker/CoarZonedDateTimePicker.vue.d.ts.map +1 -1
- package/dist/components/form-field/constants.d.ts +6 -0
- package/dist/components/form-field/constants.d.ts.map +1 -1
- package/dist/components/icon/core-icons.d.ts +2 -0
- package/dist/components/icon/core-icons.d.ts.map +1 -1
- package/dist/components/input-frame/CoarInputFrame.vue.d.ts +10 -0
- package/dist/components/input-frame/CoarInputFrame.vue.d.ts.map +1 -1
- package/dist/components/number-input/CoarNumberInput.vue.d.ts +8 -0
- package/dist/components/number-input/CoarNumberInput.vue.d.ts.map +1 -1
- package/dist/components/select/CoarSelect.vue.d.ts +13 -2
- package/dist/components/select/CoarSelect.vue.d.ts.map +1 -1
- package/dist/components/select/CoarSelectDropdownPanel.vue.d.ts +7 -4
- package/dist/components/select/CoarSelectDropdownPanel.vue.d.ts.map +1 -1
- package/dist/components/select/index.d.ts +1 -1
- package/dist/components/select/index.d.ts.map +1 -1
- package/dist/components/select/types.d.ts +13 -0
- package/dist/components/select/types.d.ts.map +1 -1
- package/dist/components/text-input/CoarTextInput.vue.d.ts +8 -1
- package/dist/components/text-input/CoarTextInput.vue.d.ts.map +1 -1
- package/dist/index.css +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3388 -3299
- package/package.json +3 -3
- package/skills/cocoar-vue-ui/SKILL.md +5 -1
- package/skills/cocoar-vue-ui/references/components/calendar/board.md +205 -0
- package/skills/cocoar-vue-ui/references/components/calendar/coar-calendar.md +32 -1
- package/skills/cocoar-vue-ui/references/components/calendar/day-view.md +21 -0
- package/skills/cocoar-vue-ui/references/components/calendar/mini-month.md +49 -0
- package/skills/cocoar-vue-ui/references/components/calendar/month-view.md +45 -0
- package/skills/cocoar-vue-ui/references/components/number-input.md +51 -0
- package/skills/cocoar-vue-ui/references/components/object-editor.md +406 -0
- package/skills/cocoar-vue-ui/references/components/select.md +92 -0
- package/skills/cocoar-vue-ui/references/components/text-input.md +53 -0
- package/skills/cocoar-vue-ui/references/guide/mobile.md +4 -1
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
<!-- Generated from apps/docs/components/object-editor.md by apps/docs/scripts/sync-skill.mjs. Do not edit; edit the docs page. -->
|
|
2
|
+
|
|
3
|
+
# Object Editor (Preview)
|
|
4
|
+
|
|
5
|
+
**Devices:** desktop ready · tablet partial · phone planned — Built for pointer and keyboard. On tablets the rows work but are dense; a phone layout is planned.
|
|
6
|
+
|
|
7
|
+
`@cocoar/vue-object-editor` edits JSON objects through a **JSON Schema** (Draft 2020-12). The schema says what a
|
|
8
|
+
value means — a string can be a date, an email address or a colour — and the editor shows each value with a fitting
|
|
9
|
+
inline control. Users never see JSON; the app gets plain JSON back.
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
pnpm add @cocoar/vue-object-editor
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { CoarObjectEditor } from '@cocoar/vue-object-editor';
|
|
17
|
+
import '@cocoar/vue-object-editor/styles';
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Basic usage
|
|
21
|
+
|
|
22
|
+
Bind the object with `v-model` and pass its schema. `mode="view"` shows the formatted values; `mode="edit"` shows
|
|
23
|
+
the controls. Both use the same rows, so switching moves nothing.
|
|
24
|
+
|
|
25
|
+
**Demo — `object-editor/demos/ObjectEditorProduct.vue`**
|
|
26
|
+
|
|
27
|
+
```vue
|
|
28
|
+
<template>
|
|
29
|
+
<div class="demo">
|
|
30
|
+
<CoarSegmentedControl v-model="mode" :options="modes" aria-label="Mode" />
|
|
31
|
+
<CoarObjectEditor v-model="product" :schema="productSchema" :mode="mode" locale="en-US" />
|
|
32
|
+
<details>
|
|
33
|
+
<summary>JSON</summary>
|
|
34
|
+
<pre>{{ JSON.stringify(product, null, 2) }}</pre>
|
|
35
|
+
</details>
|
|
36
|
+
</div>
|
|
37
|
+
</template>
|
|
38
|
+
|
|
39
|
+
<script setup lang="ts">
|
|
40
|
+
import { ref } from 'vue';
|
|
41
|
+
import { CoarSegmentedControl } from '@cocoar/vue-ui';
|
|
42
|
+
import { CoarObjectEditor } from '@cocoar/vue-object-editor';
|
|
43
|
+
import '@cocoar/vue-object-editor/styles';
|
|
44
|
+
import { createProduct, productSchema } from './product-schema';
|
|
45
|
+
|
|
46
|
+
const product = ref(createProduct());
|
|
47
|
+
const mode = ref<'view' | 'edit'>('edit');
|
|
48
|
+
const modes = [
|
|
49
|
+
{ value: 'view', label: 'View' },
|
|
50
|
+
{ value: 'edit', label: 'Edit' },
|
|
51
|
+
];
|
|
52
|
+
</script>
|
|
53
|
+
|
|
54
|
+
<style scoped>
|
|
55
|
+
.demo {
|
|
56
|
+
display: flex;
|
|
57
|
+
flex-direction: column;
|
|
58
|
+
gap: 12px;
|
|
59
|
+
width: 100%;
|
|
60
|
+
}
|
|
61
|
+
pre {
|
|
62
|
+
font-size: 12px;
|
|
63
|
+
}
|
|
64
|
+
</style>
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
What the editor does with the data:
|
|
68
|
+
|
|
69
|
+
- **A cleared value removes its key.** "Required" means the key is there and not empty.
|
|
70
|
+
- **Problems appear in their row**, found by the schema (`minimum`, `format`, `required` …) and by the checks
|
|
71
|
+
of the value types.
|
|
72
|
+
- **Values the schema does not know stay in the data**, shown read-only as "not in the schema".
|
|
73
|
+
- **Lists of objects** are shown read-only with their number of entries and kept unchanged.
|
|
74
|
+
|
|
75
|
+
## The schema
|
|
76
|
+
|
|
77
|
+
The schema is standard JSON Schema; anything that validates JSON Schema can check the data too. A few
|
|
78
|
+
`x-coar-*` keywords add what JSON Schema has no word for:
|
|
79
|
+
|
|
80
|
+
| Keyword | Where | Meaning |
|
|
81
|
+
|---------|-------|---------|
|
|
82
|
+
| `x-coar-type` | property | Id of the value type. Without it the type is recognized from the schema (`format: "date"` → date) |
|
|
83
|
+
| `x-coar-order` | object | Order of its properties. Key order alone does not survive every database |
|
|
84
|
+
| `x-coar-unit` | number | Unit after the value, such as `cm` |
|
|
85
|
+
| `x-coar-decimals` | number | Decimal places; 0 for `integer`, 2 for `number` without it |
|
|
86
|
+
| `x-coar-options` | choice | Name of an option source the app passes in `optionSources` |
|
|
87
|
+
| `x-coar-suggestions` | tags | Suggested tags |
|
|
88
|
+
|
|
89
|
+
A **choice** is `oneOf` of `{ const, title }`; several choices are an `array` with `uniqueItems` and
|
|
90
|
+
`items.anyOf` of `{ const, title }`. A plain `enum` is read too.
|
|
91
|
+
|
|
92
|
+
```json
|
|
93
|
+
{
|
|
94
|
+
"category": {
|
|
95
|
+
"title": "Category",
|
|
96
|
+
"oneOf": [
|
|
97
|
+
{ "const": "lighting", "title": "Lighting" },
|
|
98
|
+
{ "const": "furniture", "title": "Furniture" }
|
|
99
|
+
]
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Built-in value types
|
|
105
|
+
|
|
106
|
+
| Id | Data | Control |
|
|
107
|
+
|----|------|---------|
|
|
108
|
+
| `text` | `string` | Inline text input |
|
|
109
|
+
| `multiline` | `string` | One-line preview, a text area once clicked |
|
|
110
|
+
| `number` | `number` / `integer` | Inline number input with unit |
|
|
111
|
+
| `boolean` | `boolean` | Switch |
|
|
112
|
+
| `date` | `string`, `format: "date"` | Inline date picker |
|
|
113
|
+
| `email` | `string`, `format: "email"` | Inline text input |
|
|
114
|
+
| `color` | `string`, `pattern` `#RRGGBB` | Inline text input with a swatch |
|
|
115
|
+
| `choice` | `oneOf` of constants | Inline select |
|
|
116
|
+
| `choices` | `array` of constants | Tag select |
|
|
117
|
+
| `tags` | `array` of `string` | Tag select that creates tags |
|
|
118
|
+
| `object` | `object` | The rows of its properties, collapsible |
|
|
119
|
+
|
|
120
|
+
## Types of the app and option sources
|
|
121
|
+
|
|
122
|
+
An app adds its own value types with `defineObjectEditorTypes()`. A type names the schema of its data and,
|
|
123
|
+
optionally, a control and a check. In the schema it is a `$ref` into `$defs`, so the schema stays valid on its
|
|
124
|
+
own. Without a control, a type whose data is an object is edited as nested rows.
|
|
125
|
+
|
|
126
|
+
Options that come from the app, such as people from an API, are named in the schema with `x-coar-options`; the
|
|
127
|
+
app passes the list, or a function that returns one, in `optionSources`.
|
|
128
|
+
|
|
129
|
+
**Demo — `object-editor/demos/ObjectEditorCustomType.vue`**
|
|
130
|
+
|
|
131
|
+
```vue
|
|
132
|
+
<template>
|
|
133
|
+
<div class="demo">
|
|
134
|
+
<CoarObjectEditor
|
|
135
|
+
v-model="offer"
|
|
136
|
+
:schema="schema"
|
|
137
|
+
:types="types"
|
|
138
|
+
:option-sources="{ people }"
|
|
139
|
+
locale="en-US"
|
|
140
|
+
/>
|
|
141
|
+
<pre>{{ JSON.stringify(offer, null, 2) }}</pre>
|
|
142
|
+
</div>
|
|
143
|
+
</template>
|
|
144
|
+
|
|
145
|
+
<script setup lang="ts">
|
|
146
|
+
import { markRaw, ref } from 'vue';
|
|
147
|
+
import {
|
|
148
|
+
CoarObjectEditor,
|
|
149
|
+
defineObjectEditorTypes,
|
|
150
|
+
type CoarValueType,
|
|
151
|
+
type JsonObject,
|
|
152
|
+
type JsonSchema,
|
|
153
|
+
} from '@cocoar/vue-object-editor';
|
|
154
|
+
import '@cocoar/vue-object-editor/styles';
|
|
155
|
+
import MoneyControl from './MoneyControl.vue';
|
|
156
|
+
import type { Money } from './money';
|
|
157
|
+
|
|
158
|
+
// A type of the app: its data is an object, its control one field with the currency in the suffix.
|
|
159
|
+
const money: CoarValueType<Money> = {
|
|
160
|
+
id: 'money',
|
|
161
|
+
label: 'Amount of money',
|
|
162
|
+
icon: 'hash',
|
|
163
|
+
hue: 165,
|
|
164
|
+
schema: {
|
|
165
|
+
type: 'object',
|
|
166
|
+
required: ['amount', 'currency'],
|
|
167
|
+
properties: { amount: { type: 'number' }, currency: { enum: ['EUR', 'USD', 'CHF'] } },
|
|
168
|
+
},
|
|
169
|
+
control: markRaw(MoneyControl),
|
|
170
|
+
format: (value, { locale }) =>
|
|
171
|
+
value.amount === undefined
|
|
172
|
+
? '–'
|
|
173
|
+
: new Intl.NumberFormat(locale, { style: 'currency', currency: value.currency ?? 'EUR' }).format(value.amount),
|
|
174
|
+
validate: (value) => (value.amount !== undefined && !value.currency ? 'Choose a currency.' : null),
|
|
175
|
+
};
|
|
176
|
+
const types = defineObjectEditorTypes([money]);
|
|
177
|
+
|
|
178
|
+
// The schema names the source; the app gives its options, here after a short delay.
|
|
179
|
+
const people = () =>
|
|
180
|
+
new Promise<{ value: string; label: string; description: string }[]>((resolve) =>
|
|
181
|
+
setTimeout(
|
|
182
|
+
() =>
|
|
183
|
+
resolve([
|
|
184
|
+
{ value: 'u1', label: 'Anna Berger', description: 'Product management' },
|
|
185
|
+
{ value: 'u2', label: 'Lukas Huber', description: 'Design' },
|
|
186
|
+
{ value: 'u3', label: 'Sophie Wagner', description: 'Purchasing' },
|
|
187
|
+
]),
|
|
188
|
+
300,
|
|
189
|
+
),
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
const schema: JsonSchema = {
|
|
193
|
+
type: 'object',
|
|
194
|
+
required: ['price'],
|
|
195
|
+
properties: {
|
|
196
|
+
price: { $ref: '#/$defs/money', title: 'Price', 'x-coar-type': 'money' },
|
|
197
|
+
owner: { type: 'string', title: 'Owner', 'x-coar-type': 'choice', 'x-coar-options': 'people' },
|
|
198
|
+
},
|
|
199
|
+
$defs: { money: money.schema },
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
const offer = ref<JsonObject | undefined>({ price: { amount: 129.9, currency: 'EUR' }, owner: 'u2' });
|
|
203
|
+
</script>
|
|
204
|
+
|
|
205
|
+
<style scoped>
|
|
206
|
+
.demo {
|
|
207
|
+
display: flex;
|
|
208
|
+
flex-direction: column;
|
|
209
|
+
gap: 12px;
|
|
210
|
+
width: 100%;
|
|
211
|
+
}
|
|
212
|
+
pre {
|
|
213
|
+
font-size: 12px;
|
|
214
|
+
}
|
|
215
|
+
</style>
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
```ts
|
|
219
|
+
const money: CoarValueType<Money> = {
|
|
220
|
+
id: 'money', // x-coar-type and key in $defs
|
|
221
|
+
label: 'Amount of money', // name in the type list of the schema editor
|
|
222
|
+
icon: 'hash',
|
|
223
|
+
schema: { type: 'object', properties: { amount: { type: 'number' }, currency: { enum: ['EUR', 'USD'] } } },
|
|
224
|
+
control: markRaw(MoneyControl), // receives CoarValueControlProps, emits update:modelValue
|
|
225
|
+
format: (value, { locale }) => new Intl.NumberFormat(locale, { style: 'currency', currency: value.currency }).format(value.amount),
|
|
226
|
+
validate: (value) => (value.currency ? null : 'Choose a currency.'),
|
|
227
|
+
};
|
|
228
|
+
const types = defineObjectEditorTypes([money]);
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
A control receives `modelValue`, the resolved `schema`, `id`, `label`, `readonly`, `error`, `options` and
|
|
232
|
+
`locale`, and emits `update:modelValue`; `undefined` clears the value.
|
|
233
|
+
|
|
234
|
+
## Schema editor
|
|
235
|
+
|
|
236
|
+
`CoarSchemaEditor` describes the object: add properties, choose their type, mark them required, set limits, units
|
|
237
|
+
and the allowed values of a choice. Groups hold properties of their own. It writes the same JSON Schema the object
|
|
238
|
+
editor reads, so both can work on one schema side by side. Types of the app appear in its type list; their schema
|
|
239
|
+
goes to `$defs` once a property uses them, and leaves again with the last one.
|
|
240
|
+
|
|
241
|
+
**Demo — `object-editor/demos/SchemaAndObjectEditor.vue`**
|
|
242
|
+
|
|
243
|
+
```vue
|
|
244
|
+
<template>
|
|
245
|
+
<div class="demo">
|
|
246
|
+
<CoarTabGroup v-model="tab">
|
|
247
|
+
<CoarTab id="schema">
|
|
248
|
+
Schema
|
|
249
|
+
<template #content>
|
|
250
|
+
<CoarSchemaEditor v-model="schema" :types="types" class="pane" />
|
|
251
|
+
</template>
|
|
252
|
+
</CoarTab>
|
|
253
|
+
<CoarTab id="data">
|
|
254
|
+
Data
|
|
255
|
+
<template #content>
|
|
256
|
+
<CoarObjectEditor v-model="data" :schema="schema" :types="types" locale="en-US" class="pane" />
|
|
257
|
+
</template>
|
|
258
|
+
</CoarTab>
|
|
259
|
+
<CoarTab id="json">
|
|
260
|
+
JSON
|
|
261
|
+
<template #content>
|
|
262
|
+
<div class="json">
|
|
263
|
+
<pre>{{ JSON.stringify(schema, null, 2) }}</pre>
|
|
264
|
+
<pre>{{ JSON.stringify(data, null, 2) }}</pre>
|
|
265
|
+
</div>
|
|
266
|
+
</template>
|
|
267
|
+
</CoarTab>
|
|
268
|
+
</CoarTabGroup>
|
|
269
|
+
</div>
|
|
270
|
+
</template>
|
|
271
|
+
|
|
272
|
+
<script setup lang="ts">
|
|
273
|
+
import { markRaw, ref, shallowRef } from 'vue';
|
|
274
|
+
import { CoarTab, CoarTabGroup } from '@cocoar/vue-ui';
|
|
275
|
+
import {
|
|
276
|
+
CoarObjectEditor,
|
|
277
|
+
CoarSchemaEditor,
|
|
278
|
+
createObjectSchema,
|
|
279
|
+
defineObjectEditorTypes,
|
|
280
|
+
type CoarValueType,
|
|
281
|
+
type JsonObject,
|
|
282
|
+
type JsonSchema,
|
|
283
|
+
} from '@cocoar/vue-object-editor';
|
|
284
|
+
import '@cocoar/vue-object-editor/styles';
|
|
285
|
+
import MoneyControl from './MoneyControl.vue';
|
|
286
|
+
import type { Money } from './money';
|
|
287
|
+
|
|
288
|
+
// The type of the app appears in the type list of the schema editor next to the built-in ones.
|
|
289
|
+
const money: CoarValueType<Money> = {
|
|
290
|
+
id: 'money',
|
|
291
|
+
label: 'Amount of money',
|
|
292
|
+
icon: 'hash',
|
|
293
|
+
hue: 165,
|
|
294
|
+
schema: {
|
|
295
|
+
type: 'object',
|
|
296
|
+
required: ['amount', 'currency'],
|
|
297
|
+
properties: { amount: { type: 'number' }, currency: { enum: ['EUR', 'USD', 'CHF'] } },
|
|
298
|
+
},
|
|
299
|
+
control: markRaw(MoneyControl),
|
|
300
|
+
};
|
|
301
|
+
const types = defineObjectEditorTypes([money]);
|
|
302
|
+
|
|
303
|
+
const tab = ref('schema');
|
|
304
|
+
const schema = shallowRef<JsonSchema>({
|
|
305
|
+
...createObjectSchema(),
|
|
306
|
+
required: ['title'],
|
|
307
|
+
'x-coar-order': ['title', 'budget', 'start'],
|
|
308
|
+
properties: {
|
|
309
|
+
title: { type: 'string', title: 'Title', 'x-coar-type': 'text' },
|
|
310
|
+
budget: { $ref: '#/$defs/money', title: 'Budget', 'x-coar-type': 'money' },
|
|
311
|
+
start: { type: 'string', format: 'date', title: 'Start', 'x-coar-type': 'date' },
|
|
312
|
+
},
|
|
313
|
+
$defs: { money: money.schema },
|
|
314
|
+
});
|
|
315
|
+
const data = shallowRef<JsonObject | undefined>({ title: 'Spring campaign' });
|
|
316
|
+
</script>
|
|
317
|
+
|
|
318
|
+
<style scoped>
|
|
319
|
+
.demo {
|
|
320
|
+
width: 100%;
|
|
321
|
+
}
|
|
322
|
+
.pane {
|
|
323
|
+
padding-top: 12px;
|
|
324
|
+
}
|
|
325
|
+
.json {
|
|
326
|
+
display: grid;
|
|
327
|
+
grid-template-columns: 1fr 1fr;
|
|
328
|
+
gap: 12px;
|
|
329
|
+
}
|
|
330
|
+
pre {
|
|
331
|
+
font-size: 12px;
|
|
332
|
+
overflow: auto;
|
|
333
|
+
max-height: 420px;
|
|
334
|
+
}
|
|
335
|
+
</style>
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
```vue
|
|
339
|
+
<CoarSchemaEditor v-model="schema" :types="types" />
|
|
340
|
+
<CoarObjectEditor v-model="data" :schema="schema" :types="types" />
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
Every change emits a new schema object; the one passed in is never changed. Keys are letters, digits, `_` and
|
|
344
|
+
`-`, starting with a letter; renaming a property keeps its place and whether it is required. Problems the JSON
|
|
345
|
+
Schema itself cannot express — a minimum above the maximum, a choice without values, a value twice — are marked in
|
|
346
|
+
the list and explained in the inspector; `checkSchema(schema)` returns them for code.
|
|
347
|
+
|
|
348
|
+
The same operations exist as functions: `addProperty`, `removeProperty`, `renameProperty`, `moveProperty`,
|
|
349
|
+
`changePropertyType`, `updateProperty`, `setRequired` and `setOptions` take a schema and a path of keys
|
|
350
|
+
(`['dimensions', 'width']`) and return the new schema.
|
|
351
|
+
|
|
352
|
+
## API
|
|
353
|
+
|
|
354
|
+
### CoarObjectEditor props
|
|
355
|
+
|
|
356
|
+
| Prop | Type | Default | Description |
|
|
357
|
+
|------|------|---------|-------------|
|
|
358
|
+
| `v-model` | `JsonObject \| undefined` | — | The object |
|
|
359
|
+
| `schema` | `JsonSchema` | — | Its JSON Schema |
|
|
360
|
+
| `types` | `CoarObjectEditorTypes` | built-in types | From `defineObjectEditorTypes()` |
|
|
361
|
+
| `optionSources` | `Record<string, Option[] \| () => Option[] \| Promise<Option[]>>` | `{}` | Options named by `x-coar-options` |
|
|
362
|
+
| `mode` | `'view' \| 'edit'` | `'edit'` | Formatted values or controls |
|
|
363
|
+
| `locale` | `string` | browser | Locale of numbers and dates |
|
|
364
|
+
|
|
365
|
+
The component exposes `issues`: every problem of the value, as `{ pointer, keyword, message? }`.
|
|
366
|
+
|
|
367
|
+
### CoarSchemaEditor props
|
|
368
|
+
|
|
369
|
+
| Prop | Type | Default | Description |
|
|
370
|
+
|------|------|---------|-------------|
|
|
371
|
+
| `v-model` | `JsonSchema` | — | The schema; each change emits a new object |
|
|
372
|
+
| `types` | `CoarObjectEditorTypes` | built-in types | The types to choose from |
|
|
373
|
+
|
|
374
|
+
### Functions
|
|
375
|
+
|
|
376
|
+
| Function | Description |
|
|
377
|
+
|----------|-------------|
|
|
378
|
+
| `defineObjectEditorTypes(types?)` | The built-in types plus the given ones |
|
|
379
|
+
| `validateValue(schema, value)` | The problems of a value, each at its JSON Pointer |
|
|
380
|
+
| `createObjectSchema()` | An empty object schema |
|
|
381
|
+
| `checkSchema(schema)` | Bad keys, ranges and option lists, each at its path |
|
|
382
|
+
| `getAt`, `setAt`, `parsePointer`, `formatPointer` | Read and write values by JSON Pointer, without changing the original |
|
|
383
|
+
|
|
384
|
+
Validation uses [`@cfworker/json-schema`](https://github.com/cfworker/cfworker/tree/main/packages/json-schema): it
|
|
385
|
+
interprets the schema and never generates code, so a Content Security Policy without `'unsafe-eval'` works.
|
|
386
|
+
|
|
387
|
+
## i18n Keys
|
|
388
|
+
|
|
389
|
+
| Key | Default |
|
|
390
|
+
|-----|---------|
|
|
391
|
+
| `coar.objectEditor.required` | `Required.` |
|
|
392
|
+
| `coar.objectEditor.minimum` / `maximum` | `At least {min}.` / `At most {max}.` |
|
|
393
|
+
| `coar.objectEditor.minLength` / `maxLength` | `At least {min} characters.` / `At most {max} characters.` |
|
|
394
|
+
| `coar.objectEditor.formatDate` / `formatEmail` / `format` | `Not a valid date.` / `Not a valid email address.` / `Wrong format.` |
|
|
395
|
+
| `coar.objectEditor.type` | `Wrong kind of value.` |
|
|
396
|
+
| `coar.objectEditor.notAllowed` | `Not one of the allowed values.` |
|
|
397
|
+
| `coar.objectEditor.unique` | `Each value may appear only once.` |
|
|
398
|
+
| `coar.objectEditor.additional` | `Contains values the schema does not allow.` |
|
|
399
|
+
| `coar.objectEditor.invalid` | `Invalid value.` |
|
|
400
|
+
| `coar.objectEditor.notInSchema` | `not in the schema` |
|
|
401
|
+
| `coar.objectEditor.noProperties` | `The schema has no properties yet.` |
|
|
402
|
+
| `coar.objectEditor.yes` / `no` | `Yes` / `No` |
|
|
403
|
+
| `coar.objectEditor.filled` | `{count} filled` |
|
|
404
|
+
| `coar.objectEditor.entry` / `entries` | `1 entry` / `{count} entries` |
|
|
405
|
+
| `coar.objectEditor.type.<id>` | The `label` of the type |
|
|
406
|
+
| `coar.schemaEditor.*` | Labels of the schema editor (`key`, `title`, `type`, `required`, `addProperty` …) and its problems (`invalidKey`, `keyTaken`, `rangeOrder`, `noOptions`, `emptyOption`, `duplicateOption`) |
|
|
@@ -469,6 +469,86 @@ const methods = [
|
|
|
469
469
|
</script>
|
|
470
470
|
```
|
|
471
471
|
|
|
472
|
+
## Templates (Preview) {#templates}
|
|
473
|
+
|
|
474
|
+
`CoarSelect` can draw the selected value and the options with your own content, such as an avatar or a second
|
|
475
|
+
line. `#value` draws the closed select, also when nothing is selected; `#option` draws each option in the list.
|
|
476
|
+
Without a slot, the select shows the icon and label as before; each slot works without the other.
|
|
477
|
+
|
|
478
|
+
**Demo — `select/demos/SelectTemplates.vue`**
|
|
479
|
+
|
|
480
|
+
```vue
|
|
481
|
+
<template>
|
|
482
|
+
<CoarFormField label="Owner">
|
|
483
|
+
<CoarSelect
|
|
484
|
+
v-model="owner"
|
|
485
|
+
:options="options"
|
|
486
|
+
:compare-with="samePerson"
|
|
487
|
+
placeholder="Choose a person"
|
|
488
|
+
searchable
|
|
489
|
+
clearable
|
|
490
|
+
>
|
|
491
|
+
<template #value="{ option, placeholder }">
|
|
492
|
+
<span v-if="option" class="person">
|
|
493
|
+
<CoarAvatar :name="option.label" size="xs" :max-length="2" aria-hidden="true" />
|
|
494
|
+
<span>{{ option.label }}</span>
|
|
495
|
+
</span>
|
|
496
|
+
<span v-else>{{ placeholder }}</span>
|
|
497
|
+
</template>
|
|
498
|
+
<template #option="{ option }">
|
|
499
|
+
<span class="person">
|
|
500
|
+
<CoarAvatar :name="option.label" size="xs" :max-length="2" aria-hidden="true" />
|
|
501
|
+
<span class="person-copy">
|
|
502
|
+
<span>{{ option.label }}</span>
|
|
503
|
+
<small>{{ option.value.role }}</small>
|
|
504
|
+
</span>
|
|
505
|
+
</span>
|
|
506
|
+
</template>
|
|
507
|
+
</CoarSelect>
|
|
508
|
+
</CoarFormField>
|
|
509
|
+
</template>
|
|
510
|
+
|
|
511
|
+
<script setup lang="ts">
|
|
512
|
+
import { ref } from 'vue';
|
|
513
|
+
import { CoarAvatar, CoarFormField, CoarSelect, type CoarSelectOption } from '@cocoar/vue-ui';
|
|
514
|
+
|
|
515
|
+
interface Person {
|
|
516
|
+
id: string;
|
|
517
|
+
role: string;
|
|
518
|
+
}
|
|
519
|
+
const options: CoarSelectOption<Person>[] = [
|
|
520
|
+
{ value: { id: 'anna', role: 'Product management' }, label: 'Anna Berger' },
|
|
521
|
+
{ value: { id: 'lukas', role: 'Design' }, label: 'Lukas Huber' },
|
|
522
|
+
{ value: { id: 'sophie', role: 'Purchasing' }, label: 'Sophie Wagner' },
|
|
523
|
+
];
|
|
524
|
+
const owner = ref<Person | null>(options[1].value);
|
|
525
|
+
const samePerson = (a: Person, b: Person) => a.id === b.id;
|
|
526
|
+
</script>
|
|
527
|
+
|
|
528
|
+
<style scoped>
|
|
529
|
+
.person {
|
|
530
|
+
display: inline-flex;
|
|
531
|
+
align-items: center;
|
|
532
|
+
gap: 8px;
|
|
533
|
+
min-width: 0;
|
|
534
|
+
}
|
|
535
|
+
.person-copy {
|
|
536
|
+
display: flex;
|
|
537
|
+
flex-direction: column;
|
|
538
|
+
min-width: 0;
|
|
539
|
+
}
|
|
540
|
+
.person-copy small {
|
|
541
|
+
font-size: 12px;
|
|
542
|
+
color: var(--coar-text-neutral-tertiary);
|
|
543
|
+
}
|
|
544
|
+
</style>
|
|
545
|
+
```
|
|
546
|
+
|
|
547
|
+
The select keeps selection, keyboard navigation, focus, disabled options and the checkmark, so keep slot content
|
|
548
|
+
non-interactive: no buttons, links, inputs or closable tags. Every option still needs its `label`: search, sorting,
|
|
549
|
+
the option's accessible name and the overflow tooltip use it. With `width="content"` and `searchable`, the
|
|
550
|
+
`#value` content also keeps the width of the box while you search.
|
|
551
|
+
|
|
472
552
|
## API
|
|
473
553
|
|
|
474
554
|
### Props
|
|
@@ -491,6 +571,18 @@ const methods = [
|
|
|
491
571
|
| `sortGroups` | `'asc' \| 'desc' \| 'none' \| (a, b) => number` | `'asc'` | Sort order for groups |
|
|
492
572
|
| `sortOptions` | `'asc' \| 'desc' \| 'none' \| (a, b) => number` | `'none'` | Sort order for options (within each group, or all if ungrouped) |
|
|
493
573
|
|
|
574
|
+
### Slots (Preview)
|
|
575
|
+
|
|
576
|
+
`CoarSelect` only, see [Templates](#templates).
|
|
577
|
+
|
|
578
|
+
| Slot | Scope | Without the slot |
|
|
579
|
+
|------|-------|------------------|
|
|
580
|
+
| `value` | `{ option: CoarSelectOption<T> \| null, value: T \| null, placeholder: string }` | Icon and label of the selected option, or the placeholder |
|
|
581
|
+
| `option` | `{ option: CoarSelectOption<T>, selected: boolean, highlighted: boolean, index: number }` | Icon and label of the option; the checkmark is always the select's own |
|
|
582
|
+
|
|
583
|
+
The scope types are exported as `CoarSelectValueSlotProps<T>` and `CoarSelectOptionSlotProps<T>`. `index` is the
|
|
584
|
+
position in the filtered, sorted list.
|
|
585
|
+
|
|
494
586
|
## i18n Keys
|
|
495
587
|
|
|
496
588
|
These keys can be translated via [`@cocoar/vue-localization`](../foundations/localization/translations.md).
|
|
@@ -119,6 +119,50 @@ const price = ref('');
|
|
|
119
119
|
</script>
|
|
120
120
|
```
|
|
121
121
|
|
|
122
|
+
## Prefix & Suffix Actions (Preview) {#actions}
|
|
123
|
+
|
|
124
|
+
`#prefixAction` and `#suffixAction` hold interactive content at the outer edges of the field, such as an inline
|
|
125
|
+
select for the protocol of a web address. Unlike `#prefix` and `#suffix`, which show muted text, an action keeps the
|
|
126
|
+
text style of the field. An inline select there runs to the edge: its fill on hover reaches the border and follows
|
|
127
|
+
the field's corner. Both slots get `{ disabled, readonly }` of the field, so the action can follow its state.
|
|
128
|
+
|
|
129
|
+
**Demo — `text-input/demos/TextInputActions.vue`**
|
|
130
|
+
|
|
131
|
+
```vue
|
|
132
|
+
<template>
|
|
133
|
+
<CoarFormField label="Website" style="max-width: 360px;">
|
|
134
|
+
<CoarTextInput v-model="host" placeholder="example.com">
|
|
135
|
+
<template #prefixAction="{ disabled, readonly }">
|
|
136
|
+
<CoarSelect
|
|
137
|
+
v-model="scheme"
|
|
138
|
+
:options="schemes"
|
|
139
|
+
aria-label="Protocol"
|
|
140
|
+
appearance="inline"
|
|
141
|
+
width="content"
|
|
142
|
+
:disabled="disabled"
|
|
143
|
+
:readonly="readonly"
|
|
144
|
+
/>
|
|
145
|
+
</template>
|
|
146
|
+
</CoarTextInput>
|
|
147
|
+
</CoarFormField>
|
|
148
|
+
</template>
|
|
149
|
+
|
|
150
|
+
<script setup lang="ts">
|
|
151
|
+
import { ref } from 'vue';
|
|
152
|
+
import { CoarFormField, CoarSelect, CoarTextInput } from '@cocoar/vue-ui';
|
|
153
|
+
|
|
154
|
+
const host = ref('cocoar.dev');
|
|
155
|
+
const scheme = ref<string | null>('https://');
|
|
156
|
+
const schemes = [
|
|
157
|
+
{ value: 'https://', label: 'https://' },
|
|
158
|
+
{ value: 'http://', label: 'http://' },
|
|
159
|
+
];
|
|
160
|
+
</script>
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
An action is a field of its own: a select in it does not take the label, hint or error of the surrounding
|
|
164
|
+
`CoarFormField`, so give it its own name with `aria-label`.
|
|
165
|
+
|
|
122
166
|
## Clear Button
|
|
123
167
|
|
|
124
168
|
When `clearable` is enabled, a small X button appears on hover or focus so users can quickly reset the field. It's **off by default** — set `clearable` to opt in.
|
|
@@ -381,6 +425,15 @@ needs other values, set the roles on its container:
|
|
|
381
425
|
| `readonly` | `boolean` | `false` | Make read-only |
|
|
382
426
|
| `required` | `boolean` | `false` | HTML required attribute |
|
|
383
427
|
|
|
428
|
+
### Slots
|
|
429
|
+
|
|
430
|
+
| Slot | Scope | Description |
|
|
431
|
+
|------|-------|-------------|
|
|
432
|
+
| `prefix` | — | Muted content before the value, after a prefix action |
|
|
433
|
+
| `suffix` | — | Muted content after the value |
|
|
434
|
+
| `prefixAction` (Preview) | `{ disabled: boolean, readonly: boolean }` | Interactive content at the start edge, see [Actions](#actions) |
|
|
435
|
+
| `suffixAction` | `{ disabled: boolean, readonly: boolean }` | Interactive content at the end edge, see [Actions](#actions) |
|
|
436
|
+
|
|
384
437
|
> **Tip**
|
|
385
438
|
>
|
|
386
439
|
> Label, hint, and error are provided by [`CoarFormField`](./form-field.md). Wrap inputs in a `CoarFormField` to add these features.
|
|
@@ -381,13 +381,14 @@ are only being added, and testing on real devices remains the job of the app.
|
|
|
381
381
|
|---|---|---|---|---|
|
|
382
382
|
| [Drag & Drop](../components/drag-drop.md) | ready | partial | partial | The default engine 'native' uses HTML5 drag events, made for the mouse; on touch use engine 'pointer' or 'auto'. |
|
|
383
383
|
|
|
384
|
-
**Content (@cocoar/vue-markdown, -editor, -form, -mermaid, @cocoar/vue-script-editor)**
|
|
384
|
+
**Content (@cocoar/vue-markdown, -editor, -form, -mermaid, @cocoar/vue-script-editor, @cocoar/vue-object-editor)**
|
|
385
385
|
|
|
386
386
|
| Page | Desktop | Tablet | Phone | Note |
|
|
387
387
|
|---|---|---|---|---|
|
|
388
388
|
| [Markdown](../components/markdown.md) | ready | ready | partial | Wide tables get no horizontal scroll container and can overflow narrow screens. |
|
|
389
389
|
| [Markdown Editor](../components/markdown-editor.md) | ready | partial | partial | Typing and the toolbar work on touch; table row/column grips and the code-block edit button need hover. |
|
|
390
390
|
| [Markdown Form](../components/markdown-form.md) | ready | ready | partial | Works on phones; its select and date fields still open the desktop panels. |
|
|
391
|
+
| [Object Editor](../components/object-editor.md) | ready | partial | planned | Built for pointer and keyboard. On tablets the rows work but are dense; a phone layout is planned. |
|
|
391
392
|
| [Diagrams](../components/markdown-diagrams.md) | ready | partial | partial | With zoomable, touch zooms with the buttons but cannot pan a zoomed diagram. |
|
|
392
393
|
| [Mermaid Diagram](../components/mermaid.md) | ready | partial | partial | With zoomable, touch zooms with the buttons but cannot pan a zoomed diagram. |
|
|
393
394
|
| [Script Editor](../components/script-editor.md) | ready | partial | not supported | Monaco does not support mobile browsers; touch editing has gaps and phones are out of scope. |
|
|
@@ -427,6 +428,8 @@ are only being added, and testing on real devices remains the job of the app.
|
|
|
427
428
|
| [Calendar](../components/calendar/index.md) | ready | partial | planned | Touch taps, paging and long-press selection work; legacy resize targets are 6 px. Compact targets stay smaller on short/crowded events. |
|
|
428
429
|
| [`<CoarCalendar>` — Composer](../components/calendar/coar-calendar.md) | ready | partial | planned | Taps, swipe paging and long-press selection work on touch; event resize handles are only 6 px tall. |
|
|
429
430
|
| [`<CoarYearView>` — Year View](../components/calendar/year-view.md) | ready | ready | planned | Tap to drill in works on touch; a phone presentation of the calendar is planned. |
|
|
431
|
+
| [`<CoarCalendarBoard>` — Board](../components/calendar/board.md) | ready | ready | partial | The grid works on touch; on a phone seven columns are narrow, so a week usually reads better as rows of days. |
|
|
432
|
+
| [`<CoarMiniMonth>` — Mini Month](../components/calendar/mini-month.md) | ready | ready | ready | |
|
|
430
433
|
| [Month Views](../components/calendar/month-view.md) | ready | partial | planned | Taps work on touch; multi-day bar resize handles are only 6 px and a touch on a pill always drags it. |
|
|
431
434
|
| [`<CoarDayView>` — Day View](../components/calendar/day-view.md) | ready | partial | planned | Taps, swipe paging and long-press selection work on touch; event resize handles are only 6 px tall. |
|
|
432
435
|
| [`<CoarWeekView>` — Week View](../components/calendar/week-view.md) | ready | partial | planned | Taps, swipe paging and long-press selection work on touch; event resize handles are only 6 px tall. |
|