@kids-reporter/cms-core 1.0.17 → 1.0.19
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/lib/custom-fields/rich-text-editor/index.js +3 -4
- package/lib/custom-fields/rich-text-editor/views/index.js +28 -13
- package/lib/index.js +4 -2
- package/lib/local-types/kids-reporter__draft-editor.d.js +1 -0
- package/lib/utils/manual-order-relationship.js +10 -17
- package/package.json +19 -6
- package/src/custom-fields/rich-text-editor/index.ts +4 -4
- package/src/custom-fields/rich-text-editor/views/index.tsx +5 -5
- package/src/index.ts +2 -1
- package/src/local-types/kids-reporter__draft-editor.d.ts +11 -0
- package/src/utils/manual-order-relationship.ts +7 -7
|
@@ -4,14 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.richTextEditor = void 0;
|
|
7
|
-
var _types = require("@keystone-6/core/types");
|
|
8
7
|
var _core = require("@keystone-6/core");
|
|
8
|
+
var _types = require("@keystone-6/core/types");
|
|
9
9
|
const richTextEditor = ({
|
|
10
10
|
defaultValue = null,
|
|
11
11
|
disabledButtons = [],
|
|
12
12
|
...config
|
|
13
|
-
}
|
|
14
|
-
var _config$db;
|
|
13
|
+
}) => meta => {
|
|
15
14
|
if (config.isIndexed === 'unique') {
|
|
16
15
|
throw Error("isIndexed: 'unique' is not a supported option for field type textEditor");
|
|
17
16
|
}
|
|
@@ -45,7 +44,7 @@ const richTextEditor = ({
|
|
|
45
44
|
kind: 'literal',
|
|
46
45
|
value: JSON.stringify(defaultValue)
|
|
47
46
|
},
|
|
48
|
-
map:
|
|
47
|
+
map: config.db?.map
|
|
49
48
|
});
|
|
50
49
|
};
|
|
51
50
|
exports.richTextEditor = richTextEditor;
|
|
@@ -4,13 +4,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.controller = exports.Field = exports.Cell = exports.CardValue = void 0;
|
|
7
|
-
var
|
|
7
|
+
var _components = require("@keystone-6/core/admin-ui/components");
|
|
8
8
|
var _core = require("@keystone-ui/core");
|
|
9
9
|
var _fields = require("@keystone-ui/fields");
|
|
10
|
-
var _components = require("@keystone-6/core/admin-ui/components");
|
|
11
|
-
var _draftJs = require("draft-js");
|
|
12
10
|
var _draftEditor = require("@kids-reporter/draft-editor");
|
|
13
|
-
|
|
11
|
+
var _draftJs = require("draft-js");
|
|
12
|
+
var _react = _interopRequireDefault(require("react"));
|
|
13
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
14
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
15
|
// eslint-disable-line
|
|
15
16
|
|
|
16
17
|
const Field = ({
|
|
@@ -19,11 +20,17 @@ const Field = ({
|
|
|
19
20
|
onChange,
|
|
20
21
|
autoFocus // eslint-disable-line
|
|
21
22
|
}) => {
|
|
22
|
-
return /*#__PURE__*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_fields.FieldContainer, {
|
|
24
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_fields.FieldLabel, {
|
|
25
|
+
children: [field.label, /*#__PURE__*/(0, _jsxRuntime.jsx)(_core.Stack, {
|
|
26
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_draftEditor.RichTextEditor, {
|
|
27
|
+
disabledButtons: field.disabledButtons,
|
|
28
|
+
editorState: value,
|
|
29
|
+
onChange: editorState => onChange?.(editorState)
|
|
30
|
+
})
|
|
31
|
+
})]
|
|
32
|
+
})
|
|
33
|
+
});
|
|
27
34
|
};
|
|
28
35
|
exports.Field = Field;
|
|
29
36
|
const Cell = ({
|
|
@@ -32,7 +39,12 @@ const Cell = ({
|
|
|
32
39
|
linkTo
|
|
33
40
|
}) => {
|
|
34
41
|
const value = item[field.path] + '';
|
|
35
|
-
return linkTo ? /*#__PURE__*/
|
|
42
|
+
return linkTo ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.CellLink, {
|
|
43
|
+
...linkTo,
|
|
44
|
+
children: value
|
|
45
|
+
}) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.CellContainer, {
|
|
46
|
+
children: value
|
|
47
|
+
});
|
|
36
48
|
};
|
|
37
49
|
exports.Cell = Cell;
|
|
38
50
|
Cell.supportsLinkTo = true;
|
|
@@ -40,14 +52,17 @@ const CardValue = ({
|
|
|
40
52
|
item,
|
|
41
53
|
field
|
|
42
54
|
}) => {
|
|
43
|
-
return /*#__PURE__*/
|
|
55
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_fields.FieldContainer, {
|
|
56
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_fields.FieldLabel, {
|
|
57
|
+
children: field.label
|
|
58
|
+
}), item[field.path]]
|
|
59
|
+
});
|
|
44
60
|
};
|
|
45
61
|
exports.CardValue = CardValue;
|
|
46
62
|
const controller = config => {
|
|
47
|
-
var _config$fieldMeta;
|
|
48
63
|
return {
|
|
49
64
|
description: '',
|
|
50
|
-
disabledButtons:
|
|
65
|
+
disabledButtons: config.fieldMeta?.disabledButtons ?? [],
|
|
51
66
|
path: config.path,
|
|
52
67
|
label: config.label,
|
|
53
68
|
graphqlSelection: config.path,
|
package/lib/index.js
CHANGED
|
@@ -11,10 +11,12 @@ Object.defineProperty(exports, "richTextEditorButtonNames", {
|
|
|
11
11
|
}
|
|
12
12
|
});
|
|
13
13
|
exports.utils = void 0;
|
|
14
|
-
var _manualOrderRelationship = _interopRequireDefault(require("./utils/manual-order-relationship"));
|
|
15
14
|
var _richTextEditor = require("./custom-fields/rich-text-editor");
|
|
15
|
+
var _manualOrderRelationship = _interopRequireDefault(require("./utils/manual-order-relationship"));
|
|
16
16
|
var _draftEditor = require("@kids-reporter/draft-editor");
|
|
17
|
-
function _interopRequireDefault(
|
|
17
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
18
|
+
// @ts-ignore: draft-editor is not typed
|
|
19
|
+
|
|
18
20
|
const customFields = exports.customFields = {
|
|
19
21
|
richTextEditor: _richTextEditor.richTextEditor
|
|
20
22
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -53,10 +53,8 @@ var _fields = require("@keystone-6/core/fields");
|
|
|
53
53
|
* `authorsInInputOrder` is a virtual field, which means its value is computed on-the-fly, not stored in the database. This virtual field combines relationship field `authors` and monitoring field `manualOrderOfAuthors` to sort the authors in specific input order.
|
|
54
54
|
*/
|
|
55
55
|
function addManualOrderRelationshipFields(manualOrderFields = [], list) {
|
|
56
|
-
var _list$hooks;
|
|
57
56
|
manualOrderFields.forEach(mo => {
|
|
58
|
-
|
|
59
|
-
if (!((_list$fields = list.fields) !== null && _list$fields !== void 0 && _list$fields[mo.fieldName])) {
|
|
57
|
+
if (!list.fields?.[mo.fieldName]) {
|
|
60
58
|
list.fields[mo.fieldName] = (0, _fields.json)({
|
|
61
59
|
label: mo.fieldLabel,
|
|
62
60
|
ui: {
|
|
@@ -73,7 +71,7 @@ function addManualOrderRelationshipFields(manualOrderFields = [], list) {
|
|
|
73
71
|
|
|
74
72
|
// decorate `resolveInput` hook
|
|
75
73
|
list.hooks = list.hooks || {};
|
|
76
|
-
const originResolveInput =
|
|
74
|
+
const originResolveInput = list.hooks?.resolveInput;
|
|
77
75
|
list.hooks.resolveInput = async props => {
|
|
78
76
|
let resolvedData = props.resolvedData;
|
|
79
77
|
if (typeof originResolveInput === 'function') {
|
|
@@ -87,7 +85,6 @@ function addManualOrderRelationshipFields(manualOrderFields = [], list) {
|
|
|
87
85
|
// check if create/update item has the fields
|
|
88
86
|
// we want to monitor
|
|
89
87
|
for (let i = 0; i < manualOrderFields.length; i++) {
|
|
90
|
-
var _resolvedData;
|
|
91
88
|
const {
|
|
92
89
|
targetFieldName,
|
|
93
90
|
fieldName,
|
|
@@ -96,17 +93,15 @@ function addManualOrderRelationshipFields(manualOrderFields = [], list) {
|
|
|
96
93
|
} = manualOrderFields[i];
|
|
97
94
|
|
|
98
95
|
// if create/update operation creates/modifies the `${targetFieldName}` field
|
|
99
|
-
if (
|
|
100
|
-
var _resolvedData$targetF2;
|
|
96
|
+
if (resolvedData?.[targetFieldName]) {
|
|
101
97
|
let currentOrder = [];
|
|
102
98
|
|
|
103
99
|
// update operation due to `item` not being `undefiend`
|
|
104
100
|
if (item) {
|
|
105
|
-
var _resolvedData$targetF;
|
|
106
101
|
const previousOrder = Array.isArray(item[fieldName]) ? item[fieldName] : [];
|
|
107
102
|
|
|
108
103
|
// user disconnects/removes some relationship items.
|
|
109
|
-
const disconnectIds =
|
|
104
|
+
const disconnectIds = resolvedData[targetFieldName]?.disconnect?.map(obj => obj.id.toString()) || [];
|
|
110
105
|
|
|
111
106
|
// filtered out to-be-disconnected relationship items
|
|
112
107
|
currentOrder = previousOrder.filter(({
|
|
@@ -117,7 +112,7 @@ function addManualOrderRelationshipFields(manualOrderFields = [], list) {
|
|
|
117
112
|
}
|
|
118
113
|
|
|
119
114
|
// user connects/adds some relationship item.
|
|
120
|
-
const connectedIds =
|
|
115
|
+
const connectedIds = resolvedData[targetFieldName]?.connect?.map(obj => obj.id.toString()) || [];
|
|
121
116
|
if (connectedIds.length > 0) {
|
|
122
117
|
// Query relationship items from the database.
|
|
123
118
|
// Therefore, we can have other fields to record in the monitoring field
|
|
@@ -178,12 +173,10 @@ function addVirtualFieldToReturnItemsInInputOrder(list, manualOrderField) {
|
|
|
178
173
|
const virtualFieldName = `${manualOrderField.targetFieldName}InInputOrder`;
|
|
179
174
|
list.fields[virtualFieldName] = (0, _fields.virtual)({
|
|
180
175
|
field: lists => {
|
|
181
|
-
var _lists$manualOrderFie;
|
|
182
176
|
return _core.graphql.field({
|
|
183
|
-
type: _core.graphql.list(lists
|
|
177
|
+
type: _core.graphql.list(lists?.[manualOrderField.targetListName]?.types.output),
|
|
184
178
|
async resolve(item, args, context) {
|
|
185
|
-
|
|
186
|
-
const manualOrderFieldValue = (item === null || item === void 0 ? void 0 : item[manualOrderField.fieldName]) || [];
|
|
179
|
+
const manualOrderFieldValue = item?.[manualOrderField.fieldName] || [];
|
|
187
180
|
if (!Array.isArray(manualOrderFieldValue)) {
|
|
188
181
|
return [];
|
|
189
182
|
}
|
|
@@ -192,18 +185,18 @@ function addVirtualFieldToReturnItemsInInputOrder(list, manualOrderField) {
|
|
|
192
185
|
const ids = manualOrderFieldValue.map(value => value.id);
|
|
193
186
|
|
|
194
187
|
// query items from database
|
|
195
|
-
const unorderedItems = await
|
|
188
|
+
const unorderedItems = await context.db?.[manualOrderField.targetListName].findMany({
|
|
196
189
|
where: {
|
|
197
190
|
id: {
|
|
198
191
|
in: ids
|
|
199
192
|
}
|
|
200
193
|
}
|
|
201
|
-
})
|
|
194
|
+
});
|
|
202
195
|
const orderedItems = [];
|
|
203
196
|
|
|
204
197
|
// sort items according to input order
|
|
205
198
|
manualOrderFieldValue.forEach(value => {
|
|
206
|
-
const writer = unorderedItems.find(ui => `${ui
|
|
199
|
+
const writer = unorderedItems.find(ui => `${ui?.id}` === `${value?.id}`);
|
|
207
200
|
if (writer) {
|
|
208
201
|
orderedItems.push(writer);
|
|
209
202
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kids-reporter/cms-core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.19",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/index.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
9
9
|
"build": "make build",
|
|
10
|
-
"clean": "make clean"
|
|
10
|
+
"clean": "make clean",
|
|
11
|
+
"lint:check": "eslint src --ext .ts,.tsx,.js,.jsx",
|
|
12
|
+
"type-check": "tsc --noEmit"
|
|
11
13
|
},
|
|
12
14
|
"repository": {
|
|
13
15
|
"type": "git",
|
|
@@ -25,15 +27,17 @@
|
|
|
25
27
|
],
|
|
26
28
|
"license": "MIT",
|
|
27
29
|
"peerDependencies": {
|
|
28
|
-
"
|
|
30
|
+
"react": ">=18",
|
|
31
|
+
"react-dom": ">=18"
|
|
29
32
|
},
|
|
30
33
|
"dependencies": {
|
|
31
34
|
"@google-cloud/storage": "^5.18.0",
|
|
35
|
+
"@keystone-6/core": "6.5.1",
|
|
32
36
|
"@keystone-ui/button": "^7.0.2",
|
|
33
37
|
"@keystone-ui/fields": "^7.2.0",
|
|
34
38
|
"@keystone-ui/modals": "^6.0.3",
|
|
39
|
+
"@kids-reporter/draft-editor": "^1.0.19",
|
|
35
40
|
"@twreporter/errors": "^1.1.1",
|
|
36
|
-
"@kids-reporter/draft-editor": "^1.0.17",
|
|
37
41
|
"axios": "^0.26.0",
|
|
38
42
|
"draft-convert": "^2.1.12",
|
|
39
43
|
"draft-js": "^0.11.7",
|
|
@@ -41,12 +45,21 @@
|
|
|
41
45
|
"immutable": "^4.0.0",
|
|
42
46
|
"lodash": "^4.17.21",
|
|
43
47
|
"shortid": "^2.2.16",
|
|
44
|
-
"styled-components": "
|
|
48
|
+
"styled-components": "6.1.19",
|
|
45
49
|
"zlib": "^1.0.5"
|
|
46
50
|
},
|
|
47
51
|
"files": [
|
|
48
52
|
"lib",
|
|
49
53
|
"src",
|
|
50
54
|
"types"
|
|
51
|
-
]
|
|
55
|
+
],
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@babel/cli": "^7.23.9",
|
|
58
|
+
"@babel/core": "^7.23.9",
|
|
59
|
+
"@babel/preset-env": "^7.25.0",
|
|
60
|
+
"@babel/preset-react": "^7.24.7",
|
|
61
|
+
"@babel/preset-typescript": "^7.24.7",
|
|
62
|
+
"react": "18.3.1",
|
|
63
|
+
"react-dom": "18.3.1"
|
|
64
|
+
}
|
|
52
65
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import { graphql } from '@keystone-6/core'
|
|
1
2
|
import {
|
|
2
3
|
BaseListTypeInfo,
|
|
3
|
-
JSONValue,
|
|
4
|
-
FieldTypeFunc,
|
|
5
4
|
CommonFieldConfig,
|
|
5
|
+
FieldTypeFunc,
|
|
6
6
|
jsonFieldTypePolyfilledForSQLite,
|
|
7
|
+
JSONValue,
|
|
7
8
|
} from '@keystone-6/core/types'
|
|
8
|
-
import { graphql } from '@keystone-6/core'
|
|
9
9
|
|
|
10
10
|
export type JsonFieldConfig<ListTypeInfo extends BaseListTypeInfo> =
|
|
11
11
|
CommonFieldConfig<ListTypeInfo> & {
|
|
@@ -19,7 +19,7 @@ export const richTextEditor =
|
|
|
19
19
|
defaultValue = null,
|
|
20
20
|
disabledButtons = [],
|
|
21
21
|
...config
|
|
22
|
-
}: JsonFieldConfig<ListTypeInfo>
|
|
22
|
+
}: JsonFieldConfig<ListTypeInfo>): FieldTypeFunc<ListTypeInfo> =>
|
|
23
23
|
(meta) => {
|
|
24
24
|
if ((config as any).isIndexed === 'unique') {
|
|
25
25
|
throw Error(
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { jsx, Stack } from '@keystone-ui/core'; // eslint-disable-line
|
|
3
|
-
import { FieldContainer, FieldLabel } from '@keystone-ui/fields'
|
|
1
|
+
import { CellContainer, CellLink } from '@keystone-6/core/admin-ui/components'
|
|
4
2
|
import {
|
|
5
3
|
CardValueComponent,
|
|
6
4
|
CellComponent,
|
|
@@ -9,9 +7,11 @@ import {
|
|
|
9
7
|
FieldProps,
|
|
10
8
|
JSONValue,
|
|
11
9
|
} from '@keystone-6/core/types'
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
10
|
+
import { jsx, Stack } from '@keystone-ui/core' // eslint-disable-line
|
|
11
|
+
import { FieldContainer, FieldLabel } from '@keystone-ui/fields'
|
|
14
12
|
import { RichTextEditor } from '@kids-reporter/draft-editor'
|
|
13
|
+
import { convertFromRaw, convertToRaw, EditorState } from 'draft-js'
|
|
14
|
+
import React from 'react'
|
|
15
15
|
|
|
16
16
|
export const Field = ({
|
|
17
17
|
field,
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import addManualOrderRelationshipFields from './utils/manual-order-relationship'
|
|
2
1
|
import { richTextEditor } from './custom-fields/rich-text-editor'
|
|
2
|
+
import addManualOrderRelationshipFields from './utils/manual-order-relationship'
|
|
3
3
|
|
|
4
|
+
// @ts-ignore: draft-editor is not typed
|
|
4
5
|
export { buttonNames as richTextEditorButtonNames } from '@kids-reporter/draft-editor'
|
|
5
6
|
|
|
6
7
|
export const customFields = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ListConfig, graphql } from '@keystone-6/core'
|
|
1
|
+
import { graphql, ListConfig } from '@keystone-6/core'
|
|
3
2
|
import { json, virtual } from '@keystone-6/core/fields'
|
|
3
|
+
import { BaseItem } from '@keystone-6/core/types'
|
|
4
4
|
|
|
5
5
|
type ManualOrderFieldConfig = {
|
|
6
6
|
fieldName: string
|
|
@@ -58,7 +58,7 @@ type ManualOrderFieldConfig = {
|
|
|
58
58
|
*/
|
|
59
59
|
function addManualOrderRelationshipFields(
|
|
60
60
|
manualOrderFields: ManualOrderFieldConfig[] = [],
|
|
61
|
-
list: ListConfig<any
|
|
61
|
+
list: ListConfig<any>
|
|
62
62
|
) {
|
|
63
63
|
manualOrderFields.forEach((mo) => {
|
|
64
64
|
if (!list.fields?.[mo.fieldName]) {
|
|
@@ -110,9 +110,9 @@ function addManualOrderRelationshipFields(
|
|
|
110
110
|
|
|
111
111
|
// user disconnects/removes some relationship items.
|
|
112
112
|
const disconnectIds =
|
|
113
|
-
resolvedData[
|
|
114
|
-
|
|
115
|
-
|
|
113
|
+
resolvedData[targetFieldName]?.disconnect?.map(
|
|
114
|
+
(obj: { id: number }) => obj.id.toString()
|
|
115
|
+
) || []
|
|
116
116
|
|
|
117
117
|
// filtered out to-be-disconnected relationship items
|
|
118
118
|
currentOrder = previousOrder.filter(({ id }: { id: string }) => {
|
|
@@ -179,7 +179,7 @@ function addManualOrderRelationshipFields(
|
|
|
179
179
|
* And the GQL resolver will be defined in `resolve` function.
|
|
180
180
|
*/
|
|
181
181
|
function addVirtualFieldToReturnItemsInInputOrder(
|
|
182
|
-
list: ListConfig<any
|
|
182
|
+
list: ListConfig<any>,
|
|
183
183
|
manualOrderField: ManualOrderFieldConfig
|
|
184
184
|
) {
|
|
185
185
|
const virtualFieldName = `${manualOrderField.targetFieldName}InInputOrder`
|