@easy-cms/plugin-nested-docs 0.24.0 → 0.26.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 +52 -9
- package/dist/index.js +3 -2
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { AccessOptions,
|
|
1
|
+
import { AccessOptions, Config, SlugOf, EasyCMS, DocumentOf, TypedPlugin } from '@easy-cms/core';
|
|
2
2
|
|
|
3
3
|
type ID = string | number;
|
|
4
|
-
type Doc = Record<string, unknown>;
|
|
5
4
|
/** One step of a page's trail, from the top-level page down to the page itself. */
|
|
6
5
|
interface Breadcrumb {
|
|
7
6
|
/** The page's id; `null` on the page's own step while it is being created. */
|
|
@@ -34,10 +33,10 @@ interface FindByPathOptions extends AccessOptions {
|
|
|
34
33
|
readonly depth?: number;
|
|
35
34
|
}
|
|
36
35
|
/**
|
|
37
|
-
* The page at a path, e.g. `findByPath(cms, 'pages', '/about/team')`, or `null
|
|
38
|
-
* the page's own: take the locale prefix or other routing off first.
|
|
36
|
+
* The page at a path, e.g. `findByPath(cms, 'pages', '/about/team')`, or `null`, typed from
|
|
37
|
+
* your config. The path is the page's own: take the locale prefix or other routing off first.
|
|
39
38
|
*/
|
|
40
|
-
declare function findByPath(instance:
|
|
39
|
+
declare function findByPath<C extends Config, S extends SlugOf<C>>(instance: EasyCMS<C>, collection: S, path: string, options?: FindByPathOptions): Promise<DocumentOf<C, S> | null>;
|
|
41
40
|
/** A page in `getTree()`: what a menu or sidebar needs, and the pages under it. */
|
|
42
41
|
interface TreeNode {
|
|
43
42
|
readonly id: ID;
|
|
@@ -55,13 +54,13 @@ interface GetTreeOptions extends AccessOptions {
|
|
|
55
54
|
* Published pages as a tree, top-level pages first, in the list's order (`admin.list.sort`,
|
|
56
55
|
* else by title). Pages under an unpublished page are left out with it.
|
|
57
56
|
*/
|
|
58
|
-
declare function getTree(instance:
|
|
57
|
+
declare function getTree<C extends Config>(instance: EasyCMS<C>, collection: SlugOf<C>, options?: GetTreeOptions): Promise<TreeNode[]>;
|
|
59
58
|
/**
|
|
60
59
|
* Works out every page's breadcrumbs and path again, from the top level down, and saves the
|
|
61
60
|
* pages whose values changed. For pages that existed before the plugin, or to repair them.
|
|
62
61
|
* Pages whose parent was deleted move to the top level.
|
|
63
62
|
*/
|
|
64
|
-
declare function rebuildNestedDocs(instance:
|
|
63
|
+
declare function rebuildNestedDocs<C extends Config>(instance: EasyCMS<C>, collection: SlugOf<C>): Promise<{
|
|
65
64
|
checked: number;
|
|
66
65
|
updated: number;
|
|
67
66
|
}>;
|
|
@@ -92,6 +91,50 @@ interface NestedDocsPluginOptions {
|
|
|
92
91
|
* (`/about/team`), kept up to date when a page above it moves or changes its slug, and a tree
|
|
93
92
|
* in the admin's list.
|
|
94
93
|
*/
|
|
95
|
-
|
|
94
|
+
/** The fields the plugin adds to collection `S`, as the inferred document types see them. */
|
|
95
|
+
type NestedDocsFields<S extends string, P extends string = 'parent', B extends string = 'breadcrumbs', T extends string = 'path'> = readonly [
|
|
96
|
+
{
|
|
97
|
+
readonly name: P;
|
|
98
|
+
readonly type: 'relationship';
|
|
99
|
+
readonly to: S;
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
readonly name: T;
|
|
103
|
+
readonly type: 'text';
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
readonly name: B;
|
|
107
|
+
readonly type: 'array';
|
|
108
|
+
readonly fields: readonly [
|
|
109
|
+
{
|
|
110
|
+
readonly name: 'doc';
|
|
111
|
+
readonly type: 'relationship';
|
|
112
|
+
readonly to: S;
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
readonly name: 'label';
|
|
116
|
+
readonly type: 'text';
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
readonly name: 'url';
|
|
120
|
+
readonly type: 'text';
|
|
121
|
+
}
|
|
122
|
+
];
|
|
123
|
+
}
|
|
124
|
+
];
|
|
125
|
+
/** What `nestedDocsPlugin(options)` adds: its fields on each of its collections. */
|
|
126
|
+
type NestedDocsPluginTypes<S extends string, P extends string = 'parent', B extends string = 'breadcrumbs', T extends string = 'path'> = {
|
|
127
|
+
readonly fields: {
|
|
128
|
+
readonly [K in S]: NestedDocsFields<K, P, B, T>;
|
|
129
|
+
};
|
|
130
|
+
};
|
|
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
|
+
readonly collections: readonly S[];
|
|
133
|
+
readonly fields?: {
|
|
134
|
+
readonly parent?: P;
|
|
135
|
+
readonly breadcrumbs?: B;
|
|
136
|
+
readonly path?: T;
|
|
137
|
+
};
|
|
138
|
+
}): TypedPlugin<NestedDocsPluginTypes<S, P, B, T>>;
|
|
96
139
|
|
|
97
|
-
export { type Breadcrumb, type FindByPathOptions, type GetTreeOptions, type NestedCMS, type NestedDocsPluginOptions, type TreeNode, findByPath, getTree, nestedDocsPlugin, normalizePath, rebuildNestedDocs };
|
|
140
|
+
export { type Breadcrumb, type FindByPathOptions, type GetTreeOptions, type NestedCMS, type NestedDocsFields, type NestedDocsPluginOptions, type NestedDocsPluginTypes, type TreeNode, findByPath, getTree, nestedDocsPlugin, normalizePath, rebuildNestedDocs };
|
package/dist/index.js
CHANGED
|
@@ -240,12 +240,13 @@ function stripIds(value) {
|
|
|
240
240
|
|
|
241
241
|
// src/plugin.ts
|
|
242
242
|
import {
|
|
243
|
+
definePlugin,
|
|
243
244
|
NotFoundError,
|
|
244
245
|
ValidationError
|
|
245
246
|
} from "@easy-cms/core";
|
|
246
247
|
var ADMIN_MODULE = "@easy-cms/plugin-nested-docs/admin";
|
|
247
248
|
function nestedDocsPlugin(options) {
|
|
248
|
-
return (config) => {
|
|
249
|
+
return definePlugin((config) => {
|
|
249
250
|
const slugs = options.collections ?? [];
|
|
250
251
|
if (!Array.isArray(slugs) || slugs.length === 0)
|
|
251
252
|
throw new Error("nestedDocsPlugin: list the collections, e.g. { collections: ['pages'] }");
|
|
@@ -494,7 +495,7 @@ pages after an error. Default: every collection of nestedDocsPlugin (${slugs.joi
|
|
|
494
495
|
modules: [.../* @__PURE__ */ new Set([...config.admin?.modules ?? [], ADMIN_MODULE])]
|
|
495
496
|
}
|
|
496
497
|
};
|
|
497
|
-
};
|
|
498
|
+
});
|
|
498
499
|
}
|
|
499
500
|
export {
|
|
500
501
|
findByPath,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easy-cms/plugin-nested-docs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.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.
|
|
20
|
+
"@easy-cms/core": "^0.26.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@easy-cms/core": "^0.
|
|
24
|
-
"@easy-cms/db-sqlite": "^0.
|
|
25
|
-
"@easy-cms/plugin-redirects": "^0.
|
|
23
|
+
"@easy-cms/core": "^0.26.0",
|
|
24
|
+
"@easy-cms/db-sqlite": "^0.26.0",
|
|
25
|
+
"@easy-cms/plugin-redirects": "^0.26.0"
|
|
26
26
|
},
|
|
27
27
|
"engines": {
|
|
28
28
|
"node": ">=22.12"
|