@easy-cms/plugin-nested-docs 0.47.4 → 0.49.0

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/index.d.ts CHANGED
@@ -73,7 +73,7 @@ interface NestedDocsPluginOptions {
73
73
  /** The field shown in breadcrumbs. Default the collection's `useAsTitle`, else the slug. */
74
74
  readonly titleField?: string;
75
75
  /** Names of the fields the plugin adds. Default `parent`, `breadcrumbs` and `path`. */
76
- readonly fields?: {
76
+ readonly fieldNames?: {
77
77
  readonly parent?: string;
78
78
  readonly breadcrumbs?: string;
79
79
  readonly path?: string;
@@ -130,7 +130,7 @@ type NestedDocsPluginTypes<S extends string, P extends string = 'parent', B exte
130
130
  };
131
131
  declare function nestedDocsPlugin<const S extends string, const P extends string = 'parent', const B extends string = 'breadcrumbs', const T extends string = 'path'>(options: NestedDocsPluginOptions & {
132
132
  readonly collections: readonly S[];
133
- readonly fields?: {
133
+ readonly fieldNames?: {
134
134
  readonly parent?: P;
135
135
  readonly breadcrumbs?: B;
136
136
  readonly path?: T;
package/dist/index.js CHANGED
@@ -262,16 +262,20 @@ import {
262
262
  NotFoundError,
263
263
  ValidationError
264
264
  } from "@easy-cms/core";
265
+ import { checkRenamedOptions } from "@easy-cms/core/internal";
265
266
 
266
267
  // src/info.ts
267
268
  var INFO = {
268
269
  name: "@easy-cms/plugin-nested-docs",
269
- ...true ? { version: "0.47.4" } : {}
270
+ // The plugin API it is written for (`PLUGIN_API_VERSION` of @easy-cms/core).
271
+ apiVersion: 1,
272
+ ...true ? { version: "0.49.0" } : {}
270
273
  };
271
274
 
272
275
  // src/plugin.ts
273
276
  var ADMIN_MODULE = "@easy-cms/plugin-nested-docs/admin";
274
277
  function nestedDocsPlugin(options) {
278
+ checkRenamedOptions("nestedDocsPlugin", options, { fields: "fieldNames" });
275
279
  return definePlugin((config) => {
276
280
  const slugs = options.collections ?? [];
277
281
  if (!Array.isArray(slugs) || slugs.length === 0)
@@ -290,8 +294,8 @@ function nestedDocsPlugin(options) {
290
294
  const localization = config.localization;
291
295
  const source = {
292
296
  collections: /* @__PURE__ */ new Map(),
293
- locales: localization?.locales ?? [],
294
- defaultLocale: localization?.defaultLocale ?? null
297
+ locales: (localization || void 0)?.locales ?? [],
298
+ defaultLocale: (localization || void 0)?.defaultLocale ?? null
295
299
  };
296
300
  const withNesting = (collection) => {
297
301
  if (!slugs.includes(collection.slug)) return collection;
@@ -304,18 +308,18 @@ function nestedDocsPlugin(options) {
304
308
  if (!collection.fields.some((f) => f.name === titleField))
305
309
  throw new Error(`${where} has no field "${titleField}" for breadcrumbs`);
306
310
  const names = {
307
- parent: options.fields?.parent ?? "parent",
308
- breadcrumbs: options.fields?.breadcrumbs ?? "breadcrumbs",
309
- path: options.fields?.path ?? "path"
311
+ parent: options.fieldNames?.parent ?? "parent",
312
+ breadcrumbs: options.fieldNames?.breadcrumbs ?? "breadcrumbs",
313
+ path: options.fieldNames?.path ?? "path"
310
314
  };
311
315
  const ownParent = collection.fields.find((f) => f.name === names.parent);
312
316
  if (ownParent && !(ownParent.type === "relationship" && ownParent.to === collection.slug && !ownParent.hasMany))
313
317
  throw new Error(
314
- `${where} has a field "${names.parent}" that is not a relationship to "${collection.slug}"; set \`fields\``
318
+ `${where} has a field "${names.parent}" that is not a relationship to "${collection.slug}"; set \`fieldNames\``
315
319
  );
316
320
  for (const name of [names.breadcrumbs, names.path])
317
321
  if (collection.fields.some((f) => f.name === name))
318
- throw new Error(`${where} already has a field "${name}"; set \`fields\``);
322
+ throw new Error(`${where} already has a field "${name}"; set \`fieldNames\``);
319
323
  const localized = !!localization && slug.localized === true;
320
324
  const nested = {
321
325
  slug: collection.slug,
@@ -335,7 +339,7 @@ function nestedDocsPlugin(options) {
335
339
  const readOnly = { update: () => false };
336
340
  const parentField = {
337
341
  label: { en: "Parent page", th: "\u0E2B\u0E19\u0E49\u0E32\u0E41\u0E21\u0E48" },
338
- position: "sidebar",
342
+ admin: { position: "sidebar" },
339
343
  ...ownParent,
340
344
  name: names.parent,
341
345
  type: "relationship",
@@ -350,7 +354,7 @@ function nestedDocsPlugin(options) {
350
354
  label: { en: "Path", th: "\u0E40\u0E2A\u0E49\u0E19\u0E17\u0E32\u0E07 (path)" },
351
355
  index: true,
352
356
  localized,
353
- position: "sidebar",
357
+ admin: { position: "sidebar" },
354
358
  access: readOnly
355
359
  },
356
360
  {
@@ -358,9 +362,9 @@ function nestedDocsPlugin(options) {
358
362
  type: "array",
359
363
  label: { en: "Breadcrumbs", th: "\u0E40\u0E2A\u0E49\u0E19\u0E17\u0E32\u0E07\u0E19\u0E33\u0E17\u0E32\u0E07" },
360
364
  localized,
361
- position: "sidebar",
362
365
  access: readOnly,
363
366
  admin: {
367
+ position: "sidebar",
364
368
  component: {
365
369
  tag: "ecms-nested-breadcrumbs",
366
370
  props: {
@@ -380,10 +384,10 @@ function nestedDocsPlugin(options) {
380
384
  ...data,
381
385
  [names.breadcrumbs]: localized ? Object.fromEntries(source.locales.map((l) => [l, []])) : []
382
386
  });
383
- const computeTrail = async ({ data, originalDoc, cms }) => {
384
- const selfId = idOf(originalDoc?.id);
387
+ const computeTrail = async ({ data, previousDoc, cms }) => {
388
+ const selfId = idOf(previousDoc?.id);
385
389
  const parentId = idOf(data[names.parent]);
386
- if (parentId !== null && selfId !== null && parentId !== idOf(originalDoc?.[names.parent]) && (String(parentId) === String(selfId) || (await descendants(cms, nested, selfId)).some((d) => String(d) === String(parentId)))) {
390
+ if (parentId !== null && selfId !== null && parentId !== idOf(previousDoc?.[names.parent]) && (String(parentId) === String(selfId) || (await descendants(cms, nested, selfId)).some((d) => String(d) === String(parentId)))) {
387
391
  throw new ValidationError(collection.slug, [
388
392
  { field: names.parent, message: "cannot be this page or a page under it" }
389
393
  ]);
@@ -520,7 +524,7 @@ pages after an error. Default: every collection of nestedDocsPlugin (${slugs.joi
520
524
  ...config,
521
525
  collections,
522
526
  endpoints: [...config.endpoints ?? [], tree],
523
- commands: [...config.commands ?? [], rebuild],
527
+ cliCommands: [...config.cliCommands ?? [], rebuild],
524
528
  admin: {
525
529
  ...config.admin,
526
530
  modules: [.../* @__PURE__ */ new Set([...config.admin?.modules ?? [], ADMIN_MODULE])]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easy-cms/plugin-nested-docs",
3
- "version": "0.47.4",
3
+ "version": "0.49.0",
4
4
  "description": "Nested pages for Easy CMS: a parent for each page, breadcrumbs and full paths kept up to date, and a tree in the admin",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -17,12 +17,12 @@
17
17
  "dist"
18
18
  ],
19
19
  "peerDependencies": {
20
- "@easy-cms/core": "^0.47.4"
20
+ "@easy-cms/core": "^0.49.0"
21
21
  },
22
22
  "devDependencies": {
23
- "@easy-cms/core": "^0.47.4",
24
- "@easy-cms/db-sqlite": "^0.47.4",
25
- "@easy-cms/plugin-redirects": "^0.47.4"
23
+ "@easy-cms/core": "^0.49.0",
24
+ "@easy-cms/plugin-redirects": "^0.49.0",
25
+ "@easy-cms/db-sqlite": "^0.49.0"
26
26
  },
27
27
  "engines": {
28
28
  "node": ">=22.12"