lkb-fields-document 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/component-blocks/dist/lkb-fields-document-component-blocks.cjs.d.ts +2 -0
- package/component-blocks/dist/lkb-fields-document-component-blocks.cjs.js +306 -0
- package/component-blocks/dist/lkb-fields-document-component-blocks.esm.js +300 -0
- package/component-blocks/dist/lkb-fields-document-component-blocks.node.cjs.js +306 -0
- package/component-blocks/dist/lkb-fields-document-component-blocks.node.esm.js +300 -0
- package/component-blocks/package.json +4 -0
- package/dist/Cell-0ac0ac66.node.cjs.js +21 -0
- package/dist/Cell-242f7404.esm.js +17 -0
- package/dist/Cell-3103f73d.node.esm.js +17 -0
- package/dist/Cell-bfb56d74.cjs.js +21 -0
- package/dist/Field-0e0f75ed.node.cjs.js +1628 -0
- package/dist/Field-28177061.cjs.js +1628 -0
- package/dist/Field-35b79e6b.node.esm.js +1619 -0
- package/dist/Field-92d13205.esm.js +1619 -0
- package/dist/api-2f524611.esm.js +502 -0
- package/dist/api-73636987.cjs.js +506 -0
- package/dist/api-8e2b20b8.node.cjs.js +506 -0
- package/dist/api-c32e360e.node.esm.js +502 -0
- package/dist/callout-ui-2aded278.cjs.js +131 -0
- package/dist/callout-ui-3e5ca544.node.esm.js +126 -0
- package/dist/callout-ui-8b5f2376.esm.js +126 -0
- package/dist/callout-ui-ad50f301.node.cjs.js +131 -0
- package/dist/declarations/src/component-blocks.d.ts +4 -0
- package/dist/declarations/src/component-blocks.d.ts.map +1 -0
- package/dist/declarations/src/document-editor/component-blocks/api.d.ts +120 -0
- package/dist/declarations/src/document-editor/component-blocks/api.d.ts.map +1 -0
- package/dist/declarations/src/document-editor/component-blocks/types.d.ts +241 -0
- package/dist/declarations/src/document-editor/component-blocks/types.d.ts.map +1 -0
- package/dist/declarations/src/document-editor/toolset/relationship/relationship-shared.d.ts +10 -0
- package/dist/declarations/src/document-editor/toolset/relationship/relationship-shared.d.ts.map +1 -0
- package/dist/declarations/src/index.d.ts +7 -0
- package/dist/declarations/src/index.d.ts.map +1 -0
- package/dist/declarations/src/my-component-blocks/index.d.ts +46 -0
- package/dist/declarations/src/my-component-blocks/index.d.ts.map +1 -0
- package/dist/declarations/src/structure/Cell.d.ts +5 -0
- package/dist/declarations/src/structure/Cell.d.ts.map +1 -0
- package/dist/declarations/src/structure/Field.d.ts +5 -0
- package/dist/declarations/src/structure/Field.d.ts.map +1 -0
- package/dist/declarations/src/structure/controller.d.ts +10 -0
- package/dist/declarations/src/structure/controller.d.ts.map +1 -0
- package/dist/declarations/src/structure/structure.d.ts +4 -0
- package/dist/declarations/src/structure/structure.d.ts.map +1 -0
- package/dist/declarations/src/structure-views.d.ts +5 -0
- package/dist/declarations/src/structure-views.d.ts.map +1 -0
- package/dist/declarations/src/types/DocumentFeatures.d.ts +33 -0
- package/dist/declarations/src/types/DocumentFeatures.d.ts.map +1 -0
- package/dist/declarations/src/types/DocumentFieldConfig.d.ts +18 -0
- package/dist/declarations/src/types/DocumentFieldConfig.d.ts.map +1 -0
- package/dist/declarations/src/types/FormattingConfig.d.ts +28 -0
- package/dist/declarations/src/types/FormattingConfig.d.ts.map +1 -0
- package/dist/declarations/src/types/RelationshipsConfig.d.ts +9 -0
- package/dist/declarations/src/types/RelationshipsConfig.d.ts.map +1 -0
- package/dist/declarations/src/types/StructureFieldConfig.d.ts +10 -0
- package/dist/declarations/src/types/StructureFieldConfig.d.ts.map +1 -0
- package/dist/declarations/src/validation/structure-validation.d.ts +218 -0
- package/dist/declarations/src/validation/structure-validation.d.ts.map +1 -0
- package/dist/declarations/src/views/Cell.d.ts +5 -0
- package/dist/declarations/src/views/Cell.d.ts.map +1 -0
- package/dist/declarations/src/views/Field.d.ts +5 -0
- package/dist/declarations/src/views/Field.d.ts.map +1 -0
- package/dist/declarations/src/views/controller.d.ts +15 -0
- package/dist/declarations/src/views/controller.d.ts.map +1 -0
- package/dist/declarations/src/views/document.d.ts +4 -0
- package/dist/declarations/src/views/document.d.ts.map +1 -0
- package/dist/declarations/src/views.d.ts +7 -0
- package/dist/declarations/src/views.d.ts.map +1 -0
- package/dist/editor-shared-a6e340e6.node.esm.js +1993 -0
- package/dist/editor-shared-a997ae98.node.cjs.js +2007 -0
- package/dist/editor-shared-cc1293ed.cjs.js +2007 -0
- package/dist/editor-shared-da518ba3.esm.js +1993 -0
- package/dist/form-from-preview-2042b9ef.cjs.js +512 -0
- package/dist/form-from-preview-5df6e492.node.esm.js +508 -0
- package/dist/form-from-preview-9e501058.node.cjs.js +512 -0
- package/dist/form-from-preview-b3a66f37.esm.js +508 -0
- package/dist/index-06c36775.cjs.js +14 -0
- package/dist/index-586adb8f.node.esm.js +11 -0
- package/dist/index-67d52357.esm.js +11 -0
- package/dist/index-c3223fdc.node.cjs.js +14 -0
- package/dist/layouts-6412fa2a.esm.js +189 -0
- package/dist/layouts-a4a3cf0b.node.cjs.js +196 -0
- package/dist/layouts-ba9a558b.cjs.js +196 -0
- package/dist/layouts-e653b908.node.esm.js +189 -0
- package/dist/lkb-fields-document.cjs.d.ts +2 -0
- package/dist/lkb-fields-document.cjs.js +1167 -0
- package/dist/lkb-fields-document.esm.js +1162 -0
- package/dist/lkb-fields-document.node.cjs.js +1167 -0
- package/dist/lkb-fields-document.node.esm.js +1162 -0
- package/dist/shared-0533009e.cjs.js +594 -0
- package/dist/shared-4684cc24.node.cjs.js +594 -0
- package/dist/shared-5e864055.node.esm.js +579 -0
- package/dist/shared-aaba5901.esm.js +579 -0
- package/dist/toolbar-state-3359e2f3.cjs.js +994 -0
- package/dist/toolbar-state-945823b8.node.esm.js +971 -0
- package/dist/toolbar-state-9611743f.node.cjs.js +994 -0
- package/dist/toolbar-state-bc8fe661.esm.js +971 -0
- package/dist/utils-06bcddc4.node.cjs.js +747 -0
- package/dist/utils-200ff260.node.esm.js +722 -0
- package/dist/utils-6409f730.cjs.js +747 -0
- package/dist/utils-bc6a0b82.esm.js +722 -0
- package/package.json +118 -0
- package/structure-views/dist/lkb-fields-document-structure-views.cjs.d.ts +2 -0
- package/structure-views/dist/lkb-fields-document-structure-views.cjs.js +138 -0
- package/structure-views/dist/lkb-fields-document-structure-views.esm.js +131 -0
- package/structure-views/dist/lkb-fields-document-structure-views.node.cjs.js +138 -0
- package/structure-views/dist/lkb-fields-document-structure-views.node.esm.js +131 -0
- package/structure-views/package.json +4 -0
- package/views/dist/lkb-fields-document-views.cjs.d.ts +2 -0
- package/views/dist/lkb-fields-document-views.cjs.js +114 -0
- package/views/dist/lkb-fields-document-views.esm.js +95 -0
- package/views/dist/lkb-fields-document-views.node.cjs.js +114 -0
- package/views/dist/lkb-fields-document-views.node.esm.js +95 -0
- package/views/package.json +4 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var slate = require('slate');
|
|
7
|
+
var weakMemoize = require('@emotion/weak-memoize');
|
|
8
|
+
var index = require('../../dist/index-06c36775.cjs.js');
|
|
9
|
+
var editorShared = require('../../dist/editor-shared-cc1293ed.cjs.js');
|
|
10
|
+
var utils = require('../../dist/utils-6409f730.cjs.js');
|
|
11
|
+
var Field = require('../../dist/Field-28177061.cjs.js');
|
|
12
|
+
var Cell = require('../../dist/Cell-bfb56d74.cjs.js');
|
|
13
|
+
require('@braintree/sanitize-url');
|
|
14
|
+
require('slate-history');
|
|
15
|
+
require('../../dist/shared-0533009e.cjs.js');
|
|
16
|
+
require('mdast-util-from-markdown');
|
|
17
|
+
require('mdast-util-gfm-autolink-literal/from-markdown');
|
|
18
|
+
require('micromark-extension-gfm-autolink-literal');
|
|
19
|
+
require('mdast-util-gfm-strikethrough/from-markdown');
|
|
20
|
+
require('micromark-extension-gfm-strikethrough');
|
|
21
|
+
|
|
22
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
23
|
+
|
|
24
|
+
var weakMemoize__default = /*#__PURE__*/_interopDefault(weakMemoize);
|
|
25
|
+
var Field__default = /*#__PURE__*/_interopDefault(Field);
|
|
26
|
+
var Cell__default = /*#__PURE__*/_interopDefault(Cell);
|
|
27
|
+
|
|
28
|
+
function controller(config) {
|
|
29
|
+
const memoizedIsComponentBlockValid = weakMemoize__default["default"](componentBlock => weakMemoize__default["default"](props => utils.clientSideValidateProp({
|
|
30
|
+
kind: 'object',
|
|
31
|
+
fields: componentBlock.schema
|
|
32
|
+
}, props)));
|
|
33
|
+
const componentBlocks = config.customViews.componentBlocks || {};
|
|
34
|
+
const serverSideComponentBlocksSet = new Set(config.fieldMeta.componentBlocksPassedOnServer);
|
|
35
|
+
const componentBlocksOnlyBeingPassedOnTheClient = Object.keys(componentBlocks).filter(x => !serverSideComponentBlocksSet.has(x));
|
|
36
|
+
if (componentBlocksOnlyBeingPassedOnTheClient.length) {
|
|
37
|
+
throw new Error(`(${config.listKey}:${config.path}) The following component blocks are being passed in the custom view but not in the server-side field config: ${JSON.stringify(componentBlocksOnlyBeingPassedOnTheClient)}`);
|
|
38
|
+
}
|
|
39
|
+
const clientSideComponentBlocksSet = new Set(Object.keys(componentBlocks));
|
|
40
|
+
const componentBlocksOnlyBeingPassedOnTheServer = config.fieldMeta.componentBlocksPassedOnServer.filter(x => !clientSideComponentBlocksSet.has(x));
|
|
41
|
+
if (componentBlocksOnlyBeingPassedOnTheServer.length) {
|
|
42
|
+
throw new Error(`(${config.listKey}:${config.path}) The following component blocks are being passed in the server-side field config but not in the custom view: ${JSON.stringify(componentBlocksOnlyBeingPassedOnTheServer)}`);
|
|
43
|
+
}
|
|
44
|
+
const validateNode = weakMemoize__default["default"](node => {
|
|
45
|
+
if (slate.Text.isText(node)) {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
if (node.type === 'component-block') {
|
|
49
|
+
const componentBlock = componentBlocks[node.component];
|
|
50
|
+
if (componentBlock) {
|
|
51
|
+
if (!memoizedIsComponentBlockValid(componentBlock)(node.props)) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (node.type === 'link' && (typeof node.href !== 'string' || !index.isValidURL(node.href))) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
return node.children.every(node => validateNode(node));
|
|
60
|
+
});
|
|
61
|
+
return {
|
|
62
|
+
path: config.path,
|
|
63
|
+
label: config.label,
|
|
64
|
+
description: config.description,
|
|
65
|
+
graphqlSelection: `${config.path} {document(hydrateRelationships: true)}`,
|
|
66
|
+
componentBlocks: config.customViews.componentBlocks || {},
|
|
67
|
+
documentFeatures: config.fieldMeta.documentFeatures,
|
|
68
|
+
relationships: config.fieldMeta.relationships,
|
|
69
|
+
defaultValue: [{
|
|
70
|
+
type: 'paragraph',
|
|
71
|
+
children: [{
|
|
72
|
+
text: ''
|
|
73
|
+
}]
|
|
74
|
+
}],
|
|
75
|
+
deserialize: data => {
|
|
76
|
+
var _data$config$path;
|
|
77
|
+
const documentFromServer = (_data$config$path = data[config.path]) === null || _data$config$path === void 0 ? void 0 : _data$config$path.document;
|
|
78
|
+
if (!documentFromServer) {
|
|
79
|
+
return [{
|
|
80
|
+
type: 'paragraph',
|
|
81
|
+
children: [{
|
|
82
|
+
text: ''
|
|
83
|
+
}]
|
|
84
|
+
}];
|
|
85
|
+
}
|
|
86
|
+
// make a temporary editor to normalize the document
|
|
87
|
+
const editor = editorShared.createDocumentEditor(config.fieldMeta.documentFeatures, componentBlocks, config.fieldMeta.relationships);
|
|
88
|
+
editor.children = documentFromServer;
|
|
89
|
+
slate.Editor.normalize(editor, {
|
|
90
|
+
force: true
|
|
91
|
+
});
|
|
92
|
+
return editor.children;
|
|
93
|
+
},
|
|
94
|
+
serialize: value => ({
|
|
95
|
+
[config.path]: value
|
|
96
|
+
}),
|
|
97
|
+
validate(value) {
|
|
98
|
+
return value.every(node => validateNode(node));
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const allowedExportsOnCustomViews = ['componentBlocks'];
|
|
104
|
+
|
|
105
|
+
Object.defineProperty(exports, 'Field', {
|
|
106
|
+
enumerable: true,
|
|
107
|
+
get: function () { return Field__default["default"]; }
|
|
108
|
+
});
|
|
109
|
+
Object.defineProperty(exports, 'Cell', {
|
|
110
|
+
enumerable: true,
|
|
111
|
+
get: function () { return Cell__default["default"]; }
|
|
112
|
+
});
|
|
113
|
+
exports.allowedExportsOnCustomViews = allowedExportsOnCustomViews;
|
|
114
|
+
exports.controller = controller;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { Text, Editor } from 'slate';
|
|
3
|
+
import weakMemoize from '@emotion/weak-memoize';
|
|
4
|
+
import { i as isValidURL } from '../../dist/index-67d52357.esm.js';
|
|
5
|
+
import { c as createDocumentEditor } from '../../dist/editor-shared-da518ba3.esm.js';
|
|
6
|
+
import { p as clientSideValidateProp } from '../../dist/utils-bc6a0b82.esm.js';
|
|
7
|
+
export { default as Field } from '../../dist/Field-92d13205.esm.js';
|
|
8
|
+
export { default as Cell } from '../../dist/Cell-242f7404.esm.js';
|
|
9
|
+
import '@braintree/sanitize-url';
|
|
10
|
+
import 'slate-history';
|
|
11
|
+
import '../../dist/shared-aaba5901.esm.js';
|
|
12
|
+
import 'mdast-util-from-markdown';
|
|
13
|
+
import 'mdast-util-gfm-autolink-literal/from-markdown';
|
|
14
|
+
import 'micromark-extension-gfm-autolink-literal';
|
|
15
|
+
import 'mdast-util-gfm-strikethrough/from-markdown';
|
|
16
|
+
import 'micromark-extension-gfm-strikethrough';
|
|
17
|
+
|
|
18
|
+
function controller(config) {
|
|
19
|
+
const memoizedIsComponentBlockValid = weakMemoize(componentBlock => weakMemoize(props => clientSideValidateProp({
|
|
20
|
+
kind: 'object',
|
|
21
|
+
fields: componentBlock.schema
|
|
22
|
+
}, props)));
|
|
23
|
+
const componentBlocks = config.customViews.componentBlocks || {};
|
|
24
|
+
const serverSideComponentBlocksSet = new Set(config.fieldMeta.componentBlocksPassedOnServer);
|
|
25
|
+
const componentBlocksOnlyBeingPassedOnTheClient = Object.keys(componentBlocks).filter(x => !serverSideComponentBlocksSet.has(x));
|
|
26
|
+
if (componentBlocksOnlyBeingPassedOnTheClient.length) {
|
|
27
|
+
throw new Error(`(${config.listKey}:${config.path}) The following component blocks are being passed in the custom view but not in the server-side field config: ${JSON.stringify(componentBlocksOnlyBeingPassedOnTheClient)}`);
|
|
28
|
+
}
|
|
29
|
+
const clientSideComponentBlocksSet = new Set(Object.keys(componentBlocks));
|
|
30
|
+
const componentBlocksOnlyBeingPassedOnTheServer = config.fieldMeta.componentBlocksPassedOnServer.filter(x => !clientSideComponentBlocksSet.has(x));
|
|
31
|
+
if (componentBlocksOnlyBeingPassedOnTheServer.length) {
|
|
32
|
+
throw new Error(`(${config.listKey}:${config.path}) The following component blocks are being passed in the server-side field config but not in the custom view: ${JSON.stringify(componentBlocksOnlyBeingPassedOnTheServer)}`);
|
|
33
|
+
}
|
|
34
|
+
const validateNode = weakMemoize(node => {
|
|
35
|
+
if (Text.isText(node)) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
if (node.type === 'component-block') {
|
|
39
|
+
const componentBlock = componentBlocks[node.component];
|
|
40
|
+
if (componentBlock) {
|
|
41
|
+
if (!memoizedIsComponentBlockValid(componentBlock)(node.props)) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (node.type === 'link' && (typeof node.href !== 'string' || !isValidURL(node.href))) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
return node.children.every(node => validateNode(node));
|
|
50
|
+
});
|
|
51
|
+
return {
|
|
52
|
+
path: config.path,
|
|
53
|
+
label: config.label,
|
|
54
|
+
description: config.description,
|
|
55
|
+
graphqlSelection: `${config.path} {document(hydrateRelationships: true)}`,
|
|
56
|
+
componentBlocks: config.customViews.componentBlocks || {},
|
|
57
|
+
documentFeatures: config.fieldMeta.documentFeatures,
|
|
58
|
+
relationships: config.fieldMeta.relationships,
|
|
59
|
+
defaultValue: [{
|
|
60
|
+
type: 'paragraph',
|
|
61
|
+
children: [{
|
|
62
|
+
text: ''
|
|
63
|
+
}]
|
|
64
|
+
}],
|
|
65
|
+
deserialize: data => {
|
|
66
|
+
var _data$config$path;
|
|
67
|
+
const documentFromServer = (_data$config$path = data[config.path]) === null || _data$config$path === void 0 ? void 0 : _data$config$path.document;
|
|
68
|
+
if (!documentFromServer) {
|
|
69
|
+
return [{
|
|
70
|
+
type: 'paragraph',
|
|
71
|
+
children: [{
|
|
72
|
+
text: ''
|
|
73
|
+
}]
|
|
74
|
+
}];
|
|
75
|
+
}
|
|
76
|
+
// make a temporary editor to normalize the document
|
|
77
|
+
const editor = createDocumentEditor(config.fieldMeta.documentFeatures, componentBlocks, config.fieldMeta.relationships);
|
|
78
|
+
editor.children = documentFromServer;
|
|
79
|
+
Editor.normalize(editor, {
|
|
80
|
+
force: true
|
|
81
|
+
});
|
|
82
|
+
return editor.children;
|
|
83
|
+
},
|
|
84
|
+
serialize: value => ({
|
|
85
|
+
[config.path]: value
|
|
86
|
+
}),
|
|
87
|
+
validate(value) {
|
|
88
|
+
return value.every(node => validateNode(node));
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const allowedExportsOnCustomViews = ['componentBlocks'];
|
|
94
|
+
|
|
95
|
+
export { allowedExportsOnCustomViews, controller };
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var slate = require('slate');
|
|
7
|
+
var weakMemoize = require('@emotion/weak-memoize');
|
|
8
|
+
var index = require('../../dist/index-c3223fdc.node.cjs.js');
|
|
9
|
+
var editorShared = require('../../dist/editor-shared-a997ae98.node.cjs.js');
|
|
10
|
+
var utils = require('../../dist/utils-06bcddc4.node.cjs.js');
|
|
11
|
+
var Field = require('../../dist/Field-0e0f75ed.node.cjs.js');
|
|
12
|
+
var Cell = require('../../dist/Cell-0ac0ac66.node.cjs.js');
|
|
13
|
+
require('@braintree/sanitize-url');
|
|
14
|
+
require('slate-history');
|
|
15
|
+
require('../../dist/shared-4684cc24.node.cjs.js');
|
|
16
|
+
require('mdast-util-from-markdown');
|
|
17
|
+
require('mdast-util-gfm-autolink-literal/from-markdown');
|
|
18
|
+
require('micromark-extension-gfm-autolink-literal');
|
|
19
|
+
require('mdast-util-gfm-strikethrough/from-markdown');
|
|
20
|
+
require('micromark-extension-gfm-strikethrough');
|
|
21
|
+
|
|
22
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
23
|
+
|
|
24
|
+
var weakMemoize__default = /*#__PURE__*/_interopDefault(weakMemoize);
|
|
25
|
+
var Field__default = /*#__PURE__*/_interopDefault(Field);
|
|
26
|
+
var Cell__default = /*#__PURE__*/_interopDefault(Cell);
|
|
27
|
+
|
|
28
|
+
function controller(config) {
|
|
29
|
+
const memoizedIsComponentBlockValid = weakMemoize__default["default"](componentBlock => weakMemoize__default["default"](props => utils.clientSideValidateProp({
|
|
30
|
+
kind: 'object',
|
|
31
|
+
fields: componentBlock.schema
|
|
32
|
+
}, props)));
|
|
33
|
+
const componentBlocks = config.customViews.componentBlocks || {};
|
|
34
|
+
const serverSideComponentBlocksSet = new Set(config.fieldMeta.componentBlocksPassedOnServer);
|
|
35
|
+
const componentBlocksOnlyBeingPassedOnTheClient = Object.keys(componentBlocks).filter(x => !serverSideComponentBlocksSet.has(x));
|
|
36
|
+
if (componentBlocksOnlyBeingPassedOnTheClient.length) {
|
|
37
|
+
throw new Error(`(${config.listKey}:${config.path}) The following component blocks are being passed in the custom view but not in the server-side field config: ${JSON.stringify(componentBlocksOnlyBeingPassedOnTheClient)}`);
|
|
38
|
+
}
|
|
39
|
+
const clientSideComponentBlocksSet = new Set(Object.keys(componentBlocks));
|
|
40
|
+
const componentBlocksOnlyBeingPassedOnTheServer = config.fieldMeta.componentBlocksPassedOnServer.filter(x => !clientSideComponentBlocksSet.has(x));
|
|
41
|
+
if (componentBlocksOnlyBeingPassedOnTheServer.length) {
|
|
42
|
+
throw new Error(`(${config.listKey}:${config.path}) The following component blocks are being passed in the server-side field config but not in the custom view: ${JSON.stringify(componentBlocksOnlyBeingPassedOnTheServer)}`);
|
|
43
|
+
}
|
|
44
|
+
const validateNode = weakMemoize__default["default"](node => {
|
|
45
|
+
if (slate.Text.isText(node)) {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
if (node.type === 'component-block') {
|
|
49
|
+
const componentBlock = componentBlocks[node.component];
|
|
50
|
+
if (componentBlock) {
|
|
51
|
+
if (!memoizedIsComponentBlockValid(componentBlock)(node.props)) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (node.type === 'link' && (typeof node.href !== 'string' || !index.isValidURL(node.href))) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
return node.children.every(node => validateNode(node));
|
|
60
|
+
});
|
|
61
|
+
return {
|
|
62
|
+
path: config.path,
|
|
63
|
+
label: config.label,
|
|
64
|
+
description: config.description,
|
|
65
|
+
graphqlSelection: `${config.path} {document(hydrateRelationships: true)}`,
|
|
66
|
+
componentBlocks: config.customViews.componentBlocks || {},
|
|
67
|
+
documentFeatures: config.fieldMeta.documentFeatures,
|
|
68
|
+
relationships: config.fieldMeta.relationships,
|
|
69
|
+
defaultValue: [{
|
|
70
|
+
type: 'paragraph',
|
|
71
|
+
children: [{
|
|
72
|
+
text: ''
|
|
73
|
+
}]
|
|
74
|
+
}],
|
|
75
|
+
deserialize: data => {
|
|
76
|
+
var _data$config$path;
|
|
77
|
+
const documentFromServer = (_data$config$path = data[config.path]) === null || _data$config$path === void 0 ? void 0 : _data$config$path.document;
|
|
78
|
+
if (!documentFromServer) {
|
|
79
|
+
return [{
|
|
80
|
+
type: 'paragraph',
|
|
81
|
+
children: [{
|
|
82
|
+
text: ''
|
|
83
|
+
}]
|
|
84
|
+
}];
|
|
85
|
+
}
|
|
86
|
+
// make a temporary editor to normalize the document
|
|
87
|
+
const editor = editorShared.createDocumentEditor(config.fieldMeta.documentFeatures, componentBlocks, config.fieldMeta.relationships);
|
|
88
|
+
editor.children = documentFromServer;
|
|
89
|
+
slate.Editor.normalize(editor, {
|
|
90
|
+
force: true
|
|
91
|
+
});
|
|
92
|
+
return editor.children;
|
|
93
|
+
},
|
|
94
|
+
serialize: value => ({
|
|
95
|
+
[config.path]: value
|
|
96
|
+
}),
|
|
97
|
+
validate(value) {
|
|
98
|
+
return value.every(node => validateNode(node));
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const allowedExportsOnCustomViews = ['componentBlocks'];
|
|
104
|
+
|
|
105
|
+
Object.defineProperty(exports, 'Field', {
|
|
106
|
+
enumerable: true,
|
|
107
|
+
get: function () { return Field__default["default"]; }
|
|
108
|
+
});
|
|
109
|
+
Object.defineProperty(exports, 'Cell', {
|
|
110
|
+
enumerable: true,
|
|
111
|
+
get: function () { return Cell__default["default"]; }
|
|
112
|
+
});
|
|
113
|
+
exports.allowedExportsOnCustomViews = allowedExportsOnCustomViews;
|
|
114
|
+
exports.controller = controller;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { Text, Editor } from 'slate';
|
|
3
|
+
import weakMemoize from '@emotion/weak-memoize';
|
|
4
|
+
import { i as isValidURL } from '../../dist/index-586adb8f.node.esm.js';
|
|
5
|
+
import { c as createDocumentEditor } from '../../dist/editor-shared-a6e340e6.node.esm.js';
|
|
6
|
+
import { p as clientSideValidateProp } from '../../dist/utils-200ff260.node.esm.js';
|
|
7
|
+
export { default as Field } from '../../dist/Field-35b79e6b.node.esm.js';
|
|
8
|
+
export { default as Cell } from '../../dist/Cell-3103f73d.node.esm.js';
|
|
9
|
+
import '@braintree/sanitize-url';
|
|
10
|
+
import 'slate-history';
|
|
11
|
+
import '../../dist/shared-5e864055.node.esm.js';
|
|
12
|
+
import 'mdast-util-from-markdown';
|
|
13
|
+
import 'mdast-util-gfm-autolink-literal/from-markdown';
|
|
14
|
+
import 'micromark-extension-gfm-autolink-literal';
|
|
15
|
+
import 'mdast-util-gfm-strikethrough/from-markdown';
|
|
16
|
+
import 'micromark-extension-gfm-strikethrough';
|
|
17
|
+
|
|
18
|
+
function controller(config) {
|
|
19
|
+
const memoizedIsComponentBlockValid = weakMemoize(componentBlock => weakMemoize(props => clientSideValidateProp({
|
|
20
|
+
kind: 'object',
|
|
21
|
+
fields: componentBlock.schema
|
|
22
|
+
}, props)));
|
|
23
|
+
const componentBlocks = config.customViews.componentBlocks || {};
|
|
24
|
+
const serverSideComponentBlocksSet = new Set(config.fieldMeta.componentBlocksPassedOnServer);
|
|
25
|
+
const componentBlocksOnlyBeingPassedOnTheClient = Object.keys(componentBlocks).filter(x => !serverSideComponentBlocksSet.has(x));
|
|
26
|
+
if (componentBlocksOnlyBeingPassedOnTheClient.length) {
|
|
27
|
+
throw new Error(`(${config.listKey}:${config.path}) The following component blocks are being passed in the custom view but not in the server-side field config: ${JSON.stringify(componentBlocksOnlyBeingPassedOnTheClient)}`);
|
|
28
|
+
}
|
|
29
|
+
const clientSideComponentBlocksSet = new Set(Object.keys(componentBlocks));
|
|
30
|
+
const componentBlocksOnlyBeingPassedOnTheServer = config.fieldMeta.componentBlocksPassedOnServer.filter(x => !clientSideComponentBlocksSet.has(x));
|
|
31
|
+
if (componentBlocksOnlyBeingPassedOnTheServer.length) {
|
|
32
|
+
throw new Error(`(${config.listKey}:${config.path}) The following component blocks are being passed in the server-side field config but not in the custom view: ${JSON.stringify(componentBlocksOnlyBeingPassedOnTheServer)}`);
|
|
33
|
+
}
|
|
34
|
+
const validateNode = weakMemoize(node => {
|
|
35
|
+
if (Text.isText(node)) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
if (node.type === 'component-block') {
|
|
39
|
+
const componentBlock = componentBlocks[node.component];
|
|
40
|
+
if (componentBlock) {
|
|
41
|
+
if (!memoizedIsComponentBlockValid(componentBlock)(node.props)) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (node.type === 'link' && (typeof node.href !== 'string' || !isValidURL(node.href))) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
return node.children.every(node => validateNode(node));
|
|
50
|
+
});
|
|
51
|
+
return {
|
|
52
|
+
path: config.path,
|
|
53
|
+
label: config.label,
|
|
54
|
+
description: config.description,
|
|
55
|
+
graphqlSelection: `${config.path} {document(hydrateRelationships: true)}`,
|
|
56
|
+
componentBlocks: config.customViews.componentBlocks || {},
|
|
57
|
+
documentFeatures: config.fieldMeta.documentFeatures,
|
|
58
|
+
relationships: config.fieldMeta.relationships,
|
|
59
|
+
defaultValue: [{
|
|
60
|
+
type: 'paragraph',
|
|
61
|
+
children: [{
|
|
62
|
+
text: ''
|
|
63
|
+
}]
|
|
64
|
+
}],
|
|
65
|
+
deserialize: data => {
|
|
66
|
+
var _data$config$path;
|
|
67
|
+
const documentFromServer = (_data$config$path = data[config.path]) === null || _data$config$path === void 0 ? void 0 : _data$config$path.document;
|
|
68
|
+
if (!documentFromServer) {
|
|
69
|
+
return [{
|
|
70
|
+
type: 'paragraph',
|
|
71
|
+
children: [{
|
|
72
|
+
text: ''
|
|
73
|
+
}]
|
|
74
|
+
}];
|
|
75
|
+
}
|
|
76
|
+
// make a temporary editor to normalize the document
|
|
77
|
+
const editor = createDocumentEditor(config.fieldMeta.documentFeatures, componentBlocks, config.fieldMeta.relationships);
|
|
78
|
+
editor.children = documentFromServer;
|
|
79
|
+
Editor.normalize(editor, {
|
|
80
|
+
force: true
|
|
81
|
+
});
|
|
82
|
+
return editor.children;
|
|
83
|
+
},
|
|
84
|
+
serialize: value => ({
|
|
85
|
+
[config.path]: value
|
|
86
|
+
}),
|
|
87
|
+
validate(value) {
|
|
88
|
+
return value.every(node => validateNode(node));
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const allowedExportsOnCustomViews = ['componentBlocks'];
|
|
94
|
+
|
|
95
|
+
export { allowedExportsOnCustomViews, controller };
|