@webiny/app-headless-cms-common 0.0.0-unstable.085ff6572f
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/LICENSE +21 -0
- package/README.md +18 -0
- package/createFieldsList.d.ts +7 -0
- package/createFieldsList.js +35 -0
- package/createFieldsList.js.map +1 -0
- package/entries.graphql.d.ts +146 -0
- package/entries.graphql.js +115 -0
- package/entries.graphql.js.map +1 -0
- package/getModelTitleFieldId.d.ts +2 -0
- package/getModelTitleFieldId.js +13 -0
- package/getModelTitleFieldId.js.map +1 -0
- package/index.d.ts +3 -0
- package/index.js +38 -0
- package/index.js.map +1 -0
- package/package.json +52 -0
- package/types/index.d.ts +503 -0
- package/types/index.js +38 -0
- package/types/index.js.map +1 -0
- package/types/model.d.ts +89 -0
- package/types/model.js +5 -0
- package/types/model.js.map +1 -0
- package/types/shared.d.ts +5 -0
- package/types/shared.js +5 -0
- package/types/shared.js.map +1 -0
- package/types/validation.d.ts +79 -0
- package/types/validation.js +5 -0
- package/types/validation.js.map +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Webiny
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# @webiny/app-headless-cms-common
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@webiny/app-headless-cms-common)
|
|
4
|
+
[](https://www.npmjs.com/package/@webiny/app-headless-cms-common)
|
|
5
|
+
[](https://github.com/prettier/prettier)
|
|
6
|
+
[](http://makeapullrequest.com)
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
npm install --save @webiny/app-headless-cms-common
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Or if you prefer yarn:
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
yarn add @webiny/app-headless-cms-common
|
|
18
|
+
```
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.createFieldsList = createFieldsList;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _objectSpread3 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
10
|
+
var _plugins = require("@webiny/plugins");
|
|
11
|
+
function createFieldsList(_ref) {
|
|
12
|
+
var model = _ref.model,
|
|
13
|
+
fields = _ref.fields;
|
|
14
|
+
var fieldPlugins = _plugins.plugins.byType("cms-editor-field-type").reduce(function (acc, item) {
|
|
15
|
+
return (0, _objectSpread3.default)((0, _objectSpread3.default)({}, acc), {}, (0, _defineProperty2.default)({}, item.field.type, item.field));
|
|
16
|
+
}, {});
|
|
17
|
+
|
|
18
|
+
// console.log(fields, model);
|
|
19
|
+
return fields.map(function (field) {
|
|
20
|
+
if (!fieldPlugins[field.type]) {
|
|
21
|
+
console.log("Unknown field plugin for field type \"".concat(field.type, "\"."));
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
var graphql = fieldPlugins[field.type].graphql;
|
|
25
|
+
if (graphql && graphql.queryField) {
|
|
26
|
+
var queryField = graphql.queryField;
|
|
27
|
+
var selection = typeof queryField === "string" ? queryField : queryField({
|
|
28
|
+
model: model,
|
|
29
|
+
field: field
|
|
30
|
+
});
|
|
31
|
+
return "".concat(field.fieldId, " ").concat(selection);
|
|
32
|
+
}
|
|
33
|
+
return field.fieldId;
|
|
34
|
+
}).filter(Boolean).join("\n");
|
|
35
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createFieldsList","model","fields","fieldPlugins","plugins","byType","reduce","acc","item","field","type","map","console","log","graphql","queryField","selection","fieldId","filter","Boolean","join"],"sources":["createFieldsList.ts"],"sourcesContent":["import { CmsModelField, CmsEditorFieldTypePlugin, CmsModel } from \"~/types\";\nimport { plugins } from \"@webiny/plugins\";\n\ninterface CreateFieldsListParams {\n model: CmsModel;\n fields: CmsModelField[];\n}\n\nexport function createFieldsList({ model, fields }: CreateFieldsListParams): string {\n const fieldPlugins: Record<string, CmsEditorFieldTypePlugin[\"field\"]> = plugins\n .byType<CmsEditorFieldTypePlugin>(\"cms-editor-field-type\")\n .reduce((acc, item) => ({ ...acc, [item.field.type]: item.field }), {});\n\n // console.log(fields, model);\n return fields\n .map(field => {\n if (!fieldPlugins[field.type]) {\n console.log(`Unknown field plugin for field type \"${field.type}\".`);\n return null;\n }\n const { graphql } = fieldPlugins[field.type];\n\n if (graphql && graphql.queryField) {\n const { queryField } = graphql;\n const selection =\n typeof queryField === \"string\" ? queryField : queryField({ model, field });\n\n return `${field.fieldId} ${selection}`;\n }\n\n return field.fieldId;\n })\n .filter(Boolean)\n .join(\"\\n\");\n}\n"],"mappings":";;;;;;;;;AACA;AAOO,SAASA,gBAAgB,OAAoD;EAAA,IAAjDC,KAAK,QAALA,KAAK;IAAEC,MAAM,QAANA,MAAM;EAC5C,IAAMC,YAA+D,GAAGC,gBAAO,CAC1EC,MAAM,CAA2B,uBAAuB,CAAC,CACzDC,MAAM,CAAC,UAACC,GAAG,EAAEC,IAAI;IAAA,mEAAWD,GAAG,yCAAGC,IAAI,CAACC,KAAK,CAACC,IAAI,EAAGF,IAAI,CAACC,KAAK;EAAA,CAAG,EAAE,CAAC,CAAC,CAAC;;EAE3E;EACA,OAAOP,MAAM,CACRS,GAAG,CAAC,UAAAF,KAAK,EAAI;IACV,IAAI,CAACN,YAAY,CAACM,KAAK,CAACC,IAAI,CAAC,EAAE;MAC3BE,OAAO,CAACC,GAAG,iDAAyCJ,KAAK,CAACC,IAAI,SAAK;MACnE,OAAO,IAAI;IACf;IACA,IAAQI,OAAO,GAAKX,YAAY,CAACM,KAAK,CAACC,IAAI,CAAC,CAApCI,OAAO;IAEf,IAAIA,OAAO,IAAIA,OAAO,CAACC,UAAU,EAAE;MAC/B,IAAQA,UAAU,GAAKD,OAAO,CAAtBC,UAAU;MAClB,IAAMC,SAAS,GACX,OAAOD,UAAU,KAAK,QAAQ,GAAGA,UAAU,GAAGA,UAAU,CAAC;QAAEd,KAAK,EAALA,KAAK;QAAEQ,KAAK,EAALA;MAAM,CAAC,CAAC;MAE9E,iBAAUA,KAAK,CAACQ,OAAO,cAAID,SAAS;IACxC;IAEA,OAAOP,KAAK,CAACQ,OAAO;EACxB,CAAC,CAAC,CACDC,MAAM,CAACC,OAAO,CAAC,CACfC,IAAI,CAAC,IAAI,CAAC;AACnB"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { CmsContentEntryRevision, CmsContentEntry, CmsEditorContentModel, CmsErrorResponse, CmsMetaResponse, CmsModelField } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* ############################################
|
|
4
|
+
* Get CMS Entry Query
|
|
5
|
+
*/
|
|
6
|
+
export interface CmsEntryGetQueryResponse {
|
|
7
|
+
content: {
|
|
8
|
+
data: CmsContentEntry;
|
|
9
|
+
error: CmsErrorResponse | null;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export interface CmsEntryGetQueryVariables {
|
|
13
|
+
revision?: string;
|
|
14
|
+
entryId?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare const createReadQuery: (model: CmsEditorContentModel) => import("graphql").DocumentNode;
|
|
17
|
+
/**
|
|
18
|
+
* ############################################
|
|
19
|
+
* List CMS Entry Revisions Query
|
|
20
|
+
*/
|
|
21
|
+
export interface CmsEntriesListRevisionsQueryResponse {
|
|
22
|
+
revisions: {
|
|
23
|
+
data: CmsContentEntryRevision[];
|
|
24
|
+
error: CmsErrorResponse | null;
|
|
25
|
+
meta: CmsMetaResponse;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export interface CmsEntriesListRevisionsQueryVariables {
|
|
29
|
+
id: string;
|
|
30
|
+
}
|
|
31
|
+
export declare const createRevisionsQuery: (model: CmsEditorContentModel) => import("graphql").DocumentNode;
|
|
32
|
+
/**
|
|
33
|
+
* ############################################
|
|
34
|
+
* List CMS Entries Query
|
|
35
|
+
*/
|
|
36
|
+
export interface CmsEntriesListQueryResponse {
|
|
37
|
+
content: {
|
|
38
|
+
data: CmsContentEntry[];
|
|
39
|
+
error: CmsErrorResponse | null;
|
|
40
|
+
meta: CmsMetaResponse;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export interface CmsEntriesListQueryVariables {
|
|
44
|
+
where?: {
|
|
45
|
+
[key: string]: any;
|
|
46
|
+
};
|
|
47
|
+
sort?: string[];
|
|
48
|
+
limit?: number;
|
|
49
|
+
after?: string;
|
|
50
|
+
}
|
|
51
|
+
export declare const createListQuery: (model: CmsEditorContentModel, fields?: CmsModelField[]) => import("graphql").DocumentNode;
|
|
52
|
+
/**
|
|
53
|
+
* ############################################
|
|
54
|
+
* Delete Mutation
|
|
55
|
+
*/
|
|
56
|
+
export interface CmsEntryDeleteMutationResponse {
|
|
57
|
+
content: {
|
|
58
|
+
data: CmsContentEntry | null;
|
|
59
|
+
error: CmsErrorResponse | null;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export interface CmsEntryDeleteMutationVariables {
|
|
63
|
+
revision: string;
|
|
64
|
+
}
|
|
65
|
+
export declare const createDeleteMutation: (model: CmsEditorContentModel) => import("graphql").DocumentNode;
|
|
66
|
+
/**
|
|
67
|
+
* ############################################
|
|
68
|
+
* Create Mutation
|
|
69
|
+
*/
|
|
70
|
+
export interface CmsEntryCreateMutationResponse {
|
|
71
|
+
content: {
|
|
72
|
+
data: CmsContentEntry | null;
|
|
73
|
+
error: CmsErrorResponse | null;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
export interface CmsEntryCreateMutationVariables {
|
|
77
|
+
/**
|
|
78
|
+
* We have any here because we do not know which fields does entry have
|
|
79
|
+
*/
|
|
80
|
+
data: Record<string, any>;
|
|
81
|
+
}
|
|
82
|
+
export declare const createCreateMutation: (model: CmsEditorContentModel) => import("graphql").DocumentNode;
|
|
83
|
+
/**
|
|
84
|
+
* ############################################
|
|
85
|
+
* Create From Mutation
|
|
86
|
+
*/
|
|
87
|
+
export interface CmsEntryCreateFromMutationResponse {
|
|
88
|
+
content: {
|
|
89
|
+
data?: CmsContentEntry;
|
|
90
|
+
error?: CmsErrorResponse;
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
export interface CmsEntryCreateFromMutationVariables {
|
|
94
|
+
revision: string;
|
|
95
|
+
/**
|
|
96
|
+
* We have any here because we do not know which fields does entry have
|
|
97
|
+
*/
|
|
98
|
+
data?: Record<string, any>;
|
|
99
|
+
}
|
|
100
|
+
export declare const createCreateFromMutation: (model: CmsEditorContentModel) => import("graphql").DocumentNode;
|
|
101
|
+
/**
|
|
102
|
+
* ############################################
|
|
103
|
+
* Update Mutation
|
|
104
|
+
*/
|
|
105
|
+
export interface CmsEntryUpdateMutationResponse {
|
|
106
|
+
content: {
|
|
107
|
+
data?: CmsContentEntry;
|
|
108
|
+
error?: CmsErrorResponse;
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
export interface CmsEntryUpdateMutationVariables {
|
|
112
|
+
revision: string;
|
|
113
|
+
/**
|
|
114
|
+
* We have any here because we do not know which fields does entry have
|
|
115
|
+
*/
|
|
116
|
+
data: Record<string, any>;
|
|
117
|
+
}
|
|
118
|
+
export declare const createUpdateMutation: (model: CmsEditorContentModel) => import("graphql").DocumentNode;
|
|
119
|
+
/**
|
|
120
|
+
* ############################################
|
|
121
|
+
* Publish Mutation
|
|
122
|
+
*/
|
|
123
|
+
export interface CmsEntryPublishMutationResponse {
|
|
124
|
+
content: {
|
|
125
|
+
data?: CmsContentEntry;
|
|
126
|
+
error?: CmsErrorResponse;
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
export interface CmsEntryPublishMutationVariables {
|
|
130
|
+
revision: string;
|
|
131
|
+
}
|
|
132
|
+
export declare const createPublishMutation: (model: CmsEditorContentModel) => import("graphql").DocumentNode;
|
|
133
|
+
/**
|
|
134
|
+
* ############################################
|
|
135
|
+
* Unpublish Mutation
|
|
136
|
+
*/
|
|
137
|
+
export interface CmsEntryUnpublishMutationResponse {
|
|
138
|
+
content: {
|
|
139
|
+
data?: CmsContentEntry;
|
|
140
|
+
error?: CmsErrorResponse;
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
export interface CmsEntryUnpublishMutationVariables {
|
|
144
|
+
revision: string;
|
|
145
|
+
}
|
|
146
|
+
export declare const createUnpublishMutation: (model: CmsEditorContentModel) => import("graphql").DocumentNode;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.createUpdateMutation = exports.createUnpublishMutation = exports.createRevisionsQuery = exports.createReadQuery = exports.createPublishMutation = exports.createListQuery = exports.createDeleteMutation = exports.createCreateMutation = exports.createCreateFromMutation = void 0;
|
|
8
|
+
var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
|
|
9
|
+
var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
|
|
10
|
+
var _createFieldsList = require("./createFieldsList");
|
|
11
|
+
var _getModelTitleFieldId = require("./getModelTitleFieldId");
|
|
12
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9;
|
|
13
|
+
var CONTENT_META_FIELDS = /* GraphQL */"\n meta {\n title\n description\n image\n publishedOn\n version\n locked\n status\n }\n";
|
|
14
|
+
var CONTENT_ENTRY_SYSTEM_FIELDS = /* GraphQL */"\n id\n entryId\n savedOn\n createdOn\n createdBy {\n id\n type\n displayName\n }\n ownedBy {\n id\n type\n displayName\n }\n wbyAco_location {\n folderId\n }\n ".concat(CONTENT_META_FIELDS, "\n");
|
|
15
|
+
var ERROR_FIELD = /* GraphQL */"\n {\n message\n code\n data\n }\n";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* ############################################
|
|
19
|
+
* Get CMS Entry Query
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
var createReadQuery = function createReadQuery(model) {
|
|
23
|
+
/**
|
|
24
|
+
* This query now accepts both revision or entryId as we can load exact revision or latest (if entryId was sent).
|
|
25
|
+
*/
|
|
26
|
+
return (0, _graphqlTag.default)(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n query CmsEntriesGet", "($revision: ID, $entryId: ID) {\n content: get", "(revision: $revision, entryId: $entryId) {\n data {\n ", "\n ", "\n }\n error ", "\n }\n }\n "])), model.singularApiName, model.singularApiName, CONTENT_ENTRY_SYSTEM_FIELDS, (0, _createFieldsList.createFieldsList)({
|
|
27
|
+
model: model,
|
|
28
|
+
fields: model.fields
|
|
29
|
+
}), ERROR_FIELD);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* ############################################
|
|
34
|
+
* List CMS Entry Revisions Query
|
|
35
|
+
*/
|
|
36
|
+
exports.createReadQuery = createReadQuery;
|
|
37
|
+
var createRevisionsQuery = function createRevisionsQuery(model) {
|
|
38
|
+
return (0, _graphqlTag.default)(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2.default)(["\n query CmsEntriesGet", "Revisions($id: ID!) {\n revisions: get", "Revisions(id: $id) {\n data {\n ", "\n }\n error ", "\n }\n }\n "])), model.singularApiName, model.singularApiName, CONTENT_ENTRY_SYSTEM_FIELDS, ERROR_FIELD);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* ############################################
|
|
43
|
+
* List CMS Entries Query
|
|
44
|
+
*/
|
|
45
|
+
exports.createRevisionsQuery = createRevisionsQuery;
|
|
46
|
+
var createListQuery = function createListQuery(model, fields) {
|
|
47
|
+
return (0, _graphqlTag.default)(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2.default)(["\n query CmsEntriesList", "($where: ", "ListWhereInput, $sort: [", "ListSorter], $limit: Int, $after: String, $search: String) {\n content: list", "(\n where: $where\n sort: $sort\n limit: $limit\n after: $after\n search: $search\n ) {\n data {\n ", "\n ", "\n ", "\n }\n meta {\n cursor\n hasMoreItems\n totalCount\n }\n error ", "\n }\n }\n "])), model.pluralApiName, model.singularApiName, model.singularApiName, model.pluralApiName, CONTENT_ENTRY_SYSTEM_FIELDS, fields ? (0, _createFieldsList.createFieldsList)({
|
|
48
|
+
model: model,
|
|
49
|
+
fields: fields
|
|
50
|
+
}) : "", !fields ? (0, _getModelTitleFieldId.getModelTitleFieldId)(model) : "", ERROR_FIELD);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* ############################################
|
|
55
|
+
* Delete Mutation
|
|
56
|
+
*/
|
|
57
|
+
exports.createListQuery = createListQuery;
|
|
58
|
+
var createDeleteMutation = function createDeleteMutation(model) {
|
|
59
|
+
return (0, _graphqlTag.default)(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteral2.default)(["\n mutation CmsEntriesDelete", "($revision: ID!) {\n content: delete", "(revision: $revision) {\n data\n error ", "\n }\n }\n "])), model.singularApiName, model.singularApiName, ERROR_FIELD);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* ############################################
|
|
64
|
+
* Create Mutation
|
|
65
|
+
*/
|
|
66
|
+
exports.createDeleteMutation = createDeleteMutation;
|
|
67
|
+
var createCreateMutation = function createCreateMutation(model) {
|
|
68
|
+
return (0, _graphqlTag.default)(_templateObject5 || (_templateObject5 = (0, _taggedTemplateLiteral2.default)(["\n mutation CmsEntriesCreate", "($data: ", "Input!) {\n content: create", "(data: $data) {\n data {\n ", "\n ", "\n }\n error ", "\n }\n }\n "])), model.singularApiName, model.singularApiName, model.singularApiName, CONTENT_ENTRY_SYSTEM_FIELDS, (0, _createFieldsList.createFieldsList)({
|
|
69
|
+
model: model,
|
|
70
|
+
fields: model.fields
|
|
71
|
+
}), ERROR_FIELD);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* ############################################
|
|
76
|
+
* Create From Mutation
|
|
77
|
+
*/
|
|
78
|
+
exports.createCreateMutation = createCreateMutation;
|
|
79
|
+
var createCreateFromMutation = function createCreateFromMutation(model) {
|
|
80
|
+
return (0, _graphqlTag.default)(_templateObject6 || (_templateObject6 = (0, _taggedTemplateLiteral2.default)(["\n mutation CmsCreate", "From($revision: ID!, $data: ", "Input) {\n content: create", "From(revision: $revision, data: $data) {\n data {\n ", "\n ", "\n }\n error ", "\n }\n }"])), model.singularApiName, model.singularApiName, model.singularApiName, CONTENT_ENTRY_SYSTEM_FIELDS, (0, _createFieldsList.createFieldsList)({
|
|
81
|
+
model: model,
|
|
82
|
+
fields: model.fields
|
|
83
|
+
}), ERROR_FIELD);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* ############################################
|
|
88
|
+
* Update Mutation
|
|
89
|
+
*/
|
|
90
|
+
exports.createCreateFromMutation = createCreateFromMutation;
|
|
91
|
+
var createUpdateMutation = function createUpdateMutation(model) {
|
|
92
|
+
return (0, _graphqlTag.default)(_templateObject7 || (_templateObject7 = (0, _taggedTemplateLiteral2.default)(["\n mutation CmsUpdate", "($revision: ID!, $data: ", "Input!) {\n content: update", "(revision: $revision, data: $data) {\n data {\n ", "\n ", "\n }\n error ", "\n }\n }\n "])), model.singularApiName, model.singularApiName, model.singularApiName, CONTENT_ENTRY_SYSTEM_FIELDS, (0, _createFieldsList.createFieldsList)({
|
|
93
|
+
model: model,
|
|
94
|
+
fields: model.fields
|
|
95
|
+
}), ERROR_FIELD);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* ############################################
|
|
100
|
+
* Publish Mutation
|
|
101
|
+
*/
|
|
102
|
+
exports.createUpdateMutation = createUpdateMutation;
|
|
103
|
+
var createPublishMutation = function createPublishMutation(model) {
|
|
104
|
+
return (0, _graphqlTag.default)(_templateObject8 || (_templateObject8 = (0, _taggedTemplateLiteral2.default)(["\n mutation CmsPublish", "($revision: ID!) {\n content: publish", "(revision: $revision) {\n data {\n id\n ", "\n }\n error ", "\n }\n }"])), model.singularApiName, model.singularApiName, CONTENT_META_FIELDS, ERROR_FIELD);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* ############################################
|
|
109
|
+
* Unpublish Mutation
|
|
110
|
+
*/
|
|
111
|
+
exports.createPublishMutation = createPublishMutation;
|
|
112
|
+
var createUnpublishMutation = function createUnpublishMutation(model) {
|
|
113
|
+
return (0, _graphqlTag.default)(_templateObject9 || (_templateObject9 = (0, _taggedTemplateLiteral2.default)(["\n mutation CmsUnpublish", "($revision: ID!) {\n content: unpublish", "(revision: $revision) {\n data {\n id\n ", "\n }\n error ", "\n }\n }"])), model.singularApiName, model.singularApiName, CONTENT_META_FIELDS, ERROR_FIELD);
|
|
114
|
+
};
|
|
115
|
+
exports.createUnpublishMutation = createUnpublishMutation;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["CONTENT_META_FIELDS","CONTENT_ENTRY_SYSTEM_FIELDS","ERROR_FIELD","createReadQuery","model","gql","singularApiName","createFieldsList","fields","createRevisionsQuery","createListQuery","pluralApiName","getModelTitleFieldId","createDeleteMutation","createCreateMutation","createCreateFromMutation","createUpdateMutation","createPublishMutation","createUnpublishMutation"],"sources":["entries.graphql.ts"],"sourcesContent":["import gql from \"graphql-tag\";\nimport {\n CmsContentEntryRevision,\n CmsContentEntry,\n CmsEditorContentModel,\n CmsErrorResponse,\n CmsMetaResponse,\n CmsModelField\n} from \"~/types\";\nimport { createFieldsList } from \"./createFieldsList\";\nimport { getModelTitleFieldId } from \"./getModelTitleFieldId\";\n\nconst CONTENT_META_FIELDS = /* GraphQL */ `\n meta {\n title\n description\n image\n publishedOn\n version\n locked\n status\n }\n`;\n\nconst CONTENT_ENTRY_SYSTEM_FIELDS = /* GraphQL */ `\n id\n entryId\n savedOn\n createdOn\n createdBy {\n id\n type\n displayName\n }\n ownedBy {\n id\n type\n displayName\n }\n wbyAco_location {\n folderId\n }\n ${CONTENT_META_FIELDS}\n`;\n\nconst ERROR_FIELD = /* GraphQL */ `\n {\n message\n code\n data\n }\n`;\n\n/**\n * ############################################\n * Get CMS Entry Query\n */\nexport interface CmsEntryGetQueryResponse {\n content: {\n data: CmsContentEntry;\n error: CmsErrorResponse | null;\n };\n}\n\nexport interface CmsEntryGetQueryVariables {\n revision?: string;\n entryId?: string;\n}\n\nexport const createReadQuery = (model: CmsEditorContentModel) => {\n /**\n * This query now accepts both revision or entryId as we can load exact revision or latest (if entryId was sent).\n */\n return gql`\n query CmsEntriesGet${model.singularApiName}($revision: ID, $entryId: ID) {\n content: get${model.singularApiName}(revision: $revision, entryId: $entryId) {\n data {\n ${CONTENT_ENTRY_SYSTEM_FIELDS}\n ${createFieldsList({ model, fields: model.fields })}\n }\n error ${ERROR_FIELD}\n }\n }\n `;\n};\n\n/**\n * ############################################\n * List CMS Entry Revisions Query\n */\nexport interface CmsEntriesListRevisionsQueryResponse {\n revisions: {\n data: CmsContentEntryRevision[];\n error: CmsErrorResponse | null;\n meta: CmsMetaResponse;\n };\n}\n\nexport interface CmsEntriesListRevisionsQueryVariables {\n id: string;\n}\n\nexport const createRevisionsQuery = (model: CmsEditorContentModel) => {\n return gql`\n query CmsEntriesGet${model.singularApiName}Revisions($id: ID!) {\n revisions: get${model.singularApiName}Revisions(id: $id) {\n data {\n ${CONTENT_ENTRY_SYSTEM_FIELDS}\n }\n error ${ERROR_FIELD}\n }\n }\n `;\n};\n\n/**\n * ############################################\n * List CMS Entries Query\n */\nexport interface CmsEntriesListQueryResponse {\n content: {\n data: CmsContentEntry[];\n error: CmsErrorResponse | null;\n meta: CmsMetaResponse;\n };\n}\n\nexport interface CmsEntriesListQueryVariables {\n // TODO @ts-refactor better list types\n where?: {\n [key: string]: any;\n };\n sort?: string[];\n limit?: number;\n after?: string;\n}\n\nexport const createListQuery = (model: CmsEditorContentModel, fields?: CmsModelField[]) => {\n return gql`\n query CmsEntriesList${model.pluralApiName}($where: ${\n model.singularApiName\n }ListWhereInput, $sort: [${\n model.singularApiName\n }ListSorter], $limit: Int, $after: String, $search: String) {\n content: list${model.pluralApiName}(\n where: $where\n sort: $sort\n limit: $limit\n after: $after\n search: $search\n ) {\n data {\n ${CONTENT_ENTRY_SYSTEM_FIELDS}\n ${fields ? createFieldsList({ model, fields }) : \"\"}\n ${!fields ? getModelTitleFieldId(model) : \"\"}\n }\n meta {\n cursor\n hasMoreItems\n totalCount\n }\n error ${ERROR_FIELD}\n }\n }\n `;\n};\n\n/**\n * ############################################\n * Delete Mutation\n */\nexport interface CmsEntryDeleteMutationResponse {\n content: {\n data: CmsContentEntry | null;\n error: CmsErrorResponse | null;\n };\n}\n\nexport interface CmsEntryDeleteMutationVariables {\n revision: string;\n}\n\nexport const createDeleteMutation = (model: CmsEditorContentModel) => {\n return gql`\n mutation CmsEntriesDelete${model.singularApiName}($revision: ID!) {\n content: delete${model.singularApiName}(revision: $revision) {\n data\n error ${ERROR_FIELD}\n }\n }\n `;\n};\n\n/**\n * ############################################\n * Create Mutation\n */\nexport interface CmsEntryCreateMutationResponse {\n content: {\n data: CmsContentEntry | null;\n error: CmsErrorResponse | null;\n };\n}\n\nexport interface CmsEntryCreateMutationVariables {\n /**\n * We have any here because we do not know which fields does entry have\n */\n data: Record<string, any>;\n}\n\nexport const createCreateMutation = (model: CmsEditorContentModel) => {\n return gql`\n mutation CmsEntriesCreate${model.singularApiName}($data: ${model.singularApiName}Input!) {\n content: create${model.singularApiName}(data: $data) {\n data {\n ${CONTENT_ENTRY_SYSTEM_FIELDS}\n ${createFieldsList({ model, fields: model.fields })}\n }\n error ${ERROR_FIELD}\n }\n }\n `;\n};\n\n/**\n * ############################################\n * Create From Mutation\n */\nexport interface CmsEntryCreateFromMutationResponse {\n content: {\n data?: CmsContentEntry;\n error?: CmsErrorResponse;\n };\n}\n\nexport interface CmsEntryCreateFromMutationVariables {\n revision: string;\n /**\n * We have any here because we do not know which fields does entry have\n */\n data?: Record<string, any>;\n}\n\nexport const createCreateFromMutation = (model: CmsEditorContentModel) => {\n return gql`\n mutation CmsCreate${model.singularApiName}From($revision: ID!, $data: ${\n model.singularApiName\n }Input) {\n content: create${model.singularApiName}From(revision: $revision, data: $data) {\n data {\n ${CONTENT_ENTRY_SYSTEM_FIELDS}\n ${createFieldsList({ model, fields: model.fields })}\n }\n error ${ERROR_FIELD}\n }\n }`;\n};\n\n/**\n * ############################################\n * Update Mutation\n */\nexport interface CmsEntryUpdateMutationResponse {\n content: {\n data?: CmsContentEntry;\n error?: CmsErrorResponse;\n };\n}\n\nexport interface CmsEntryUpdateMutationVariables {\n revision: string;\n /**\n * We have any here because we do not know which fields does entry have\n */\n data: Record<string, any>;\n}\n\nexport const createUpdateMutation = (model: CmsEditorContentModel) => {\n return gql`\n mutation CmsUpdate${model.singularApiName}($revision: ID!, $data: ${\n model.singularApiName\n }Input!) {\n content: update${model.singularApiName}(revision: $revision, data: $data) {\n data {\n ${CONTENT_ENTRY_SYSTEM_FIELDS}\n ${createFieldsList({ model, fields: model.fields })}\n }\n error ${ERROR_FIELD}\n }\n }\n `;\n};\n\n/**\n * ############################################\n * Publish Mutation\n */\nexport interface CmsEntryPublishMutationResponse {\n content: {\n data?: CmsContentEntry;\n error?: CmsErrorResponse;\n };\n}\n\nexport interface CmsEntryPublishMutationVariables {\n revision: string;\n}\n\nexport const createPublishMutation = (model: CmsEditorContentModel) => {\n return gql`\n mutation CmsPublish${model.singularApiName}($revision: ID!) {\n content: publish${model.singularApiName}(revision: $revision) {\n data {\n id\n ${CONTENT_META_FIELDS}\n }\n error ${ERROR_FIELD}\n }\n }`;\n};\n\n/**\n * ############################################\n * Unpublish Mutation\n */\nexport interface CmsEntryUnpublishMutationResponse {\n content: {\n data?: CmsContentEntry;\n error?: CmsErrorResponse;\n };\n}\n\nexport interface CmsEntryUnpublishMutationVariables {\n revision: string;\n}\n\nexport const createUnpublishMutation = (model: CmsEditorContentModel) => {\n return gql`\n mutation CmsUnpublish${model.singularApiName}($revision: ID!) {\n content: unpublish${model.singularApiName}(revision: $revision) {\n data {\n id\n ${CONTENT_META_FIELDS}\n }\n error ${ERROR_FIELD}\n }\n }`;\n};\n"],"mappings":";;;;;;;;AAAA;AASA;AACA;AAA8D;AAE9D,IAAMA,mBAAmB,GAAG,6JAU3B;AAED,IAAMC,2BAA2B,GAAG,0QAkB9BD,mBAAmB,OACxB;AAED,IAAME,WAAW,GAAG,4EAMnB;;AAED;AACA;AACA;AACA;;AAaO,IAAMC,eAAe,GAAG,SAAlBA,eAAe,CAAIC,KAA4B,EAAK;EAC7D;AACJ;AACA;EACI,WAAOC,mBAAG,wXACeD,KAAK,CAACE,eAAe,EACxBF,KAAK,CAACE,eAAe,EAEzBL,2BAA2B,EAC3B,IAAAM,kCAAgB,EAAC;IAAEH,KAAK,EAALA,KAAK;IAAEI,MAAM,EAAEJ,KAAK,CAACI;EAAO,CAAC,CAAC,EAE/CN,WAAW;AAInC,CAAC;;AAED;AACA;AACA;AACA;AAHA;AAgBO,IAAMO,oBAAoB,GAAG,SAAvBA,oBAAoB,CAAIL,KAA4B,EAAK;EAClE,WAAOC,mBAAG,kUACeD,KAAK,CAACE,eAAe,EACtBF,KAAK,CAACE,eAAe,EAE3BL,2BAA2B,EAEzBC,WAAW;AAInC,CAAC;;AAED;AACA;AACA;AACA;AAHA;AAsBO,IAAMQ,eAAe,GAAG,SAAlBA,eAAe,CAAIN,KAA4B,EAAEI,MAAwB,EAAK;EACvF,WAAOH,mBAAG,otBACgBD,KAAK,CAACO,aAAa,EACzCP,KAAK,CAACE,eAAe,EAErBF,KAAK,CAACE,eAAe,EAEFF,KAAK,CAACO,aAAa,EAQxBV,2BAA2B,EAC3BO,MAAM,GAAG,IAAAD,kCAAgB,EAAC;IAAEH,KAAK,EAALA,KAAK;IAAEI,MAAM,EAANA;EAAO,CAAC,CAAC,GAAG,EAAE,EACjD,CAACA,MAAM,GAAG,IAAAI,0CAAoB,EAACR,KAAK,CAAC,GAAG,EAAE,EAOxCF,WAAW;AAInC,CAAC;;AAED;AACA;AACA;AACA;AAHA;AAeO,IAAMW,oBAAoB,GAAG,SAAvBA,oBAAoB,CAAIT,KAA4B,EAAK;EAClE,WAAOC,mBAAG,0RACqBD,KAAK,CAACE,eAAe,EAC3BF,KAAK,CAACE,eAAe,EAE1BJ,WAAW;AAInC,CAAC;;AAED;AACA;AACA;AACA;AAHA;AAkBO,IAAMY,oBAAoB,GAAG,SAAvBA,oBAAoB,CAAIV,KAA4B,EAAK;EAClE,WAAOC,mBAAG,8VACqBD,KAAK,CAACE,eAAe,EAAWF,KAAK,CAACE,eAAe,EAC3DF,KAAK,CAACE,eAAe,EAE5BL,2BAA2B,EAC3B,IAAAM,kCAAgB,EAAC;IAAEH,KAAK,EAALA,KAAK;IAAEI,MAAM,EAAEJ,KAAK,CAACI;EAAO,CAAC,CAAC,EAE/CN,WAAW;AAInC,CAAC;;AAED;AACA;AACA;AACA;AAHA;AAmBO,IAAMa,wBAAwB,GAAG,SAA3BA,wBAAwB,CAAIX,KAA4B,EAAK;EACtE,WAAOC,mBAAG,yXACcD,KAAK,CAACE,eAAe,EACzCF,KAAK,CAACE,eAAe,EAEJF,KAAK,CAACE,eAAe,EAExBL,2BAA2B,EAC3B,IAAAM,kCAAgB,EAAC;IAAEH,KAAK,EAALA,KAAK;IAAEI,MAAM,EAAEJ,KAAK,CAACI;EAAO,CAAC,CAAC,EAE/CN,WAAW;AAGnC,CAAC;;AAED;AACA;AACA;AACA;AAHA;AAmBO,IAAMc,oBAAoB,GAAG,SAAvBA,oBAAoB,CAAIZ,KAA4B,EAAK;EAClE,WAAOC,mBAAG,4XACcD,KAAK,CAACE,eAAe,EACzCF,KAAK,CAACE,eAAe,EAEAF,KAAK,CAACE,eAAe,EAE5BL,2BAA2B,EAC3B,IAAAM,kCAAgB,EAAC;IAAEH,KAAK,EAALA,KAAK;IAAEI,MAAM,EAAEJ,KAAK,CAACI;EAAO,CAAC,CAAC,EAE/CN,WAAW;AAInC,CAAC;;AAED;AACA;AACA;AACA;AAHA;AAeO,IAAMe,qBAAqB,GAAG,SAAxBA,qBAAqB,CAAIb,KAA4B,EAAK;EACnE,WAAOC,mBAAG,sVACeD,KAAK,CAACE,eAAe,EACpBF,KAAK,CAACE,eAAe,EAG7BN,mBAAmB,EAEjBE,WAAW;AAGnC,CAAC;;AAED;AACA;AACA;AACA;AAHA;AAeO,IAAMgB,uBAAuB,GAAG,SAA1BA,uBAAuB,CAAId,KAA4B,EAAK;EACrE,WAAOC,mBAAG,0VACiBD,KAAK,CAACE,eAAe,EACpBF,KAAK,CAACE,eAAe,EAG/BN,mBAAmB,EAEjBE,WAAW;AAGnC,CAAC;AAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getModelTitleFieldId = void 0;
|
|
7
|
+
var getModelTitleFieldId = function getModelTitleFieldId(model) {
|
|
8
|
+
if (!model.titleFieldId || model.titleFieldId === "id") {
|
|
9
|
+
return "";
|
|
10
|
+
}
|
|
11
|
+
return model.titleFieldId;
|
|
12
|
+
};
|
|
13
|
+
exports.getModelTitleFieldId = getModelTitleFieldId;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["getModelTitleFieldId","model","titleFieldId"],"sources":["getModelTitleFieldId.ts"],"sourcesContent":["import { CmsEditorContentModel } from \"~/types\";\n\nexport const getModelTitleFieldId = (model: CmsEditorContentModel): string => {\n if (!model.titleFieldId || model.titleFieldId === \"id\") {\n return \"\";\n }\n return model.titleFieldId;\n};\n"],"mappings":";;;;;;AAEO,IAAMA,oBAAoB,GAAG,SAAvBA,oBAAoB,CAAIC,KAA4B,EAAa;EAC1E,IAAI,CAACA,KAAK,CAACC,YAAY,IAAID,KAAK,CAACC,YAAY,KAAK,IAAI,EAAE;IACpD,OAAO,EAAE;EACb;EACA,OAAOD,KAAK,CAACC,YAAY;AAC7B,CAAC;AAAC"}
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _entries = require("./entries.graphql");
|
|
7
|
+
Object.keys(_entries).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _entries[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function get() {
|
|
13
|
+
return _entries[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
var _getModelTitleFieldId = require("./getModelTitleFieldId");
|
|
18
|
+
Object.keys(_getModelTitleFieldId).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _getModelTitleFieldId[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function get() {
|
|
24
|
+
return _getModelTitleFieldId[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
var _createFieldsList = require("./createFieldsList");
|
|
29
|
+
Object.keys(_createFieldsList).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _createFieldsList[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function get() {
|
|
35
|
+
return _createFieldsList[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./entries.graphql\";\nexport * from \"./getModelTitleFieldId\";\nexport * from \"./createFieldsList\";\n"],"mappings":";;;;;AAAA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@webiny/app-headless-cms-common",
|
|
3
|
+
"version": "0.0.0-unstable.085ff6572f",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/webiny/webiny-js.git"
|
|
8
|
+
},
|
|
9
|
+
"contributors": [
|
|
10
|
+
"Pavel Denisjuk <pavel@webiny.com>",
|
|
11
|
+
"Sven Al Hamad <sven@webiny.com>",
|
|
12
|
+
"Adrian Smijulj <adrian@webiny.com>"
|
|
13
|
+
],
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@babel/runtime": "7.20.13",
|
|
17
|
+
"@fortawesome/fontawesome-svg-core": "1.3.0",
|
|
18
|
+
"@types/react": "17.0.39",
|
|
19
|
+
"@webiny/app-security": "0.0.0-unstable.085ff6572f",
|
|
20
|
+
"@webiny/form": "0.0.0-unstable.085ff6572f",
|
|
21
|
+
"@webiny/plugins": "0.0.0-unstable.085ff6572f",
|
|
22
|
+
"graphql": "15.8.0",
|
|
23
|
+
"graphql-tag": "2.12.6",
|
|
24
|
+
"prop-types": "15.8.1",
|
|
25
|
+
"react": "17.0.2",
|
|
26
|
+
"react-dnd": "11.1.3"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@babel/cli": "7.20.7",
|
|
30
|
+
"@babel/core": "7.20.12",
|
|
31
|
+
"@babel/preset-env": "7.20.2",
|
|
32
|
+
"@babel/preset-react": "7.18.6",
|
|
33
|
+
"@babel/preset-typescript": "7.18.6",
|
|
34
|
+
"@webiny/cli": "0.0.0-unstable.085ff6572f",
|
|
35
|
+
"@webiny/project-utils": "0.0.0-unstable.085ff6572f",
|
|
36
|
+
"babel-plugin-emotion": "9.2.11",
|
|
37
|
+
"babel-plugin-lodash": "3.3.4",
|
|
38
|
+
"babel-plugin-module-resolver": "4.1.0",
|
|
39
|
+
"rimraf": "3.0.2",
|
|
40
|
+
"ttypescript": "1.5.15",
|
|
41
|
+
"typescript": "4.7.4"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public",
|
|
45
|
+
"directory": "dist"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "yarn webiny run build",
|
|
49
|
+
"watch": "yarn webiny run watch"
|
|
50
|
+
},
|
|
51
|
+
"gitHead": "085ff6572f6bb6a76d218088b06d9f4ef92bbea7"
|
|
52
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,503 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { ReactElement, ReactNode } from "react";
|
|
3
|
+
import { Plugin } from "@webiny/plugins/types";
|
|
4
|
+
import { BindComponent as BaseBindComponent, BindComponentProps as BaseBindComponentProps, BindComponentRenderProp as BaseBindComponentRenderProp, FormAPI } from "@webiny/form";
|
|
5
|
+
import { IconName, IconPrefix } from "@fortawesome/fontawesome-svg-core";
|
|
6
|
+
import { SecurityPermission } from "@webiny/app-security/types";
|
|
7
|
+
import { CmsModelFieldValidator, CmsModelFieldValidatorsFactory, CmsModelFieldValidatorsGroup } from "./validation";
|
|
8
|
+
import { CmsModel, CmsModelField } from "./model";
|
|
9
|
+
import { CmsIdentity } from "./shared";
|
|
10
|
+
import { DragObjectWithType } from "react-dnd";
|
|
11
|
+
export * from "./validation";
|
|
12
|
+
export * from "./model";
|
|
13
|
+
export * from "./shared";
|
|
14
|
+
interface QueryFieldParams {
|
|
15
|
+
model: CmsModel;
|
|
16
|
+
field: CmsModelField;
|
|
17
|
+
}
|
|
18
|
+
interface Position {
|
|
19
|
+
row: number;
|
|
20
|
+
index: number;
|
|
21
|
+
}
|
|
22
|
+
export interface DragSource extends DragObjectWithType {
|
|
23
|
+
parent?: string;
|
|
24
|
+
pos?: Partial<Position>;
|
|
25
|
+
type: "row" | "field" | "newField";
|
|
26
|
+
fieldType?: string;
|
|
27
|
+
field?: CmsModelField | null;
|
|
28
|
+
fields?: CmsModelField[];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* @deprecated Use `CmsModelFieldTypePlugin`.
|
|
32
|
+
*/
|
|
33
|
+
export declare type CmsEditorFieldTypePlugin = CmsModelFieldTypePlugin;
|
|
34
|
+
export interface CmsModelFieldTypePlugin extends Plugin {
|
|
35
|
+
/**
|
|
36
|
+
* a plugin type
|
|
37
|
+
*/
|
|
38
|
+
type: "cms-editor-field-type";
|
|
39
|
+
field: {
|
|
40
|
+
/**
|
|
41
|
+
* A unique identifier of the field type (text, number, json, myField, ...).
|
|
42
|
+
*
|
|
43
|
+
* ```ts
|
|
44
|
+
* type: "myField"
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
type: string;
|
|
48
|
+
/**
|
|
49
|
+
* A display name for the field.
|
|
50
|
+
*
|
|
51
|
+
* ```ts
|
|
52
|
+
* label: "Field name"
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
label: string;
|
|
56
|
+
/**
|
|
57
|
+
* A list of available validators for the model field.
|
|
58
|
+
*
|
|
59
|
+
* ```ts
|
|
60
|
+
* validators: [
|
|
61
|
+
* "required",
|
|
62
|
+
* "gte",
|
|
63
|
+
* "lte"
|
|
64
|
+
* ]
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
validators?: string[] | CmsModelFieldValidatorsGroup | CmsModelFieldValidatorsFactory;
|
|
68
|
+
/**
|
|
69
|
+
* A list of available validators when a model field accepts a list (array) of values.
|
|
70
|
+
*
|
|
71
|
+
* ```ts
|
|
72
|
+
* listValidators: [
|
|
73
|
+
* "minLength",
|
|
74
|
+
* "maxLength"
|
|
75
|
+
* ]
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
listValidators?: string[] | CmsModelFieldValidatorsGroup | CmsModelFieldValidatorsFactory;
|
|
79
|
+
/**
|
|
80
|
+
* An explanation of the field displayed beneath the label.
|
|
81
|
+
*
|
|
82
|
+
* ```ts
|
|
83
|
+
* description: "A short description of the field"
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
description: string;
|
|
87
|
+
/**
|
|
88
|
+
* A ReactNode to display the icon for the field.
|
|
89
|
+
*
|
|
90
|
+
* ```tsx
|
|
91
|
+
* icon: <MyIconComponent />
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
icon: React.ReactNode;
|
|
95
|
+
/**
|
|
96
|
+
* Is it allowed to have multiple values in this field?
|
|
97
|
+
*
|
|
98
|
+
* ```ts
|
|
99
|
+
* allowMultipleValues: true
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
allowMultipleValues?: boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Does this field type have a fixed list of values that can be selected?
|
|
105
|
+
*
|
|
106
|
+
* ```ts
|
|
107
|
+
* allowPredefinedValues: false
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
allowPredefinedValues?: boolean;
|
|
111
|
+
/**
|
|
112
|
+
* A ReactNode label when multiple values are enabled.
|
|
113
|
+
*/
|
|
114
|
+
multipleValuesLabel?: React.ReactNode;
|
|
115
|
+
/**
|
|
116
|
+
* These are default values when the field is first created. This is a representation of the field that is stored in the database.
|
|
117
|
+
*
|
|
118
|
+
* ```ts
|
|
119
|
+
* createField: () => ({
|
|
120
|
+
* type: "fieldType",
|
|
121
|
+
* validation: [],
|
|
122
|
+
* renderer: {
|
|
123
|
+
* name: "fieldTypeRenderer"
|
|
124
|
+
* }
|
|
125
|
+
* })
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
createField: () => Pick<CmsModelField, "type" | "validation" | "renderer" | "settings">;
|
|
129
|
+
/**
|
|
130
|
+
* If `true` (default), this field will be configurable via a settings dialog.
|
|
131
|
+
* If `false`, a user will not be able to open the settings dialog, not will the dialog be opened on field drop.
|
|
132
|
+
*/
|
|
133
|
+
canEditSettings?: boolean;
|
|
134
|
+
/**
|
|
135
|
+
* Determine if a `draggable` can be dropped into this field.
|
|
136
|
+
* NOTE: This is only applicable to nested field types.
|
|
137
|
+
*/
|
|
138
|
+
canAccept?(field: CmsModelField, draggable: DragSource): boolean;
|
|
139
|
+
/**
|
|
140
|
+
* If `true` (default), will allow fields to be laid out into columns (next to each other).
|
|
141
|
+
* If `false`, horizontal layout will not be allowed.
|
|
142
|
+
* NOTE: This is only applicable to nested field types.
|
|
143
|
+
*/
|
|
144
|
+
allowLayout?: boolean;
|
|
145
|
+
/**
|
|
146
|
+
* A ReactNode that you can add in the section below the help text when creating/editing field.
|
|
147
|
+
*
|
|
148
|
+
* ```tsx
|
|
149
|
+
* renderSettings: (params) => {
|
|
150
|
+
* return <FieldSettingsComponent />;
|
|
151
|
+
* }
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
renderSettings?: (params: {
|
|
155
|
+
afterChangeLabel: (value: string) => void;
|
|
156
|
+
uniqueFieldIdValidator: (fieldId: string) => void;
|
|
157
|
+
contentModel: CmsModel;
|
|
158
|
+
}) => React.ReactNode;
|
|
159
|
+
/**
|
|
160
|
+
* A ReactNode that renders in the Predefined values tab.
|
|
161
|
+
*
|
|
162
|
+
* ```tsx
|
|
163
|
+
* renderPredefinedValues: (params) => {
|
|
164
|
+
* const {form: {Bind}} = params;
|
|
165
|
+
* return (
|
|
166
|
+
* <Bind name="fieldProperty">
|
|
167
|
+
* <InputComponent />
|
|
168
|
+
* </Bind>
|
|
169
|
+
* );
|
|
170
|
+
* }
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
renderPredefinedValues?: (params: {
|
|
174
|
+
getBind: (index?: number) => any;
|
|
175
|
+
}) => React.ReactElement;
|
|
176
|
+
/**
|
|
177
|
+
* Object wrapper for GraphQL stuff
|
|
178
|
+
*/
|
|
179
|
+
graphql?: {
|
|
180
|
+
/**
|
|
181
|
+
* Define field selection.
|
|
182
|
+
*
|
|
183
|
+
* ```ts
|
|
184
|
+
* graphql: {
|
|
185
|
+
* queryField: `
|
|
186
|
+
* {
|
|
187
|
+
* id
|
|
188
|
+
* title
|
|
189
|
+
* createdOn
|
|
190
|
+
* }
|
|
191
|
+
* `,
|
|
192
|
+
* }
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
queryField?: string | ((params: QueryFieldParams) => string);
|
|
196
|
+
};
|
|
197
|
+
render?(params: any): React.ReactElement;
|
|
198
|
+
tags?: string[];
|
|
199
|
+
/**
|
|
200
|
+
* Render additional information in the Admin UI Model edit view
|
|
201
|
+
*/
|
|
202
|
+
renderInfo?: (params: {
|
|
203
|
+
field: CmsModelField;
|
|
204
|
+
model: CmsModel;
|
|
205
|
+
}) => React.ReactElement;
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
export interface CmsModelFieldRendererProps {
|
|
209
|
+
field: CmsModelField;
|
|
210
|
+
Label: React.FC;
|
|
211
|
+
getBind: (index?: number, key?: string) => BindComponent;
|
|
212
|
+
contentModel: CmsModel;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* @deprecated Use `CmsModelFieldRendererProps`.
|
|
216
|
+
*/
|
|
217
|
+
export declare type CmsEditorFieldRendererProps = CmsModelFieldRendererProps;
|
|
218
|
+
/**
|
|
219
|
+
* @deprecated Use `CmsModelFieldRendererPlugin`.
|
|
220
|
+
*/
|
|
221
|
+
export declare type CmsEditorFieldRendererPlugin = CmsModelFieldRendererPlugin;
|
|
222
|
+
export interface CmsModelFieldRendererPlugin extends Plugin {
|
|
223
|
+
/**
|
|
224
|
+
* a plugin type
|
|
225
|
+
*/
|
|
226
|
+
type: "cms-editor-field-renderer";
|
|
227
|
+
renderer: {
|
|
228
|
+
/**
|
|
229
|
+
* Name of the renderer to match the one from `createField()` method in `CmsModelFieldTypePlugin`.
|
|
230
|
+
*
|
|
231
|
+
* ```ts
|
|
232
|
+
* renderName: "myFieldTypeRenderer"
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
rendererName: string;
|
|
236
|
+
/**
|
|
237
|
+
* A display name for the field in the UI. It is a `ReactNode` type, so you can use a JSX element.
|
|
238
|
+
*
|
|
239
|
+
* ```tsx
|
|
240
|
+
* name: <MyFieldNameComponent />
|
|
241
|
+
* ```
|
|
242
|
+
*/
|
|
243
|
+
name: React.ReactNode;
|
|
244
|
+
/**
|
|
245
|
+
* A description for the field in the UI. Works exactly like the `name` property.
|
|
246
|
+
*
|
|
247
|
+
* ```tsx
|
|
248
|
+
* name: <MyFieldDescriptionComponent />
|
|
249
|
+
* ```
|
|
250
|
+
*/
|
|
251
|
+
description: React.ReactNode;
|
|
252
|
+
/**
|
|
253
|
+
* A method that determines if the field can be rendered by this plugin.
|
|
254
|
+
*
|
|
255
|
+
* ```ts
|
|
256
|
+
* canUse({ field }) {
|
|
257
|
+
* return (
|
|
258
|
+
* field.type === "myType" && !field.multipleValues
|
|
259
|
+
* );
|
|
260
|
+
* }
|
|
261
|
+
* ```
|
|
262
|
+
*/
|
|
263
|
+
canUse(props: {
|
|
264
|
+
field: CmsModelField;
|
|
265
|
+
fieldPlugin: CmsModelFieldTypePlugin;
|
|
266
|
+
}): boolean;
|
|
267
|
+
/**
|
|
268
|
+
* Renders a field in the UI.
|
|
269
|
+
*
|
|
270
|
+
* ```tsx
|
|
271
|
+
* render({ field, getBind }) {
|
|
272
|
+
* const Bind = getBind();
|
|
273
|
+
*
|
|
274
|
+
* return (
|
|
275
|
+
* <Bind>
|
|
276
|
+
* {bind => {
|
|
277
|
+
* return (
|
|
278
|
+
* <Input
|
|
279
|
+
* value={bind.value}
|
|
280
|
+
* onChange={bind.onChange}
|
|
281
|
+
* />
|
|
282
|
+
* )
|
|
283
|
+
* }}
|
|
284
|
+
* </Bind>
|
|
285
|
+
* );
|
|
286
|
+
* }
|
|
287
|
+
* ```
|
|
288
|
+
*/
|
|
289
|
+
render(props: CmsModelFieldRendererProps): React.ReactNode;
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
export interface CmsEditorFieldPredefinedValuesEntry {
|
|
293
|
+
label: string;
|
|
294
|
+
value: string;
|
|
295
|
+
selected?: boolean;
|
|
296
|
+
}
|
|
297
|
+
export interface CmsEditorFieldPredefinedValues {
|
|
298
|
+
enabled: boolean;
|
|
299
|
+
values: CmsEditorFieldPredefinedValuesEntry[];
|
|
300
|
+
}
|
|
301
|
+
export interface CmsDynamicZoneTemplate {
|
|
302
|
+
id: string;
|
|
303
|
+
name: string;
|
|
304
|
+
gqlTypeName: string;
|
|
305
|
+
description: string;
|
|
306
|
+
icon: string;
|
|
307
|
+
fields: CmsModelField[];
|
|
308
|
+
layout: string[][];
|
|
309
|
+
validation: CmsModelFieldValidator[];
|
|
310
|
+
}
|
|
311
|
+
export declare type CmsContentEntryStatusType = "draft" | "published" | "unpublished";
|
|
312
|
+
/**
|
|
313
|
+
* @deprecated Use `CmsContentEntry`.
|
|
314
|
+
*/
|
|
315
|
+
export declare type CmsEditorContentEntry = CmsContentEntry;
|
|
316
|
+
export interface CmsContentEntry {
|
|
317
|
+
id: string;
|
|
318
|
+
savedOn: string;
|
|
319
|
+
modelId: string;
|
|
320
|
+
createdBy: CmsIdentity;
|
|
321
|
+
meta: {
|
|
322
|
+
title: string;
|
|
323
|
+
description?: string;
|
|
324
|
+
image?: string;
|
|
325
|
+
publishedOn: string;
|
|
326
|
+
locked: boolean;
|
|
327
|
+
status: CmsContentEntryStatusType;
|
|
328
|
+
version: number;
|
|
329
|
+
};
|
|
330
|
+
[key: string]: any;
|
|
331
|
+
}
|
|
332
|
+
export interface CmsContentEntryRevision {
|
|
333
|
+
id: string;
|
|
334
|
+
savedOn: string;
|
|
335
|
+
modelId: string;
|
|
336
|
+
createdBy: CmsIdentity;
|
|
337
|
+
meta: {
|
|
338
|
+
title: string;
|
|
339
|
+
publishedOn: string;
|
|
340
|
+
locked: boolean;
|
|
341
|
+
status: CmsContentEntryStatusType;
|
|
342
|
+
version: number;
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
export declare type CmsEditorContentTab = React.FC<{
|
|
346
|
+
activeTab: boolean;
|
|
347
|
+
}>;
|
|
348
|
+
export interface CmsEditorFieldOptionPlugin extends Plugin {
|
|
349
|
+
type: "cms-editor-field-option";
|
|
350
|
+
render(): ReactElement;
|
|
351
|
+
}
|
|
352
|
+
export interface CmsContentDetailsPlugin extends Plugin {
|
|
353
|
+
render: (params: any) => ReactNode;
|
|
354
|
+
}
|
|
355
|
+
export interface FieldLayoutPosition {
|
|
356
|
+
row: number;
|
|
357
|
+
index: number | null;
|
|
358
|
+
}
|
|
359
|
+
export interface CmsEditorFormSettingsPlugin extends Plugin {
|
|
360
|
+
type: "cms-editor-form-settings";
|
|
361
|
+
title: string;
|
|
362
|
+
description: string;
|
|
363
|
+
icon: React.ReactElement;
|
|
364
|
+
render(props: {
|
|
365
|
+
Bind: BaseBindComponent;
|
|
366
|
+
form: FormAPI;
|
|
367
|
+
formData: any;
|
|
368
|
+
}): React.ReactNode;
|
|
369
|
+
renderHeaderActions?(props: {
|
|
370
|
+
Bind: BaseBindComponent;
|
|
371
|
+
form: FormAPI;
|
|
372
|
+
formData: any;
|
|
373
|
+
}): React.ReactNode;
|
|
374
|
+
}
|
|
375
|
+
export interface CmsIcon {
|
|
376
|
+
/**
|
|
377
|
+
* [ pack, icon ], ex: ["fab", "cog"]
|
|
378
|
+
*/
|
|
379
|
+
id: [IconPrefix, IconName];
|
|
380
|
+
/**
|
|
381
|
+
* Icon name
|
|
382
|
+
*/
|
|
383
|
+
name: string;
|
|
384
|
+
/**
|
|
385
|
+
* SVG element
|
|
386
|
+
*/
|
|
387
|
+
svg: ReactElement;
|
|
388
|
+
}
|
|
389
|
+
export interface CmsIconsPlugin extends Plugin {
|
|
390
|
+
type: "cms-icons";
|
|
391
|
+
getIcons(): CmsIcon[];
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Transform field value when sending data to the API.
|
|
395
|
+
*/
|
|
396
|
+
export interface CmsFieldValueTransformer<TField extends CmsModelField = CmsModelField> extends Plugin {
|
|
397
|
+
/**
|
|
398
|
+
* A plugin type.
|
|
399
|
+
*/
|
|
400
|
+
type: "cms-field-value-transformer";
|
|
401
|
+
/**
|
|
402
|
+
* A field type for the value transformer. Or a list of field types.
|
|
403
|
+
*/
|
|
404
|
+
fieldType: string | string[];
|
|
405
|
+
/**
|
|
406
|
+
* A transformer function that takes a value and returns a new one.
|
|
407
|
+
*/
|
|
408
|
+
transform: (value: any, field: TField) => any;
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Define a custom form layout renderer for a specific content model.
|
|
412
|
+
*/
|
|
413
|
+
export interface CmsContentFormRendererPlugin extends Plugin {
|
|
414
|
+
/**
|
|
415
|
+
* A plugin type.
|
|
416
|
+
*/
|
|
417
|
+
type: "cms-content-form-renderer";
|
|
418
|
+
/**
|
|
419
|
+
* Content model ID that will use this renderer.
|
|
420
|
+
*/
|
|
421
|
+
modelId: string;
|
|
422
|
+
/**
|
|
423
|
+
* A function that will render a custom form layout.
|
|
424
|
+
*/
|
|
425
|
+
render(props: {
|
|
426
|
+
/**
|
|
427
|
+
* Content model that is being rendered.
|
|
428
|
+
*/
|
|
429
|
+
contentModel: CmsModel;
|
|
430
|
+
/**
|
|
431
|
+
* Content entry data handled by the Form element.
|
|
432
|
+
*/
|
|
433
|
+
data: Record<string, any>;
|
|
434
|
+
/**
|
|
435
|
+
* A component to bind data to the Form.
|
|
436
|
+
*/
|
|
437
|
+
Bind: BindComponent;
|
|
438
|
+
/**
|
|
439
|
+
* Content model fields to render.
|
|
440
|
+
*/
|
|
441
|
+
fields: Record<string, React.ReactElement>;
|
|
442
|
+
}): React.ReactNode;
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* #########################
|
|
446
|
+
* Data types
|
|
447
|
+
* #########################
|
|
448
|
+
*/
|
|
449
|
+
export interface CmsSecurityPermission extends SecurityPermission {
|
|
450
|
+
accessLevel?: "full" | "no" | "custom";
|
|
451
|
+
models?: Record<string, string>;
|
|
452
|
+
groups?: Record<string, string>;
|
|
453
|
+
endpoints?: string[];
|
|
454
|
+
locales?: string[];
|
|
455
|
+
rwd?: string;
|
|
456
|
+
own?: boolean;
|
|
457
|
+
pw?: string;
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* @category GraphQL
|
|
461
|
+
* @category Error
|
|
462
|
+
*/
|
|
463
|
+
export interface CmsErrorResponse {
|
|
464
|
+
message: string;
|
|
465
|
+
code: string;
|
|
466
|
+
data: Record<string, any> | Record<string, any>[];
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* @category GraphQL
|
|
470
|
+
* @category Meta
|
|
471
|
+
*/
|
|
472
|
+
export interface CmsMetaResponse {
|
|
473
|
+
totalCount: number;
|
|
474
|
+
cursor: string | null;
|
|
475
|
+
hasMoreItems: boolean;
|
|
476
|
+
}
|
|
477
|
+
/***
|
|
478
|
+
* ###### FORM ########
|
|
479
|
+
*/
|
|
480
|
+
export interface BindComponentRenderProp<T = any, F = Record<string, any>> extends BaseBindComponentRenderProp<T, F> {
|
|
481
|
+
parentName: string;
|
|
482
|
+
appendValue: (value: any, index?: number) => void;
|
|
483
|
+
prependValue: (value: any) => void;
|
|
484
|
+
appendValues: (values: any[]) => void;
|
|
485
|
+
removeValue: (index: number) => void;
|
|
486
|
+
moveValueUp: (index: number) => void;
|
|
487
|
+
moveValueDown: (index: number) => void;
|
|
488
|
+
}
|
|
489
|
+
interface BindComponentProps extends Omit<BaseBindComponentProps, "children" | "name"> {
|
|
490
|
+
name?: string;
|
|
491
|
+
children?: ((props: BindComponentRenderProp) => React.ReactElement) | React.ReactElement;
|
|
492
|
+
}
|
|
493
|
+
export declare type BindComponent = React.FC<BindComponentProps> & {
|
|
494
|
+
parentName?: string;
|
|
495
|
+
};
|
|
496
|
+
/**
|
|
497
|
+
* After RequestReview and RequestChanges was removed, we need an option to add new status filters
|
|
498
|
+
*/
|
|
499
|
+
export interface CmsEntryFilterStatusPlugin extends Plugin {
|
|
500
|
+
type: "cms.entry.filter.status";
|
|
501
|
+
label: string;
|
|
502
|
+
value: string;
|
|
503
|
+
}
|
package/types/index.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _validation = require("./validation");
|
|
7
|
+
Object.keys(_validation).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _validation[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function get() {
|
|
13
|
+
return _validation[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
var _model = require("./model");
|
|
18
|
+
Object.keys(_model).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _model[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function get() {
|
|
24
|
+
return _model[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
var _shared = require("./shared");
|
|
29
|
+
Object.keys(_shared).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _shared[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function get() {
|
|
35
|
+
return _shared[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["import * as React from \"react\";\nimport { ReactElement, ReactNode } from \"react\";\nimport { Plugin } from \"@webiny/plugins/types\";\nimport {\n BindComponent as BaseBindComponent,\n BindComponentProps as BaseBindComponentProps,\n BindComponentRenderProp as BaseBindComponentRenderProp,\n FormAPI\n} from \"@webiny/form\";\nimport { IconName, IconPrefix } from \"@fortawesome/fontawesome-svg-core\";\nimport { SecurityPermission } from \"@webiny/app-security/types\";\nimport {\n CmsModelFieldValidator,\n CmsModelFieldValidatorsFactory,\n CmsModelFieldValidatorsGroup\n} from \"./validation\";\nimport { CmsModel, CmsModelField } from \"./model\";\nimport { CmsIdentity } from \"~/types/shared\";\nimport { DragObjectWithType } from \"react-dnd\";\n\nexport * from \"./validation\";\nexport * from \"./model\";\nexport * from \"./shared\";\n\ninterface QueryFieldParams {\n model: CmsModel;\n field: CmsModelField;\n}\n\ninterface Position {\n row: number;\n index: number;\n}\n\nexport interface DragSource extends DragObjectWithType {\n parent?: string;\n pos?: Partial<Position>;\n type: \"row\" | \"field\" | \"newField\";\n fieldType?: string;\n field?: CmsModelField | null;\n fields?: CmsModelField[];\n}\n\n/**\n * @deprecated Use `CmsModelFieldTypePlugin`.\n */\nexport type CmsEditorFieldTypePlugin = CmsModelFieldTypePlugin;\n\nexport interface CmsModelFieldTypePlugin extends Plugin {\n /**\n * a plugin type\n */\n type: \"cms-editor-field-type\";\n field: {\n /**\n * A unique identifier of the field type (text, number, json, myField, ...).\n *\n * ```ts\n * type: \"myField\"\n * ```\n */\n type: string;\n /**\n * A display name for the field.\n *\n * ```ts\n * label: \"Field name\"\n * ```\n */\n label: string;\n /**\n * A list of available validators for the model field.\n *\n * ```ts\n * validators: [\n * \"required\",\n * \"gte\",\n * \"lte\"\n * ]\n * ```\n */\n validators?: string[] | CmsModelFieldValidatorsGroup | CmsModelFieldValidatorsFactory;\n /**\n * A list of available validators when a model field accepts a list (array) of values.\n *\n * ```ts\n * listValidators: [\n * \"minLength\",\n * \"maxLength\"\n * ]\n * ```\n */\n listValidators?: string[] | CmsModelFieldValidatorsGroup | CmsModelFieldValidatorsFactory;\n /**\n * An explanation of the field displayed beneath the label.\n *\n * ```ts\n * description: \"A short description of the field\"\n * ```\n */\n description: string;\n /**\n * A ReactNode to display the icon for the field.\n *\n * ```tsx\n * icon: <MyIconComponent />\n * ```\n */\n icon: React.ReactNode;\n /**\n * Is it allowed to have multiple values in this field?\n *\n * ```ts\n * allowMultipleValues: true\n * ```\n */\n allowMultipleValues?: boolean;\n /**\n * Does this field type have a fixed list of values that can be selected?\n *\n * ```ts\n * allowPredefinedValues: false\n * ```\n */\n allowPredefinedValues?: boolean;\n /**\n * A ReactNode label when multiple values are enabled.\n */\n multipleValuesLabel?: React.ReactNode;\n /**\n * These are default values when the field is first created. This is a representation of the field that is stored in the database.\n *\n * ```ts\n * createField: () => ({\n * type: \"fieldType\",\n * validation: [],\n * renderer: {\n * name: \"fieldTypeRenderer\"\n * }\n * })\n * ```\n */\n createField: () => Pick<CmsModelField, \"type\" | \"validation\" | \"renderer\" | \"settings\">;\n /**\n * If `true` (default), this field will be configurable via a settings dialog.\n * If `false`, a user will not be able to open the settings dialog, not will the dialog be opened on field drop.\n */\n canEditSettings?: boolean;\n /**\n * Determine if a `draggable` can be dropped into this field.\n * NOTE: This is only applicable to nested field types.\n */\n canAccept?(field: CmsModelField, draggable: DragSource): boolean;\n /**\n * If `true` (default), will allow fields to be laid out into columns (next to each other).\n * If `false`, horizontal layout will not be allowed.\n * NOTE: This is only applicable to nested field types.\n */\n allowLayout?: boolean;\n /**\n * A ReactNode that you can add in the section below the help text when creating/editing field.\n *\n * ```tsx\n * renderSettings: (params) => {\n * return <FieldSettingsComponent />;\n * }\n * ```\n */\n renderSettings?: (params: {\n afterChangeLabel: (value: string) => void;\n uniqueFieldIdValidator: (fieldId: string) => void;\n contentModel: CmsModel;\n }) => React.ReactNode;\n /**\n * A ReactNode that renders in the Predefined values tab.\n *\n * ```tsx\n * renderPredefinedValues: (params) => {\n * const {form: {Bind}} = params;\n * return (\n * <Bind name=\"fieldProperty\">\n * <InputComponent />\n * </Bind>\n * );\n * }\n * ```\n */\n renderPredefinedValues?: (params: {\n getBind: (index?: number) => any;\n }) => React.ReactElement;\n /**\n * Object wrapper for GraphQL stuff\n */\n graphql?: {\n /**\n * Define field selection.\n *\n * ```ts\n * graphql: {\n * queryField: `\n * {\n * id\n * title\n * createdOn\n * }\n * `,\n * }\n * ```\n */\n queryField?: string | ((params: QueryFieldParams) => string);\n };\n render?(params: any): React.ReactElement;\n tags?: string[];\n /**\n * Render additional information in the Admin UI Model edit view\n */\n renderInfo?: (params: { field: CmsModelField; model: CmsModel }) => React.ReactElement;\n };\n}\n\nexport interface CmsModelFieldRendererProps {\n field: CmsModelField;\n Label: React.FC;\n getBind: (index?: number, key?: string) => BindComponent;\n contentModel: CmsModel;\n}\n\n/**\n * @deprecated Use `CmsModelFieldRendererProps`.\n */\nexport type CmsEditorFieldRendererProps = CmsModelFieldRendererProps;\n\n/**\n * @deprecated Use `CmsModelFieldRendererPlugin`.\n */\nexport type CmsEditorFieldRendererPlugin = CmsModelFieldRendererPlugin;\n\nexport interface CmsModelFieldRendererPlugin extends Plugin {\n /**\n * a plugin type\n */\n type: \"cms-editor-field-renderer\";\n renderer: {\n /**\n * Name of the renderer to match the one from `createField()` method in `CmsModelFieldTypePlugin`.\n *\n * ```ts\n * renderName: \"myFieldTypeRenderer\"\n * ```\n */\n rendererName: string;\n /**\n * A display name for the field in the UI. It is a `ReactNode` type, so you can use a JSX element.\n *\n * ```tsx\n * name: <MyFieldNameComponent />\n * ```\n */\n name: React.ReactNode;\n /**\n * A description for the field in the UI. Works exactly like the `name` property.\n *\n * ```tsx\n * name: <MyFieldDescriptionComponent />\n * ```\n */\n description: React.ReactNode;\n /**\n * A method that determines if the field can be rendered by this plugin.\n *\n * ```ts\n * canUse({ field }) {\n * return (\n * field.type === \"myType\" && !field.multipleValues\n * );\n * }\n * ```\n */\n canUse(props: { field: CmsModelField; fieldPlugin: CmsModelFieldTypePlugin }): boolean;\n /**\n * Renders a field in the UI.\n *\n * ```tsx\n * render({ field, getBind }) {\n * const Bind = getBind();\n *\n * return (\n * <Bind>\n * {bind => {\n * return (\n * <Input\n * value={bind.value}\n * onChange={bind.onChange}\n * />\n * )\n * }}\n * </Bind>\n * );\n * }\n * ```\n */\n render(props: CmsModelFieldRendererProps): React.ReactNode;\n };\n}\n\nexport interface CmsEditorFieldPredefinedValuesEntry {\n label: string;\n value: string;\n selected?: boolean;\n}\n\nexport interface CmsEditorFieldPredefinedValues {\n enabled: boolean;\n values: CmsEditorFieldPredefinedValuesEntry[];\n}\n\nexport interface CmsDynamicZoneTemplate {\n id: string;\n name: string;\n gqlTypeName: string;\n description: string;\n icon: string;\n fields: CmsModelField[];\n layout: string[][];\n validation: CmsModelFieldValidator[];\n}\n\nexport type CmsContentEntryStatusType = \"draft\" | \"published\" | \"unpublished\";\n\n/**\n * @deprecated Use `CmsContentEntry`.\n */\nexport type CmsEditorContentEntry = CmsContentEntry;\n\nexport interface CmsContentEntry {\n id: string;\n savedOn: string;\n modelId: string;\n createdBy: CmsIdentity;\n meta: {\n title: string;\n description?: string;\n image?: string;\n publishedOn: string;\n locked: boolean;\n status: CmsContentEntryStatusType;\n version: number;\n };\n [key: string]: any;\n}\n\nexport interface CmsContentEntryRevision {\n id: string;\n savedOn: string;\n modelId: string;\n createdBy: CmsIdentity;\n meta: {\n title: string;\n publishedOn: string;\n locked: boolean;\n status: CmsContentEntryStatusType;\n version: number;\n };\n}\n\nexport type CmsEditorContentTab = React.FC<{ activeTab: boolean }>;\n\n// ------------------------------------------------------------------------------------------------------------\nexport interface CmsEditorFieldOptionPlugin extends Plugin {\n type: \"cms-editor-field-option\";\n render(): ReactElement;\n}\n\nexport interface CmsContentDetailsPlugin extends Plugin {\n render: (params: any) => ReactNode;\n}\n\nexport interface FieldLayoutPosition {\n row: number;\n index: number | null;\n}\n\nexport interface CmsEditorFormSettingsPlugin extends Plugin {\n type: \"cms-editor-form-settings\";\n title: string;\n description: string;\n icon: React.ReactElement;\n render(props: { Bind: BaseBindComponent; form: FormAPI; formData: any }): React.ReactNode;\n renderHeaderActions?(props: {\n Bind: BaseBindComponent;\n form: FormAPI;\n formData: any;\n }): React.ReactNode;\n}\n\nexport interface CmsIcon {\n /**\n * [ pack, icon ], ex: [\"fab\", \"cog\"]\n */\n id: [IconPrefix, IconName];\n /**\n * Icon name\n */\n name: string;\n /**\n * SVG element\n */\n svg: ReactElement;\n}\n\nexport interface CmsIconsPlugin extends Plugin {\n type: \"cms-icons\";\n getIcons(): CmsIcon[];\n}\n\n/**\n * Transform field value when sending data to the API.\n */\nexport interface CmsFieldValueTransformer<TField extends CmsModelField = CmsModelField>\n extends Plugin {\n /**\n * A plugin type.\n */\n type: \"cms-field-value-transformer\";\n /**\n * A field type for the value transformer. Or a list of field types.\n */\n fieldType: string | string[];\n /**\n * A transformer function that takes a value and returns a new one.\n */\n transform: (value: any, field: TField) => any;\n}\n\n/**\n * Define a custom form layout renderer for a specific content model.\n */\nexport interface CmsContentFormRendererPlugin extends Plugin {\n /**\n * A plugin type.\n */\n type: \"cms-content-form-renderer\";\n /**\n * Content model ID that will use this renderer.\n */\n modelId: string;\n\n /**\n * A function that will render a custom form layout.\n */\n render(props: {\n /**\n * Content model that is being rendered.\n */\n contentModel: CmsModel;\n /**\n * Content entry data handled by the Form element.\n */\n data: Record<string, any>;\n /**\n * A component to bind data to the Form.\n */\n Bind: BindComponent;\n /**\n * Content model fields to render.\n */\n fields: Record<string, React.ReactElement>;\n }): React.ReactNode;\n}\n/**\n * #########################\n * Data types\n * #########################\n */\nexport interface CmsSecurityPermission extends SecurityPermission {\n accessLevel?: \"full\" | \"no\" | \"custom\";\n models?: Record<string, string>;\n groups?: Record<string, string>;\n endpoints?: string[];\n locales?: string[];\n rwd?: string;\n own?: boolean;\n pw?: string;\n}\n\n/**\n * @category GraphQL\n * @category Error\n */\nexport interface CmsErrorResponse {\n message: string;\n code: string;\n data: Record<string, any> | Record<string, any>[];\n}\n/**\n * @category GraphQL\n * @category Meta\n */\nexport interface CmsMetaResponse {\n totalCount: number;\n cursor: string | null;\n hasMoreItems: boolean;\n}\n\n/***\n * ###### FORM ########\n */\nexport interface BindComponentRenderProp<T = any, F = Record<string, any>>\n extends BaseBindComponentRenderProp<T, F> {\n parentName: string;\n appendValue: (value: any, index?: number) => void;\n prependValue: (value: any) => void;\n appendValues: (values: any[]) => void;\n removeValue: (index: number) => void;\n moveValueUp: (index: number) => void;\n moveValueDown: (index: number) => void;\n}\n\ninterface BindComponentProps extends Omit<BaseBindComponentProps, \"children\" | \"name\"> {\n name?: string;\n children?: ((props: BindComponentRenderProp) => React.ReactElement) | React.ReactElement;\n}\n\nexport type BindComponent = React.FC<BindComponentProps> & {\n parentName?: string;\n};\n\n/**\n * After RequestReview and RequestChanges was removed, we need an option to add new status filters\n */\nexport interface CmsEntryFilterStatusPlugin extends Plugin {\n type: \"cms.entry.filter.status\";\n label: string;\n value: string;\n}\n"],"mappings":";;;;;AAoBA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
|
package/types/model.d.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { CmsModelFieldValidator } from "./validation";
|
|
2
|
+
import { CmsDynamicZoneTemplate, CmsEditorFieldPredefinedValues } from "./index";
|
|
3
|
+
import { CmsIdentity } from "./shared";
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated Use `CmsModelField` instead.
|
|
6
|
+
*/
|
|
7
|
+
export declare type CmsEditorField<T = unknown> = CmsModelField<T>;
|
|
8
|
+
export interface CmsModelFieldSettings<T = unknown> {
|
|
9
|
+
defaultValue?: string | null | undefined;
|
|
10
|
+
defaultSetValue?: string;
|
|
11
|
+
type?: string;
|
|
12
|
+
fields?: CmsModelField<T>[];
|
|
13
|
+
layout?: string[][];
|
|
14
|
+
models?: Pick<CmsModel, "modelId">[];
|
|
15
|
+
templates?: CmsDynamicZoneTemplate[];
|
|
16
|
+
imagesOnly?: boolean;
|
|
17
|
+
[key: string]: any;
|
|
18
|
+
}
|
|
19
|
+
export declare type CmsModelField<T = unknown> = T & {
|
|
20
|
+
id: string;
|
|
21
|
+
type: string;
|
|
22
|
+
fieldId: CmsEditorFieldId;
|
|
23
|
+
storageId?: string;
|
|
24
|
+
label: string;
|
|
25
|
+
helpText?: string;
|
|
26
|
+
placeholderText?: string;
|
|
27
|
+
validation?: CmsModelFieldValidator[];
|
|
28
|
+
listValidation?: CmsModelFieldValidator[];
|
|
29
|
+
multipleValues?: boolean;
|
|
30
|
+
predefinedValues?: CmsEditorFieldPredefinedValues;
|
|
31
|
+
settings?: CmsModelFieldSettings<T>;
|
|
32
|
+
renderer: {
|
|
33
|
+
name: string;
|
|
34
|
+
};
|
|
35
|
+
tags?: string[];
|
|
36
|
+
};
|
|
37
|
+
export declare type CmsEditorFieldId = string;
|
|
38
|
+
export declare type CmsEditorFieldsLayout = CmsEditorFieldId[][];
|
|
39
|
+
/**
|
|
40
|
+
* @category GraphQL
|
|
41
|
+
* @category Model
|
|
42
|
+
*/
|
|
43
|
+
export declare type CmsEditorContentModel = CmsModel;
|
|
44
|
+
/**
|
|
45
|
+
* @category GraphQL
|
|
46
|
+
* @category Group
|
|
47
|
+
*/
|
|
48
|
+
export interface CmsGroup {
|
|
49
|
+
id: string;
|
|
50
|
+
name: string;
|
|
51
|
+
slug: string;
|
|
52
|
+
icon?: string;
|
|
53
|
+
description?: string;
|
|
54
|
+
contentModels: CmsModel[];
|
|
55
|
+
createdBy: CmsIdentity;
|
|
56
|
+
/**
|
|
57
|
+
* Tells if this group is a plugin one (cannot be changed/deleted)
|
|
58
|
+
*/
|
|
59
|
+
plugin?: boolean;
|
|
60
|
+
}
|
|
61
|
+
export interface CmsModel {
|
|
62
|
+
id: string;
|
|
63
|
+
group: Pick<CmsGroup, "id" | "name">;
|
|
64
|
+
description?: string;
|
|
65
|
+
version: number;
|
|
66
|
+
layout?: CmsEditorFieldsLayout;
|
|
67
|
+
fields: CmsModelField[];
|
|
68
|
+
lockedFields: CmsModelField[];
|
|
69
|
+
icon: string;
|
|
70
|
+
name: string;
|
|
71
|
+
modelId: string;
|
|
72
|
+
singularApiName: string;
|
|
73
|
+
pluralApiName: string;
|
|
74
|
+
titleFieldId: string | null;
|
|
75
|
+
descriptionFieldId: string | null;
|
|
76
|
+
imageFieldId: string | null;
|
|
77
|
+
settings: {
|
|
78
|
+
[key: string]: any;
|
|
79
|
+
};
|
|
80
|
+
status: string;
|
|
81
|
+
savedOn: string;
|
|
82
|
+
meta: any;
|
|
83
|
+
createdBy: CmsIdentity;
|
|
84
|
+
tags: string[];
|
|
85
|
+
/**
|
|
86
|
+
* If model is a plugin one (it cannot be changed/deleted)
|
|
87
|
+
*/
|
|
88
|
+
plugin?: boolean;
|
|
89
|
+
}
|
package/types/model.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["model.ts"],"sourcesContent":["import { CmsModelFieldValidator } from \"~/types/validation\";\nimport { CmsDynamicZoneTemplate, CmsEditorFieldPredefinedValues } from \"~/types/index\";\nimport { CmsIdentity } from \"~/types/shared\";\n\n/**\n * @deprecated Use `CmsModelField` instead.\n */\nexport type CmsEditorField<T = unknown> = CmsModelField<T>;\n\nexport interface CmsModelFieldSettings<T = unknown> {\n defaultValue?: string | null | undefined;\n defaultSetValue?: string;\n type?: string;\n fields?: CmsModelField<T>[];\n layout?: string[][];\n models?: Pick<CmsModel, \"modelId\">[];\n templates?: CmsDynamicZoneTemplate[];\n imagesOnly?: boolean;\n [key: string]: any;\n}\n\nexport type CmsModelField<T = unknown> = T & {\n id: string;\n type: string;\n fieldId: CmsEditorFieldId;\n storageId?: string;\n label: string;\n helpText?: string;\n placeholderText?: string;\n validation?: CmsModelFieldValidator[];\n listValidation?: CmsModelFieldValidator[];\n multipleValues?: boolean;\n predefinedValues?: CmsEditorFieldPredefinedValues;\n settings?: CmsModelFieldSettings<T>;\n renderer: {\n name: string;\n };\n tags?: string[];\n};\n\nexport type CmsEditorFieldId = string;\nexport type CmsEditorFieldsLayout = CmsEditorFieldId[][];\n\n/**\n * @category GraphQL\n * @category Model\n */\nexport type CmsEditorContentModel = CmsModel;\n\n/**\n * @category GraphQL\n * @category Group\n */\nexport interface CmsGroup {\n id: string;\n name: string;\n slug: string;\n icon?: string;\n description?: string;\n contentModels: CmsModel[];\n createdBy: CmsIdentity;\n /**\n * Tells if this group is a plugin one (cannot be changed/deleted)\n */\n plugin?: boolean;\n}\n\nexport interface CmsModel {\n id: string;\n group: Pick<CmsGroup, \"id\" | \"name\">;\n description?: string;\n version: number;\n layout?: CmsEditorFieldsLayout;\n fields: CmsModelField[];\n lockedFields: CmsModelField[];\n icon: string;\n name: string;\n modelId: string;\n singularApiName: string;\n pluralApiName: string;\n titleFieldId: string | null;\n descriptionFieldId: string | null;\n imageFieldId: string | null;\n settings: {\n [key: string]: any;\n };\n status: string;\n savedOn: string;\n meta: any;\n createdBy: CmsIdentity;\n tags: string[];\n /**\n * If model is a plugin one (it cannot be changed/deleted)\n */\n plugin?: boolean;\n}\n"],"mappings":""}
|
package/types/shared.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["shared.ts"],"sourcesContent":["export interface CmsIdentity {\n id: string;\n displayName: string;\n type: string;\n}\n"],"mappings":""}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { Plugin } from "@webiny/plugins/types";
|
|
3
|
+
import { CmsModelField } from ".";
|
|
4
|
+
export interface CmsModelFieldValidatorConfigAdapter {
|
|
5
|
+
isRequired(): boolean;
|
|
6
|
+
getName(): string;
|
|
7
|
+
getLabel(): string;
|
|
8
|
+
getDescription(): string;
|
|
9
|
+
getDefaultMessage(): string;
|
|
10
|
+
getDefaultSettings(): Record<string, any> | undefined;
|
|
11
|
+
getVariables(): CmsModelFieldValidatorVariable[];
|
|
12
|
+
getVariableDescription(variableName: string): string | undefined;
|
|
13
|
+
}
|
|
14
|
+
export interface CmsModelFieldValidatorVariable {
|
|
15
|
+
name: string;
|
|
16
|
+
description: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* This interface is used in the validator configuration UI (Field dialog).
|
|
20
|
+
*/
|
|
21
|
+
export interface CmsModelFieldValidatorConfig {
|
|
22
|
+
name: string;
|
|
23
|
+
required?: boolean;
|
|
24
|
+
label?: string;
|
|
25
|
+
description?: string;
|
|
26
|
+
defaultMessage?: string;
|
|
27
|
+
defaultSettings?: Record<string, any>;
|
|
28
|
+
variables?: CmsModelFieldValidatorVariable[];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* This interface allows you to control the title, description, and validators located in the specific
|
|
32
|
+
* validators group, like `validators` or `listValidators` within the Field dialog.
|
|
33
|
+
*/
|
|
34
|
+
export interface CmsModelFieldValidatorsGroup {
|
|
35
|
+
validators: (string | CmsModelFieldValidatorConfig)[];
|
|
36
|
+
title?: string;
|
|
37
|
+
description?: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* This interface allows you to generate validators based on the field configuration.
|
|
41
|
+
*/
|
|
42
|
+
export interface CmsModelFieldValidatorsFactory {
|
|
43
|
+
(field: CmsModelField): string[] | CmsModelFieldValidatorsGroup;
|
|
44
|
+
}
|
|
45
|
+
export interface CmsModelFieldValidator {
|
|
46
|
+
name: string;
|
|
47
|
+
message?: string;
|
|
48
|
+
settings?: any;
|
|
49
|
+
}
|
|
50
|
+
export interface CmsModelFieldValidatorPlugin<T = any> extends Plugin {
|
|
51
|
+
type: "cms-model-field-validator";
|
|
52
|
+
validator: {
|
|
53
|
+
name: string;
|
|
54
|
+
label: string;
|
|
55
|
+
description: string;
|
|
56
|
+
defaultMessage: string;
|
|
57
|
+
variables?: CmsModelFieldValidatorVariable[];
|
|
58
|
+
defaultSettings?: Record<string, any>;
|
|
59
|
+
getVariableValues?: (context: {
|
|
60
|
+
validator: CmsModelFieldValidator;
|
|
61
|
+
}) => Record<string, string>;
|
|
62
|
+
renderSettings?: (config: CmsModelFieldValidatorConfigAdapter) => React.ReactElement;
|
|
63
|
+
renderCustomUi?: () => React.ReactElement;
|
|
64
|
+
validate: (value: T, context: {
|
|
65
|
+
validator: CmsModelFieldValidator;
|
|
66
|
+
field: CmsModelField;
|
|
67
|
+
}) => Promise<any>;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
export interface CmsModelFieldRegexValidatorExpressionPlugin extends Plugin {
|
|
71
|
+
type: "cms-model-field-regex-validator-expression";
|
|
72
|
+
pattern: {
|
|
73
|
+
name: string;
|
|
74
|
+
message: string;
|
|
75
|
+
label: string;
|
|
76
|
+
regex: string;
|
|
77
|
+
flags: string;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["validation.ts"],"sourcesContent":["import * as React from \"react\";\nimport { Plugin } from \"@webiny/plugins/types\";\nimport { CmsModelField } from \"~/types\";\n\nexport interface CmsModelFieldValidatorConfigAdapter {\n isRequired(): boolean;\n getName(): string;\n getLabel(): string;\n getDescription(): string;\n getDefaultMessage(): string;\n getDefaultSettings(): Record<string, any> | undefined;\n getVariables(): CmsModelFieldValidatorVariable[];\n getVariableDescription(variableName: string): string | undefined;\n}\n\nexport interface CmsModelFieldValidatorVariable {\n name: string;\n description: string;\n}\n\n/**\n * This interface is used in the validator configuration UI (Field dialog).\n */\nexport interface CmsModelFieldValidatorConfig {\n name: string;\n required?: boolean;\n label?: string;\n description?: string;\n defaultMessage?: string;\n defaultSettings?: Record<string, any>;\n variables?: CmsModelFieldValidatorVariable[];\n}\n\n/**\n * This interface allows you to control the title, description, and validators located in the specific\n * validators group, like `validators` or `listValidators` within the Field dialog.\n */\nexport interface CmsModelFieldValidatorsGroup {\n validators: (string | CmsModelFieldValidatorConfig)[];\n title?: string;\n description?: string;\n}\n\n/**\n * This interface allows you to generate validators based on the field configuration.\n */\nexport interface CmsModelFieldValidatorsFactory {\n (field: CmsModelField): string[] | CmsModelFieldValidatorsGroup;\n}\n\nexport interface CmsModelFieldValidator {\n name: string;\n message?: string;\n settings?: any;\n}\n\nexport interface CmsModelFieldValidatorPlugin<T = any> extends Plugin {\n type: \"cms-model-field-validator\";\n validator: {\n name: string;\n label: string;\n description: string;\n defaultMessage: string;\n variables?: CmsModelFieldValidatorVariable[];\n defaultSettings?: Record<string, any>;\n getVariableValues?: (context: {\n validator: CmsModelFieldValidator;\n }) => Record<string, string>;\n renderSettings?: (config: CmsModelFieldValidatorConfigAdapter) => React.ReactElement;\n renderCustomUi?: () => React.ReactElement;\n validate: (\n value: T,\n context: {\n validator: CmsModelFieldValidator;\n field: CmsModelField;\n }\n ) => Promise<any>;\n };\n}\n\nexport interface CmsModelFieldRegexValidatorExpressionPlugin extends Plugin {\n type: \"cms-model-field-regex-validator-expression\";\n pattern: {\n name: string;\n message: string;\n label: string;\n regex: string;\n flags: string;\n };\n}\n"],"mappings":""}
|