@ditojs/admin 2.10.1 → 2.10.3

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": "@ditojs/admin",
3
- "version": "2.10.1",
3
+ "version": "2.10.3",
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,7 +33,7 @@
33
33
  "not ie_mob > 0"
34
34
  ],
35
35
  "dependencies": {
36
- "@ditojs/ui": "^2.10.0",
36
+ "@ditojs/ui": "^2.10.2",
37
37
  "@ditojs/utils": "^2.10.0",
38
38
  "@kyvg/vue3-notification": "^2.9.1",
39
39
  "@lk77/vue3-color": "^3.0.6",
@@ -78,12 +78,12 @@
78
78
  "@vitejs/plugin-vue": "^4.2.3",
79
79
  "@vue/compiler-sfc": "^3.3.4",
80
80
  "pug": "^3.0.2",
81
- "sass": "1.62.1",
81
+ "sass": "1.63.2",
82
82
  "typescript": "^5.1.3",
83
83
  "vite": "^4.3.9"
84
84
  },
85
85
  "types": "types",
86
- "gitHead": "add6bbbdd21d0980af235994b96c4641ace5eeda",
86
+ "gitHead": "64c92430531216d8f463835bc07c4ac8e2370bf0",
87
87
  "scripts": {
88
88
  "build": "vite build",
89
89
  "watch": "yarn build --mode 'development' --watch",
@@ -22,7 +22,7 @@ const contexts = new WeakMap()
22
22
 
23
23
  function get(context, key, defaultValue) {
24
24
  const object = contexts.get(toRaw(context))
25
- const value = object[key]
25
+ const value = key in object ? object[key] : undefined
26
26
  // If `object` explicitly sets the key to `undefined`, return it.
27
27
  return value !== undefined || hasOwnProperty.call(object, key)
28
28
  ? value
@@ -1,7 +1,14 @@
1
1
  <template lang="pug">
2
2
  .dito-create-button
3
+ button.dito-button(
4
+ v-if="creatableForm"
5
+ :type="isInlined ? 'button' : 'submit'"
6
+ :disabled="disabled"
7
+ v-bind="getButtonAttributes(verb)"
8
+ @click="createItem(creatableForm)"
9
+ ) {{ text }}
3
10
  template(
4
- v-if="showPulldown"
11
+ v-else-if="creatableForms"
5
12
  )
6
13
  button.dito-button(
7
14
  type="button"
@@ -11,22 +18,14 @@
11
18
  ) {{ text }}
12
19
  ul.dito-pulldown(:class="{ 'dito-open': pulldown.open }")
13
20
  li(
14
- v-for="(form, type) in forms"
21
+ v-for="(form, type) in creatableForms"
15
22
  )
16
23
  a(
17
- v-if="isFormCreatable(form)"
18
24
  v-show="shouldShowSchema(form)"
19
25
  :class="getFormClass(form, type)"
20
26
  @mousedown.stop="onPulldownMouseDown(type)"
21
27
  @mouseup="onPulldownMouseUp(type)"
22
28
  ) {{ getLabel(form) }}
23
- button.dito-button(
24
- v-else-if="isFormCreatable(forms.default)"
25
- :type="isInlined ? 'button' : 'submit'"
26
- :disabled="disabled"
27
- v-bind="getButtonAttributes(verb)"
28
- @click="createItem(forms.default)"
29
- ) {{ text }}
30
29
  </template>
31
30
 
32
31
  <script>
@@ -64,16 +63,22 @@ export default DitoComponent.component('DitoCreateButton', {
64
63
  return getFormSchemas(this.schema, this.context)
65
64
  },
66
65
 
67
- isInlined() {
68
- return isInlined(this.schema)
66
+ creatableForms() {
67
+ const entries = Object.entries(this.forms).filter(
68
+ (type, form) => this.isFormCreatable(form)
69
+ )
70
+ return entries.length > 0
71
+ ? Object.fromEntries(entries)
72
+ : null
69
73
  },
70
74
 
71
- showPulldown() {
72
- const forms = Object.values(this.forms)
73
- return (
74
- (forms.length > 1 || !this.forms.default) &&
75
- forms.some(this.isFormCreatable)
76
- )
75
+ creatableForm() {
76
+ const forms = this.creatableForms
77
+ return forms && Object.keys(forms).length === 1 && forms.default || null
78
+ },
79
+
80
+ isInlined() {
81
+ return isInlined(this.schema)
77
82
  }
78
83
  },
79
84
 
@@ -92,7 +97,7 @@ export default DitoComponent.component('DitoCreateButton', {
92
97
  },
93
98
 
94
99
  createItem(form, type = null) {
95
- if (this.isFormCreatable(form) && !this.shouldDisableSchema(form)) {
100
+ if (!this.shouldDisableSchema(form)) {
96
101
  if (this.isInlined) {
97
102
  this.sourceComponent.createItem(form, type)
98
103
  } else {
@@ -90,10 +90,6 @@ export default DitoComponent.component('DitoPanel', {
90
90
  return getButtonSchemas(this.schema.panelButtons)
91
91
  },
92
92
 
93
- target() {
94
- return this.schema.target || this.dataPath
95
- },
96
-
97
93
  hasOwnData() {
98
94
  return !!this.ownData
99
95
  },
@@ -17,7 +17,7 @@ export default {
17
17
  },
18
18
 
19
19
  mouseup: () => {
20
- if (this.onPulldownMouseUp(null)) {
20
+ if (this.onPulldownMouseUp()) {
21
21
  this.pulldown.handlers.remove()
22
22
  }
23
23
  }
@@ -28,8 +28,8 @@ export default {
28
28
  },
29
29
 
30
30
  methods: {
31
- onPulldownMouseDown(value) {
32
- if (!value) {
31
+ onPulldownMouseDown(value = null) {
32
+ if (value === null) {
33
33
  this.setPulldownOpen(true)
34
34
  this.checkTime = true
35
35
  } else {
@@ -37,11 +37,11 @@ export default {
37
37
  }
38
38
  },
39
39
 
40
- onPulldownMouseUp(value) {
40
+ onPulldownMouseUp(value = null) {
41
41
  const { startTime } = this.pulldown
42
42
  if (!this.checkTime || startTime && (Date.now() - startTime > 250)) {
43
43
  this.setPulldownOpen(false)
44
- if (value) {
44
+ if (value !== null) {
45
45
  this.onPulldownSelect(value)
46
46
  }
47
47
  return true
@@ -69,7 +69,6 @@ export function createFiltersPanel(api, filters, dataPath, query) {
69
69
  type: 'panel',
70
70
  label: 'Filters',
71
71
  name: '$filters',
72
- target: dataPath,
73
72
  // Override the default value
74
73
  disabled: false,
75
74
  sticky,
@@ -152,6 +151,15 @@ function createFiltersButtons(small) {
152
151
  }
153
152
  }
154
153
 
154
+ function getDataName(filterName) {
155
+ // Prefix filter data keys with '$' to avoid conflicts with other data keys:
156
+ return `$${filterName}`
157
+ }
158
+
159
+ function getFilterName(dataName) {
160
+ return dataName.startsWith('$') ? dataName.slice(1) : null
161
+ }
162
+
155
163
  function createFiltersComponents(filters) {
156
164
  const comps = {}
157
165
  for (const filter of Object.values(getNamedSchemas(filters) || {})) {
@@ -177,8 +185,8 @@ function createFiltersComponents(filters) {
177
185
  }
178
186
  }
179
187
  }
180
- comps[filter.name] = {
181
- label: form.label,
188
+ comps[getDataName(filter.name)] = {
189
+ label: form.label ?? labelize(filter.name),
182
190
  type: 'object',
183
191
  width,
184
192
  default: () => ({}),
@@ -194,23 +202,31 @@ function createFiltersComponents(filters) {
194
202
  return comps
195
203
  }
196
204
 
197
- function getComponentsForFilter(schema, name) {
198
- const component = schema.components[name]
205
+ function getComponentsForFilter(schema, dataName) {
206
+ const component = schema.components[dataName]
199
207
  return component?.form?.components
200
208
  }
201
209
 
202
210
  function formatFiltersData(schema, data) {
203
211
  const filters = []
204
- for (const name in data) {
205
- const entry = data[name]
212
+ for (const dataName in data) {
213
+ const entry = data[dataName]
206
214
  if (entry) {
207
215
  // Map components sequence to arguments:
208
- const args = Object.keys(getComponentsForFilter(schema, name)).map(
216
+ const args = Object.keys(
217
+ getComponentsForFilter(schema, dataName)
218
+ ).map(
209
219
  key => entry[key] ?? null
210
220
  )
211
221
  // Only apply filter if there are some arguments that aren't null:
212
222
  if (args.some(value => value !== null)) {
213
- filters.push(`${name}:${args.map(JSON.stringify).join(',')}`)
223
+ filters.push(
224
+ `${
225
+ getFilterName(dataName)
226
+ }:${
227
+ args.map(JSON.stringify).join(',')
228
+ }`
229
+ )
214
230
  }
215
231
  }
216
232
  }
@@ -223,20 +239,20 @@ function parseFiltersData(schema, query) {
223
239
  // from $route.query back to param lists per filter:
224
240
  if (query) {
225
241
  for (const filter of asArray(query.filter)) {
226
- const [, name, json] = filter.match(/^(\w+):(.*)$/)
242
+ const [, filterName, json] = filter.match(/^(\w+):(.*)$/)
227
243
  try {
228
- filters[name] = asArray(JSON.parse(`[${json}]`))
244
+ filters[filterName] = asArray(JSON.parse(`[${json}]`))
229
245
  } catch (error) {}
230
246
  }
231
247
  }
232
248
  const filtersData = {}
233
- for (const name in schema.components) {
249
+ for (const dataName in schema.components) {
234
250
  const data = {}
235
251
  // If we have retrieved params from the query, fetch the associated
236
252
  // form components so we can map the values back to object keys:
237
- const args = filters[name]
253
+ const args = filters[getFilterName(dataName)]
238
254
  if (args) {
239
- const components = getComponentsForFilter(schema, name)
255
+ const components = getComponentsForFilter(schema, dataName)
240
256
  if (components) {
241
257
  let index = 0
242
258
  for (const key in components) {
@@ -244,7 +260,7 @@ function parseFiltersData(schema, query) {
244
260
  }
245
261
  }
246
262
  }
247
- filtersData[name] = data
263
+ filtersData[dataName] = data
248
264
  }
249
265
  return filtersData
250
266
  }
@@ -847,10 +847,9 @@ export function processSchemaData(
847
847
  : componentDataPath
848
848
  const context = new DitoContext(options.component, {
849
849
  schema: componentSchema,
850
- data: item,
851
- value: item,
852
- dataPath: itemDataPath,
853
- index,
850
+ data,
851
+ dataPath: componentDataPath,
852
+ name,
854
853
  rootData: options.rootData
855
854
  })
856
855
  const getForms = (