@ditojs/admin 2.7.5 → 2.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/dito-admin.es.js +1417 -1376
  2. package/dist/dito-admin.umd.js +5 -5
  3. package/dist/style.css +1 -1
  4. package/package.json +5 -5
  5. package/src/DitoContext.js +4 -0
  6. package/src/DitoTypeComponent.js +1 -1
  7. package/src/components/DitoClipboard.vue +22 -0
  8. package/src/components/DitoContainer.vue +7 -12
  9. package/src/components/DitoCreateButton.vue +21 -1
  10. package/src/components/DitoDialog.vue +5 -0
  11. package/src/components/DitoEditButtons.vue +35 -25
  12. package/src/components/DitoElement.vue +2 -2
  13. package/src/components/DitoForm.vue +9 -4
  14. package/src/components/DitoHeader.vue +22 -6
  15. package/src/components/DitoLabel.vue +41 -23
  16. package/src/components/DitoPane.vue +47 -35
  17. package/src/components/DitoRoot.vue +1 -2
  18. package/src/components/DitoSchema.vue +139 -165
  19. package/src/components/DitoSchemaInlined.vue +12 -9
  20. package/src/components/DitoTabs.vue +65 -23
  21. package/src/components/DitoTreeItem.vue +1 -1
  22. package/src/components/DitoView.vue +0 -1
  23. package/src/mixins/DitoMixin.js +6 -5
  24. package/src/mixins/ItemMixin.js +5 -1
  25. package/src/mixins/TypeMixin.js +14 -30
  26. package/src/styles/_button.scss +13 -12
  27. package/src/styles/_settings.scss +2 -2
  28. package/src/types/DitoTypeList.vue +1 -1
  29. package/src/types/DitoTypeMultiselect.vue +2 -3
  30. package/src/types/DitoTypeObject.vue +6 -4
  31. package/src/types/DitoTypePanel.vue +1 -1
  32. package/src/types/DitoTypeSection.vue +38 -10
  33. package/src/types/DitoTypeSelect.vue +2 -1
  34. package/src/types/DitoTypeUpload.vue +2 -2
  35. package/src/utils/options.js +1 -1
  36. package/src/utils/schema.js +8 -6
  37. package/types/index.d.ts +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ditojs/admin",
3
- "version": "2.7.5",
3
+ "version": "2.8.1",
4
4
  "type": "module",
5
5
  "description": "Dito.js Admin is a schema based admin interface for Dito.js Server, featuring auto-generated views and forms and built with Vue.js",
6
6
  "repository": "https://github.com/ditojs/dito/tree/master/packages/admin",
@@ -33,8 +33,8 @@
33
33
  "not ie_mob > 0"
34
34
  ],
35
35
  "dependencies": {
36
- "@ditojs/ui": "^2.7.3",
37
- "@ditojs/utils": "^2.7.1",
36
+ "@ditojs/ui": "^2.8.0",
37
+ "@ditojs/utils": "^2.8.0",
38
38
  "@kyvg/vue3-notification": "^2.9.0",
39
39
  "@lk77/vue3-color": "^3.0.6",
40
40
  "@tiptap/core": "^2.0.3",
@@ -74,7 +74,7 @@
74
74
  "vue-upload-component": "^3.1.8"
75
75
  },
76
76
  "devDependencies": {
77
- "@ditojs/build": "^2.5.0",
77
+ "@ditojs/build": "^2.8.0",
78
78
  "@vitejs/plugin-vue": "^4.2.1",
79
79
  "@vue/compiler-sfc": "^3.2.47",
80
80
  "pug": "^3.0.2",
@@ -83,7 +83,7 @@
83
83
  "vite": "^4.3.5"
84
84
  },
85
85
  "types": "types",
86
- "gitHead": "d88c47b18f85103460099db95afb067c8c244253",
86
+ "gitHead": "26db3d0a7ebbed92b052bd7cffa078e9cdae7497",
87
87
  "scripts": {
88
88
  "build": "vite build",
89
89
  "watch": "yarn build --mode 'development' --watch",
@@ -216,6 +216,10 @@ export default class DitoContext {
216
216
  return get(this, 'options', undefined)
217
217
  }
218
218
 
219
+ get open() {
220
+ return get(this, 'open', undefined)
221
+ }
222
+
219
223
  // TODO: Rename this to `searchTerm` or `searchQuery`, to perhaps free `query`
220
224
  // for the actual `resourceComponent.query` object?
221
225
  get query() {
@@ -21,7 +21,7 @@ export default {
21
21
  generateLabel: true,
22
22
  excludeValue: false,
23
23
  ignoreMissingValue: null,
24
- omitPadding: false,
24
+ omitSpacing: false,
25
25
 
26
26
  component: DitoComponent.component,
27
27
 
@@ -165,3 +165,25 @@ export default DitoComponent.component('DitoClipboard', {
165
165
  }
166
166
  })
167
167
  </script>
168
+
169
+ <style lang="scss">
170
+ @import '../styles/_imports';
171
+
172
+ .dito-clipboard {
173
+ display: flex;
174
+
175
+ .dito-schema & {
176
+ // Push clipboard to the right in the flex layout, see:
177
+ // https://codepen.io/tholex/pen/hveBx/
178
+ margin-left: auto;
179
+ }
180
+
181
+ .dito-header & {
182
+ margin-left: 0;
183
+
184
+ .dito-button {
185
+ margin: 0 0 $tab-margin $tab-margin;
186
+ }
187
+ }
188
+ }
189
+ </style>
@@ -51,7 +51,7 @@ import {
51
51
  getAllPanelEntries,
52
52
  getTypeComponent,
53
53
  hasLabel,
54
- omitPadding
54
+ omitSpacing
55
55
  } from '../utils/schema.js'
56
56
  import { parseFraction } from '../utils/math.js'
57
57
 
@@ -73,8 +73,7 @@ export default DitoComponent.component('DitoContainer', {
73
73
 
74
74
  data() {
75
75
  return {
76
- errors: null,
77
- isMounted: false
76
+ errors: null
78
77
  }
79
78
  },
80
79
 
@@ -184,7 +183,7 @@ export default DitoComponent.component('DitoContainer', {
184
183
  'dito-disabled': this.componentDisabled,
185
184
  'dito-has-errors': !!this.errors,
186
185
  [`${prefix}--label-vertical`]: this.verticalLabels,
187
- [`${prefix}--omit-padding`]: omitPadding(this.schema),
186
+ [`${prefix}--omit-spacing`]: omitSpacing(this.schema),
188
187
  ...(isString(classes) ? { [classes]: true } : classes)
189
188
  }
190
189
  },
@@ -228,10 +227,6 @@ export default DitoComponent.component('DitoContainer', {
228
227
  }
229
228
  },
230
229
 
231
- mounted() {
232
- this.isMounted = true
233
- },
234
-
235
230
  methods: {
236
231
  onErrors(errors) {
237
232
  this.errors = errors
@@ -258,7 +253,7 @@ export default DitoComponent.component('DitoContainer', {
258
253
  max-width: 100%;
259
254
  // Cannot use margin here as it needs to be part of box-sizing for
260
255
  // percentages in flex-basis to work.
261
- padding: $form-spacing $form-spacing-half;
256
+ padding: $form-spacing-half;
262
257
 
263
258
  .dito-page .dito-pane > & {
264
259
  @container (width < #{calc($content-width * 0.8)}) {
@@ -300,15 +295,15 @@ export default DitoComponent.component('DitoContainer', {
300
295
  // have labels, add some spacing to the top to align with the other
301
296
  // components (e.g. buttons):
302
297
  > .dito-component:first-child:not(.dito-section, .dito-list, .dito-object) {
303
- margin-top: $line-height * $font-size + $form-spacing-half;
298
+ margin-top: $input-height;
304
299
  }
305
300
  }
306
301
 
307
- &--omit-padding {
302
+ &--omit-spacing {
308
303
  padding: 0;
309
304
 
310
305
  > .dito-label {
311
- margin: $form-spacing $form-spacing-half 0;
306
+ margin: $form-spacing-half $form-spacing-half 0;
312
307
  }
313
308
  }
314
309
  }
@@ -40,6 +40,19 @@ export default DitoComponent.component('DitoCreateButton', {
40
40
 
41
41
  props: {
42
42
  schema: { type: Object, required: true },
43
+ // The next four props are there for `DitoContext` and the `context()`
44
+ // getter in `DitoMixin`.
45
+ // TODO: Should they be moved to shared mixin that defines them as required
46
+ // and also provides the `context()` getter, perhaps `ContextMixin`?
47
+ // `schema` could be included as well, and `ContextMixin` could be used in
48
+ // `DitoForm`, `DitoView`, `DitoPanel`, `DitoSchema`, `DitoEditButtons`,
49
+ // etc? But the problem with the root components is that they don't have
50
+ // these props. We could add a `contextAttributes()` getter for easy passing
51
+ // on as `v-bind="contextAttributes"`.
52
+ dataPath: { type: String, required: true },
53
+ data: { type: [Object, Array], default: null },
54
+ meta: { type: Object, required: true },
55
+ store: { type: Object, required: true },
43
56
  path: { type: String, required: true },
44
57
  verb: { type: String, required: true },
45
58
  text: { type: String, default: null },
@@ -68,7 +81,14 @@ export default DitoComponent.component('DitoCreateButton', {
68
81
  isFormCreatable(form) {
69
82
  // Forms can be excluded from the list by providing `if: false` or
70
83
  // `creatable: false`.
71
- return form.creatable !== false && this.shouldRenderSchema(form)
84
+ return (
85
+ this.shouldRenderSchema(form) &&
86
+ this.getSchemaValue('creatable', {
87
+ type: Boolean,
88
+ default: true,
89
+ schema: form
90
+ })
91
+ )
72
92
  },
73
93
 
74
94
  createItem(form, type = null) {
@@ -11,6 +11,11 @@
11
11
  form.dito-scroll-parent(
12
12
  @submit.prevent="submit"
13
13
  )
14
+ // Add an invisible button that prevents the clearable buttons from being
15
+ // pressed when the user presses the Enter key:
16
+ button(
17
+ v-show="false"
18
+ )
14
19
  DitoSchema(
15
20
  :schema="schema"
16
21
  :data="dialogData"
@@ -10,28 +10,32 @@ DitoButtons.dito-edit-buttons.dito-buttons-round(
10
10
  )
11
11
  //- Firefox doesn't like <button> here, so use <a> instead:
12
12
  a.dito-button(
13
- v-if="hasDraggable"
14
- :class="{ 'dito-disabled': disabled }"
13
+ v-if="draggable"
14
+ :class="{ 'dito-disabled': isDraggableDisabled }"
15
15
  v-bind="getButtonAttributes(verbs.drag)"
16
16
  )
17
17
  RouterLink.dito-button(
18
- v-if="hasEditable"
19
- :class="{ 'dito-disabled': disabled || !editPath }"
18
+ v-if="editable"
19
+ :class="{ 'dito-disabled': isEditableDisabled }"
20
20
  :to="editPath ? { path: editPath } : {}"
21
21
  v-bind="getButtonAttributes(verbs.edit)"
22
22
  )
23
23
  DitoCreateButton(
24
- v-if="hasCreatable"
24
+ v-if="creatable"
25
25
  :schema="schema"
26
+ :dataPath="dataPath"
27
+ :data="data"
28
+ :meta="meta"
29
+ :store="store"
26
30
  :path="createPath"
27
31
  :verb="verbs.create"
28
32
  :text="createButtonText"
29
- :disabled="disabled || !createPath"
33
+ :disabled="isCreatableDisabled"
30
34
  )
31
35
  button.dito-button(
32
- v-if="hasDeletable"
36
+ v-if="deletable"
33
37
  type="button"
34
- :disabled="disabled || !isFormDeletable"
38
+ :disabled="isDeletableDisabled"
35
39
  v-bind="getButtonAttributes(verbs.delete)"
36
40
  @click="$emit('delete')"
37
41
  )
@@ -66,24 +70,28 @@ export default DitoComponent.component('DitoEditButtons', {
66
70
  return this.getLabel(this.schema.form)
67
71
  },
68
72
 
69
- hasDraggable() {
70
- return this.hasOption('draggable')
73
+ isDraggableDisabled() {
74
+ return this.disabled || !this.hasSchemaOption('draggable')
71
75
  },
72
76
 
73
- hasEditable() {
74
- return this.hasOption('editable')
77
+ isDeletableDisabled() {
78
+ return this.disabled || !this.hasSchemaOption('deletable')
75
79
  },
76
80
 
77
- hasCreatable() {
78
- return this.hasOption('creatable')
79
- },
80
-
81
- hasDeletable() {
82
- return this.hasOption('deletable')
81
+ isCreatableDisabled() {
82
+ return (
83
+ this.disabled ||
84
+ !this.createPath ||
85
+ !this.hasSchemaOption('creatable')
86
+ )
83
87
  },
84
88
 
85
- isFormDeletable() {
86
- return this.schema.deletable !== false
89
+ isEditableDisabled() {
90
+ return (
91
+ this.disabled ||
92
+ !this.editPath ||
93
+ !this.hasSchemaOption('editable')
94
+ )
87
95
  },
88
96
 
89
97
  createButtonText() {
@@ -101,11 +109,13 @@ export default DitoComponent.component('DitoEditButtons', {
101
109
  },
102
110
 
103
111
  methods: {
104
- hasOption(name) {
105
- // The options of the outer component are passed to the buttons component
106
- // through properties `this[name]`, but can be disabled on a per-form
107
- // basis by setting `schema[name]` to `false`.
108
- return !!(this[name] && this.schema[name] !== false)
112
+ hasSchemaOption(name) {
113
+ // All options can be disabled on a per-form basis by setting
114
+ // `schema[name]` to `false` or a callback returning `false`.
115
+ return this.getSchemaValue(name, {
116
+ type: Boolean,
117
+ default: true
118
+ })
109
119
  }
110
120
  }
111
121
  })
@@ -26,14 +26,14 @@ export default DitoComponent.component('DitoElement', {
26
26
 
27
27
  classes() {
28
28
  return {
29
- ...this.$attrs.class,
29
+ ...asObject(this.$attrs.class),
30
30
  ...asObject(this.options.class)
31
31
  }
32
32
  },
33
33
 
34
34
  styles() {
35
35
  return {
36
- ...this.$attrs.style,
36
+ ...asObject(this.$attrs.style),
37
37
  ...asObject(this.options.style)
38
38
  }
39
39
  }
@@ -12,9 +12,10 @@
12
12
  v-show="!isActive"
13
13
  )
14
14
  //- Use a <div> for inlined forms, as we shouldn't nest actual <form> tags.
15
- component.dito-scroll-parent(
15
+ component(
16
16
  v-show="isActive"
17
17
  :is="isNestedRoute ? 'div' : 'form'"
18
+ :class="{ 'dito-scroll-parent': isRootForm }"
18
19
  @submit.prevent
19
20
  )
20
21
  //- Prevent implicit submission of the form, for example when typing enter
@@ -32,12 +33,12 @@
32
33
  :meta="meta"
33
34
  :store="store"
34
35
  :disabled="isLoading"
35
- :scrollable="!isNestedRoute"
36
- headerInMenu
36
+ :scrollable="isRootForm"
37
37
  generateLabels
38
38
  )
39
39
  template(#buttons)
40
- DitoButtons.dito-buttons-round.dito-buttons-main.dito-buttons-large(
40
+ DitoButtons.dito-buttons-round.dito-buttons-large.dito-buttons-main(
41
+ :class="{ 'dito-buttons-sticky': isRootForm }"
41
42
  :buttons="buttonSchemas"
42
43
  :dataPath="dataPath"
43
44
  :data="data"
@@ -122,6 +123,10 @@ export default DitoComponent.component('DitoForm', {
122
123
  )
123
124
  },
124
125
 
126
+ isRootForm() {
127
+ return this.dataPath === '' && !this.isNestedRoute
128
+ },
129
+
125
130
  isActive() {
126
131
  return this.isLastRoute || this.isLastUnnestedRoute
127
132
  },
@@ -85,13 +85,10 @@ export default DitoComponent.component('DitoHeader', {
85
85
  @include user-select(none);
86
86
 
87
87
  &::after {
88
- // Cover the gaps between the different headers that might appear due to
89
- // layout rounding imprecisions.
88
+ // Set the full-width header background to the header color.
90
89
  content: '';
91
- top: 0;
92
- bottom: 0;
93
- left: calc(100% - 1px);
94
- width: 2px;
90
+ inset: 0;
91
+ width: 100vw;
95
92
  position: absolute;
96
93
  background: inherit;
97
94
  z-index: -1;
@@ -175,5 +172,24 @@ export default DitoComponent.component('DitoHeader', {
175
172
  border-radius: 100%;
176
173
  }
177
174
  }
175
+
176
+ &__teleport {
177
+ // Align the teleported schema headers on top of to the header menu.
178
+ position: absolute;
179
+ inset: 0;
180
+ display: flex;
181
+ justify-content: flex-end;
182
+ padding: 0 $header-padding-hor;
183
+ // Turn off pointer events so that DitoTrail keeps receiving events...
184
+ pointer-events: none;
185
+ // ...but move them to the children.
186
+ > * {
187
+ pointer-events: auto;
188
+ }
189
+
190
+ .dito-button {
191
+ margin: 0 0 $tab-margin $tab-margin;
192
+ }
193
+ }
178
194
  }
179
195
  </style>
@@ -7,20 +7,23 @@ component.dito-label(
7
7
  )
8
8
  .dito-chevron(
9
9
  v-if="collapsible"
10
- :class="{ 'dito-opened': !collapsed }"
10
+ :class="{ 'dito-open': !collapsed }"
11
11
  )
12
- .dito-label__inner
13
- DitoElement.dito-label-prefix(
12
+ .dito-label__inner(
13
+ v-if="text || prefixes.length > 0 || suffixes.length > 0"
14
+ )
15
+ DitoElement.dito-label__prefix(
14
16
  v-for="(prefix, index) of prefixes"
15
17
  :key="`prefix-${index}`"
16
18
  tag="span"
17
19
  :content="prefix"
18
20
  )
19
21
  label(
22
+ v-if="text"
20
23
  :for="dataPath"
21
24
  v-html="text"
22
25
  )
23
- DitoElement.dito-label-suffix(
26
+ DitoElement.dito-label__suffix(
24
27
  v-for="(suffix, index) of suffixes"
25
28
  :key="`suffix-${index}`"
26
29
  tag="span"
@@ -30,7 +33,6 @@ component.dito-label(
30
33
  v-if="info"
31
34
  :data-info="info"
32
35
  )
33
- slot(name="edit-buttons")
34
36
  </template>
35
37
 
36
38
  <script>
@@ -39,7 +41,7 @@ import { isObject, asArray } from '@ditojs/utils'
39
41
 
40
42
  // @vue/component
41
43
  export default DitoComponent.component('DitoLabel', {
42
- emits: ['expand'],
44
+ emits: ['open'],
43
45
 
44
46
  props: {
45
47
  label: { type: [String, Object], default: null },
@@ -79,7 +81,7 @@ export default DitoComponent.component('DitoLabel', {
79
81
  methods: {
80
82
  onClick() {
81
83
  this.appState.activeLabel = this
82
- this.$emit('expand', this.collapsed)
84
+ this.$emit('open', this.collapsed)
83
85
  }
84
86
  }
85
87
  })
@@ -96,35 +98,45 @@ export default DitoComponent.component('DitoLabel', {
96
98
  position: relative;
97
99
  // Vertically center all items in the label, e.g. chevron, edit-buttons.
98
100
  align-items: center;
99
- margin: 0 $form-spacing-half $form-spacing-half 0;
101
+ min-height: $input-height;
102
+ margin-right: $form-spacing-half; // When inlined.
103
+
104
+ &:has(.dito-schema-header) {
105
+ // The container's label is used as teleport for a nested section or object
106
+ // label. Hide `&__inner`, as it is be duplicated inside the nested label.
107
+ > #{$self}__inner {
108
+ display: none;
109
+ }
110
+ }
100
111
 
101
- .dito-container:not(.dito-container--label-vertical) > & {
102
- // When labels are not vertical (e.g. compact layout, next to component),
103
- // clear bottom padding for better vertical alignment.
104
- margin-bottom: 0;
112
+ &:not(:has(+ .dito-tabs)) {
113
+ // Take full width but only if there aren't also tabs to be centered.
114
+ flex: 1;
105
115
  }
106
116
 
107
117
  &__inner {
108
118
  display: flex;
109
- // Stretch to full available width so that buttons appear right-aligned:
110
- flex: 1 1 auto;
119
+ flex: 1 0 0%;
120
+ overflow: hidden;
111
121
  }
112
122
 
113
123
  label {
114
124
  cursor: inherit;
115
125
  font-weight: bold;
116
- white-space: nowrap;
117
126
  }
118
127
 
119
128
  label,
120
- .dito-label-prefix,
121
- .dito-label-suffix {
129
+ &__prefix,
130
+ &__suffix {
122
131
  @include user-select(none);
123
132
  @include ellipsis;
133
+
134
+ white-space: nowrap;
135
+ line-height: $input-height;
124
136
  }
125
137
 
126
- .dito-label-prefix + label,
127
- label + .dito-label-suffix {
138
+ &__prefix + label,
139
+ label + &__suffix {
128
140
  &::before {
129
141
  content: '\a0'; // &nbsp;
130
142
  }
@@ -140,11 +152,17 @@ export default DitoComponent.component('DitoLabel', {
140
152
 
141
153
  &.dito-width-fill {
142
154
  width: 100%;
155
+
143
156
  // In order for ellipsis to work on labels without affecting other layout,
144
- // we need to position it absolutely inside its container.
145
- #{$self}__inner {
146
- position: absolute;
147
- inset: 0;
157
+ // we need to position it absolutely inside its container. But we can only
158
+ // do so if there is't also a chevron or other UX elements besides it.
159
+ &:has(> #{$self}__inner:only-child) {
160
+ flex: 1; // When in `.dito-schema-header`.
161
+
162
+ > #{$self}__inner {
163
+ position: absolute;
164
+ inset: 0;
165
+ }
148
166
  }
149
167
 
150
168
  &::after {