@cocoar/vue-ui 3.4.0-beta.40 → 4.0.0-beta.44
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocoar/vue-ui",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-beta.44",
|
|
4
4
|
"description": "Cocoar Design System — a tablet-first Vue 3 component library with 30+ accessible, themeable components",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"skills"
|
|
59
59
|
],
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@cocoar/vue-localization": "
|
|
61
|
+
"@cocoar/vue-localization": "4.0.0-beta.44",
|
|
62
62
|
"@fontsource/cascadia-code": "^5.2.3",
|
|
63
63
|
"@fontsource/inter": "^5.2.8",
|
|
64
64
|
"@fontsource/onest": "^5.3.1",
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"vue": "^3.5.32",
|
|
85
85
|
"vue-router": "^5.0.4"
|
|
86
86
|
},
|
|
87
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "37e83b70b9cca55981246bfc20f9df73cb47e4e1",
|
|
88
88
|
"scripts": {
|
|
89
89
|
"build": "vite build",
|
|
90
90
|
"test": "vitest run",
|
|
@@ -99,6 +99,7 @@ of each other.
|
|
|
99
99
|
- [Migrating to 2.11](references/guide/migration.md) — Migration guide for Cocoar UI 2.11: date/time pickers move onto CoarFormField, the clear button becomes opt-in, and two CSS tokens are renamed.
|
|
100
100
|
- [Migrating Page Builder to 3.0](references/guide/migration-page-builder-3.md) — Migration guide for @cocoar/vue-page-builder 3.0: four PageConfig concepts removed, several names disambiguated, and documents migrated to schemaVersion 6.
|
|
101
101
|
- [Migrating text on saturated fills](references/guide/migration-color-roles.md) — Text on saturated fills now has one computed ink role per base colour, with explicit overrides for custom themes.
|
|
102
|
+
- [Migrating the Object Editor values](references/guide/migration-object-editor-values.md) — Object Editor: values are kept as set. null, empty text, empty lists and empty groups are values; only Remove deletes a key. presence="filled" keeps the form behaviour.
|
|
102
103
|
|
|
103
104
|
### Foundations
|
|
104
105
|
|
|
@@ -20,15 +20,27 @@ import '@cocoar/vue-object-editor/styles';
|
|
|
20
20
|
## Basic usage
|
|
21
21
|
|
|
22
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.
|
|
23
|
+
the controls. Both use the same rows, so switching moves nothing. `striped` puts every second row on a light
|
|
24
|
+
background; a theme can do that for every editor (see [Theming](#theming)).
|
|
24
25
|
|
|
25
26
|
**Demo — `object-editor/demos/ObjectEditorProduct.vue`**
|
|
26
27
|
|
|
27
28
|
```vue
|
|
28
29
|
<template>
|
|
29
30
|
<div class="demo">
|
|
30
|
-
<
|
|
31
|
-
|
|
31
|
+
<div class="toolbar">
|
|
32
|
+
<CoarSegmentedControl v-model="mode" :options="modes" aria-label="Mode" />
|
|
33
|
+
<CoarSwitch v-model="striped" size="s" label="Striped" />
|
|
34
|
+
<CoarTextInput v-model="search" size="s" placeholder="Search properties…" aria-label="Search properties" clearable />
|
|
35
|
+
</div>
|
|
36
|
+
<CoarObjectEditor
|
|
37
|
+
v-model="product"
|
|
38
|
+
v-model:search="search"
|
|
39
|
+
:schema="productSchema"
|
|
40
|
+
:mode="mode"
|
|
41
|
+
:striped="striped"
|
|
42
|
+
locale="en-US"
|
|
43
|
+
/>
|
|
32
44
|
<details>
|
|
33
45
|
<summary>JSON</summary>
|
|
34
46
|
<pre>{{ JSON.stringify(product, null, 2) }}</pre>
|
|
@@ -38,13 +50,15 @@ the controls. Both use the same rows, so switching moves nothing.
|
|
|
38
50
|
|
|
39
51
|
<script setup lang="ts">
|
|
40
52
|
import { ref } from 'vue';
|
|
41
|
-
import { CoarSegmentedControl } from '@cocoar/vue-ui';
|
|
53
|
+
import { CoarSegmentedControl, CoarSwitch, CoarTextInput } from '@cocoar/vue-ui';
|
|
42
54
|
import { CoarObjectEditor } from '@cocoar/vue-object-editor';
|
|
43
55
|
import '@cocoar/vue-object-editor/styles';
|
|
44
56
|
import { createProduct, productSchema } from './product-schema';
|
|
45
57
|
|
|
46
58
|
const product = ref(createProduct());
|
|
47
59
|
const mode = ref<'view' | 'edit'>('edit');
|
|
60
|
+
const striped = ref(false);
|
|
61
|
+
const search = ref('');
|
|
48
62
|
const modes = [
|
|
49
63
|
{ value: 'view', label: 'View' },
|
|
50
64
|
{ value: 'edit', label: 'Edit' },
|
|
@@ -58,6 +72,11 @@ const modes = [
|
|
|
58
72
|
gap: 12px;
|
|
59
73
|
width: 100%;
|
|
60
74
|
}
|
|
75
|
+
.toolbar {
|
|
76
|
+
display: flex;
|
|
77
|
+
align-items: center;
|
|
78
|
+
gap: 16px;
|
|
79
|
+
}
|
|
61
80
|
pre {
|
|
62
81
|
font-size: 12px;
|
|
63
82
|
}
|
|
@@ -66,11 +85,259 @@ pre {
|
|
|
66
85
|
|
|
67
86
|
What the editor does with the data:
|
|
68
87
|
|
|
69
|
-
- **A
|
|
88
|
+
- **A value is there when its key is.** `null`, `""`, `[]` and `{}` are values; only **Remove** in the
|
|
89
|
+
row's menu deletes a key (see [Values and absence](#values-and-absence)).
|
|
70
90
|
- **Problems appear in their row**, found by the schema (`minimum`, `format`, `required` …) and by the checks
|
|
71
|
-
of the value types.
|
|
91
|
+
of the value types. A problem of a part without its own row names that part (`mode: Required.`); one that
|
|
92
|
+
belongs to no row is listed above the rows.
|
|
93
|
+
- **A definition that contains itself** (`$ref` to an enclosing definition) starts closed and opens one level
|
|
94
|
+
per click.
|
|
72
95
|
- **Values the schema does not know stay in the data**, shown read-only as "not in the schema".
|
|
73
|
-
- **Lists
|
|
96
|
+
- **Lists and maps** of single values get a row per entry, see [Lists and maps](#lists-and-maps). **Lists of
|
|
97
|
+
groups** (arrays of objects) are shown read-only with their number of entries and kept unchanged.
|
|
98
|
+
- **Search** (`v-model:search`) finds rows by title, key or path, see [Search](#search).
|
|
99
|
+
|
|
100
|
+
## Values and absence (Changed) {#values-and-absence}
|
|
101
|
+
|
|
102
|
+
The editor stores exactly what is set, the way JSON Schema reads it:
|
|
103
|
+
|
|
104
|
+
| State | Shown as | In the JSON |
|
|
105
|
+
|-------|----------|-------------|
|
|
106
|
+
| not set | `–` | no key |
|
|
107
|
+
| `null` | `null` | `"x": null` |
|
|
108
|
+
| empty | `""`, `[]`, `{}` | `"x": ""` … |
|
|
109
|
+
|
|
110
|
+
- An emptied text is `""`, an emptied tag list `[]`. The row's menu (⋯) has **Remove value**, which deletes the
|
|
111
|
+
key, and **Set to null** where the schema allows `null` (`type: ["boolean", "null"]`, an `anyOf` with
|
|
112
|
+
`{ "type": "null" }`, or `null` in `enum`). `false` and `0` are always values.
|
|
113
|
+
- A field that cannot show "no value" — an emptied number, date or choice — writes `null` when the schema allows
|
|
114
|
+
it. Otherwise nothing is written: the row asks for a value, and leaving the field restores the old one.
|
|
115
|
+
- `required` is met by the key, also with `null`.
|
|
116
|
+
- Rows below a group that is `null` are locked: editing them would replace that `null` with an object. The
|
|
117
|
+
group's menu has **Fill in this group**, which writes `{}`.
|
|
118
|
+
|
|
119
|
+
Forms that want "empty means missing" pass `presence="filled"`: emptying a value then removes its key, and an
|
|
120
|
+
empty value fails `required`. This was the behaviour before; see
|
|
121
|
+
[Migrating the Object Editor values](../guide/migration-object-editor-values.md).
|
|
122
|
+
|
|
123
|
+
## Lists and maps {#lists-and-maps}
|
|
124
|
+
|
|
125
|
+
An **ordered list** (`type: "array"` with single-value `items`) and a **map** (`type: "object"` with a schema in
|
|
126
|
+
`additionalProperties`) show one row per entry, with the control of the entry's type. The product above has both:
|
|
127
|
+
`highlights` and `prices`.
|
|
128
|
+
|
|
129
|
+
- A list keeps its order and duplicates; `false` and `0` are values. The list's menu adds an item; an item's menu
|
|
130
|
+
moves, inserts below and removes it. **Alt+↑** / **Alt+↓** move the focused item.
|
|
131
|
+
- A map's keys are edited in place. A key that exists already is refused and marked at the key; the map's menu
|
|
132
|
+
adds an entry.
|
|
133
|
+
- A problem of an entry appears in its row (`/prices/AT`).
|
|
134
|
+
- An inherited list or map is copied into the document when one of its entries changes: the copy replaces it.
|
|
135
|
+
|
|
136
|
+
Strings that must be unique are `tags` (`uniqueItems: true`); strings in order are a `list`.
|
|
137
|
+
|
|
138
|
+
## Search {#search}
|
|
139
|
+
|
|
140
|
+
`v-model:search` filters the rows by title, key or path (`dimensions.width`), also below closed groups, and keeps
|
|
141
|
+
the groups that lead to a match. Clearing it brings back the groups as they were. Values are never searched, so a
|
|
142
|
+
secret cannot match. It works together with `view="local"`.
|
|
143
|
+
|
|
144
|
+
`focus(pointer)` (on the component's ref) opens the groups of a row, scrolls to it and focuses its control — for
|
|
145
|
+
links from search results or from the app's own messages.
|
|
146
|
+
|
|
147
|
+
## Inherited values {#inherited-values}
|
|
148
|
+
|
|
149
|
+
A layered configuration edits one layer and shows what the layers below give. `base` holds those values,
|
|
150
|
+
read-only: a row without a local key shows the base value, softer and marked with where it comes from. Editing
|
|
151
|
+
writes the local document; **Reset to inherited** in the menu removes the local key again, and a group the reset
|
|
152
|
+
leaves empty goes with it. `view="local"` shows only
|
|
153
|
+
the keys the document sets — also `false`, `0`, `null` and empty values — with the groups that lead to them.
|
|
154
|
+
Switching views never changes the document.
|
|
155
|
+
|
|
156
|
+
**Demo — `object-editor/demos/ObjectEditorInherited.vue`**
|
|
157
|
+
|
|
158
|
+
```vue
|
|
159
|
+
<template>
|
|
160
|
+
<div class="demo">
|
|
161
|
+
<div class="toolbar">
|
|
162
|
+
<CoarSegmentedControl v-model="view" :options="views" aria-label="Rows" />
|
|
163
|
+
</div>
|
|
164
|
+
<CoarObjectEditor
|
|
165
|
+
v-model="layer"
|
|
166
|
+
:schema="schema"
|
|
167
|
+
:base="product"
|
|
168
|
+
:origin="origin"
|
|
169
|
+
:view="view"
|
|
170
|
+
:validate="false"
|
|
171
|
+
locale="en-US"
|
|
172
|
+
/>
|
|
173
|
+
<div class="json">
|
|
174
|
+
<div>
|
|
175
|
+
<strong>Inherited (product)</strong>
|
|
176
|
+
<pre>{{ JSON.stringify(product, null, 2) }}</pre>
|
|
177
|
+
</div>
|
|
178
|
+
<div>
|
|
179
|
+
<strong>This layer (customer)</strong>
|
|
180
|
+
<pre>{{ JSON.stringify(layer, null, 2) }}</pre>
|
|
181
|
+
</div>
|
|
182
|
+
</div>
|
|
183
|
+
</div>
|
|
184
|
+
</template>
|
|
185
|
+
|
|
186
|
+
<script setup lang="ts">
|
|
187
|
+
import { ref } from 'vue';
|
|
188
|
+
import { CoarSegmentedControl } from '@cocoar/vue-ui';
|
|
189
|
+
import { CoarObjectEditor, type JsonObject, type JsonSchema } from '@cocoar/vue-object-editor';
|
|
190
|
+
import '@cocoar/vue-object-editor/styles';
|
|
191
|
+
|
|
192
|
+
const schema: JsonSchema = {
|
|
193
|
+
type: 'object',
|
|
194
|
+
'x-coar-order': ['enabled', 'retries', 'region', 'proxy'],
|
|
195
|
+
properties: {
|
|
196
|
+
enabled: { type: ['boolean', 'null'], title: 'Enabled' },
|
|
197
|
+
retries: { type: 'integer', title: 'Retries', minimum: 0 },
|
|
198
|
+
region: { title: 'Region', enum: ['eu', 'us', 'asia'] },
|
|
199
|
+
proxy: {
|
|
200
|
+
type: ['object', 'null'],
|
|
201
|
+
title: 'Proxy',
|
|
202
|
+
properties: { host: { type: 'string', title: 'Host' }, port: { type: 'integer', title: 'Port' } },
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
// What the product layer gives. The app owns how layers combine; the editor only shows it.
|
|
208
|
+
const product: JsonObject = { enabled: true, retries: 3, region: 'eu', proxy: { host: 'proxy.example', port: 8080 } };
|
|
209
|
+
const layer = ref<JsonObject | undefined>({ retries: 0, proxy: { port: 3128 } });
|
|
210
|
+
|
|
211
|
+
const origin = () => ({ label: 'product', title: 'Inherited from the product defaults' });
|
|
212
|
+
const view = ref<'all' | 'local'>('all');
|
|
213
|
+
const views = [
|
|
214
|
+
{ value: 'all', label: 'All properties' },
|
|
215
|
+
{ value: 'local', label: 'Only this layer' },
|
|
216
|
+
];
|
|
217
|
+
</script>
|
|
218
|
+
|
|
219
|
+
<style scoped>
|
|
220
|
+
.demo {
|
|
221
|
+
display: flex;
|
|
222
|
+
flex-direction: column;
|
|
223
|
+
gap: 12px;
|
|
224
|
+
width: 100%;
|
|
225
|
+
}
|
|
226
|
+
.json {
|
|
227
|
+
display: grid;
|
|
228
|
+
grid-template-columns: 1fr 1fr;
|
|
229
|
+
gap: 12px;
|
|
230
|
+
}
|
|
231
|
+
pre {
|
|
232
|
+
font-size: 12px;
|
|
233
|
+
}
|
|
234
|
+
</style>
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
```vue
|
|
238
|
+
<CoarObjectEditor
|
|
239
|
+
v-model="layer"
|
|
240
|
+
:schema="schema"
|
|
241
|
+
:base="inherited"
|
|
242
|
+
:origin="(pointer) => ({ label: sourceOf(pointer) })"
|
|
243
|
+
:view="onlyLocal ? 'local' : 'all'"
|
|
244
|
+
/>
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
The editor looks up a value per path: the local one, else the base one. It does not merge — how layers combine is
|
|
248
|
+
the app's rule. `origin` names the source of an inherited value; `conflict: true` shows "differs by context"
|
|
249
|
+
instead of a value that would look authoritative. To check the effective document, turn `validate` off and pass
|
|
250
|
+
the app's own `issues`: missing local keys are then no error, and the problems still appear in their rows.
|
|
251
|
+
|
|
252
|
+
## Sensitive values {#sensitive-values}
|
|
253
|
+
|
|
254
|
+
Secrets stay with the app: its control writes them, its type decides how they look. Three hooks keep them out of
|
|
255
|
+
everything else:
|
|
256
|
+
|
|
257
|
+
- **`resolveType`** chooses a type from a marker the schema already has, without changing the stored schema:
|
|
258
|
+
`({ schema }) => schema['x-cocoar-secret'] ? 'secret' : undefined`.
|
|
259
|
+
- **`sensitive: true`** on the type: its value appears only through the type's own `format` or `view`, never
|
|
260
|
+
as generic text. **`validateSchema: false`**: the stored form (an encrypted envelope) differs from the logical
|
|
261
|
+
schema (`type: "string"`), so the schema's checks are skipped at this value.
|
|
262
|
+
- **`redact(pointer, value)`** masks any other value as dots, read-only and without a control, also unknown keys
|
|
263
|
+
the schema does not describe.
|
|
264
|
+
|
|
265
|
+
A missing required key is still reported where `validateSchema` is `false`: it is a check of the parent object.
|
|
266
|
+
|
|
267
|
+
**Demo — `object-editor/demos/ObjectEditorSecret.vue`**
|
|
268
|
+
|
|
269
|
+
```vue
|
|
270
|
+
<template>
|
|
271
|
+
<div class="demo">
|
|
272
|
+
<CoarObjectEditor
|
|
273
|
+
v-model="settings"
|
|
274
|
+
:schema="schema"
|
|
275
|
+
:types="types"
|
|
276
|
+
:resolve-type="resolveType"
|
|
277
|
+
:redact="isEnvelope"
|
|
278
|
+
locale="en-US"
|
|
279
|
+
/>
|
|
280
|
+
<pre>{{ JSON.stringify(settings, null, 2) }}</pre>
|
|
281
|
+
</div>
|
|
282
|
+
</template>
|
|
283
|
+
|
|
284
|
+
<script setup lang="ts">
|
|
285
|
+
import { markRaw, ref } from 'vue';
|
|
286
|
+
import {
|
|
287
|
+
CoarObjectEditor,
|
|
288
|
+
defineObjectEditorTypes,
|
|
289
|
+
type CoarValueType,
|
|
290
|
+
type JsonObject,
|
|
291
|
+
type JsonSchema,
|
|
292
|
+
type JsonValue,
|
|
293
|
+
} from '@cocoar/vue-object-editor';
|
|
294
|
+
import '@cocoar/vue-object-editor/styles';
|
|
295
|
+
import SecretControl from './SecretControl.vue';
|
|
296
|
+
|
|
297
|
+
// The app's secret type: its own control, shown as dots, stored as an envelope.
|
|
298
|
+
const secret: CoarValueType = {
|
|
299
|
+
id: 'secret',
|
|
300
|
+
label: 'Secret',
|
|
301
|
+
icon: 'lock',
|
|
302
|
+
hue: 0,
|
|
303
|
+
schema: { type: 'string' },
|
|
304
|
+
sensitive: true,
|
|
305
|
+
validateSchema: false,
|
|
306
|
+
control: markRaw(SecretControl),
|
|
307
|
+
format: () => '••••••',
|
|
308
|
+
};
|
|
309
|
+
const types = defineObjectEditorTypes([secret]);
|
|
310
|
+
|
|
311
|
+
// The schema keeps its own marker; the editor picks the type from it.
|
|
312
|
+
const schema: JsonSchema = {
|
|
313
|
+
type: 'object',
|
|
314
|
+
properties: {
|
|
315
|
+
user: { type: 'string', title: 'User' },
|
|
316
|
+
password: { type: 'string', title: 'Password', 'x-cocoar-secret': true },
|
|
317
|
+
},
|
|
318
|
+
};
|
|
319
|
+
const resolveType = ({ schema: property }: { schema: JsonSchema }) => (property['x-cocoar-secret'] ? 'secret' : undefined);
|
|
320
|
+
const isEnvelope = (_pointer: string, value: JsonValue) => typeof value === 'object' && value !== null && '$enc' in value;
|
|
321
|
+
|
|
322
|
+
const settings = ref<JsonObject | undefined>({
|
|
323
|
+
user: 'service',
|
|
324
|
+
password: { $enc: 'demo', data: 'c2VjcmV0' },
|
|
325
|
+
legacyToken: { $enc: 'demo', data: 'b2xk' },
|
|
326
|
+
});
|
|
327
|
+
</script>
|
|
328
|
+
|
|
329
|
+
<style scoped>
|
|
330
|
+
.demo {
|
|
331
|
+
display: flex;
|
|
332
|
+
flex-direction: column;
|
|
333
|
+
gap: 12px;
|
|
334
|
+
width: 100%;
|
|
335
|
+
}
|
|
336
|
+
pre {
|
|
337
|
+
font-size: 12px;
|
|
338
|
+
}
|
|
339
|
+
</style>
|
|
340
|
+
```
|
|
74
341
|
|
|
75
342
|
## The schema
|
|
76
343
|
|
|
@@ -110,11 +377,15 @@ A **choice** is `oneOf` of `{ const, title }`; several choices are an `array` wi
|
|
|
110
377
|
| `number` | `number` / `integer` | Inline number input with unit |
|
|
111
378
|
| `boolean` | `boolean` | Switch |
|
|
112
379
|
| `date` | `string`, `format: "date"` | Inline date picker |
|
|
380
|
+
| `date-time` | `string`, `format: "date-time"` | Inline date-time picker; stored as ISO 8601 with offset |
|
|
113
381
|
| `email` | `string`, `format: "email"` | Inline text input |
|
|
114
382
|
| `color` | `string`, `pattern` `#RRGGBB` | Inline text input with a swatch |
|
|
115
383
|
| `choice` | `oneOf` of constants | Inline select |
|
|
116
384
|
| `choices` | `array` of constants | Tag select |
|
|
117
|
-
| `tags` | `array` of `string` | Tag select that creates tags |
|
|
385
|
+
| `tags` | `array` of unique `string` | Tag select that creates tags |
|
|
386
|
+
| `list` | `array` of single values, in order | A row per item |
|
|
387
|
+
| `map` | `object` with `additionalProperties` | A row per key |
|
|
388
|
+
| `group-list` | `array` of objects | Read-only, number of entries |
|
|
118
389
|
| `object` | `object` | The rows of its properties, collapsible |
|
|
119
390
|
|
|
120
391
|
## Types of the app and option sources
|
|
@@ -349,6 +620,26 @@ The same operations exist as functions: `addProperty`, `removeProperty`, `rename
|
|
|
349
620
|
`changePropertyType`, `updateProperty`, `setRequired` and `setOptions` take a schema and a path of keys
|
|
350
621
|
(`['dimensions', 'width']`) and return the new schema.
|
|
351
622
|
|
|
623
|
+
### Profiles of the app
|
|
624
|
+
|
|
625
|
+
An app whose backend accepts only part of JSON Schema passes a `profile`:
|
|
626
|
+
|
|
627
|
+
```vue
|
|
628
|
+
<CoarSchemaEditor
|
|
629
|
+
v-model="schema"
|
|
630
|
+
:profile="{
|
|
631
|
+
types: ['text', 'number', 'boolean', 'choice', 'list', 'map'], // offered types
|
|
632
|
+
choiceEncoding: 'enum', // choices as a plain enum, without texts
|
|
633
|
+
diagnostics: (schema) => backendProblems(schema), // [{ path: ['retries'], message: '…' }]
|
|
634
|
+
}"
|
|
635
|
+
/>
|
|
636
|
+
```
|
|
637
|
+
|
|
638
|
+
The schema editor changes only what is edited: `$defs`, annotations (`$comment`, `x-…` of other tools) and
|
|
639
|
+
references stay as imported. A property with keywords it cannot edit (`allOf`, `if`, `patternProperties` …) shows
|
|
640
|
+
them and offers only key, title and description. A type change that would drop keywords names them and waits for
|
|
641
|
+
a confirmation. **Allows null** writes `type: [t, "null"]`, and keeps an existing `anyOf` with `{ "type": "null" }`.
|
|
642
|
+
|
|
352
643
|
## API
|
|
353
644
|
|
|
354
645
|
### CoarObjectEditor props
|
|
@@ -361,8 +652,19 @@ The same operations exist as functions: `addProperty`, `removeProperty`, `rename
|
|
|
361
652
|
| `optionSources` | `Record<string, Option[] \| () => Option[] \| Promise<Option[]>>` | `{}` | Options named by `x-coar-options` |
|
|
362
653
|
| `mode` | `'view' \| 'edit'` | `'edit'` | Formatted values or controls |
|
|
363
654
|
| `locale` | `string` | browser | Locale of numbers and dates |
|
|
364
|
-
|
|
365
|
-
|
|
655
|
+
| `striped` | `boolean` | `false` | Every second row on a light background, for this editor (see [Theming](#theming)) |
|
|
656
|
+
| `presence` | `'key' \| 'filled'` | `'key'` | When a value counts as there, see [Values and absence](#values-and-absence) |
|
|
657
|
+
| `base` | `JsonObject` | — | Read-only values where the document has no key, see [Inherited values](#inherited-values) |
|
|
658
|
+
| `origin` | `(pointer) => { label, title?, conflict? }` | — | Where an inherited value comes from |
|
|
659
|
+
| `view` | `'all' \| 'local'` | `'all'` | `local`: only keys the document sets, with their groups |
|
|
660
|
+
| `validate` | `boolean` | `true` | `false`: no built-in validation |
|
|
661
|
+
| `issues` | `ObjectEditorIssue[]` | `[]` | Problems the app found, shown in their rows |
|
|
662
|
+
| `resolveType` | `({ schema, pointer, typeId }) => string \| undefined` | — | Chooses the type of a property, see [Sensitive values](#sensitive-values) |
|
|
663
|
+
| `redact` | `(pointer, value) => boolean` | — | Masks a value as dots |
|
|
664
|
+
| `v-model:search` | `string` | `''` | Filters rows by title, key or path, see [Search](#search) |
|
|
665
|
+
|
|
666
|
+
The component exposes `issues` (every problem of the value, as `{ pointer, keyword, message? }`) and
|
|
667
|
+
`focus(pointer)`.
|
|
366
668
|
|
|
367
669
|
### CoarSchemaEditor props
|
|
368
670
|
|
|
@@ -370,13 +672,15 @@ The component exposes `issues`: every problem of the value, as `{ pointer, keywo
|
|
|
370
672
|
|------|------|---------|-------------|
|
|
371
673
|
| `v-model` | `JsonSchema` | — | The schema; each change emits a new object |
|
|
372
674
|
| `types` | `CoarObjectEditorTypes` | built-in types | The types to choose from |
|
|
675
|
+
| `profile` | `{ types?, choiceEncoding?, diagnostics? }` | — | What can be authored, see [Profiles of the app](#profiles-of-the-app) |
|
|
373
676
|
|
|
374
677
|
### Functions
|
|
375
678
|
|
|
376
679
|
| Function | Description |
|
|
377
680
|
|----------|-------------|
|
|
378
681
|
| `defineObjectEditorTypes(types?)` | The built-in types plus the given ones |
|
|
379
|
-
| `validateValue(schema, value)` | The problems of a value, each at its JSON Pointer |
|
|
682
|
+
| `validateValue(schema, value, { presence? })` | The problems of a value, each at its JSON Pointer |
|
|
683
|
+
| `allowsNull(schema)`, `nonNullSchema(root, schema)` | Whether a schema allows `null`; the schema without its `null` alternative |
|
|
380
684
|
| `createObjectSchema()` | An empty object schema |
|
|
381
685
|
| `checkSchema(schema)` | Bad keys, ranges and option lists, each at its path |
|
|
382
686
|
| `getAt`, `setAt`, `parsePointer`, `formatPointer` | Read and write values by JSON Pointer, without changing the original |
|
|
@@ -384,6 +688,21 @@ The component exposes `issues`: every problem of the value, as `{ pointer, keywo
|
|
|
384
688
|
Validation uses [`@cfworker/json-schema`](https://github.com/cfworker/cfworker/tree/main/packages/json-schema): it
|
|
385
689
|
interprets the schema and never generates code, so a Content Security Policy without `'unsafe-eval'` works.
|
|
386
690
|
|
|
691
|
+
## Theming
|
|
692
|
+
|
|
693
|
+
The rows sit on the background of the page. To give every second row a background in every object editor of an
|
|
694
|
+
app, set its token in the theme or style preset; the `striped` prop sets the same token for one editor.
|
|
695
|
+
|
|
696
|
+
| Token | Default | Description |
|
|
697
|
+
|-------|---------|-------------|
|
|
698
|
+
| `--coar-object-editor-row-stripe` | `transparent` | Background of every second row |
|
|
699
|
+
|
|
700
|
+
```css
|
|
701
|
+
:root {
|
|
702
|
+
--coar-object-editor-row-stripe: var(--coar-background-neutral-secondary);
|
|
703
|
+
}
|
|
704
|
+
```
|
|
705
|
+
|
|
387
706
|
## i18n Keys
|
|
388
707
|
|
|
389
708
|
| Key | Default |
|
|
@@ -403,4 +722,16 @@ interprets the schema and never generates code, so a Content Security Policy wit
|
|
|
403
722
|
| `coar.objectEditor.filled` | `{count} filled` |
|
|
404
723
|
| `coar.objectEditor.entry` / `entries` | `1 entry` / `{count} entries` |
|
|
405
724
|
| `coar.objectEditor.type.<id>` | The `label` of the type |
|
|
406
|
-
| `coar.
|
|
725
|
+
| `coar.objectEditor.remove` / `reset` / `setNull` | `Remove value` / `Reset to inherited` / `Set to null` |
|
|
726
|
+
| `coar.objectEditor.actions` | `Actions for {title}` |
|
|
727
|
+
| `coar.objectEditor.needsValue` | `Enter a value, or remove it from the menu.` |
|
|
728
|
+
| `coar.objectEditor.lockedByNull` | `{group} is null: fill it in from its menu to edit this value` |
|
|
729
|
+
| `coar.objectEditor.fillGroup` | `Fill in this group` |
|
|
730
|
+
| `coar.objectEditor.inherited` / `conflict` | `inherited` / `differs by context` |
|
|
731
|
+
| `coar.objectEditor.literalHint` | `This value is set; Remove deletes it.` |
|
|
732
|
+
| `coar.objectEditor.noLocalValues` | `No values are set here.` |
|
|
733
|
+
| `coar.objectEditor.noMatches` | `No property matches the search.` |
|
|
734
|
+
| `coar.objectEditor.item` / `items` | `1 item` / `{count} items` |
|
|
735
|
+
| `coar.objectEditor.addItem` / `addEntry` / `insertBelow` / `moveUp` / `moveDown` / `removeEntry` | `Add item` / `Add entry` / `Insert below` / `Move up` / `Move down` / `Remove` |
|
|
736
|
+
| `coar.objectEditor.mapKey` / `keyEmpty` / `keyTaken` | `Key` / `A key cannot be empty.` / `This key exists already.` |
|
|
737
|
+
| `coar.schemaEditor.*` | Labels of the schema editor (`key`, `title`, `type`, `required`, `addProperty` …) and its problems (`invalidKey`, `keyTaken`, `rangeOrder`, `noOptions`, `emptyOption`, `duplicateOption`), and `allowsNull`, `itemType`, `valueType`, `unsupported`, `typeDrops`, `changeType` |
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<!-- Generated from apps/docs/guide/migration-object-editor-values.md by apps/docs/scripts/sync-skill.mjs. Do not edit; edit the docs page. -->
|
|
2
|
+
|
|
3
|
+
# Migrating the Object Editor values
|
|
4
|
+
|
|
5
|
+
`@cocoar/vue-object-editor` now keeps values the way JSON Schema reads them. Before, an emptied value removed its
|
|
6
|
+
key, and `null`, `""`, `[]` and `{}` were treated as missing. Now they are values, and only **Remove value** in
|
|
7
|
+
the row's menu deletes a key.
|
|
8
|
+
|
|
9
|
+
## TL;DR
|
|
10
|
+
|
|
11
|
+
| If you… | …then you need to |
|
|
12
|
+
| --- | --- |
|
|
13
|
+
| Edit configuration or other sparse JSON | **Nothing.** `null` and empty values now survive editing. |
|
|
14
|
+
| Use the editor as a form where "empty" should mean "not filled in" | Pass `presence="filled"`: emptying removes the key, and an empty value fails `required`, as before. |
|
|
15
|
+
| Call `validateValue` and count `""` as missing for `required` | Pass `{ presence: 'filled' }` as the third argument. |
|
|
16
|
+
| Wrote a value control that emits `undefined` for "empty" | Emit the empty value itself (`""`, `[]`). Emit `undefined` only when the control cannot show a value at all (an emptied number field): the editor then writes `null` where the schema allows it, and otherwise keeps the value. |
|
|
17
|
+
|
|
18
|
+
## What changed
|
|
19
|
+
|
|
20
|
+
| | Before | Now (`presence="key"`) |
|
|
21
|
+
| --- | --- | --- |
|
|
22
|
+
| Emptied text | key removed | `""` |
|
|
23
|
+
| Emptied tag list | key removed | `[]` |
|
|
24
|
+
| Emptied number, date, choice | key removed | `null` when allowed, otherwise the value stays |
|
|
25
|
+
| `required` with `null` or `""` | fails | met |
|
|
26
|
+
| Removing a key | emptying the field | **Remove value** in the row's menu |
|
|
27
|
+
| `type: ["boolean", "null"]` | shown as a JSON value | Yes/no field with **Set to null** |
|
|
28
|
+
|
|
29
|
+
See [Values and absence](../components/object-editor.md#values-and-absence).
|
|
30
|
+
|
|
31
|
+
## Type ids
|
|
32
|
+
|
|
33
|
+
| Before | Now |
|
|
34
|
+
| --- | --- |
|
|
35
|
+
| `list` (array of objects, read-only) | `group-list` |
|
|
36
|
+
| — | `list`: an ordered array of single values, edited row by row |
|
|
37
|
+
| `tags` for any array of strings | `tags` for unique strings (`uniqueItems: true`); strings in order are a `list` |
|
|
38
|
+
|
|
39
|
+
A schema that names `x-coar-type: "list"` for an array of objects now asks for a list of single values: change it to
|
|
40
|
+
`group-list`, or remove `x-coar-type` and let the editor recognize the array.
|