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.
Files changed (112) hide show
  1. package/component-blocks/dist/lkb-fields-document-component-blocks.cjs.d.ts +2 -0
  2. package/component-blocks/dist/lkb-fields-document-component-blocks.cjs.js +306 -0
  3. package/component-blocks/dist/lkb-fields-document-component-blocks.esm.js +300 -0
  4. package/component-blocks/dist/lkb-fields-document-component-blocks.node.cjs.js +306 -0
  5. package/component-blocks/dist/lkb-fields-document-component-blocks.node.esm.js +300 -0
  6. package/component-blocks/package.json +4 -0
  7. package/dist/Cell-0ac0ac66.node.cjs.js +21 -0
  8. package/dist/Cell-242f7404.esm.js +17 -0
  9. package/dist/Cell-3103f73d.node.esm.js +17 -0
  10. package/dist/Cell-bfb56d74.cjs.js +21 -0
  11. package/dist/Field-0e0f75ed.node.cjs.js +1628 -0
  12. package/dist/Field-28177061.cjs.js +1628 -0
  13. package/dist/Field-35b79e6b.node.esm.js +1619 -0
  14. package/dist/Field-92d13205.esm.js +1619 -0
  15. package/dist/api-2f524611.esm.js +502 -0
  16. package/dist/api-73636987.cjs.js +506 -0
  17. package/dist/api-8e2b20b8.node.cjs.js +506 -0
  18. package/dist/api-c32e360e.node.esm.js +502 -0
  19. package/dist/callout-ui-2aded278.cjs.js +131 -0
  20. package/dist/callout-ui-3e5ca544.node.esm.js +126 -0
  21. package/dist/callout-ui-8b5f2376.esm.js +126 -0
  22. package/dist/callout-ui-ad50f301.node.cjs.js +131 -0
  23. package/dist/declarations/src/component-blocks.d.ts +4 -0
  24. package/dist/declarations/src/component-blocks.d.ts.map +1 -0
  25. package/dist/declarations/src/document-editor/component-blocks/api.d.ts +120 -0
  26. package/dist/declarations/src/document-editor/component-blocks/api.d.ts.map +1 -0
  27. package/dist/declarations/src/document-editor/component-blocks/types.d.ts +241 -0
  28. package/dist/declarations/src/document-editor/component-blocks/types.d.ts.map +1 -0
  29. package/dist/declarations/src/document-editor/toolset/relationship/relationship-shared.d.ts +10 -0
  30. package/dist/declarations/src/document-editor/toolset/relationship/relationship-shared.d.ts.map +1 -0
  31. package/dist/declarations/src/index.d.ts +7 -0
  32. package/dist/declarations/src/index.d.ts.map +1 -0
  33. package/dist/declarations/src/my-component-blocks/index.d.ts +46 -0
  34. package/dist/declarations/src/my-component-blocks/index.d.ts.map +1 -0
  35. package/dist/declarations/src/structure/Cell.d.ts +5 -0
  36. package/dist/declarations/src/structure/Cell.d.ts.map +1 -0
  37. package/dist/declarations/src/structure/Field.d.ts +5 -0
  38. package/dist/declarations/src/structure/Field.d.ts.map +1 -0
  39. package/dist/declarations/src/structure/controller.d.ts +10 -0
  40. package/dist/declarations/src/structure/controller.d.ts.map +1 -0
  41. package/dist/declarations/src/structure/structure.d.ts +4 -0
  42. package/dist/declarations/src/structure/structure.d.ts.map +1 -0
  43. package/dist/declarations/src/structure-views.d.ts +5 -0
  44. package/dist/declarations/src/structure-views.d.ts.map +1 -0
  45. package/dist/declarations/src/types/DocumentFeatures.d.ts +33 -0
  46. package/dist/declarations/src/types/DocumentFeatures.d.ts.map +1 -0
  47. package/dist/declarations/src/types/DocumentFieldConfig.d.ts +18 -0
  48. package/dist/declarations/src/types/DocumentFieldConfig.d.ts.map +1 -0
  49. package/dist/declarations/src/types/FormattingConfig.d.ts +28 -0
  50. package/dist/declarations/src/types/FormattingConfig.d.ts.map +1 -0
  51. package/dist/declarations/src/types/RelationshipsConfig.d.ts +9 -0
  52. package/dist/declarations/src/types/RelationshipsConfig.d.ts.map +1 -0
  53. package/dist/declarations/src/types/StructureFieldConfig.d.ts +10 -0
  54. package/dist/declarations/src/types/StructureFieldConfig.d.ts.map +1 -0
  55. package/dist/declarations/src/validation/structure-validation.d.ts +218 -0
  56. package/dist/declarations/src/validation/structure-validation.d.ts.map +1 -0
  57. package/dist/declarations/src/views/Cell.d.ts +5 -0
  58. package/dist/declarations/src/views/Cell.d.ts.map +1 -0
  59. package/dist/declarations/src/views/Field.d.ts +5 -0
  60. package/dist/declarations/src/views/Field.d.ts.map +1 -0
  61. package/dist/declarations/src/views/controller.d.ts +15 -0
  62. package/dist/declarations/src/views/controller.d.ts.map +1 -0
  63. package/dist/declarations/src/views/document.d.ts +4 -0
  64. package/dist/declarations/src/views/document.d.ts.map +1 -0
  65. package/dist/declarations/src/views.d.ts +7 -0
  66. package/dist/declarations/src/views.d.ts.map +1 -0
  67. package/dist/editor-shared-a6e340e6.node.esm.js +1993 -0
  68. package/dist/editor-shared-a997ae98.node.cjs.js +2007 -0
  69. package/dist/editor-shared-cc1293ed.cjs.js +2007 -0
  70. package/dist/editor-shared-da518ba3.esm.js +1993 -0
  71. package/dist/form-from-preview-2042b9ef.cjs.js +512 -0
  72. package/dist/form-from-preview-5df6e492.node.esm.js +508 -0
  73. package/dist/form-from-preview-9e501058.node.cjs.js +512 -0
  74. package/dist/form-from-preview-b3a66f37.esm.js +508 -0
  75. package/dist/index-06c36775.cjs.js +14 -0
  76. package/dist/index-586adb8f.node.esm.js +11 -0
  77. package/dist/index-67d52357.esm.js +11 -0
  78. package/dist/index-c3223fdc.node.cjs.js +14 -0
  79. package/dist/layouts-6412fa2a.esm.js +189 -0
  80. package/dist/layouts-a4a3cf0b.node.cjs.js +196 -0
  81. package/dist/layouts-ba9a558b.cjs.js +196 -0
  82. package/dist/layouts-e653b908.node.esm.js +189 -0
  83. package/dist/lkb-fields-document.cjs.d.ts +2 -0
  84. package/dist/lkb-fields-document.cjs.js +1167 -0
  85. package/dist/lkb-fields-document.esm.js +1162 -0
  86. package/dist/lkb-fields-document.node.cjs.js +1167 -0
  87. package/dist/lkb-fields-document.node.esm.js +1162 -0
  88. package/dist/shared-0533009e.cjs.js +594 -0
  89. package/dist/shared-4684cc24.node.cjs.js +594 -0
  90. package/dist/shared-5e864055.node.esm.js +579 -0
  91. package/dist/shared-aaba5901.esm.js +579 -0
  92. package/dist/toolbar-state-3359e2f3.cjs.js +994 -0
  93. package/dist/toolbar-state-945823b8.node.esm.js +971 -0
  94. package/dist/toolbar-state-9611743f.node.cjs.js +994 -0
  95. package/dist/toolbar-state-bc8fe661.esm.js +971 -0
  96. package/dist/utils-06bcddc4.node.cjs.js +747 -0
  97. package/dist/utils-200ff260.node.esm.js +722 -0
  98. package/dist/utils-6409f730.cjs.js +747 -0
  99. package/dist/utils-bc6a0b82.esm.js +722 -0
  100. package/package.json +118 -0
  101. package/structure-views/dist/lkb-fields-document-structure-views.cjs.d.ts +2 -0
  102. package/structure-views/dist/lkb-fields-document-structure-views.cjs.js +138 -0
  103. package/structure-views/dist/lkb-fields-document-structure-views.esm.js +131 -0
  104. package/structure-views/dist/lkb-fields-document-structure-views.node.cjs.js +138 -0
  105. package/structure-views/dist/lkb-fields-document-structure-views.node.esm.js +131 -0
  106. package/structure-views/package.json +4 -0
  107. package/views/dist/lkb-fields-document-views.cjs.d.ts +2 -0
  108. package/views/dist/lkb-fields-document-views.cjs.js +114 -0
  109. package/views/dist/lkb-fields-document-views.esm.js +95 -0
  110. package/views/dist/lkb-fields-document-views.node.cjs.js +114 -0
  111. package/views/dist/lkb-fields-document-views.node.esm.js +95 -0
  112. package/views/package.json +4 -0
package/package.json ADDED
@@ -0,0 +1,118 @@
1
+ {
2
+ "name": "lkb-fields-document",
3
+ "description": "LKB Document Field Type",
4
+ "version": "1.0.0",
5
+ "license": "MIT",
6
+ "main": "dist/lkb-fields-document.cjs.js",
7
+ "module": "dist/lkb-fields-document.esm.js",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/lkb-fields-document.cjs.js",
11
+ "node": {
12
+ "module": "./dist/lkb-fields-document.node.esm.js",
13
+ "default": "./dist/lkb-fields-document.node.cjs.js"
14
+ },
15
+ "react-server": {
16
+ "module": "./dist/lkb-fields-document.node.esm.js",
17
+ "default": "./dist/lkb-fields-document.node.cjs.js"
18
+ },
19
+ "module": "./dist/lkb-fields-document.esm.js",
20
+ "default": "./dist/lkb-fields-document.cjs.js"
21
+ },
22
+ "./views": {
23
+ "types": "./views/dist/lkb-fields-document-views.cjs.js",
24
+ "node": {
25
+ "module": "./views/dist/lkb-fields-document-views.node.esm.js",
26
+ "default": "./views/dist/lkb-fields-document-views.node.cjs.js"
27
+ },
28
+ "react-server": {
29
+ "module": "./views/dist/lkb-fields-document-views.node.esm.js",
30
+ "default": "./views/dist/lkb-fields-document-views.node.cjs.js"
31
+ },
32
+ "module": "./views/dist/lkb-fields-document-views.esm.js",
33
+ "default": "./views/dist/lkb-fields-document-views.cjs.js"
34
+ },
35
+ "./structure-views": {
36
+ "types": "./structure-views/dist/lkb-fields-document-structure-views.cjs.js",
37
+ "node": {
38
+ "module": "./structure-views/dist/lkb-fields-document-structure-views.node.esm.js",
39
+ "default": "./structure-views/dist/lkb-fields-document-structure-views.node.cjs.js"
40
+ },
41
+ "react-server": {
42
+ "module": "./structure-views/dist/lkb-fields-document-structure-views.node.esm.js",
43
+ "default": "./structure-views/dist/lkb-fields-document-structure-views.node.cjs.js"
44
+ },
45
+ "module": "./structure-views/dist/lkb-fields-document-structure-views.esm.js",
46
+ "default": "./structure-views/dist/lkb-fields-document-structure-views.cjs.js"
47
+ },
48
+ "./component-blocks": {
49
+ "types": "./component-blocks/dist/lkb-fields-document-component-blocks.cjs.js",
50
+ "node": {
51
+ "module": "./component-blocks/dist/lkb-fields-document-component-blocks.node.esm.js",
52
+ "default": "./component-blocks/dist/lkb-fields-document-component-blocks.node.cjs.js"
53
+ },
54
+ "react-server": {
55
+ "module": "./component-blocks/dist/lkb-fields-document-component-blocks.node.esm.js",
56
+ "default": "./component-blocks/dist/lkb-fields-document-component-blocks.node.cjs.js"
57
+ },
58
+ "module": "./component-blocks/dist/lkb-fields-document-component-blocks.esm.js",
59
+ "default": "./component-blocks/dist/lkb-fields-document-component-blocks.cjs.js"
60
+ },
61
+ "./package.json": "./package.json"
62
+ },
63
+ "files": [
64
+ "dist",
65
+ "component-blocks",
66
+ "primitives",
67
+ "views",
68
+ "structure-views"
69
+ ],
70
+ "preconstruct": {
71
+ "entrypoints": [
72
+ "component-blocks.tsx",
73
+ "index.ts",
74
+ "views.tsx",
75
+ "structure-views.tsx"
76
+ ]
77
+ },
78
+ "dependencies": {
79
+ "@braintree/sanitize-url": "7.0.4",
80
+ "@emotion/weak-memoize": "^0.4.0",
81
+ "@keystar/ui": "^0.7.16",
82
+ "@react-aria/i18n": "^3.12.1",
83
+ "@react-aria/overlays": "^3.23.2",
84
+ "@react-stately/list": "^3.10.8",
85
+ "@react-stately/overlays": "^3.6.10",
86
+ "@react-aria/utils": "^3.25.1",
87
+ "@types/react": "19.2.4",
88
+ "graphql": "^16.8.1",
89
+ "is-hotkey": "^0.2.0",
90
+ "match-sorter": "^8.0.0",
91
+ "mdast-util-from-markdown": "^0.8.5",
92
+ "mdast-util-gfm-autolink-literal": "^0.1.3",
93
+ "mdast-util-gfm-strikethrough": "^0.2.3",
94
+ "micromark-extension-gfm-autolink-literal": "0.5.7",
95
+ "micromark-extension-gfm-strikethrough": "0.6.5",
96
+ "react": "19.2.4",
97
+ "react-dom": "19.2.4",
98
+ "scroll-into-view-if-needed": "^3.0.0",
99
+ "slate": "^0.112.0",
100
+ "slate-history": "^0.113.0",
101
+ "slate-react": "^0.112.0",
102
+ "zod": "^3.23.8"
103
+ },
104
+ "devDependencies": {
105
+ "lkb-core": "workspace:^",
106
+ "@types/is-hotkey": "^0.1.7"
107
+ },
108
+ "peerDependencies": {
109
+ "lkb-core": "workspace:^"
110
+ },
111
+ "imports": {
112
+ "#fields-ui": {
113
+ "node": "./src/document-editor/component-blocks/fields-ui-empty.tsx",
114
+ "react-server": "./src/document-editor/component-blocks/fields-ui-empty.tsx",
115
+ "default": "./src/document-editor/component-blocks/fields-ui.tsx"
116
+ }
117
+ }
118
+ }
@@ -0,0 +1,2 @@
1
+ export * from "../../dist/declarations/src/structure-views.js";
2
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGtiLWZpZWxkcy1kb2N1bWVudC1zdHJ1Y3R1cmUtdmlld3MuY2pzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9kaXN0L2RlY2xhcmF0aW9ucy9zcmMvc3RydWN0dXJlLXZpZXdzLmQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEifQ==
@@ -0,0 +1,138 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var utils = require('../../dist/utils-6409f730.cjs.js');
6
+ var React = require('react');
7
+ var field = require('@keystar/ui/field');
8
+ var formFromPreview = require('../../dist/form-from-preview-2042b9ef.cjs.js');
9
+ var jsxRuntime = require('react/jsx-runtime');
10
+ var typography = require('@keystar/ui/typography');
11
+ require('slate');
12
+ require('lkb-core/admin-ui/context');
13
+ require('lkb-core/fields/types/relationship/views');
14
+ require('lkb-core/admin-ui/utils');
15
+ require('@keystar/ui/button');
16
+ require('@keystar/ui/dialog');
17
+ require('@keystar/ui/icon');
18
+ require('@keystar/ui/list-view');
19
+ require('@keystar/ui/drag-and-drop');
20
+ require('@keystar/ui/tooltip');
21
+ require('@keystar/ui/layout');
22
+ require('@keystar/ui/icon/icons/trash2Icon');
23
+ require('@keystar/ui/slots');
24
+
25
+ function serializeValue(schema, value, kind) {
26
+ if (schema.kind === 'conditional') {
27
+ return {
28
+ [value.discriminant]: serializeValue(schema.values[value.discriminant], value.value, kind)
29
+ };
30
+ }
31
+ if (schema.kind === 'array') {
32
+ if (value === null) return [];
33
+ return value.map(x => serializeValue(schema.element, x, kind));
34
+ }
35
+ if (schema.kind === 'form') return value;
36
+ if (schema.kind === 'object') {
37
+ return Object.fromEntries(Object.entries(schema.fields).map(([key, val]) => {
38
+ return [key, serializeValue(val, value[key], kind)];
39
+ }));
40
+ }
41
+ if (schema.kind === 'relationship') {
42
+ if (Array.isArray(value)) {
43
+ return {
44
+ [kind === 'create' ? 'connect' : 'set']: value.map(x => ({
45
+ id: x.id
46
+ }))
47
+ };
48
+ }
49
+ if (value === null) {
50
+ if (kind === 'create') return;
51
+ return {
52
+ disconnect: true
53
+ };
54
+ }
55
+ return {
56
+ connect: {
57
+ id: value.id
58
+ }
59
+ };
60
+ }
61
+ if (schema.kind === 'child') {
62
+ throw new Error('Child fields are not supported in the structure field');
63
+ }
64
+ utils.assertNever(schema);
65
+ }
66
+
67
+ function controller(config) {
68
+ if (!config.customViews.schema) throw new Error(`No schema in custom view. Did you forgot to set \`views\` to a file that exports a \`schema\` on ${config.listKey}.${config.path}`);
69
+ return {
70
+ path: config.path,
71
+ label: config.label,
72
+ description: config.description,
73
+ graphqlSelection: `${config.path} { json(hydrateRelationships: true) }`,
74
+ schema: config.customViews.schema,
75
+ defaultValue: {
76
+ kind: 'create',
77
+ value: utils.getInitialPropsValue(config.customViews.schema)
78
+ },
79
+ validate: value => utils.clientSideValidateProp(config.customViews.schema, value.value),
80
+ deserialize: data => {
81
+ var _data$json, _data;
82
+ return {
83
+ kind: 'update',
84
+ value: (_data$json = (_data = data[`${config.path}`]) === null || _data === void 0 ? void 0 : _data.json) !== null && _data$json !== void 0 ? _data$json : null
85
+ };
86
+ },
87
+ serialize: value => {
88
+ return {
89
+ [config.path]: serializeValue(config.customViews.schema, value.value, value.kind)
90
+ };
91
+ }
92
+ };
93
+ }
94
+
95
+ function Field({
96
+ field: field$1,
97
+ value,
98
+ onChange,
99
+ autoFocus,
100
+ forceValidation
101
+ }) {
102
+ const valueRef = React.useRef(value);
103
+ React.useEffect(() => {
104
+ valueRef.current = value;
105
+ });
106
+ const createPreviewProps = React.useMemo(() => {
107
+ return utils.createGetPreviewProps(field$1.schema, getNewVal => {
108
+ onChange === null || onChange === void 0 || onChange({
109
+ kind: valueRef.current.kind,
110
+ value: getNewVal(valueRef.current.value)
111
+ });
112
+ }, () => undefined);
113
+ }, [field$1.schema, onChange]);
114
+ return /*#__PURE__*/jsxRuntime.jsx(field.Field, {
115
+ label: field$1.label,
116
+ description: field$1.description,
117
+ children: inputProps => /*#__PURE__*/jsxRuntime.jsx(formFromPreview.FormValueContentFromPreviewProps, {
118
+ autoFocus: autoFocus,
119
+ forceValidation: forceValidation,
120
+ ...createPreviewProps(value.value)
121
+ })
122
+ });
123
+ }
124
+
125
+ const Cell = ({
126
+ value
127
+ }) => {
128
+ return /*#__PURE__*/jsxRuntime.jsx(typography.Text, {
129
+ children: JSON.stringify(value.json)
130
+ });
131
+ };
132
+
133
+ const allowedExportsOnCustomViews = ['schema'];
134
+
135
+ exports.Cell = Cell;
136
+ exports.Field = Field;
137
+ exports.allowedExportsOnCustomViews = allowedExportsOnCustomViews;
138
+ exports.controller = controller;
@@ -0,0 +1,131 @@
1
+ import { a as assertNever, g as getInitialPropsValue, p as clientSideValidateProp, q as createGetPreviewProps } from '../../dist/utils-bc6a0b82.esm.js';
2
+ import { useRef, useEffect, useMemo } from 'react';
3
+ import { Field as Field$1 } from '@keystar/ui/field';
4
+ import { F as FormValueContentFromPreviewProps } from '../../dist/form-from-preview-b3a66f37.esm.js';
5
+ import { jsx } from 'react/jsx-runtime';
6
+ import { Text } from '@keystar/ui/typography';
7
+ import 'slate';
8
+ import 'lkb-core/admin-ui/context';
9
+ import 'lkb-core/fields/types/relationship/views';
10
+ import 'lkb-core/admin-ui/utils';
11
+ import '@keystar/ui/button';
12
+ import '@keystar/ui/dialog';
13
+ import '@keystar/ui/icon';
14
+ import '@keystar/ui/list-view';
15
+ import '@keystar/ui/drag-and-drop';
16
+ import '@keystar/ui/tooltip';
17
+ import '@keystar/ui/layout';
18
+ import '@keystar/ui/icon/icons/trash2Icon';
19
+ import '@keystar/ui/slots';
20
+
21
+ function serializeValue(schema, value, kind) {
22
+ if (schema.kind === 'conditional') {
23
+ return {
24
+ [value.discriminant]: serializeValue(schema.values[value.discriminant], value.value, kind)
25
+ };
26
+ }
27
+ if (schema.kind === 'array') {
28
+ if (value === null) return [];
29
+ return value.map(x => serializeValue(schema.element, x, kind));
30
+ }
31
+ if (schema.kind === 'form') return value;
32
+ if (schema.kind === 'object') {
33
+ return Object.fromEntries(Object.entries(schema.fields).map(([key, val]) => {
34
+ return [key, serializeValue(val, value[key], kind)];
35
+ }));
36
+ }
37
+ if (schema.kind === 'relationship') {
38
+ if (Array.isArray(value)) {
39
+ return {
40
+ [kind === 'create' ? 'connect' : 'set']: value.map(x => ({
41
+ id: x.id
42
+ }))
43
+ };
44
+ }
45
+ if (value === null) {
46
+ if (kind === 'create') return;
47
+ return {
48
+ disconnect: true
49
+ };
50
+ }
51
+ return {
52
+ connect: {
53
+ id: value.id
54
+ }
55
+ };
56
+ }
57
+ if (schema.kind === 'child') {
58
+ throw new Error('Child fields are not supported in the structure field');
59
+ }
60
+ assertNever(schema);
61
+ }
62
+
63
+ function controller(config) {
64
+ if (!config.customViews.schema) throw new Error(`No schema in custom view. Did you forgot to set \`views\` to a file that exports a \`schema\` on ${config.listKey}.${config.path}`);
65
+ return {
66
+ path: config.path,
67
+ label: config.label,
68
+ description: config.description,
69
+ graphqlSelection: `${config.path} { json(hydrateRelationships: true) }`,
70
+ schema: config.customViews.schema,
71
+ defaultValue: {
72
+ kind: 'create',
73
+ value: getInitialPropsValue(config.customViews.schema)
74
+ },
75
+ validate: value => clientSideValidateProp(config.customViews.schema, value.value),
76
+ deserialize: data => {
77
+ var _data$json, _data;
78
+ return {
79
+ kind: 'update',
80
+ value: (_data$json = (_data = data[`${config.path}`]) === null || _data === void 0 ? void 0 : _data.json) !== null && _data$json !== void 0 ? _data$json : null
81
+ };
82
+ },
83
+ serialize: value => {
84
+ return {
85
+ [config.path]: serializeValue(config.customViews.schema, value.value, value.kind)
86
+ };
87
+ }
88
+ };
89
+ }
90
+
91
+ function Field({
92
+ field,
93
+ value,
94
+ onChange,
95
+ autoFocus,
96
+ forceValidation
97
+ }) {
98
+ const valueRef = useRef(value);
99
+ useEffect(() => {
100
+ valueRef.current = value;
101
+ });
102
+ const createPreviewProps = useMemo(() => {
103
+ return createGetPreviewProps(field.schema, getNewVal => {
104
+ onChange === null || onChange === void 0 || onChange({
105
+ kind: valueRef.current.kind,
106
+ value: getNewVal(valueRef.current.value)
107
+ });
108
+ }, () => undefined);
109
+ }, [field.schema, onChange]);
110
+ return /*#__PURE__*/jsx(Field$1, {
111
+ label: field.label,
112
+ description: field.description,
113
+ children: inputProps => /*#__PURE__*/jsx(FormValueContentFromPreviewProps, {
114
+ autoFocus: autoFocus,
115
+ forceValidation: forceValidation,
116
+ ...createPreviewProps(value.value)
117
+ })
118
+ });
119
+ }
120
+
121
+ const Cell = ({
122
+ value
123
+ }) => {
124
+ return /*#__PURE__*/jsx(Text, {
125
+ children: JSON.stringify(value.json)
126
+ });
127
+ };
128
+
129
+ const allowedExportsOnCustomViews = ['schema'];
130
+
131
+ export { Cell, Field, allowedExportsOnCustomViews, controller };
@@ -0,0 +1,138 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var utils = require('../../dist/utils-06bcddc4.node.cjs.js');
6
+ var React = require('react');
7
+ var field = require('@keystar/ui/field');
8
+ var formFromPreview = require('../../dist/form-from-preview-9e501058.node.cjs.js');
9
+ var jsxRuntime = require('react/jsx-runtime');
10
+ var typography = require('@keystar/ui/typography');
11
+ require('slate');
12
+ require('lkb-core/admin-ui/context');
13
+ require('lkb-core/fields/types/relationship/views');
14
+ require('lkb-core/admin-ui/utils');
15
+ require('@keystar/ui/button');
16
+ require('@keystar/ui/dialog');
17
+ require('@keystar/ui/icon');
18
+ require('@keystar/ui/list-view');
19
+ require('@keystar/ui/drag-and-drop');
20
+ require('@keystar/ui/tooltip');
21
+ require('@keystar/ui/layout');
22
+ require('@keystar/ui/icon/icons/trash2Icon');
23
+ require('@keystar/ui/slots');
24
+
25
+ function serializeValue(schema, value, kind) {
26
+ if (schema.kind === 'conditional') {
27
+ return {
28
+ [value.discriminant]: serializeValue(schema.values[value.discriminant], value.value, kind)
29
+ };
30
+ }
31
+ if (schema.kind === 'array') {
32
+ if (value === null) return [];
33
+ return value.map(x => serializeValue(schema.element, x, kind));
34
+ }
35
+ if (schema.kind === 'form') return value;
36
+ if (schema.kind === 'object') {
37
+ return Object.fromEntries(Object.entries(schema.fields).map(([key, val]) => {
38
+ return [key, serializeValue(val, value[key], kind)];
39
+ }));
40
+ }
41
+ if (schema.kind === 'relationship') {
42
+ if (Array.isArray(value)) {
43
+ return {
44
+ [kind === 'create' ? 'connect' : 'set']: value.map(x => ({
45
+ id: x.id
46
+ }))
47
+ };
48
+ }
49
+ if (value === null) {
50
+ if (kind === 'create') return;
51
+ return {
52
+ disconnect: true
53
+ };
54
+ }
55
+ return {
56
+ connect: {
57
+ id: value.id
58
+ }
59
+ };
60
+ }
61
+ if (schema.kind === 'child') {
62
+ throw new Error('Child fields are not supported in the structure field');
63
+ }
64
+ utils.assertNever(schema);
65
+ }
66
+
67
+ function controller(config) {
68
+ if (!config.customViews.schema) throw new Error(`No schema in custom view. Did you forgot to set \`views\` to a file that exports a \`schema\` on ${config.listKey}.${config.path}`);
69
+ return {
70
+ path: config.path,
71
+ label: config.label,
72
+ description: config.description,
73
+ graphqlSelection: `${config.path} { json(hydrateRelationships: true) }`,
74
+ schema: config.customViews.schema,
75
+ defaultValue: {
76
+ kind: 'create',
77
+ value: utils.getInitialPropsValue(config.customViews.schema)
78
+ },
79
+ validate: value => utils.clientSideValidateProp(config.customViews.schema, value.value),
80
+ deserialize: data => {
81
+ var _data$json, _data;
82
+ return {
83
+ kind: 'update',
84
+ value: (_data$json = (_data = data[`${config.path}`]) === null || _data === void 0 ? void 0 : _data.json) !== null && _data$json !== void 0 ? _data$json : null
85
+ };
86
+ },
87
+ serialize: value => {
88
+ return {
89
+ [config.path]: serializeValue(config.customViews.schema, value.value, value.kind)
90
+ };
91
+ }
92
+ };
93
+ }
94
+
95
+ function Field({
96
+ field: field$1,
97
+ value,
98
+ onChange,
99
+ autoFocus,
100
+ forceValidation
101
+ }) {
102
+ const valueRef = React.useRef(value);
103
+ React.useEffect(() => {
104
+ valueRef.current = value;
105
+ });
106
+ const createPreviewProps = React.useMemo(() => {
107
+ return utils.createGetPreviewProps(field$1.schema, getNewVal => {
108
+ onChange === null || onChange === void 0 || onChange({
109
+ kind: valueRef.current.kind,
110
+ value: getNewVal(valueRef.current.value)
111
+ });
112
+ }, () => undefined);
113
+ }, [field$1.schema, onChange]);
114
+ return /*#__PURE__*/jsxRuntime.jsx(field.Field, {
115
+ label: field$1.label,
116
+ description: field$1.description,
117
+ children: inputProps => /*#__PURE__*/jsxRuntime.jsx(formFromPreview.FormValueContentFromPreviewProps, {
118
+ autoFocus: autoFocus,
119
+ forceValidation: forceValidation,
120
+ ...createPreviewProps(value.value)
121
+ })
122
+ });
123
+ }
124
+
125
+ const Cell = ({
126
+ value
127
+ }) => {
128
+ return /*#__PURE__*/jsxRuntime.jsx(typography.Text, {
129
+ children: JSON.stringify(value.json)
130
+ });
131
+ };
132
+
133
+ const allowedExportsOnCustomViews = ['schema'];
134
+
135
+ exports.Cell = Cell;
136
+ exports.Field = Field;
137
+ exports.allowedExportsOnCustomViews = allowedExportsOnCustomViews;
138
+ exports.controller = controller;
@@ -0,0 +1,131 @@
1
+ import { a as assertNever, g as getInitialPropsValue, p as clientSideValidateProp, q as createGetPreviewProps } from '../../dist/utils-200ff260.node.esm.js';
2
+ import { useRef, useEffect, useMemo } from 'react';
3
+ import { Field as Field$1 } from '@keystar/ui/field';
4
+ import { F as FormValueContentFromPreviewProps } from '../../dist/form-from-preview-5df6e492.node.esm.js';
5
+ import { jsx } from 'react/jsx-runtime';
6
+ import { Text } from '@keystar/ui/typography';
7
+ import 'slate';
8
+ import 'lkb-core/admin-ui/context';
9
+ import 'lkb-core/fields/types/relationship/views';
10
+ import 'lkb-core/admin-ui/utils';
11
+ import '@keystar/ui/button';
12
+ import '@keystar/ui/dialog';
13
+ import '@keystar/ui/icon';
14
+ import '@keystar/ui/list-view';
15
+ import '@keystar/ui/drag-and-drop';
16
+ import '@keystar/ui/tooltip';
17
+ import '@keystar/ui/layout';
18
+ import '@keystar/ui/icon/icons/trash2Icon';
19
+ import '@keystar/ui/slots';
20
+
21
+ function serializeValue(schema, value, kind) {
22
+ if (schema.kind === 'conditional') {
23
+ return {
24
+ [value.discriminant]: serializeValue(schema.values[value.discriminant], value.value, kind)
25
+ };
26
+ }
27
+ if (schema.kind === 'array') {
28
+ if (value === null) return [];
29
+ return value.map(x => serializeValue(schema.element, x, kind));
30
+ }
31
+ if (schema.kind === 'form') return value;
32
+ if (schema.kind === 'object') {
33
+ return Object.fromEntries(Object.entries(schema.fields).map(([key, val]) => {
34
+ return [key, serializeValue(val, value[key], kind)];
35
+ }));
36
+ }
37
+ if (schema.kind === 'relationship') {
38
+ if (Array.isArray(value)) {
39
+ return {
40
+ [kind === 'create' ? 'connect' : 'set']: value.map(x => ({
41
+ id: x.id
42
+ }))
43
+ };
44
+ }
45
+ if (value === null) {
46
+ if (kind === 'create') return;
47
+ return {
48
+ disconnect: true
49
+ };
50
+ }
51
+ return {
52
+ connect: {
53
+ id: value.id
54
+ }
55
+ };
56
+ }
57
+ if (schema.kind === 'child') {
58
+ throw new Error('Child fields are not supported in the structure field');
59
+ }
60
+ assertNever(schema);
61
+ }
62
+
63
+ function controller(config) {
64
+ if (!config.customViews.schema) throw new Error(`No schema in custom view. Did you forgot to set \`views\` to a file that exports a \`schema\` on ${config.listKey}.${config.path}`);
65
+ return {
66
+ path: config.path,
67
+ label: config.label,
68
+ description: config.description,
69
+ graphqlSelection: `${config.path} { json(hydrateRelationships: true) }`,
70
+ schema: config.customViews.schema,
71
+ defaultValue: {
72
+ kind: 'create',
73
+ value: getInitialPropsValue(config.customViews.schema)
74
+ },
75
+ validate: value => clientSideValidateProp(config.customViews.schema, value.value),
76
+ deserialize: data => {
77
+ var _data$json, _data;
78
+ return {
79
+ kind: 'update',
80
+ value: (_data$json = (_data = data[`${config.path}`]) === null || _data === void 0 ? void 0 : _data.json) !== null && _data$json !== void 0 ? _data$json : null
81
+ };
82
+ },
83
+ serialize: value => {
84
+ return {
85
+ [config.path]: serializeValue(config.customViews.schema, value.value, value.kind)
86
+ };
87
+ }
88
+ };
89
+ }
90
+
91
+ function Field({
92
+ field,
93
+ value,
94
+ onChange,
95
+ autoFocus,
96
+ forceValidation
97
+ }) {
98
+ const valueRef = useRef(value);
99
+ useEffect(() => {
100
+ valueRef.current = value;
101
+ });
102
+ const createPreviewProps = useMemo(() => {
103
+ return createGetPreviewProps(field.schema, getNewVal => {
104
+ onChange === null || onChange === void 0 || onChange({
105
+ kind: valueRef.current.kind,
106
+ value: getNewVal(valueRef.current.value)
107
+ });
108
+ }, () => undefined);
109
+ }, [field.schema, onChange]);
110
+ return /*#__PURE__*/jsx(Field$1, {
111
+ label: field.label,
112
+ description: field.description,
113
+ children: inputProps => /*#__PURE__*/jsx(FormValueContentFromPreviewProps, {
114
+ autoFocus: autoFocus,
115
+ forceValidation: forceValidation,
116
+ ...createPreviewProps(value.value)
117
+ })
118
+ });
119
+ }
120
+
121
+ const Cell = ({
122
+ value
123
+ }) => {
124
+ return /*#__PURE__*/jsx(Text, {
125
+ children: JSON.stringify(value.json)
126
+ });
127
+ };
128
+
129
+ const allowedExportsOnCustomViews = ['schema'];
130
+
131
+ export { Cell, Field, allowedExportsOnCustomViews, controller };
@@ -0,0 +1,4 @@
1
+ {
2
+ "main": "dist/lkb-fields-document-structure-views.cjs.js",
3
+ "module": "dist/lkb-fields-document-structure-views.esm.js"
4
+ }
@@ -0,0 +1,2 @@
1
+ export * from "../../dist/declarations/src/views.js";
2
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGtiLWZpZWxkcy1kb2N1bWVudC12aWV3cy5janMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL2Rpc3QvZGVjbGFyYXRpb25zL3NyYy92aWV3cy5kLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBIn0=