@conduction/nextcloud-vue 2.56.0-beta.15 → 2.56.0-beta.16

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.
@@ -2134,7 +2134,12 @@ var script = {
2134
2134
  * the new object. When the referenced schema cannot be loaded, the
2135
2135
  * term alone is saved as before, so the field never dead-ends.
2136
2136
  *
2137
+ * The form is the one the schema's index page shows for its own Add
2138
+ * button: that page's `createOverride` saves it and its form settings
2139
+ * shape it, with the typed term in the name.
2140
+ *
2137
2141
  * @spec openspec/changes/form-pickers-from-schema/specs/schema-utilities/spec.md
2142
+ * @spec openspec/changes/nested-create-uses-page-config/specs/schema-utilities/spec.md
2138
2143
  * @param {object} field The reference field descriptor.
2139
2144
  * @param {string} term The typed search term.
2140
2145
  * @return {Promise<object|null>} The created object, or null.
@@ -2151,21 +2156,37 @@ var script = {
2151
2156
  store.registerObjectType(slug, schemaRef, register);
2152
2157
  }
2153
2158
  const labelField = this.referenceLabelField(field);
2159
+ const loadSchema = async () => {
2160
+ try {
2161
+ return await store.fetchSchema(slug)
2162
+ } catch {
2163
+ return null
2164
+ }
2165
+ };
2154
2166
  // The app may own how this schema is created (pipelinq's client and
2155
2167
  // contact need a contact-first endpoint; a plain save 400s). A
2156
2168
  // create override keeps this form and saves through the app's
2157
2169
  // handler; a create modal (only when no override exists) opens the
2158
2170
  // app's own dialog instead of the generic form.
2159
- const appCreate = this.appCreateFor(register, schemaRef);
2171
+ //
2172
+ // A stored schema usually names its reference by id (`$ref: 28`)
2173
+ // while the manifest page names it by slug (`schema: 'client'`), so
2174
+ // when the reference itself matches no page, the referenced schema
2175
+ // is loaded and its slug, id and uuid are tried too.
2176
+ let schema;
2177
+ let appCreate = this.appCreateFor(register, [schemaRef]);
2178
+ if (!appCreate.page) {
2179
+ schema = await loadSchema();
2180
+ if (schema) {
2181
+ appCreate = this.appCreateFor(register, [schemaRef, schema.slug, schema.id, schema.uuid]);
2182
+ }
2183
+ }
2160
2184
  if (!appCreate.override && appCreate.modal) {
2161
2185
  return this.openAppCreateModal(appCreate.modal, store, slug, labelField, term)
2162
2186
  }
2163
2187
  const override = appCreate.override;
2164
- let schema = null;
2165
- try {
2166
- schema = await store.fetchSchema(slug);
2167
- } catch {
2168
- schema = null;
2188
+ if (schema === undefined) {
2189
+ schema = await loadSchema();
2169
2190
  }
2170
2191
  if (!schema || !schema.properties) {
2171
2192
  const payload = { [labelField]: term };
@@ -2174,36 +2195,84 @@ var script = {
2174
2195
  : store.saveObject(slug, payload)
2175
2196
  }
2176
2197
  const initialData = {};
2177
- if (term && schema.properties[labelField]) {
2178
- initialData[labelField] = term;
2198
+ const prefillKey = this.nestedPrefillKey(schema, labelField);
2199
+ if (term && prefillKey) {
2200
+ initialData[prefillKey] = term;
2179
2201
  }
2202
+ const form = appCreate.form || this.nestedFormConfig(null);
2180
2203
  return new Promise((resolve) => {
2181
- this.nestedCreate = { field, schema, register, slug, schemaRef, initialData, override, resolve };
2204
+ this.nestedCreate = { field, schema, register, slug, schemaRef, initialData, override, form, resolve };
2182
2205
  })
2183
2206
  },
2184
2207
 
2208
+ /**
2209
+ * The property of the referenced schema the typed term belongs in: the
2210
+ * reference's label field when the schema has it, else its name, title
2211
+ * or label. Visibility is decided by the form (a page `fieldOverrides`
2212
+ * entry can make a read-only name editable), not here.
2213
+ *
2214
+ * @spec openspec/changes/nested-create-uses-page-config/specs/schema-utilities/spec.md
2215
+ * @param {object} schema The referenced schema.
2216
+ * @param {string} labelField The reference's label field.
2217
+ * @return {string|null} The property key, or null when none fits.
2218
+ */
2219
+ nestedPrefillKey(schema, labelField) {
2220
+ const properties = (schema && schema.properties) || {};
2221
+ return [labelField, 'name', 'title', 'label'].find((key) => properties[key]) || null
2222
+ },
2223
+
2224
+ /**
2225
+ * The create-form settings of the index page that lists a schema, in
2226
+ * the shape the nested CnFormDialog binds: the same `excludeFields`,
2227
+ * `includeFields`, `fieldOverrides`, `formSize` and `formColumns`
2228
+ * CnIndexPage hands its own Add form, so creating from a picker shows
2229
+ * the form the page shows. Without a page, the form's defaults.
2230
+ *
2231
+ * @spec openspec/changes/nested-create-uses-page-config/specs/schema-utilities/spec.md
2232
+ * @param {object|null} config The page's `config`, or null.
2233
+ * @return {{excludeFields: string[], includeFields: (string[]|null), fieldOverrides: object, size: string, columns: number}} The form settings.
2234
+ */
2235
+ nestedFormConfig(config) {
2236
+ const c = config || {};
2237
+ const isMap = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
2238
+ return {
2239
+ excludeFields: Array.isArray(c.excludeFields) ? c.excludeFields : [],
2240
+ includeFields: Array.isArray(c.includeFields) ? c.includeFields : null,
2241
+ fieldOverrides: isMap(c.fieldOverrides) ? c.fieldOverrides : {},
2242
+ size: typeof c.formSize === 'string' && c.formSize !== '' ? c.formSize : 'normal',
2243
+ columns: c.formColumns === 2 ? 2 : 1,
2244
+ }
2245
+ },
2246
+
2185
2247
  /**
2186
2248
  * How the app creates objects of a schema, read off the manifest page
2187
2249
  * that lists them: the index page whose `config.schema` (and, when it
2188
2250
  * names one, `config.register`) matches. Its `config.createOverride` is
2189
2251
  * resolved to the registered handler; its `config.createModal` is the
2190
- * registry key of a `kind: 'modal'` dialog.
2252
+ * registry key of a `kind: 'modal'` dialog; its form settings
2253
+ * (`fieldOverrides` and friends) shape the nested form.
2191
2254
  *
2192
- * @spec openspec/changes/review-round-two/specs/schema-utilities/spec.md
2255
+ * The schema is matched on any of the given references, so a caller
2256
+ * holding the referenced schema can pass its slug, id and uuid: the
2257
+ * manifest names a schema by slug, a stored `$ref` often by id.
2258
+ *
2259
+ * @spec openspec/changes/nested-create-uses-page-config/specs/schema-utilities/spec.md
2193
2260
  * @param {string} register The reference's register.
2194
- * @param {string} schemaRef The reference's schema slug or id.
2195
- * @return {{override: (((formData: object, ctx: object) => Promise<object>)|null), modal: (string|null)}} What the app declared.
2261
+ * @param {string|Array<string|number>} schemaRefs The schema's slug, id or uuid, one or several.
2262
+ * @return {{page: (object|null), override: (((formData: object, ctx: object) => Promise<object>)|null), modal: (string|null), form: (object|null)}} What the app declared.
2196
2263
  */
2197
- appCreateFor(register, schemaRef) {
2198
- const none = { override: null, modal: null };
2264
+ appCreateFor(register, schemaRefs) {
2265
+ const none = { page: null, override: null, modal: null, form: null };
2199
2266
  const pages = this.cnManifest && Array.isArray(this.cnManifest.pages) ? this.cnManifest.pages : [];
2200
- const wanted = String(schemaRef).toLowerCase();
2267
+ const wanted = (Array.isArray(schemaRefs) ? schemaRefs : [schemaRefs])
2268
+ .filter((ref) => ref !== undefined && ref !== null && ref !== '')
2269
+ .map((ref) => String(ref).toLowerCase());
2201
2270
  const page = pages.find((p) => {
2202
2271
  const config = p && p.config;
2203
2272
  if (!config || config.schema === undefined || config.schema === null) {
2204
2273
  return false
2205
2274
  }
2206
- if (String(config.schema).toLowerCase() !== wanted) {
2275
+ if (!wanted.includes(String(config.schema).toLowerCase())) {
2207
2276
  return false
2208
2277
  }
2209
2278
  return !config.register || String(config.register) === String(register)
@@ -2221,7 +2290,7 @@ var script = {
2221
2290
  const modal = modalEntry && modalEntry.kind === 'modal' && typeof this.cnOpenModal === 'function'
2222
2291
  ? config.createModal
2223
2292
  : null;
2224
- return { override: override || null, modal }
2293
+ return { page, override: override || null, modal, form: this.nestedFormConfig(config) }
2225
2294
  },
2226
2295
 
2227
2296
  /**