lkb-fields-document 1.0.0 → 1.0.1

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 (109) hide show
  1. package/component-blocks/dist/lkb-fields-document-component-blocks.cjs.d.ts +2 -2
  2. package/component-blocks/dist/lkb-fields-document-component-blocks.cjs.js +16 -306
  3. package/component-blocks/dist/lkb-fields-document-component-blocks.node.cjs.js +16 -306
  4. package/dist/lkb-fields-document.cjs.d.ts +2 -2
  5. package/dist/lkb-fields-document.cjs.js +16 -1167
  6. package/dist/lkb-fields-document.node.cjs.js +16 -1167
  7. package/package.json +6 -6
  8. package/structure-views/dist/lkb-fields-document-structure-views.cjs.d.ts +2 -2
  9. package/structure-views/dist/lkb-fields-document-structure-views.cjs.js +16 -138
  10. package/structure-views/dist/lkb-fields-document-structure-views.node.cjs.js +16 -138
  11. package/views/dist/lkb-fields-document-views.cjs.d.ts +2 -2
  12. package/views/dist/lkb-fields-document-views.cjs.js +13 -111
  13. package/views/dist/lkb-fields-document-views.node.cjs.js +13 -111
  14. package/component-blocks/dist/lkb-fields-document-component-blocks.esm.js +0 -300
  15. package/component-blocks/dist/lkb-fields-document-component-blocks.node.esm.js +0 -300
  16. package/dist/Cell-0ac0ac66.node.cjs.js +0 -21
  17. package/dist/Cell-242f7404.esm.js +0 -17
  18. package/dist/Cell-3103f73d.node.esm.js +0 -17
  19. package/dist/Cell-bfb56d74.cjs.js +0 -21
  20. package/dist/Field-0e0f75ed.node.cjs.js +0 -1628
  21. package/dist/Field-28177061.cjs.js +0 -1628
  22. package/dist/Field-35b79e6b.node.esm.js +0 -1619
  23. package/dist/Field-92d13205.esm.js +0 -1619
  24. package/dist/api-2f524611.esm.js +0 -502
  25. package/dist/api-73636987.cjs.js +0 -506
  26. package/dist/api-8e2b20b8.node.cjs.js +0 -506
  27. package/dist/api-c32e360e.node.esm.js +0 -502
  28. package/dist/callout-ui-2aded278.cjs.js +0 -131
  29. package/dist/callout-ui-3e5ca544.node.esm.js +0 -126
  30. package/dist/callout-ui-8b5f2376.esm.js +0 -126
  31. package/dist/callout-ui-ad50f301.node.cjs.js +0 -131
  32. package/dist/declarations/src/component-blocks.d.ts +0 -4
  33. package/dist/declarations/src/component-blocks.d.ts.map +0 -1
  34. package/dist/declarations/src/document-editor/component-blocks/api.d.ts +0 -120
  35. package/dist/declarations/src/document-editor/component-blocks/api.d.ts.map +0 -1
  36. package/dist/declarations/src/document-editor/component-blocks/types.d.ts +0 -241
  37. package/dist/declarations/src/document-editor/component-blocks/types.d.ts.map +0 -1
  38. package/dist/declarations/src/document-editor/toolset/relationship/relationship-shared.d.ts +0 -10
  39. package/dist/declarations/src/document-editor/toolset/relationship/relationship-shared.d.ts.map +0 -1
  40. package/dist/declarations/src/index.d.ts +0 -7
  41. package/dist/declarations/src/index.d.ts.map +0 -1
  42. package/dist/declarations/src/my-component-blocks/index.d.ts +0 -46
  43. package/dist/declarations/src/my-component-blocks/index.d.ts.map +0 -1
  44. package/dist/declarations/src/structure/Cell.d.ts +0 -5
  45. package/dist/declarations/src/structure/Cell.d.ts.map +0 -1
  46. package/dist/declarations/src/structure/Field.d.ts +0 -5
  47. package/dist/declarations/src/structure/Field.d.ts.map +0 -1
  48. package/dist/declarations/src/structure/controller.d.ts +0 -10
  49. package/dist/declarations/src/structure/controller.d.ts.map +0 -1
  50. package/dist/declarations/src/structure/structure.d.ts +0 -4
  51. package/dist/declarations/src/structure/structure.d.ts.map +0 -1
  52. package/dist/declarations/src/structure-views.d.ts +0 -5
  53. package/dist/declarations/src/structure-views.d.ts.map +0 -1
  54. package/dist/declarations/src/types/DocumentFeatures.d.ts +0 -33
  55. package/dist/declarations/src/types/DocumentFeatures.d.ts.map +0 -1
  56. package/dist/declarations/src/types/DocumentFieldConfig.d.ts +0 -18
  57. package/dist/declarations/src/types/DocumentFieldConfig.d.ts.map +0 -1
  58. package/dist/declarations/src/types/FormattingConfig.d.ts +0 -28
  59. package/dist/declarations/src/types/FormattingConfig.d.ts.map +0 -1
  60. package/dist/declarations/src/types/RelationshipsConfig.d.ts +0 -9
  61. package/dist/declarations/src/types/RelationshipsConfig.d.ts.map +0 -1
  62. package/dist/declarations/src/types/StructureFieldConfig.d.ts +0 -10
  63. package/dist/declarations/src/types/StructureFieldConfig.d.ts.map +0 -1
  64. package/dist/declarations/src/validation/structure-validation.d.ts +0 -218
  65. package/dist/declarations/src/validation/structure-validation.d.ts.map +0 -1
  66. package/dist/declarations/src/views/Cell.d.ts +0 -5
  67. package/dist/declarations/src/views/Cell.d.ts.map +0 -1
  68. package/dist/declarations/src/views/Field.d.ts +0 -5
  69. package/dist/declarations/src/views/Field.d.ts.map +0 -1
  70. package/dist/declarations/src/views/controller.d.ts +0 -15
  71. package/dist/declarations/src/views/controller.d.ts.map +0 -1
  72. package/dist/declarations/src/views/document.d.ts +0 -4
  73. package/dist/declarations/src/views/document.d.ts.map +0 -1
  74. package/dist/declarations/src/views.d.ts +0 -7
  75. package/dist/declarations/src/views.d.ts.map +0 -1
  76. package/dist/editor-shared-a6e340e6.node.esm.js +0 -1993
  77. package/dist/editor-shared-a997ae98.node.cjs.js +0 -2007
  78. package/dist/editor-shared-cc1293ed.cjs.js +0 -2007
  79. package/dist/editor-shared-da518ba3.esm.js +0 -1993
  80. package/dist/form-from-preview-2042b9ef.cjs.js +0 -512
  81. package/dist/form-from-preview-5df6e492.node.esm.js +0 -508
  82. package/dist/form-from-preview-9e501058.node.cjs.js +0 -512
  83. package/dist/form-from-preview-b3a66f37.esm.js +0 -508
  84. package/dist/index-06c36775.cjs.js +0 -14
  85. package/dist/index-586adb8f.node.esm.js +0 -11
  86. package/dist/index-67d52357.esm.js +0 -11
  87. package/dist/index-c3223fdc.node.cjs.js +0 -14
  88. package/dist/layouts-6412fa2a.esm.js +0 -189
  89. package/dist/layouts-a4a3cf0b.node.cjs.js +0 -196
  90. package/dist/layouts-ba9a558b.cjs.js +0 -196
  91. package/dist/layouts-e653b908.node.esm.js +0 -189
  92. package/dist/lkb-fields-document.esm.js +0 -1162
  93. package/dist/lkb-fields-document.node.esm.js +0 -1162
  94. package/dist/shared-0533009e.cjs.js +0 -594
  95. package/dist/shared-4684cc24.node.cjs.js +0 -594
  96. package/dist/shared-5e864055.node.esm.js +0 -579
  97. package/dist/shared-aaba5901.esm.js +0 -579
  98. package/dist/toolbar-state-3359e2f3.cjs.js +0 -994
  99. package/dist/toolbar-state-945823b8.node.esm.js +0 -971
  100. package/dist/toolbar-state-9611743f.node.cjs.js +0 -994
  101. package/dist/toolbar-state-bc8fe661.esm.js +0 -971
  102. package/dist/utils-06bcddc4.node.cjs.js +0 -747
  103. package/dist/utils-200ff260.node.esm.js +0 -722
  104. package/dist/utils-6409f730.cjs.js +0 -747
  105. package/dist/utils-bc6a0b82.esm.js +0 -722
  106. package/structure-views/dist/lkb-fields-document-structure-views.esm.js +0 -131
  107. package/structure-views/dist/lkb-fields-document-structure-views.node.esm.js +0 -131
  108. package/views/dist/lkb-fields-document-views.esm.js +0 -95
  109. package/views/dist/lkb-fields-document-views.node.esm.js +0 -95
@@ -1,1628 +0,0 @@
1
- 'use client';
2
- 'use strict';
3
-
4
- Object.defineProperty(exports, '__esModule', { value: true });
5
-
6
- var field = require('@keystar/ui/field');
7
- var style = require('@keystar/ui/style');
8
- var typography = require('@keystar/ui/typography');
9
- var React = require('react');
10
- var isHotkey = require('is-hotkey');
11
- var slate = require('slate');
12
- var slateReact = require('slate-react');
13
- var editorShared = require('./editor-shared-cc1293ed.cjs.js');
14
- var utils = require('./utils-6409f730.cjs.js');
15
- var icon = require('@keystar/ui/icon');
16
- var boldIcon = require('@keystar/ui/icon/icons/boldIcon');
17
- var italicIcon = require('@keystar/ui/icon/icons/italicIcon');
18
- var plusIcon = require('@keystar/ui/icon/icons/plusIcon');
19
- var chevronDownIcon = require('@keystar/ui/icon/icons/chevronDownIcon');
20
- var codeIcon = require('@keystar/ui/icon/icons/codeIcon');
21
- var removeFormattingIcon = require('@keystar/ui/icon/icons/removeFormattingIcon');
22
- var strikethroughIcon = require('@keystar/ui/icon/icons/strikethroughIcon');
23
- var subscriptIcon = require('@keystar/ui/icon/icons/subscriptIcon');
24
- var superscriptIcon = require('@keystar/ui/icon/icons/superscriptIcon');
25
- var typeIcon = require('@keystar/ui/icon/icons/typeIcon');
26
- var underlineIcon = require('@keystar/ui/icon/icons/underlineIcon');
27
- var maximizeIcon = require('@keystar/ui/icon/icons/maximizeIcon');
28
- var minimizeIcon = require('@keystar/ui/icon/icons/minimizeIcon');
29
- var editor = require('@keystar/ui/editor');
30
- var linkIcon = require('@keystar/ui/icon/icons/linkIcon');
31
- var externalLinkIcon = require('@keystar/ui/icon/icons/externalLinkIcon');
32
- var editIcon = require('@keystar/ui/icon/icons/editIcon');
33
- var toolbarState = require('./toolbar-state-3359e2f3.cjs.js');
34
- var index = require('./index-06c36775.cjs.js');
35
- var button = require('@keystar/ui/button');
36
- var dialog = require('@keystar/ui/dialog');
37
- var layout = require('@keystar/ui/layout');
38
- var tooltip = require('@keystar/ui/tooltip');
39
- require('@react-aria/i18n');
40
- require('@keystar/ui/number-field');
41
- var picker = require('@keystar/ui/picker');
42
- require('@keystar/ui/combobox');
43
- var textField = require('@keystar/ui/text-field');
44
- var tag = require('@keystar/ui/tag');
45
- var jsxRuntime = require('react/jsx-runtime');
46
- require('@keystar/ui/checkbox');
47
- var slots = require('@keystar/ui/slots');
48
- var unlinkIcon = require('@keystar/ui/icon/icons/unlinkIcon');
49
- var layouts = require('./layouts-ba9a558b.cjs.js');
50
- var shared = require('./shared-0533009e.cjs.js');
51
- var listIcon = require('@keystar/ui/icon/icons/listIcon');
52
- var listOrderedIcon = require('@keystar/ui/icon/icons/listOrderedIcon');
53
- var quoteIcon = require('@keystar/ui/icon/icons/quoteIcon');
54
- var alignLeftIcon = require('@keystar/ui/icon/icons/alignLeftIcon');
55
- var alignRightIcon = require('@keystar/ui/icon/icons/alignRightIcon');
56
- var alignCenterIcon = require('@keystar/ui/icon/icons/alignCenterIcon');
57
- var menu = require('@keystar/ui/menu');
58
- var minusIcon = require('@keystar/ui/icon/icons/minusIcon');
59
- var actionGroup = require('@keystar/ui/action-group');
60
- var matchSorter = require('match-sorter');
61
- var scrollIntoView = require('scroll-into-view-if-needed');
62
- var overlays$1 = require('@react-aria/overlays');
63
- var list = require('@react-stately/list');
64
- var overlays = require('@react-stately/overlays');
65
- var overlays$2 = require('@keystar/ui/overlays');
66
- var listbox = require('@keystar/ui/listbox');
67
- var core = require('@keystar/ui/core');
68
- require('slate-history');
69
- require('@emotion/weak-memoize');
70
- require('mdast-util-from-markdown');
71
- require('mdast-util-gfm-autolink-literal/from-markdown');
72
- require('micromark-extension-gfm-autolink-literal');
73
- require('mdast-util-gfm-strikethrough/from-markdown');
74
- require('micromark-extension-gfm-strikethrough');
75
- require('@keystar/ui/icon/icons/trash2Icon');
76
- require('./api-73636987.cjs.js');
77
- require('lkb-core');
78
- require('@keystar/ui/drag-and-drop');
79
- require('./form-from-preview-2042b9ef.cjs.js');
80
- require('lkb-core/admin-ui/context');
81
- require('lkb-core/fields/types/relationship/views');
82
- require('lkb-core/admin-ui/utils');
83
- require('@keystar/ui/list-view');
84
- require('@keystar/ui/icon/icons/trashIcon');
85
- require('@react-aria/utils');
86
- require('@braintree/sanitize-url');
87
-
88
- function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
89
-
90
- var isHotkey__default = /*#__PURE__*/_interopDefault(isHotkey);
91
- var scrollIntoView__default = /*#__PURE__*/_interopDefault(scrollIntoView);
92
-
93
- function LinkElement({
94
- attributes,
95
- children,
96
- element: __elementForGettingPath
97
- }) {
98
- const editor = slateReact.useSlateStatic();
99
- const [currentElement, setNode] = toolbarState.useElementWithSetNodes(editor, __elementForGettingPath);
100
- const href = currentElement.href;
101
-
102
- // const [localForceValidation, setLocalForceValidation] = useState(false)
103
- const [dialogOpen, setDialogOpen] = React.useState(false);
104
- const activePopoverElement = toolbarState.useActiveBlockPopover();
105
- const selected = activePopoverElement === __elementForGettingPath;
106
- React.useEffect(() => {
107
- if (selected && !href) {
108
- setDialogOpen(true);
109
- }
110
- }, [href, selected]);
111
- const unlink = toolbarState.useEventCallback(() => {
112
- slate.Transforms.unwrapNodes(editor, {
113
- at: slateReact.ReactEditor.findPath(editor, __elementForGettingPath)
114
- });
115
- });
116
- // const forceValidation = useForceValidation()
117
- // TODO: show the invalid state
118
- // const showInvalidState = isValidURL(href) ? false : forceValidation || localForceValidation
119
- return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
120
- children: [/*#__PURE__*/jsxRuntime.jsxs(toolbarState.BlockPopoverTrigger, {
121
- element: __elementForGettingPath,
122
- children: [/*#__PURE__*/jsxRuntime.jsx("a", {
123
- href: href,
124
- ...attributes,
125
- children: children
126
- }), /*#__PURE__*/jsxRuntime.jsx(toolbarState.BlockPopover, {
127
- placement: "bottom start",
128
- children: /*#__PURE__*/jsxRuntime.jsxs(layout.Flex, {
129
- gap: "small",
130
- padding: "regular",
131
- children: [/*#__PURE__*/jsxRuntime.jsxs(tooltip.TooltipTrigger, {
132
- children: [/*#__PURE__*/jsxRuntime.jsx(button.ActionButton, {
133
- prominence: "low",
134
- onPress: () => setDialogOpen(true),
135
- children: /*#__PURE__*/jsxRuntime.jsx(icon.Icon, {
136
- src: editIcon.editIcon
137
- })
138
- }), /*#__PURE__*/jsxRuntime.jsx(tooltip.Tooltip, {
139
- children: "Edit"
140
- })]
141
- }), /*#__PURE__*/jsxRuntime.jsxs(tooltip.TooltipTrigger, {
142
- children: [/*#__PURE__*/jsxRuntime.jsx(button.ActionButton, {
143
- prominence: "low",
144
- onPress: () => {
145
- window.open(href, '_blank', 'noopener,noreferrer');
146
- },
147
- children: /*#__PURE__*/jsxRuntime.jsx(icon.Icon, {
148
- src: externalLinkIcon.externalLinkIcon
149
- })
150
- }), /*#__PURE__*/jsxRuntime.jsx(tooltip.Tooltip, {
151
- children: /*#__PURE__*/jsxRuntime.jsx(typography.Text, {
152
- truncate: 3,
153
- children: href
154
- })
155
- })]
156
- }), /*#__PURE__*/jsxRuntime.jsxs(tooltip.TooltipTrigger, {
157
- children: [/*#__PURE__*/jsxRuntime.jsx(button.ActionButton, {
158
- prominence: "low",
159
- onPress: unlink,
160
- children: /*#__PURE__*/jsxRuntime.jsx(icon.Icon, {
161
- src: unlinkIcon.unlinkIcon
162
- })
163
- }), /*#__PURE__*/jsxRuntime.jsx(tooltip.Tooltip, {
164
- children: "Unlink"
165
- })]
166
- })]
167
- })
168
- })]
169
- }), /*#__PURE__*/jsxRuntime.jsx(dialog.DialogContainer, {
170
- onDismiss: () => {
171
- setDialogOpen(false);
172
- toolbarState.focusWithPreviousSelection(editor);
173
- },
174
- children: dialogOpen && /*#__PURE__*/jsxRuntime.jsx(LinkDialog, {
175
- text: slate.Node.string(currentElement),
176
- href: href,
177
- onSubmit: ({
178
- href
179
- }) => {
180
- setNode({
181
- href
182
- });
183
- }
184
- })
185
- })]
186
- });
187
- }
188
- function LinkDialog({
189
- onSubmit,
190
- ...props
191
- }) {
192
- let [href, setHref] = React.useState(props.href || '');
193
- let [touched, setTouched] = React.useState(false);
194
- let {
195
- dismiss
196
- } = dialog.useDialogContainer();
197
- const showInvalidState = touched && !index.isValidURL(href);
198
- return /*#__PURE__*/jsxRuntime.jsx(dialog.Dialog, {
199
- size: "small",
200
- children: /*#__PURE__*/jsxRuntime.jsxs("form", {
201
- style: {
202
- display: 'contents'
203
- },
204
- onSubmit: event => {
205
- if (event.target !== event.currentTarget) return;
206
- event.preventDefault();
207
- if (!showInvalidState) {
208
- dismiss();
209
- onSubmit({
210
- href
211
- });
212
- }
213
- },
214
- children: [/*#__PURE__*/jsxRuntime.jsxs(typography.Heading, {
215
- children: [props.href ? '编辑' : '添加', "\u94FE\u63A5"]
216
- }), /*#__PURE__*/jsxRuntime.jsx(slots.Content, {
217
- children: /*#__PURE__*/jsxRuntime.jsxs(layout.Flex, {
218
- gap: "large",
219
- direction: "column",
220
- children: [/*#__PURE__*/jsxRuntime.jsx(textField.TextField, {
221
- label: "\u6587\u672C",
222
- value: props.text,
223
- isReadOnly: true
224
- }), /*#__PURE__*/jsxRuntime.jsx(textField.TextField, {
225
- autoFocus: true,
226
- isRequired: true,
227
- onBlur: () => setTouched(true),
228
- label: "\u94FE\u63A5",
229
- onChange: setHref,
230
- value: href,
231
- errorMessage: showInvalidState && '请输入有效的链接地址.'
232
- })]
233
- })
234
- }), /*#__PURE__*/jsxRuntime.jsxs(button.ButtonGroup, {
235
- children: [/*#__PURE__*/jsxRuntime.jsx(button.Button, {
236
- onPress: dismiss,
237
- children: "\u53D6\u6D88"
238
- }), /*#__PURE__*/jsxRuntime.jsx(button.Button, {
239
- prominence: "high",
240
- type: "submit",
241
- children: "\u4FDD\u5B58"
242
- })]
243
- })]
244
- })
245
- });
246
- }
247
- let _linkIcon = /*#__PURE__*/jsxRuntime.jsx(icon.Icon, {
248
- src: linkIcon.linkIcon
249
- });
250
- function LinkButton() {
251
- const {
252
- editor,
253
- links: {
254
- isDisabled,
255
- isSelected
256
- }
257
- } = toolbarState.useToolbarState();
258
- return React.useMemo(() => /*#__PURE__*/jsxRuntime.jsx(button.ActionButton, {
259
- prominence: "low",
260
- isDisabled: isDisabled,
261
- isSelected: isSelected,
262
- onPress: () => {
263
- editorShared.wrapLink(editor, '');
264
- slateReact.ReactEditor.focus(editor);
265
- },
266
- children: _linkIcon
267
- }), [isSelected, isDisabled, editor]);
268
- }
269
- const linkButton = /*#__PURE__*/jsxRuntime.jsxs(tooltip.TooltipTrigger, {
270
- children: [/*#__PURE__*/jsxRuntime.jsx(LinkButton, {}), /*#__PURE__*/jsxRuntime.jsx(tooltip.Tooltip, {
271
- children: /*#__PURE__*/jsxRuntime.jsx(typography.Text, {
272
- children: "Link"
273
- })
274
- })]
275
- });
276
-
277
- function ListButtons(props) {
278
- const {
279
- editor: editor$1,
280
- lists
281
- } = toolbarState.useToolbarState();
282
- const items = React.useMemo(() => {
283
- return [!!props.lists.unordered && {
284
- label: '无序列表',
285
- key: 'unordered',
286
- shortcut: '-⎵',
287
- icon: listIcon.listIcon
288
- }, !!props.lists.unordered && {
289
- label: '有序列表',
290
- key: 'ordered',
291
- shortcut: '1.⎵',
292
- icon: listOrderedIcon.listOrderedIcon
293
- }].filter(removeFalse);
294
- }, [props.lists]);
295
- return React.useMemo(() => {
296
- const disabledKeys = [];
297
- if (lists.ordered.isDisabled) disabledKeys.push('ordered');
298
- if (lists.unordered.isDisabled) disabledKeys.push('unordered');
299
- const activeListType = lists.ordered.isSelected ? 'ordered' : lists.unordered.isSelected ? 'unordered' : null;
300
- return /*#__PURE__*/jsxRuntime.jsx(editor.EditorToolbarGroup, {
301
- value: activeListType,
302
- disabledKeys: disabledKeys,
303
- onChange: key => {
304
- const format = `${key}-list`;
305
- shared.toggleList(editor$1, format);
306
- slateReact.ReactEditor.focus(editor$1);
307
- },
308
- selectionMode: "single",
309
- children: items.map(item => /*#__PURE__*/jsxRuntime.jsxs(tooltip.TooltipTrigger, {
310
- children: [/*#__PURE__*/jsxRuntime.jsx(editor.EditorToolbarItem, {
311
- value: item.key,
312
- children: /*#__PURE__*/jsxRuntime.jsx(icon.Icon, {
313
- src: item.icon
314
- })
315
- }), /*#__PURE__*/jsxRuntime.jsxs(tooltip.Tooltip, {
316
- children: [/*#__PURE__*/jsxRuntime.jsx(typography.Text, {
317
- children: item.label
318
- }), /*#__PURE__*/jsxRuntime.jsx(typography.Kbd, {
319
- children: item.shortcut
320
- })]
321
- })]
322
- }, item.key))
323
- });
324
- }, [editor$1, lists.ordered.isDisabled, lists.ordered.isSelected, lists.unordered.isDisabled, lists.unordered.isSelected, props.lists.ordered, props.lists.unordered]);
325
- }
326
- function removeFalse(val) {
327
- return val !== false;
328
- }
329
-
330
- const BlockquoteElement = ({
331
- attributes,
332
- children
333
- }) => {
334
- return /*#__PURE__*/jsxRuntime.jsx("blockquote", {
335
- ...attributes,
336
- children: children
337
- });
338
- };
339
- const BlockquoteButton = () => {
340
- const {
341
- editor: editor$1,
342
- blockquote: {
343
- isDisabled,
344
- isSelected
345
- }
346
- } = toolbarState.useToolbarState();
347
- return React.useMemo(() => /*#__PURE__*/jsxRuntime.jsx(editor.EditorToolbarButton, {
348
- isSelected: isSelected,
349
- isDisabled: isDisabled,
350
- onPress: () => {
351
- editorShared.insertBlockquote(editor$1);
352
- slateReact.ReactEditor.focus(editor$1);
353
- },
354
- children: /*#__PURE__*/jsxRuntime.jsx(icon.Icon, {
355
- src: quoteIcon.quoteIcon
356
- })
357
- }), [editor$1, isDisabled, isSelected]);
358
- };
359
- const blockquoteButton = /*#__PURE__*/jsxRuntime.jsxs(tooltip.TooltipTrigger, {
360
- children: [/*#__PURE__*/jsxRuntime.jsx(BlockquoteButton, {}), /*#__PURE__*/jsxRuntime.jsxs(tooltip.Tooltip, {
361
- children: [/*#__PURE__*/jsxRuntime.jsx(typography.Text, {
362
- children: "\u5F15\u7528"
363
- }), /*#__PURE__*/jsxRuntime.jsx(typography.Kbd, {
364
- children: '>⎵'
365
- })]
366
- })]
367
- });
368
-
369
- function CodeButton() {
370
- const {
371
- editor: editor$1,
372
- code: {
373
- isDisabled,
374
- isSelected
375
- }
376
- } = toolbarState.useToolbarState();
377
- return React.useMemo(() => /*#__PURE__*/jsxRuntime.jsx(editor.EditorToolbarButton, {
378
- isSelected: isSelected,
379
- isDisabled: isDisabled,
380
- onPress: () => {
381
- if (isSelected) {
382
- slate.Transforms.unwrapNodes(editor$1, {
383
- match: node => node.type === 'code'
384
- });
385
- } else {
386
- slate.Transforms.wrapNodes(editor$1, {
387
- type: 'code',
388
- children: [{
389
- text: ''
390
- }]
391
- });
392
- }
393
- slateReact.ReactEditor.focus(editor$1);
394
- },
395
- children: /*#__PURE__*/jsxRuntime.jsx(icon.Icon, {
396
- src: codeIcon.codeIcon
397
- })
398
- }), [isDisabled, isSelected, editor$1]);
399
- }
400
- const codeButton = /*#__PURE__*/jsxRuntime.jsxs(tooltip.TooltipTrigger, {
401
- children: [/*#__PURE__*/jsxRuntime.jsx(CodeButton, {}), /*#__PURE__*/jsxRuntime.jsxs(tooltip.Tooltip, {
402
- children: [/*#__PURE__*/jsxRuntime.jsx(typography.Text, {
403
- children: "\u4EE3\u7801\u5757"
404
- }), /*#__PURE__*/jsxRuntime.jsx(typography.Kbd, {
405
- children: "```"
406
- })]
407
- })]
408
- });
409
-
410
- const values = {
411
- start: {
412
- key: 'start',
413
- label: '左对齐',
414
- icon: /*#__PURE__*/jsxRuntime.jsx(icon.Icon, {
415
- src: alignLeftIcon.alignLeftIcon
416
- })
417
- },
418
- center: {
419
- key: 'center',
420
- label: '居中对齐',
421
- icon: /*#__PURE__*/jsxRuntime.jsx(icon.Icon, {
422
- src: alignCenterIcon.alignCenterIcon
423
- })
424
- },
425
- end: {
426
- key: 'end',
427
- label: '右对齐',
428
- icon: /*#__PURE__*/jsxRuntime.jsx(icon.Icon, {
429
- src: alignRightIcon.alignRightIcon
430
- })
431
- }
432
- };
433
- const TextAlignMenu = ({
434
- alignment
435
- }) => {
436
- const toolbarState$1 = toolbarState.useToolbarState();
437
- const items = React.useMemo(() => [values.start, ...Object.keys(alignment).map(x => values[x])], [alignment]);
438
- return React.useMemo(() => /*#__PURE__*/jsxRuntime.jsxs(menu.MenuTrigger, {
439
- children: [/*#__PURE__*/jsxRuntime.jsxs(tooltip.TooltipTrigger, {
440
- children: [/*#__PURE__*/jsxRuntime.jsxs(editor.EditorToolbarButton, {
441
- children: [values[toolbarState$1.alignment.selected].icon, /*#__PURE__*/jsxRuntime.jsx(icon.Icon, {
442
- src: chevronDownIcon.chevronDownIcon
443
- })]
444
- }), /*#__PURE__*/jsxRuntime.jsx(tooltip.Tooltip, {
445
- children: /*#__PURE__*/jsxRuntime.jsx(typography.Text, {
446
- children: "\u6587\u672C\u5BF9\u9F50"
447
- })
448
- })]
449
- }), /*#__PURE__*/jsxRuntime.jsx(menu.Menu, {
450
- selectionMode: "single",
451
- selectedKeys: [toolbarState$1.alignment.selected],
452
- items: items,
453
- onAction: key => {
454
- if (key === 'start') {
455
- slate.Transforms.unsetNodes(toolbarState$1.editor, 'textAlign', {
456
- match: node => node.type === 'paragraph' || node.type === 'heading'
457
- });
458
- } else {
459
- slate.Transforms.setNodes(toolbarState$1.editor, {
460
- textAlign: key
461
- }, {
462
- match: node => node.type === 'paragraph' || node.type === 'heading'
463
- });
464
- }
465
- slateReact.ReactEditor.focus(toolbarState$1.editor);
466
- },
467
- children: item => {
468
- return /*#__PURE__*/jsxRuntime.jsxs(tag.Item, {
469
- textValue: item.label,
470
- children: [/*#__PURE__*/jsxRuntime.jsx(typography.Text, {
471
- children: item.label
472
- }), item.icon]
473
- }, item.key);
474
- }
475
- })]
476
- }), [items, toolbarState$1.alignment.selected, toolbarState$1.editor]);
477
- };
478
-
479
- const DividerButtonInner = () => {
480
- const {
481
- editor: editor$1,
482
- dividers: {
483
- isDisabled
484
- }
485
- } = toolbarState.useToolbarState();
486
- return React.useMemo(() => /*#__PURE__*/jsxRuntime.jsx(editor.EditorToolbarButton, {
487
- isDisabled: isDisabled,
488
- isSelected: false,
489
- onPress: () => {
490
- editorShared.insertDivider(editor$1);
491
- },
492
- children: /*#__PURE__*/jsxRuntime.jsx(icon.Icon, {
493
- src: minusIcon.minusIcon
494
- })
495
- }), [editor$1, isDisabled]);
496
- };
497
- const DividerButton = /*#__PURE__*/jsxRuntime.jsxs(tooltip.TooltipTrigger, {
498
- delay: 200,
499
- children: [/*#__PURE__*/jsxRuntime.jsx(DividerButtonInner, {}), /*#__PURE__*/jsxRuntime.jsxs(tooltip.Tooltip, {
500
- children: [/*#__PURE__*/jsxRuntime.jsx(typography.Text, {
501
- children: "\u6DFB\u52A0\u5206\u9694\u7EBF"
502
- }), /*#__PURE__*/jsxRuntime.jsx(typography.Kbd, {
503
- children: "---"
504
- })]
505
- })]
506
- });
507
-
508
- function Toolbar({
509
- documentFeatures,
510
- viewState
511
- }) {
512
- const relationship = React.useContext(toolbarState.DocumentFieldRelationshipsContext);
513
- const blockComponent = React.useContext(toolbarState.ComponentBlockContext);
514
- const hasBlockItems = Object.entries(relationship).length || Object.keys(blockComponent).length;
515
- const hasMarks = Object.values(documentFeatures.formatting.inlineMarks).some(x => x);
516
- const hasAlignment = documentFeatures.formatting.alignment.center || documentFeatures.formatting.alignment.end;
517
- const hasLists = documentFeatures.formatting.listTypes.unordered || documentFeatures.formatting.listTypes.ordered;
518
- return /*#__PURE__*/jsxRuntime.jsxs(ToolbarWrapper, {
519
- children: [/*#__PURE__*/jsxRuntime.jsxs(ToolbarScrollArea, {
520
- children: [!!documentFeatures.formatting.headingLevels.length && /*#__PURE__*/jsxRuntime.jsx(HeadingMenu, {
521
- headingLevels: documentFeatures.formatting.headingLevels
522
- }), /*#__PURE__*/jsxRuntime.jsxs(editor.EditorToolbar, {
523
- children: [hasMarks && /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
524
- children: [/*#__PURE__*/jsxRuntime.jsx(editor.EditorToolbarSeparator, {}), /*#__PURE__*/jsxRuntime.jsx(InlineMarks, {
525
- marks: documentFeatures.formatting.inlineMarks
526
- })]
527
- }), /*#__PURE__*/jsxRuntime.jsx(editor.EditorToolbarSeparator, {}), (hasAlignment || hasLists) && /*#__PURE__*/jsxRuntime.jsxs(editor.EditorToolbarGroup, {
528
- children: [hasAlignment && /*#__PURE__*/jsxRuntime.jsx(TextAlignMenu, {
529
- alignment: documentFeatures.formatting.alignment
530
- }), hasLists && /*#__PURE__*/jsxRuntime.jsx(ListButtons, {
531
- lists: documentFeatures.formatting.listTypes
532
- })]
533
- }), /*#__PURE__*/jsxRuntime.jsxs(editor.EditorToolbarGroup, {
534
- children: [documentFeatures.dividers && DividerButton, documentFeatures.links && linkButton, documentFeatures.formatting.blockTypes.blockquote && blockquoteButton, !!documentFeatures.layouts.length && /*#__PURE__*/jsxRuntime.jsx(layouts.LayoutsButton, {
535
- layouts: documentFeatures.layouts
536
- }), documentFeatures.formatting.blockTypes.code && codeButton]
537
- }), React.useMemo(() => {
538
- return viewState && /*#__PURE__*/jsxRuntime.jsx(editor.EditorToolbarGroup, {
539
- children: /*#__PURE__*/jsxRuntime.jsxs(tooltip.TooltipTrigger, {
540
- children: [/*#__PURE__*/jsxRuntime.jsx(editor.EditorToolbarButton, {
541
- isSelected: viewState.expanded,
542
- onPress: () => {
543
- viewState.toggle();
544
- },
545
- children: /*#__PURE__*/jsxRuntime.jsx(icon.Icon, {
546
- src: viewState.expanded ? minimizeIcon.minimizeIcon : maximizeIcon.maximizeIcon
547
- })
548
- }), /*#__PURE__*/jsxRuntime.jsx(tooltip.Tooltip, {
549
- children: viewState.expanded ? '折叠' : '展开'
550
- })]
551
- })
552
- });
553
- }, [viewState])]
554
- })]
555
- }), !!hasBlockItems && /*#__PURE__*/jsxRuntime.jsx(InsertBlockMenu, {})]
556
- });
557
- }
558
- const headingMenuVals = new Map([['normal', 'normal'], ['1', 1], ['2', 2], ['3', 3], ['4', 4], ['5', 5], ['6', 6]]);
559
- const HeadingMenu = ({
560
- headingLevels
561
- }) => {
562
- const {
563
- editor,
564
- textStyles
565
- } = toolbarState.useToolbarState();
566
- const isDisabled = textStyles.allowedHeadingLevels.length === 0;
567
- const items = React.useMemo(() => {
568
- let resolvedItems = [{
569
- name: '段落',
570
- id: 'normal'
571
- }];
572
- headingLevels.forEach(level => {
573
- resolvedItems.push({
574
- name: `标题 ${level}`,
575
- id: level.toString()
576
- });
577
- });
578
- return resolvedItems;
579
- }, [headingLevels]);
580
- const selected = textStyles.selected.toString();
581
- return React.useMemo(() => /*#__PURE__*/jsxRuntime.jsx(picker.Picker, {
582
- flexShrink: 0,
583
- width: "scale.1700",
584
- prominence: "low",
585
- items: items,
586
- isDisabled: isDisabled,
587
- selectedKey: selected,
588
- onSelectionChange: selected => {
589
- let key = headingMenuVals.get(selected);
590
- if (key === 'normal') {
591
- slate.Editor.withoutNormalizing(editor, () => {
592
- slate.Transforms.unsetNodes(editor, 'level', {
593
- match: n => n.type === 'heading'
594
- });
595
- slate.Transforms.setNodes(editor, {
596
- type: 'paragraph'
597
- }, {
598
- match: n => n.type === 'heading'
599
- });
600
- });
601
- } else if (key) {
602
- slate.Transforms.setNodes(editor, {
603
- type: 'heading',
604
- level: key
605
- }, {
606
- match: node => node.type === 'paragraph' || node.type === 'heading'
607
- });
608
- }
609
- slateReact.ReactEditor.focus(editor);
610
- },
611
- children: item => /*#__PURE__*/jsxRuntime.jsx(picker.Item, {
612
- children: item.name
613
- }, item.id)
614
- }), [editor, isDisabled, items, selected]);
615
- };
616
- function InsertBlockMenu() {
617
- const editor = slateReact.useSlateStatic();
618
- const componentBlocks = React.useContext(toolbarState.ComponentBlockContext);
619
- return /*#__PURE__*/jsxRuntime.jsxs(menu.MenuTrigger, {
620
- align: "end",
621
- children: [/*#__PURE__*/jsxRuntime.jsxs(tooltip.TooltipTrigger, {
622
- children: [/*#__PURE__*/jsxRuntime.jsxs(button.ActionButton, {
623
- marginY: "regular",
624
- marginEnd: "medium",
625
- children: [/*#__PURE__*/jsxRuntime.jsx(icon.Icon, {
626
- src: plusIcon.plusIcon
627
- }), /*#__PURE__*/jsxRuntime.jsx(icon.Icon, {
628
- src: chevronDownIcon.chevronDownIcon
629
- })]
630
- }), /*#__PURE__*/jsxRuntime.jsxs(tooltip.Tooltip, {
631
- children: [/*#__PURE__*/jsxRuntime.jsx(typography.Text, {
632
- children: "Insert"
633
- }), /*#__PURE__*/jsxRuntime.jsx(typography.Kbd, {
634
- children: "/"
635
- })]
636
- })]
637
- }), /*#__PURE__*/jsxRuntime.jsx(menu.Menu, {
638
- onAction: key => {
639
- toolbarState.insertComponentBlock(editor, componentBlocks, key);
640
- },
641
- items: Object.entries(componentBlocks),
642
- children: ([key, item]) => /*#__PURE__*/jsxRuntime.jsx(picker.Item, {
643
- children: item.label
644
- }, key)
645
- })]
646
- });
647
- }
648
- const inlineMarks = [{
649
- key: 'bold',
650
- label: 'Bold',
651
- icon: boldIcon.boldIcon,
652
- shortcut: `B`
653
- }, {
654
- key: 'italic',
655
- label: 'Italic',
656
- icon: italicIcon.italicIcon,
657
- shortcut: `I`
658
- }, {
659
- key: 'underline',
660
- label: 'Underline',
661
- icon: underlineIcon.underlineIcon,
662
- shortcut: `U`
663
- }, {
664
- key: 'strikethrough',
665
- label: 'Strikethrough',
666
- icon: strikethroughIcon.strikethroughIcon
667
- }, {
668
- key: 'code',
669
- label: 'Code',
670
- icon: codeIcon.codeIcon
671
- }, {
672
- key: 'superscript',
673
- label: 'Superscript',
674
- icon: superscriptIcon.superscriptIcon
675
- }, {
676
- key: 'subscript',
677
- label: 'Subscript',
678
- icon: subscriptIcon.subscriptIcon
679
- }, {
680
- key: 'clearFormatting',
681
- label: 'Clear formatting',
682
- icon: removeFormattingIcon.removeFormattingIcon
683
- }];
684
- function InlineMarks({
685
- marks: _marksShown
686
- }) {
687
- const {
688
- editor,
689
- clearFormatting: {
690
- isDisabled
691
- },
692
- marks
693
- } = toolbarState.useToolbarState();
694
- const marksShown = useMemoStringified(_marksShown);
695
- const selectedKeys = useMemoStringified(Object.keys(marks).filter(key => marks[key].isSelected));
696
- const disabledKeys = useMemoStringified(Object.keys(marks).filter(key => marks[key].isDisabled).concat(isDisabled ? 'clearFormatting' : []));
697
- return React.useMemo(() => {
698
- const items = inlineMarks.filter(item => item.key === 'clearFormatting' || marksShown[item.key]);
699
- return /*#__PURE__*/jsxRuntime.jsx(actionGroup.ActionGroup, {
700
- UNSAFE_className: style.css({
701
- minWidth: `calc(${style.tokenSchema.size.element.medium} * 4)`
702
- }),
703
- prominence: "low",
704
- density: "compact",
705
- buttonLabelBehavior: "hide",
706
- overflowMode: "collapse",
707
- summaryIcon: /*#__PURE__*/jsxRuntime.jsx(icon.Icon, {
708
- src: typeIcon.typeIcon
709
- }),
710
- items: items,
711
- selectionMode: "multiple",
712
- selectedKeys: selectedKeys,
713
- disabledKeys: disabledKeys,
714
- onAction: key => {
715
- if (key === 'clearFormatting') {
716
- utils.clearFormatting(editor);
717
- } else {
718
- var _Editor$marks;
719
- const mark = key;
720
- if ((_Editor$marks = slate.Editor.marks(editor)) !== null && _Editor$marks !== void 0 && _Editor$marks[mark]) {
721
- slate.Editor.removeMark(editor, mark);
722
- } else {
723
- slate.Editor.addMark(editor, mark, true);
724
- }
725
- }
726
- slateReact.ReactEditor.focus(editor);
727
- },
728
- children: item => {
729
- return /*#__PURE__*/jsxRuntime.jsxs(picker.Item, {
730
- textValue: item.label,
731
- children: [/*#__PURE__*/jsxRuntime.jsx(typography.Text, {
732
- children: item.label
733
- }), 'shortcut' in item && /*#__PURE__*/jsxRuntime.jsx(typography.Kbd, {
734
- meta: true,
735
- children: item.shortcut
736
- }), /*#__PURE__*/jsxRuntime.jsx(icon.Icon, {
737
- src: item.icon
738
- })]
739
- }, item.key);
740
- }
741
- });
742
- }, [disabledKeys, editor, marksShown, selectedKeys]);
743
- }
744
- function useMemoStringified(value) {
745
- return React.useMemo(() => value, [JSON.stringify(value)]);
746
- }
747
- function useEntryLayoutSplitPaneContext() {
748
- return null;
749
- }
750
- const ToolbarContainer = ({
751
- children
752
- }) => {
753
- return /*#__PURE__*/jsxRuntime.jsx("div", {
754
- className: style.css({
755
- display: 'flex'
756
- }),
757
- children: children
758
- });
759
- };
760
- const ToolbarWrapper = ({
761
- children
762
- }) => {
763
- let entryLayoutPane = useEntryLayoutSplitPaneContext();
764
- return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {
765
- children: /*#__PURE__*/jsxRuntime.jsx("div", {
766
- "data-layout": entryLayoutPane,
767
- className: style.css({
768
- backdropFilter: 'blur(8px)',
769
- backgroundClip: 'padding-box',
770
- backgroundColor: `color-mix(in srgb, transparent, ${style.tokenSchema.color.background.canvas} 90%)`,
771
- borderBottom: `${style.tokenSchema.size.border.regular} solid color-mix(in srgb, transparent, ${style.tokenSchema.color.foreground.neutral} 10%)`,
772
- borderStartEndRadius: style.tokenSchema.size.radius.medium,
773
- borderStartStartRadius: style.tokenSchema.size.radius.medium,
774
- minWidth: 0,
775
- position: 'sticky',
776
- top: 0,
777
- zIndex: 2,
778
- '&[data-layout="main"]': {
779
- borderRadius: 0
780
- }
781
- }),
782
- children: /*#__PURE__*/jsxRuntime.jsx(ToolbarContainer, {
783
- children: children
784
- })
785
- })
786
- });
787
- };
788
- const ToolbarScrollArea = props => {
789
- let entryLayoutPane = useEntryLayoutSplitPaneContext();
790
- return /*#__PURE__*/jsxRuntime.jsx(layout.Flex, {
791
- "data-layout": entryLayoutPane,
792
- paddingY: "regular",
793
- paddingX: "medium",
794
- gap: "large",
795
- flex: true,
796
- minWidth: 0,
797
- UNSAFE_className: style.css({
798
- msOverflowStyle: 'none' /* for Internet Explorer, Edge */,
799
- scrollbarWidth: 'none' /* for Firefox */,
800
- overflowX: 'auto',
801
- /* for Chrome, Safari, and Opera */
802
- '&::-webkit-scrollbar': {
803
- display: 'none'
804
- },
805
- '&[data-layout="main"]': {
806
- paddingInline: 0
807
- }
808
- }),
809
- ...props
810
- });
811
- };
812
-
813
- function HeadingElement({
814
- attributes,
815
- children,
816
- element
817
- }) {
818
- const Tag = `h${element.level}`;
819
- return /*#__PURE__*/jsxRuntime.jsx(Tag, {
820
- ...attributes,
821
- style: {
822
- textAlign: element.textAlign
823
- },
824
- children: children
825
- });
826
- }
827
-
828
- const renderElement = props => {
829
- switch (props.element.type) {
830
- case 'layout':
831
- return /*#__PURE__*/jsxRuntime.jsx(layouts.LayoutContainer, {
832
- attributes: props.attributes,
833
- children: props.children,
834
- element: props.element
835
- });
836
- case 'layout-area':
837
- return /*#__PURE__*/jsxRuntime.jsx(layouts.LayoutArea, {
838
- ...props
839
- });
840
- case 'code':
841
- return /*#__PURE__*/jsxRuntime.jsx(CodeElement, {
842
- ...props
843
- });
844
- case 'component-block':
845
- {
846
- return /*#__PURE__*/jsxRuntime.jsx(toolbarState.ComponentBlocksElement, {
847
- attributes: props.attributes,
848
- children: props.children,
849
- element: props.element
850
- });
851
- }
852
- case 'component-inline-prop':
853
- case 'component-block-prop':
854
- return /*#__PURE__*/jsxRuntime.jsx(toolbarState.ComponentInlineProp, {
855
- ...props
856
- });
857
- case 'heading':
858
- return /*#__PURE__*/jsxRuntime.jsx(HeadingElement, {
859
- attributes: props.attributes,
860
- children: props.children,
861
- element: props.element
862
- });
863
- case 'link':
864
- return /*#__PURE__*/jsxRuntime.jsx(LinkElement, {
865
- attributes: props.attributes,
866
- children: props.children,
867
- element: props.element
868
- });
869
- case 'ordered-list':
870
- return /*#__PURE__*/jsxRuntime.jsx("ol", {
871
- ...props.attributes,
872
- children: props.children
873
- });
874
- case 'unordered-list':
875
- return /*#__PURE__*/jsxRuntime.jsx("ul", {
876
- ...props.attributes,
877
- children: props.children
878
- });
879
- case 'list-item':
880
- return /*#__PURE__*/jsxRuntime.jsx("li", {
881
- ...props.attributes,
882
- children: props.children
883
- });
884
- case 'list-item-content':
885
- return /*#__PURE__*/jsxRuntime.jsx("span", {
886
- ...props.attributes,
887
- children: props.children
888
- });
889
- case 'blockquote':
890
- return /*#__PURE__*/jsxRuntime.jsx(BlockquoteElement, {
891
- ...props
892
- });
893
- case 'relationship':
894
- return /*#__PURE__*/jsxRuntime.jsx(toolbarState.RelationshipElement, {
895
- attributes: props.attributes,
896
- children: props.children,
897
- element: props.element
898
- });
899
- case 'divider':
900
- return /*#__PURE__*/jsxRuntime.jsx(DividerElement, {
901
- ...props
902
- });
903
- default:
904
- return /*#__PURE__*/jsxRuntime.jsx("p", {
905
- style: {
906
- textAlign: props.element.textAlign
907
- },
908
- ...props.attributes,
909
- children: props.children
910
- });
911
- }
912
- };
913
-
914
- /* Block Elements */
915
-
916
- const CodeElement = ({
917
- attributes,
918
- children
919
- }) => {
920
- return /*#__PURE__*/jsxRuntime.jsx("pre", {
921
- spellCheck: "false",
922
- ...attributes,
923
- children: /*#__PURE__*/jsxRuntime.jsx("code", {
924
- children: children
925
- })
926
- });
927
- };
928
- function DividerElement({
929
- attributes,
930
- children
931
- }) {
932
- const selected = slateReact.useSelected();
933
- return /*#__PURE__*/jsxRuntime.jsxs("div", {
934
- ...attributes,
935
- style: {
936
- caretColor: 'transparent'
937
- },
938
- children: [/*#__PURE__*/jsxRuntime.jsx("hr", {
939
- style: {
940
- backgroundColor: selected ? style.tokenSchema.color.alias.borderSelected : style.tokenSchema.color.alias.borderIdle
941
- }
942
- }), children]
943
- });
944
- }
945
-
946
- function getOptions(toolbarState$1, componentBlocks, relationships) {
947
- const options = [...Object.entries(relationships).map(([relationship, {
948
- label
949
- }]) => ({
950
- label,
951
- insert: editor => {
952
- slate.Transforms.insertNodes(editor, {
953
- type: 'relationship',
954
- relationship,
955
- data: null,
956
- children: [{
957
- text: ''
958
- }]
959
- });
960
- }
961
- })), ...Object.keys(componentBlocks).map(key => ({
962
- label: componentBlocks[key].label,
963
- insert: editor => {
964
- toolbarState.insertComponentBlock(editor, componentBlocks, key);
965
- }
966
- })), ...toolbarState$1.textStyles.allowedHeadingLevels.filter(a => toolbarState$1.editorDocumentFeatures.formatting.headingLevels.includes(a)).map(level => ({
967
- label: `Heading ${level}`,
968
- insert(editor) {
969
- utils.insertNodesButReplaceIfSelectionIsAtEmptyParagraphOrHeading(editor, {
970
- type: 'heading',
971
- level,
972
- children: [{
973
- text: ''
974
- }]
975
- });
976
- }
977
- })), !toolbarState$1.blockquote.isDisabled && toolbarState$1.editorDocumentFeatures.formatting.blockTypes.blockquote && {
978
- label: 'Blockquote',
979
- insert(editor) {
980
- utils.insertNodesButReplaceIfSelectionIsAtEmptyParagraphOrHeading(editor, {
981
- type: 'blockquote',
982
- children: [{
983
- text: ''
984
- }]
985
- });
986
- }
987
- }, !toolbarState$1.code.isDisabled && toolbarState$1.editorDocumentFeatures.formatting.blockTypes.code && {
988
- label: 'Code block',
989
- insert(editor) {
990
- utils.insertNodesButReplaceIfSelectionIsAtEmptyParagraphOrHeading(editor, {
991
- type: 'code',
992
- children: [{
993
- text: ''
994
- }]
995
- });
996
- }
997
- }, !toolbarState$1.dividers.isDisabled && toolbarState$1.editorDocumentFeatures.dividers && {
998
- label: 'Divider',
999
- insert(editor) {
1000
- utils.insertNodesButReplaceIfSelectionIsAtEmptyParagraphOrHeading(editor, {
1001
- type: 'divider',
1002
- children: [{
1003
- text: ''
1004
- }]
1005
- });
1006
- }
1007
- }, !!toolbarState$1.editorDocumentFeatures.layouts.length && {
1008
- label: 'Layout',
1009
- insert(editor) {
1010
- shared.insertLayout(editor, toolbarState$1.editorDocumentFeatures.layouts[0]);
1011
- }
1012
- }, !toolbarState$1.lists.ordered.isDisabled && toolbarState$1.editorDocumentFeatures.formatting.listTypes.ordered && {
1013
- label: 'Numbered List',
1014
- keywords: ['ordered list'],
1015
- insert(editor) {
1016
- utils.insertNodesButReplaceIfSelectionIsAtEmptyParagraphOrHeading(editor, {
1017
- type: 'ordered-list',
1018
- children: [{
1019
- text: ''
1020
- }]
1021
- });
1022
- }
1023
- }, !toolbarState$1.lists.unordered.isDisabled && toolbarState$1.editorDocumentFeatures.formatting.listTypes.unordered && {
1024
- label: 'Bullet List',
1025
- keywords: ['unordered list'],
1026
- insert(editor) {
1027
- utils.insertNodesButReplaceIfSelectionIsAtEmptyParagraphOrHeading(editor, {
1028
- type: 'unordered-list',
1029
- children: [{
1030
- text: ''
1031
- }]
1032
- });
1033
- }
1034
- }];
1035
- return options.filter(x => typeof x !== 'boolean');
1036
- }
1037
- function insertOption(editor, text, option) {
1038
- const path = slateReact.ReactEditor.findPath(editor, text);
1039
- slate.Transforms.delete(editor, {
1040
- at: {
1041
- focus: slate.Editor.start(editor, path),
1042
- anchor: slate.Editor.end(editor, path)
1043
- }
1044
- });
1045
- option.insert(editor);
1046
- }
1047
- function InsertMenu({
1048
- children,
1049
- text
1050
- }) {
1051
- const toolbarState$1 = toolbarState.useToolbarState();
1052
- const {
1053
- editor
1054
- } = toolbarState$1;
1055
- const componentBlocks = React.useContext(toolbarState.ComponentBlockContext);
1056
- const relationships = toolbarState.useDocumentFieldRelationships();
1057
- const options = matchSorter.matchSorter(getOptions(toolbarState$1, componentBlocks, relationships), text.text.slice(1), {
1058
- keys: ['label', 'keywords']
1059
- }).map((option, index) => ({
1060
- ...option,
1061
- index
1062
- }));
1063
- const stateRef = React.useRef({
1064
- options,
1065
- text
1066
- });
1067
- React.useEffect(() => {
1068
- stateRef.current = {
1069
- options,
1070
- text
1071
- };
1072
- });
1073
- const listenerRef = React.useRef(_event => {});
1074
- React.useEffect(() => {
1075
- listenerRef.current = event => {
1076
- if (event.defaultPrevented) return;
1077
- switch (event.key) {
1078
- case 'ArrowDown':
1079
- {
1080
- if (stateRef.current.options.length) {
1081
- event.preventDefault();
1082
- state.selectionManager.setFocused(true);
1083
- state.selectionManager.setFocusedKey((Number(state.selectionManager.focusedKey) === stateRef.current.options.length - 1 ? 0 : Number(state.selectionManager.focusedKey) + 1).toString());
1084
- }
1085
- return;
1086
- }
1087
- case 'ArrowUp':
1088
- {
1089
- if (stateRef.current.options.length) {
1090
- event.preventDefault();
1091
- state.selectionManager.setFocused(true);
1092
- state.selectionManager.setFocusedKey((state.selectionManager.focusedKey === '0' ? stateRef.current.options.length - 1 : Number(state.selectionManager.focusedKey) - 1).toString());
1093
- }
1094
- return;
1095
- }
1096
- case 'Enter':
1097
- {
1098
- const option = stateRef.current.options[Number(state.selectionManager.focusedKey)];
1099
- if (option) {
1100
- insertOption(editor, stateRef.current.text, option);
1101
- event.preventDefault();
1102
- }
1103
- return;
1104
- }
1105
- case 'Escape':
1106
- {
1107
- const path = slateReact.ReactEditor.findPath(editor, stateRef.current.text);
1108
- slate.Transforms.unsetNodes(editor, 'insertMenu', {
1109
- at: path
1110
- });
1111
- event.preventDefault();
1112
- return;
1113
- }
1114
- }
1115
- };
1116
- });
1117
- React.useEffect(() => {
1118
- const domNode = slateReact.ReactEditor.toDOMNode(editor, editor);
1119
- let listener = event => listenerRef.current(event);
1120
- domNode.addEventListener('keydown', listener);
1121
- return () => {
1122
- domNode.removeEventListener('keydown', listener);
1123
- };
1124
- }, [editor]);
1125
- const triggerRef = React.useRef(null);
1126
- const overlayState = overlays.useOverlayTriggerState({
1127
- isOpen: true
1128
- });
1129
- const {
1130
- triggerProps: {
1131
- onPress,
1132
- ...triggerProps
1133
- },
1134
- overlayProps
1135
- } = overlays$1.useOverlayTrigger({
1136
- type: 'listbox'
1137
- }, overlayState, triggerRef);
1138
- let state = list.useListState({
1139
- items: options,
1140
- children: item => /*#__PURE__*/jsxRuntime.jsx(listbox.Item, {
1141
- children: item.label
1142
- }, item.index)
1143
- });
1144
- React.useEffect(() => {
1145
- if (!state.selectionManager.isFocused && state.collection.size) {
1146
- state.selectionManager.setFocused(true);
1147
- state.selectionManager.setFocusedKey('0');
1148
- }
1149
- }, [state]);
1150
- const scrollableRef = React.useRef(null);
1151
- React.useEffect(() => {
1152
- var _scrollableRef$curren;
1153
- const element = (_scrollableRef$curren = scrollableRef.current) === null || _scrollableRef$curren === void 0 || (_scrollableRef$curren = _scrollableRef$curren.querySelector('[role="listbox"] [role="presentation"]')) === null || _scrollableRef$curren === void 0 ? void 0 : _scrollableRef$curren.children[state.selectionManager.focusedKey];
1154
- if (element) {
1155
- scrollIntoView__default["default"](element, {
1156
- scrollMode: 'if-needed',
1157
- boundary: scrollableRef.current,
1158
- block: 'nearest'
1159
- });
1160
- }
1161
- }, [state.selectionManager.focusedKey]);
1162
- const listboxRef = React.useRef(null);
1163
- let layout = listbox.useListBoxLayout();
1164
- return /*#__PURE__*/jsxRuntime.jsxs(React.Fragment, {
1165
- children: [/*#__PURE__*/jsxRuntime.jsx("span", {
1166
- ...triggerProps,
1167
- role: "button",
1168
- className: style.css({
1169
- color: style.tokenSchema.color.foreground.accent,
1170
- fontWeight: style.tokenSchema.typography.fontWeight.medium
1171
- }),
1172
- ref: triggerRef,
1173
- children: children
1174
- }), /*#__PURE__*/jsxRuntime.jsx(overlays$2.Popover, {
1175
- width: "alias.singleLineWidth",
1176
- placement: "bottom start",
1177
- isNonModal: true,
1178
- hideArrow: true,
1179
- ...overlayProps,
1180
- state: overlayState,
1181
- triggerRef: triggerRef,
1182
- children: /*#__PURE__*/jsxRuntime.jsx("div", {
1183
- className: style.css({
1184
- overflow: 'scroll',
1185
- maxHeight: 300
1186
- }),
1187
- ref: scrollableRef,
1188
- children: /*#__PURE__*/jsxRuntime.jsx(listbox.ListBoxBase, {
1189
- state: state,
1190
- shouldUseVirtualFocus: true,
1191
- layout: layout,
1192
- ref: listboxRef,
1193
- onAction: key => {
1194
- insertOption(editor, text, options[key]);
1195
- }
1196
- })
1197
- })
1198
- })]
1199
- });
1200
- }
1201
-
1202
- function Placeholder({
1203
- placeholder,
1204
- children
1205
- }) {
1206
- const [width, setWidth] = React.useState(0);
1207
- return /*#__PURE__*/jsxRuntime.jsxs("span", {
1208
- className: style.css({
1209
- position: 'relative',
1210
- display: 'inline-block',
1211
- width
1212
- }),
1213
- children: [/*#__PURE__*/jsxRuntime.jsx("span", {
1214
- contentEditable: false,
1215
- className: style.css({
1216
- position: 'absolute',
1217
- pointerEvents: 'none',
1218
- display: 'inline-block',
1219
- left: 0,
1220
- top: 0,
1221
- maxWidth: '100%',
1222
- whiteSpace: 'nowrap',
1223
- opacity: '0.5',
1224
- userSelect: 'none',
1225
- fontStyle: 'normal',
1226
- fontWeight: 'normal',
1227
- textDecoration: 'none',
1228
- textAlign: 'left'
1229
- }),
1230
- children: /*#__PURE__*/jsxRuntime.jsx("span", {
1231
- ref: node => {
1232
- if (node) {
1233
- const offsetWidth = node.offsetWidth;
1234
- if (offsetWidth !== width) {
1235
- setWidth(offsetWidth);
1236
- }
1237
- }
1238
- },
1239
- children: placeholder
1240
- })
1241
- }), children]
1242
- });
1243
- }
1244
- const Leaf = ({
1245
- leaf,
1246
- text,
1247
- children,
1248
- attributes
1249
- }) => {
1250
- const {
1251
- underline,
1252
- strikethrough,
1253
- bold,
1254
- italic,
1255
- code,
1256
- keyboard,
1257
- superscript,
1258
- subscript,
1259
- placeholder,
1260
- insertMenu
1261
- } = leaf;
1262
- if (placeholder !== undefined) {
1263
- children = /*#__PURE__*/jsxRuntime.jsx(Placeholder, {
1264
- placeholder: placeholder,
1265
- children: children
1266
- });
1267
- }
1268
- if (insertMenu) {
1269
- children = /*#__PURE__*/jsxRuntime.jsx(InsertMenu, {
1270
- text: text,
1271
- children: children
1272
- });
1273
- }
1274
- if (code) {
1275
- children = /*#__PURE__*/jsxRuntime.jsx("code", {
1276
- children: children
1277
- });
1278
- }
1279
- if (bold) {
1280
- children = /*#__PURE__*/jsxRuntime.jsx("strong", {
1281
- children: children
1282
- });
1283
- }
1284
- if (strikethrough) {
1285
- children = /*#__PURE__*/jsxRuntime.jsx("s", {
1286
- children: children
1287
- });
1288
- }
1289
- if (italic) {
1290
- children = /*#__PURE__*/jsxRuntime.jsx("em", {
1291
- children: children
1292
- });
1293
- }
1294
- if (keyboard) {
1295
- children = /*#__PURE__*/jsxRuntime.jsx("kbd", {
1296
- children: children
1297
- });
1298
- }
1299
- if (superscript) {
1300
- children = /*#__PURE__*/jsxRuntime.jsx("sup", {
1301
- children: children
1302
- });
1303
- }
1304
- if (subscript) {
1305
- children = /*#__PURE__*/jsxRuntime.jsx("sub", {
1306
- children: children
1307
- });
1308
- }
1309
- if (underline) {
1310
- children = /*#__PURE__*/jsxRuntime.jsx("u", {
1311
- children: children
1312
- });
1313
- }
1314
- return /*#__PURE__*/jsxRuntime.jsx("span", {
1315
- ...attributes,
1316
- children: children
1317
- });
1318
- };
1319
- const renderLeaf = props => {
1320
- return /*#__PURE__*/jsxRuntime.jsx(Leaf, {
1321
- ...props
1322
- });
1323
- };
1324
-
1325
- const styles = style.css({
1326
- flex: 1,
1327
- background: style.tokenSchema.color.background.canvas,
1328
- borderColor: style.tokenSchema.color.alias.borderIdle,
1329
- outline: 0,
1330
- padding: style.tokenSchema.size.space.medium,
1331
- minHeight: 120,
1332
- scrollbarGutter: 'stable',
1333
- overflowY: 'auto',
1334
- height: 224,
1335
- resize: 'vertical',
1336
- borderBottomLeftRadius: style.tokenSchema.size.radius.medium,
1337
- borderBottomRightRadius: style.tokenSchema.size.radius.medium,
1338
- '&[data-expanded=true]': {
1339
- // the !important is necessary to override the height set by resizing as an inline style
1340
- height: 'auto !important',
1341
- resize: 'none'
1342
- },
1343
- 'ol ol ol ol ol ol ol ol ol': {
1344
- listStyle: 'lower-roman'
1345
- },
1346
- 'ol ol ol ol ol ol ol ol': {
1347
- listStyle: 'lower-alpha'
1348
- },
1349
- 'ol ol ol ol ol ol ol': {
1350
- listStyle: 'decimal'
1351
- },
1352
- 'ol ol ol ol ol ol': {
1353
- listStyle: 'lower-roman'
1354
- },
1355
- 'ol ol ol ol ol': {
1356
- listStyle: 'lower-alpha'
1357
- },
1358
- 'ol ol ol ol': {
1359
- listStyle: 'decimal'
1360
- },
1361
- 'ol ol ol': {
1362
- listStyle: 'lower-roman'
1363
- },
1364
- 'ol ol': {
1365
- listStyle: 'lower-alpha'
1366
- },
1367
- ol: {
1368
- listStyle: 'decimal'
1369
- },
1370
- 'ul ul ul ul ul ul ul ul ul': {
1371
- listStyle: 'square'
1372
- },
1373
- 'ul ul ul ul ul ul ul ul': {
1374
- listStyle: 'circle'
1375
- },
1376
- 'ul ul ul ul ul ul ul': {
1377
- listStyle: 'disc'
1378
- },
1379
- 'ul ul ul ul ul ul': {
1380
- listStyle: 'square'
1381
- },
1382
- 'ul ul ul ul ul': {
1383
- listStyle: 'circle'
1384
- },
1385
- 'ul ul ul ul': {
1386
- listStyle: 'disc'
1387
- },
1388
- 'ul ul ul': {
1389
- listStyle: 'square'
1390
- },
1391
- 'ul ul': {
1392
- listStyle: 'circle'
1393
- },
1394
- ul: {
1395
- listStyle: 'disc'
1396
- }
1397
- });
1398
- const HOTKEYS = {
1399
- 'mod+b': 'bold',
1400
- 'mod+i': 'italic',
1401
- 'mod+u': 'underline'
1402
- };
1403
- function isMarkActive(editor, mark) {
1404
- const marks = slate.Editor.marks(editor);
1405
- if (marks !== null && marks !== void 0 && marks[mark]) {
1406
- return true;
1407
- }
1408
- // see the stuff about marks in toolbar-state for why this is here
1409
- for (const entry of slate.Editor.nodes(editor, {
1410
- match: slate.Text.isText
1411
- })) {
1412
- if (entry[0][mark]) {
1413
- return true;
1414
- }
1415
- }
1416
- return false;
1417
- }
1418
- const getKeyDownHandler = editor => event => {
1419
- if (event.defaultPrevented) return;
1420
- for (const hotkey in HOTKEYS) {
1421
- if (isHotkey__default["default"](hotkey, event.nativeEvent)) {
1422
- event.preventDefault();
1423
- const mark = HOTKEYS[hotkey];
1424
- const isActive = isMarkActive(editor, mark);
1425
- if (isActive) {
1426
- slate.Editor.removeMark(editor, mark);
1427
- } else {
1428
- slate.Editor.addMark(editor, mark, true);
1429
- }
1430
- return;
1431
- }
1432
- }
1433
- if (isHotkey__default["default"]('mod+\\', event.nativeEvent)) {
1434
- utils.clearFormatting(editor);
1435
- return;
1436
- }
1437
- if (isHotkey__default["default"]('mod+k', event.nativeEvent)) {
1438
- event.preventDefault();
1439
- editorShared.wrapLink(editor, '');
1440
- return;
1441
- }
1442
- if (event.key === 'Tab') {
1443
- const didAction = event.shiftKey ? shared.unnestList(editor) : shared.nestList(editor);
1444
- if (didAction) {
1445
- event.preventDefault();
1446
- return;
1447
- }
1448
- }
1449
- if (event.key === 'Tab' && editor.selection) {
1450
- const layoutArea = slate.Editor.above(editor, {
1451
- match: node => node.type === 'layout-area'
1452
- });
1453
- if (layoutArea) {
1454
- const layoutAreaToEnter = event.shiftKey ? slate.Editor.before(editor, layoutArea[1], {
1455
- unit: 'block'
1456
- }) : slate.Editor.after(editor, layoutArea[1], {
1457
- unit: 'block'
1458
- });
1459
- slate.Transforms.setSelection(editor, {
1460
- anchor: layoutAreaToEnter,
1461
- focus: layoutAreaToEnter
1462
- });
1463
- event.preventDefault();
1464
- }
1465
- }
1466
- };
1467
- function DocumentEditor({
1468
- onChange,
1469
- value,
1470
- componentBlocks,
1471
- relationships,
1472
- documentFeatures,
1473
- initialExpanded = true,
1474
- ...props
1475
- }) {
1476
- const [expanded, setExpanded] = React.useState(initialExpanded);
1477
- const editor = React.useMemo(() => editorShared.createDocumentEditor(documentFeatures, componentBlocks, relationships, {
1478
- ReactEditor: slateReact.ReactEditor,
1479
- withReact: slateReact.withReact
1480
- }), [documentFeatures, componentBlocks, relationships]);
1481
- return /*#__PURE__*/jsxRuntime.jsx(core.KeystarProvider, {
1482
- children: /*#__PURE__*/jsxRuntime.jsx("div", {
1483
- className: style.css({
1484
- border: `${style.tokenSchema.size.border.regular} solid ${style.tokenSchema.color.border.neutral}`,
1485
- borderRadius: style.tokenSchema.size.radius.medium
1486
- }),
1487
- children: /*#__PURE__*/jsxRuntime.jsxs(DocumentEditorProvider, {
1488
- componentBlocks: componentBlocks,
1489
- documentFeatures: documentFeatures,
1490
- relationships: relationships,
1491
- editor: editor,
1492
- value: value,
1493
- onChange: value => {
1494
- onChange === null || onChange === void 0 || onChange(value);
1495
- // this fixes a strange issue in Safari where the selection stays inside of the editor
1496
- // after a blur event happens but the selection is still in the editor
1497
- // so the cursor is visually in the wrong place and it inserts text backwards
1498
- const selection = window.getSelection();
1499
- if (selection && !slateReact.ReactEditor.isFocused(editor)) {
1500
- const editorNode = slateReact.ReactEditor.toDOMNode(editor, editor);
1501
- if (selection.anchorNode === editorNode) {
1502
- slateReact.ReactEditor.focus(editor);
1503
- }
1504
- }
1505
- },
1506
- children: [React.useMemo(() => onChange !== undefined && /*#__PURE__*/jsxRuntime.jsx(Toolbar, {
1507
- documentFeatures: documentFeatures,
1508
- viewState: {
1509
- expanded,
1510
- toggle: () => {
1511
- setExpanded(v => !v);
1512
- }
1513
- }
1514
- }), [expanded, documentFeatures, onChange]), /*#__PURE__*/jsxRuntime.jsx(typography.Prose, {
1515
- size: "regular",
1516
- children: /*#__PURE__*/jsxRuntime.jsx(DocumentEditorEditable, {
1517
- "data-expanded": expanded,
1518
- ...props,
1519
- readOnly: onChange === undefined
1520
- })
1521
- })]
1522
- })
1523
- })
1524
- });
1525
- }
1526
- function DocumentEditorProvider({
1527
- children,
1528
- editor,
1529
- onChange,
1530
- value,
1531
- componentBlocks,
1532
- documentFeatures,
1533
- relationships
1534
- }) {
1535
- const identity = React.useMemo(() => Math.random().toString(36), [editor]);
1536
- return /*#__PURE__*/jsxRuntime.jsx(slateReact.Slate
1537
- // this fixes issues with Slate crashing when a fast refresh occcurs
1538
- , {
1539
- editor: editor,
1540
- initialValue: value,
1541
- onChange: value => {
1542
- onChange(value);
1543
- // this fixes a strange issue in Safari where the selection stays inside of the editor
1544
- // after a blur event happens but the selection is still in the editor
1545
- // so the cursor is visually in the wrong place and it inserts text backwards
1546
- const selection = window.getSelection();
1547
- if (selection && !slateReact.ReactEditor.isFocused(editor)) {
1548
- const editorNode = slateReact.ReactEditor.toDOMNode(editor, editor);
1549
- if (selection.anchorNode === editorNode) {
1550
- slateReact.ReactEditor.focus(editor);
1551
- }
1552
- }
1553
- },
1554
- children: /*#__PURE__*/jsxRuntime.jsx(toolbarState.ToolbarStateProvider, {
1555
- componentBlocks: componentBlocks,
1556
- editorDocumentFeatures: documentFeatures,
1557
- relationships: relationships,
1558
- children: children
1559
- })
1560
- }, identity);
1561
- }
1562
- function DocumentEditorEditable(props) {
1563
- var _props$className;
1564
- const editor = slateReact.useSlate();
1565
- const componentBlocks = React.useContext(toolbarState.ComponentBlockContext);
1566
- const onKeyDown = React.useMemo(() => getKeyDownHandler(editor), [editor]);
1567
- return /*#__PURE__*/jsxRuntime.jsx(toolbarState.ActiveBlockPopoverProvider, {
1568
- editor: editor,
1569
- children: /*#__PURE__*/jsxRuntime.jsx(slateReact.Editable, {
1570
- decorate: React.useCallback(([node, path]) => {
1571
- const decorations = [];
1572
- if (node.type === 'component-block') {
1573
- if (node.children.length === 1 && slate.Element.isElement(node.children[0]) && node.children[0].type === 'component-inline-prop' && node.children[0].propPath === undefined) {
1574
- return decorations;
1575
- }
1576
- node.children.forEach((child, index) => {
1577
- if (slate.Node.string(child) === '' && slate.Element.isElement(child) && (child.type === 'component-block-prop' || child.type === 'component-inline-prop') && child.propPath !== undefined) {
1578
- const start = slate.Editor.start(editor, [...path, index]);
1579
- const placeholder = utils.getPlaceholderTextForPropPath(child.propPath, componentBlocks[node.component].schema, node.props);
1580
- if (placeholder) {
1581
- decorations.push({
1582
- placeholder,
1583
- anchor: start,
1584
- focus: start
1585
- });
1586
- }
1587
- }
1588
- });
1589
- }
1590
- return decorations;
1591
- }, [editor, componentBlocks]),
1592
- className: `${styles} ${(_props$className = props.className) !== null && _props$className !== void 0 ? _props$className : ''}`,
1593
- onKeyDown: onKeyDown,
1594
- renderElement: renderElement,
1595
- renderLeaf: renderLeaf,
1596
- ...props
1597
- })
1598
- });
1599
- }
1600
-
1601
- // Field 组件用于在编辑视图中显示字段值
1602
- function Field(props) {
1603
- const {
1604
- autoFocus,
1605
- field: field$1,
1606
- forceValidation,
1607
- onChange,
1608
- value
1609
- } = props;
1610
- return /*#__PURE__*/jsxRuntime.jsx(field.Field, {
1611
- label: field$1.label,
1612
- description: field$1.description,
1613
- children: inputProps => /*#__PURE__*/jsxRuntime.jsx(toolbarState.ForceValidationProvider, {
1614
- value: !!forceValidation,
1615
- children: /*#__PURE__*/jsxRuntime.jsx(DocumentEditor, {
1616
- ...inputProps,
1617
- autoFocus: autoFocus,
1618
- componentBlocks: field$1.componentBlocks,
1619
- documentFeatures: field$1.documentFeatures,
1620
- onChange: onChange,
1621
- relationships: field$1.relationships,
1622
- value: value
1623
- })
1624
- })
1625
- });
1626
- }
1627
-
1628
- exports["default"] = Field;