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,512 +0,0 @@
1
- 'use strict';
2
-
3
- var context = require('lkb-core/admin-ui/context');
4
- var views = require('lkb-core/fields/types/relationship/views');
5
- var utils$1 = require('lkb-core/admin-ui/utils');
6
- var button = require('@keystar/ui/button');
7
- var dialog = require('@keystar/ui/dialog');
8
- var field = require('@keystar/ui/field');
9
- var typography = require('@keystar/ui/typography');
10
- var icon = require('@keystar/ui/icon');
11
- var listView = require('@keystar/ui/list-view');
12
- var dragAndDrop = require('@keystar/ui/drag-and-drop');
13
- var tooltip = require('@keystar/ui/tooltip');
14
- var layout = require('@keystar/ui/layout');
15
- var trash2Icon = require('@keystar/ui/icon/icons/trash2Icon');
16
- var React = require('react');
17
- var utils = require('./utils-06bcddc4.node.cjs.js');
18
- var slots = require('@keystar/ui/slots');
19
- var jsxRuntime = require('react/jsx-runtime');
20
-
21
- const previewPropsToValueConverter = {
22
- child() {
23
- return null;
24
- },
25
- form(props) {
26
- return props.value;
27
- },
28
- array(props) {
29
- const values = props.elements.map(x => previewPropsToValue(x));
30
- utils.setKeysForArrayValue(values, props.elements.map(x => x.key));
31
- return values;
32
- },
33
- conditional(props) {
34
- return {
35
- discriminant: props.discriminant,
36
- value: previewPropsToValue(props.value)
37
- };
38
- },
39
- object(props) {
40
- return Object.fromEntries(Object.entries(props.fields).map(([key, val]) => [key, previewPropsToValue(val)]));
41
- },
42
- relationship(props) {
43
- return props.value;
44
- }
45
- };
46
- const valueToUpdaters = {
47
- child() {
48
- return undefined;
49
- },
50
- form(value) {
51
- return value;
52
- },
53
- array(value, schema) {
54
- const keys = utils.getKeysForArrayValue(value);
55
- return value.map((x, i) => ({
56
- key: keys[i],
57
- value: valueToUpdater(x, schema.element)
58
- }));
59
- },
60
- conditional(value, schema) {
61
- return {
62
- discriminant: value.discriminant,
63
- value: valueToUpdater(value.value, schema.values[value.discriminant.toString()])
64
- };
65
- },
66
- object(value, schema) {
67
- return Object.fromEntries(Object.entries(schema.fields).map(([key, schema]) => [key, valueToUpdater(value[key], schema)]));
68
- },
69
- relationship(value) {
70
- return value;
71
- }
72
- };
73
- function previewPropsToValue(props) {
74
- return previewPropsToValueConverter[props.schema.kind](props);
75
- }
76
- function valueToUpdater(value, schema) {
77
- return valueToUpdaters[schema.kind](value, schema);
78
- }
79
-
80
- // this exists because for props.schema.kind === 'form', ts doesn't narrow props, only props.schema
81
- function isKind(props, kind) {
82
- return props.schema.kind === kind;
83
- }
84
- function previewPropsOnChange(value, props) {
85
- // child fields can't be updated through preview props, so we don't do anything here
86
- if (isKind(props, 'child')) return;
87
- if (isKind(props, 'form') || isKind(props, 'relationship') || isKind(props, 'object') || isKind(props, 'array')) {
88
- props.onChange(valueToUpdater(value, props.schema));
89
- return;
90
- }
91
- if (isKind(props, 'conditional')) {
92
- const updater = valueToUpdater(value, props.schema);
93
- props.onChange(updater.discriminant, updater.value);
94
- return;
95
- }
96
- utils.assertNever(props);
97
- }
98
- function ArrayFieldPreview(props) {
99
- const {
100
- elements,
101
- onChange,
102
- schema
103
- } = props;
104
- const {
105
- label
106
- } = schema;
107
- const [modalState, setModalState] = React.useState('closed');
108
- return /*#__PURE__*/jsxRuntime.jsx(field.Field, {
109
- label: label,
110
- labelElementType: "span",
111
- children: groupProps => /*#__PURE__*/jsxRuntime.jsxs(layout.VStack, {
112
- gap: "medium",
113
- role: "group",
114
- minWidth: 0,
115
- ...groupProps,
116
- children: [/*#__PURE__*/jsxRuntime.jsx(ArrayFieldListView, {
117
- ...props,
118
- "aria-label": label !== null && label !== void 0 ? label : '',
119
- onOpenItem: index => {
120
- const element = elements.at(index);
121
- if (!element) return;
122
- setModalState({
123
- index,
124
- value: previewPropsToValue(element),
125
- forceValidation: false
126
- });
127
- }
128
- }), /*#__PURE__*/jsxRuntime.jsx(button.ActionButton, {
129
- alignSelf: "start",
130
- autoFocus: props.autoFocus,
131
- onPress: () => {
132
- onChange([...elements.map(x => ({
133
- key: x.key
134
- })), {
135
- key: undefined
136
- }]);
137
- },
138
- children: "\u6DFB\u52A0\u9009\u9879"
139
- }), /*#__PURE__*/jsxRuntime.jsx(dialog.DialogContainer, {
140
- onDismiss: () => {
141
- setModalState('closed');
142
- },
143
- children: (() => {
144
- if (props.schema.element.kind === 'child') return;
145
- if (modalState === 'closed') return;
146
- const element = elements.at(modalState.index);
147
- if (!element) return;
148
- const onModalChange = cb => {
149
- setModalState(state => {
150
- if (state === 'closed') return state;
151
- return {
152
- index: modalState.index,
153
- forceValidation: state.forceValidation,
154
- value: cb(state.value)
155
- };
156
- });
157
- };
158
- return /*#__PURE__*/jsxRuntime.jsxs(dialog.Dialog, {
159
- children: [/*#__PURE__*/jsxRuntime.jsx(typography.Heading, {
160
- children: "\u7F16\u8F91\u9009\u9879"
161
- }), /*#__PURE__*/jsxRuntime.jsx(slots.Content, {
162
- children: /*#__PURE__*/jsxRuntime.jsx(ArrayFieldItemModalContent, {
163
- onChange: onModalChange,
164
- schema: element.schema /* TODO FIXME */,
165
- value: modalState.value
166
- })
167
- }), /*#__PURE__*/jsxRuntime.jsxs(button.ButtonGroup, {
168
- children: [/*#__PURE__*/jsxRuntime.jsx(button.Button, {
169
- prominence: "low",
170
- onPress: () => {
171
- setModalState('closed');
172
- },
173
- children: "\u53D6\u6D88"
174
- }), /*#__PURE__*/jsxRuntime.jsx(button.Button, {
175
- prominence: "high",
176
- onPress: () => {
177
- if (!utils.clientSideValidateProp(element.schema, modalState.value)) {
178
- setModalState(state => ({
179
- ...state /* TODO FIXME */,
180
- forceValidation: true
181
- }));
182
- return;
183
- }
184
- previewPropsOnChange(modalState.value, element);
185
- setModalState('closed');
186
- },
187
- children: "\u786E\u5B9A"
188
- })]
189
- })]
190
- });
191
- })()
192
- })]
193
- })
194
- });
195
- }
196
- function RelationshipFieldPreview(props) {
197
- const {
198
- autoFocus,
199
- onChange,
200
- schema,
201
- value
202
- } = props;
203
- const {
204
- label,
205
- listKey,
206
- many
207
- } = schema;
208
- const list = context.useList(listKey);
209
- const formValue = function () {
210
- if (many) {
211
- if (value !== null && !('length' in value)) throw TypeError('bad value');
212
- const manyValue = value === null ? [] : value.map(x => ({
213
- id: x.id,
214
- label: x.label || x.id.toString(),
215
- data: x.data,
216
- built: undefined
217
- }));
218
- return {
219
- kind: 'many',
220
- id: '',
221
- // unused
222
- initialValue: manyValue,
223
- value: manyValue
224
- };
225
- }
226
- if (value !== null && 'length' in value) throw TypeError('bad value');
227
- const oneValue = value ? {
228
- id: value.id,
229
- label: value.label || value.id.toString(),
230
- data: value.data,
231
- built: undefined
232
- } : null;
233
- return {
234
- kind: 'one',
235
- id: '',
236
- // unused
237
- initialValue: oneValue,
238
- value: oneValue
239
- };
240
- }();
241
- return /*#__PURE__*/jsxRuntime.jsx(views.Field, {
242
- autoFocus: autoFocus,
243
- isRequired: false,
244
- field: {
245
- path: '',
246
- // unused
247
- label,
248
- description: '',
249
- // TODO
250
- display: 'select',
251
- listKey: '',
252
- // unused
253
- refListKey: list.key,
254
- refLabelField: list.labelField,
255
- refSearchFields: list.initialSearchFields,
256
- hideCreate: true,
257
- many
258
- },
259
- onChange: val => {
260
- if (val.kind === 'count') return; // shouldnt happen
261
- const {
262
- value
263
- } = val;
264
- if (value === null) {
265
- onChange(null);
266
- return;
267
- }
268
- if (Array.isArray(value)) {
269
- onChange(value.map(x => ({
270
- id: x.id,
271
- label: x.label
272
- })));
273
- return;
274
- }
275
- onChange({
276
- id: value.id,
277
- label: value.label
278
- });
279
- },
280
- value: formValue,
281
- itemValue: {}
282
- });
283
- }
284
- function FormFieldPreview({
285
- schema,
286
- autoFocus,
287
- forceValidation,
288
- onChange,
289
- value
290
- }) {
291
- return /*#__PURE__*/jsxRuntime.jsx(schema.Input, {
292
- autoFocus: !!autoFocus,
293
- value: value,
294
- onChange: onChange,
295
- forceValidation: !!forceValidation
296
- });
297
- }
298
- function canFieldBeFocused(schema) {
299
- if (schema.kind === 'child') return false;
300
- if (schema.kind === 'array') return true;
301
- if (schema.kind === 'conditional') return true;
302
- if (schema.kind === 'form') return true;
303
- if (schema.kind === 'relationship') return true;
304
- if (schema.kind === 'object') {
305
- for (const innerProp of Object.values(schema.fields)) {
306
- if (canFieldBeFocused(innerProp)) return true;
307
- }
308
- return false;
309
- }
310
- utils.assertNever(schema);
311
- }
312
- function findFocusableObjectFieldKey(schema) {
313
- for (const [key, innerProp] of Object.entries(schema.fields)) {
314
- const childFocusable = canFieldBeFocused(innerProp);
315
- if (childFocusable) return key;
316
- }
317
- }
318
- function ObjectFieldPreview({
319
- schema,
320
- autoFocus,
321
- fields
322
- }) {
323
- const firstFocusable = autoFocus ? findFocusableObjectFieldKey(schema) : undefined;
324
- return /*#__PURE__*/jsxRuntime.jsxs(layout.HStack, {
325
- gap: "medium",
326
- paddingTop: "medium",
327
- children: [/*#__PURE__*/jsxRuntime.jsx(utils$1.GroupIndicatorLine, {}), /*#__PURE__*/jsxRuntime.jsx(layout.VStack, {
328
- gap: "xlarge",
329
- flex: true,
330
- minWidth: 0,
331
- children: [...function* () {
332
- for (const [key, propVal] of Object.entries(fields)) {
333
- if (!isNonChildFieldPreviewProps(propVal)) continue;
334
- yield /*#__PURE__*/jsxRuntime.jsx(FormValueContentFromPreviewProps, {
335
- autoFocus: key === firstFocusable,
336
- ...propVal
337
- }, key);
338
- }
339
- }()]
340
- })]
341
- });
342
- }
343
- function ConditionalFieldPreview({
344
- schema,
345
- autoFocus,
346
- discriminant,
347
- onChange,
348
- value
349
- }) {
350
- const schemaDiscriminant = schema.discriminant;
351
- return /*#__PURE__*/jsxRuntime.jsxs(layout.HStack, {
352
- gap: "xlarge",
353
- children: [React.useMemo(() => /*#__PURE__*/jsxRuntime.jsx(schemaDiscriminant.Input, {
354
- autoFocus: !!autoFocus,
355
- value: discriminant,
356
- onChange: onChange,
357
- forceValidation: false
358
- }), [autoFocus, schemaDiscriminant, discriminant, onChange]), isNonChildFieldPreviewProps(value) && /*#__PURE__*/jsxRuntime.jsx(FormValueContentFromPreviewProps, {
359
- ...value
360
- })]
361
- });
362
- }
363
- function isNonChildFieldPreviewProps(props) {
364
- return props.schema.kind !== 'child';
365
- }
366
- const fieldRenderers = {
367
- array: ArrayFieldPreview,
368
- relationship: RelationshipFieldPreview,
369
- child: () => null,
370
- form: FormFieldPreview,
371
- object: ObjectFieldPreview,
372
- conditional: ConditionalFieldPreview
373
- };
374
- const FormValueContentFromPreviewProps = /*#__PURE__*/React.memo(function FormValueContentFromPreview(props) {
375
- const Comp = fieldRenderers[props.schema.kind];
376
- return /*#__PURE__*/jsxRuntime.jsx(Comp, {
377
- ...props
378
- });
379
- });
380
- function useEventCallback(callback) {
381
- const callbackRef = React.useRef(callback);
382
- const cb = React.useCallback((...args) => {
383
- return callbackRef.current(...args);
384
- }, []);
385
- React.useEffect(() => {
386
- callbackRef.current = callback;
387
- });
388
- return cb;
389
- }
390
- function ArrayFieldListView(props) {
391
- const onMove = (keys, target) => {
392
- const targetIndex = props.elements.findIndex(x => x.key === target.key);
393
- if (targetIndex === -1) return;
394
- const allKeys = props.elements.map(x => ({
395
- key: x.key
396
- }));
397
- const indexToMoveTo = target.dropPosition === 'before' ? targetIndex : targetIndex + 1;
398
- const indices = keys.map(key => allKeys.findIndex(x => x.key === key));
399
- props.onChange(dragAndDrop.move(allKeys, indices, indexToMoveTo));
400
- };
401
- const dragType = React.useMemo(() => Math.random().toString(36), []);
402
- const {
403
- dragAndDropHooks
404
- } = dragAndDrop.useDragAndDrop({
405
- getItems(keys) {
406
- // Use a drag type so the items can only be reordered within this list
407
- // and not dragged elsewhere.
408
- return [...keys].map(key => {
409
- key = JSON.stringify(key);
410
- return {
411
- [dragType]: key,
412
- 'text/plain': key
413
- };
414
- });
415
- },
416
- getAllowedDropOperations() {
417
- return ['move', 'cancel'];
418
- },
419
- async onDrop(e) {
420
- if (e.target.type !== 'root' && e.target.dropPosition !== 'on') {
421
- let keys = [];
422
- for (let item of e.items) {
423
- if (item.kind === 'text') {
424
- let key;
425
- if (item.types.has(dragType)) {
426
- key = JSON.parse(await item.getText(dragType));
427
- keys.push(key);
428
- } else if (item.types.has('text/plain')) {
429
- // Fallback for Chrome Android case: https://bugs.chromium.org/p/chromium/issues/detail?id=1293803
430
- // Multiple drag items are contained in a single string so we need to split them out
431
- key = await item.getText('text/plain');
432
- keys = key.split('\n').map(val => val.replaceAll('"', ''));
433
- }
434
- }
435
- }
436
- onMove(keys, e.target);
437
- }
438
- },
439
- getDropOperation(target) {
440
- if (target.type === 'root' || target.dropPosition === 'on') return 'cancel';
441
- return 'move';
442
- }
443
- });
444
- const onRemoveKey = useEventCallback(key => {
445
- props.onChange(props.elements.map(x => ({
446
- key: x.key
447
- })).filter(val => val.key !== key));
448
- });
449
- return /*#__PURE__*/jsxRuntime.jsx(listView.ListView, {
450
- items: props.elements,
451
- dragAndDropHooks: dragAndDropHooks,
452
- height: props.elements.length ? undefined : 'scale.2000',
453
- selectionMode: "none",
454
- renderEmptyState: arrayFieldEmptyState,
455
- onAction: key => {
456
- const i = props.elements.findIndex(x => x.key === key);
457
- if (i === -1) return;
458
- props.onOpenItem(i);
459
- },
460
- children: item => {
461
- var _props$schema$itemLab, _props$schema;
462
- const label = ((_props$schema$itemLab = (_props$schema = props.schema).itemLabel) === null || _props$schema$itemLab === void 0 ? void 0 : _props$schema$itemLab.call(_props$schema, item)) || `选项 ${props.elements.indexOf(item) + 1}`;
463
- return /*#__PURE__*/jsxRuntime.jsxs(listView.Item, {
464
- textValue: label,
465
- children: [/*#__PURE__*/jsxRuntime.jsx(typography.Text, {
466
- children: label
467
- }), /*#__PURE__*/jsxRuntime.jsxs(tooltip.TooltipTrigger, {
468
- placement: "start",
469
- children: [/*#__PURE__*/jsxRuntime.jsx(button.ActionButton, {
470
- onPress: () => onRemoveKey(item.key),
471
- children: /*#__PURE__*/jsxRuntime.jsx(icon.Icon, {
472
- src: trash2Icon.trash2Icon
473
- })
474
- }), /*#__PURE__*/jsxRuntime.jsx(tooltip.Tooltip, {
475
- children: "\u5220\u9664"
476
- })]
477
- })]
478
- }, item.key);
479
- }
480
- });
481
- }
482
- function ArrayFieldItemModalContent(props) {
483
- const previewProps = React.useMemo(() => utils.createGetPreviewProps(props.schema, props.onChange, () => undefined), [props.schema, props.onChange])(props.value);
484
- return /*#__PURE__*/jsxRuntime.jsx(FormValueContentFromPreviewProps, {
485
- ...previewProps
486
- });
487
- }
488
- function arrayFieldEmptyState() {
489
- return /*#__PURE__*/jsxRuntime.jsxs(layout.VStack, {
490
- gap: "large",
491
- alignItems: "center",
492
- justifyContent: "center",
493
- height: "100%",
494
- padding: "regular",
495
- children: [/*#__PURE__*/jsxRuntime.jsx(typography.Text, {
496
- elementType: "h3",
497
- align: "center",
498
- color: "neutralSecondary",
499
- size: "large",
500
- weight: "medium",
501
- children: "Empty list"
502
- }), /*#__PURE__*/jsxRuntime.jsx(typography.Text, {
503
- align: "center",
504
- color: "neutralTertiary",
505
- children: "Add the first item to see it here."
506
- })]
507
- });
508
- }
509
-
510
- exports.FormValueContentFromPreviewProps = FormValueContentFromPreviewProps;
511
- exports.previewPropsOnChange = previewPropsOnChange;
512
- exports.previewPropsToValue = previewPropsToValue;