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,2 +1,2 @@
1
- export * from "../../dist/declarations/src/component-blocks.js";
2
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGtiLWZpZWxkcy1kb2N1bWVudC1jb21wb25lbnQtYmxvY2tzLmNqcy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vZGlzdC9kZWNsYXJhdGlvbnMvc3JjL2NvbXBvbmVudC1ibG9ja3MuZC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSJ9
1
+ export * from "../../src/component-blocks.js";
2
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGtiLWZpZWxkcy1kb2N1bWVudC1jb21wb25lbnQtYmxvY2tzLmNqcy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2NvbXBvbmVudC1ibG9ja3MudHN4Il0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBIn0=
@@ -1,306 +1,16 @@
1
- 'use client';
2
- 'use strict';
3
-
4
- Object.defineProperty(exports, '__esModule', { value: true });
5
-
6
- var api = require('../../dist/api-73636987.cjs.js');
7
- var jsxRuntime = require('react/jsx-runtime');
8
- var layout = require('@keystar/ui/layout');
9
- var style = require('@keystar/ui/style');
10
- var callout_ui = require('../../dist/callout-ui-2aded278.cjs.js');
11
- require('lkb-core');
12
- require('@keystar/ui/button');
13
- require('@keystar/ui/drag-and-drop');
14
- require('react');
15
- require('../../dist/index-06c36775.cjs.js');
16
- require('slate');
17
- require('@braintree/sanitize-url');
18
- require('@react-aria/i18n');
19
- require('@keystar/ui/number-field');
20
- require('@keystar/ui/picker');
21
- require('@keystar/ui/combobox');
22
- require('@keystar/ui/text-field');
23
- require('@keystar/ui/tag');
24
- require('@keystar/ui/typography');
25
- require('@keystar/ui/checkbox');
26
-
27
- const quoteBlock = api.component({
28
- preview: props => {
29
- return /*#__PURE__*/jsxRuntime.jsxs("div", {
30
- style: {
31
- borderLeft: '3px solid #CBD5E0',
32
- paddingLeft: 16
33
- },
34
- children: [/*#__PURE__*/jsxRuntime.jsx("div", {
35
- style: {
36
- fontStyle: 'italic',
37
- color: '#4A5568'
38
- },
39
- children: props.fields.content.element
40
- }), /*#__PURE__*/jsxRuntime.jsxs("div", {
41
- style: {
42
- fontWeight: 'bold',
43
- color: '#718096'
44
- },
45
- children: [/*#__PURE__*/jsxRuntime.jsx(api.NotEditable, {
46
- children: "\u2014 "
47
- }), props.fields.attribution.element]
48
- })]
49
- });
50
- },
51
- label: '内容引用',
52
- schema: {
53
- content: api.fields.child({
54
- kind: 'block',
55
- placeholder: 'Quote...',
56
- formatting: {
57
- inlineMarks: 'inherit',
58
- softBreaks: 'inherit'
59
- },
60
- links: 'inherit'
61
- }),
62
- attribution: api.fields.child({
63
- kind: 'inline',
64
- placeholder: 'Attribution...'
65
- })
66
- },
67
- chromeless: true
68
- });
69
-
70
- const carousel = api.component({
71
- label: '旋转木马',
72
- preview: function Preview(props) {
73
- return /*#__PURE__*/jsxRuntime.jsx(api.NotEditable, {
74
- children: /*#__PURE__*/jsxRuntime.jsx("div", {
75
- className: style.css({
76
- overflowY: 'scroll',
77
- display: 'flex',
78
- scrollSnapType: 'y mandatory'
79
- }),
80
- children: props.fields.items.elements.map(item => {
81
- return /*#__PURE__*/jsxRuntime.jsxs(layout.Box, {
82
- margin: "xsmall",
83
- className: style.css({
84
- minWidth: '61.8%',
85
- scrollSnapAlign: 'center',
86
- scrollSnapStop: 'always',
87
- margin: 4,
88
- padding: 8,
89
- boxSizing: 'border-box',
90
- borderRadius: 6,
91
- background: '#eff3f6'
92
- }),
93
- children: [/*#__PURE__*/jsxRuntime.jsx("img", {
94
- role: "presentation",
95
- src: item.fields.imageSrc.value,
96
- className: style.css({
97
- objectFit: 'cover',
98
- objectPosition: 'center center',
99
- height: 240,
100
- width: '100%',
101
- borderRadius: 4
102
- })
103
- }), /*#__PURE__*/jsxRuntime.jsx("h1", {
104
- className: style.css({
105
- '&&': {
106
- fontSize: '1.25rem',
107
- lineHeight: 'unset',
108
- marginTop: 8
109
- }
110
- }),
111
- children: item.fields.title.value
112
- })]
113
- }, item.key);
114
- })
115
- })
116
- });
117
- },
118
- schema: {
119
- items: api.fields.array(api.fields.object({
120
- title: api.fields.text({
121
- label: '标题'
122
- }),
123
- imageSrc: api.fields.url({
124
- label: '图片 URL',
125
- defaultValue: '/assets/images/placeholder.jpeg'
126
- })
127
- }))
128
- }
129
- });
130
-
131
- const callout = api.component({
132
- preview: function (props) {
133
- return /*#__PURE__*/jsxRuntime.jsx(callout_ui.Callout, {
134
- tone: props.fields.tone.value,
135
- children: props.fields.content.element
136
- });
137
- },
138
- label: '提示面板',
139
- chromeless: true,
140
- schema: {
141
- tone: api.fields.select({
142
- label: 'Tone',
143
- options: [{
144
- value: 'info',
145
- label: '消息'
146
- }, {
147
- value: 'caution',
148
- label: '警告'
149
- }, {
150
- value: 'positive',
151
- label: '成功'
152
- }, {
153
- value: 'critical',
154
- label: '错误'
155
- }],
156
- defaultValue: 'info'
157
- }),
158
- content: api.fields.child({
159
- kind: 'block',
160
- placeholder: '',
161
- formatting: 'inherit',
162
- dividers: 'inherit',
163
- links: 'inherit'
164
- })
165
- },
166
- toolbar({
167
- props,
168
- onRemove
169
- }) {
170
- return /*#__PURE__*/jsxRuntime.jsx(callout_ui.CalloutToolbar, {
171
- onChange: tone => {
172
- props.fields.tone.onChange(tone);
173
- },
174
- onRemove: onRemove,
175
- tone: props.fields.tone.value,
176
- tones: props.fields.tone.schema.options
177
- });
178
- }
179
- });
180
-
181
- // 上传函数
182
- async function uploadImage(albumId, file, name, altText) {
183
- const operations = {
184
- variables: {
185
- data: {
186
- name,
187
- altText,
188
- image: {
189
- upload: null
190
- },
191
- album: {
192
- connect: {
193
- id: albumId
194
- }
195
- }
196
- }
197
- },
198
- query: `mutation ($data: ImageCreateInput!) {
199
- item: createImage(data: $data) {
200
- id
201
- name
202
- image { url }
203
- album { id name }
204
- __typename
205
- }
206
- }`
207
- };
208
- const map = {
209
- '1': ['variables.data.image.upload']
210
- };
211
-
212
- // useMutation
213
- const formData = new FormData();
214
- formData.append('operations', JSON.stringify(operations));
215
- formData.append('map', JSON.stringify(map));
216
- formData.append('1', file); // 这里的 '1' 对应 map 中的键
217
-
218
- try {
219
- const response = await fetch('/api/graphql', {
220
- method: 'POST',
221
- body: formData,
222
- headers: {
223
- 'x-apollo-operation-name': 'UploadImage',
224
- 'apollo-require-preflight': 'true'
225
- }
226
- // 注意:不要手动设置 Content-Type,浏览器会自动设置正确的 boundary
227
- });
228
- const result = await response.json();
229
- if (result.errors) {
230
- throw new Error(result.errors[0].message);
231
- }
232
- return result.data.item;
233
- } catch (error) {
234
- console.log('上传失败:', error);
235
- throw error;
236
- }
237
- }
238
-
239
- const Image = api.component({
240
- label: '图片',
241
- schema: {
242
- webImageUrl: api.fields.text({
243
- label: 'Web 图片地址'
244
- }),
245
- uploadedImageUrl: api.fields.file({
246
- label: '使用上传的图片',
247
- allowedFileTypes: ['image/png', 'image/jpg', 'image/jpeg', 'image/gif', 'image/webp'],
248
- isImage: true,
249
- onUpload(file) {
250
- // console.log(file)
251
- return new Promise((resolve, reject) => {
252
- // 使用固定的 albumId:cmhepys2l0000dd2m4cxaozc8,文档相关的临时图片都存放在这儿。
253
- try {
254
- uploadImage('cmhepys2l0000dd2m4cxaozc8', file, file.name).then(ret => resolve(ret.image.url)).catch(reject);
255
- } catch (e) {
256
- reject(e);
257
- }
258
- });
259
- }
260
- }),
261
- caption: api.fields.conditional(api.fields.checkbox({
262
- label: '显示图片描述'
263
- }), {
264
- false: api.fields.empty(),
265
- true: api.fields.child({
266
- kind: 'block',
267
- placeholder: '输入图片描述',
268
- formatting: 'inherit',
269
- links: 'inherit'
270
- })
271
- })
272
- },
273
- preview: function Image(props) {
274
- const imageUrl = props.fields.webImageUrl.value || props.fields.uploadedImageUrl.value || '/assets/images/placeholder.jpeg';
275
- return /*#__PURE__*/jsxRuntime.jsxs("div", {
276
- children: [/*#__PURE__*/jsxRuntime.jsx(api.NotEditable, {
277
- children: /*#__PURE__*/jsxRuntime.jsx("img", {
278
- src: imageUrl,
279
- className: style.css({
280
- display: 'block',
281
- width: '100%',
282
- minHeight: 10
283
- })
284
- })
285
- }), props.fields.caption.discriminant ? /*#__PURE__*/jsxRuntime.jsx("div", {
286
- className: style.css({
287
- textAlign: 'center',
288
- marginTop: 5
289
- }),
290
- children: props.fields.caption.value.element
291
- }) : null]
292
- });
293
- }
294
- });
295
-
296
- const componentBlocks = {
297
- quoteBlock,
298
- carousel,
299
- callout,
300
- Image
301
- };
302
-
303
- exports.NotEditable = api.NotEditable;
304
- exports.component = api.component;
305
- exports.fields = api.fields;
306
- exports.componentBlocks = componentBlocks;
1
+ "use strict";
2
+ // this file might look strange and you might be wondering what it's for
3
+ // it's lets you import your source files by importing this entrypoint
4
+ // as you would import it if it was built with preconstruct build
5
+ // this file is slightly different to some others though
6
+ // it has a require hook which compiles your code with Babel
7
+ // this means that you don't have to set up @babel/register or anything like that
8
+ // but you can still require this module and it'll be compiled
9
+
10
+ // this bit of code imports the require hook and registers it
11
+ let unregister = require("../../../../node_modules/.pnpm/@preconstruct+hook@0.4.0/node_modules/@preconstruct/hook").___internalHook(typeof __dirname === 'undefined' ? undefined : __dirname, "../../../..", "../..");
12
+
13
+ // this re-exports the source file
14
+ module.exports = require("../../src/component-blocks.tsx");
15
+
16
+ unregister();
@@ -1,306 +1,16 @@
1
- 'use client';
2
- 'use strict';
3
-
4
- Object.defineProperty(exports, '__esModule', { value: true });
5
-
6
- var api = require('../../dist/api-8e2b20b8.node.cjs.js');
7
- var jsxRuntime = require('react/jsx-runtime');
8
- var layout = require('@keystar/ui/layout');
9
- var style = require('@keystar/ui/style');
10
- var callout_ui = require('../../dist/callout-ui-ad50f301.node.cjs.js');
11
- require('lkb-core');
12
- require('@keystar/ui/button');
13
- require('@keystar/ui/drag-and-drop');
14
- require('react');
15
- require('../../dist/index-c3223fdc.node.cjs.js');
16
- require('slate');
17
- require('@braintree/sanitize-url');
18
- require('@react-aria/i18n');
19
- require('@keystar/ui/number-field');
20
- require('@keystar/ui/picker');
21
- require('@keystar/ui/combobox');
22
- require('@keystar/ui/text-field');
23
- require('@keystar/ui/tag');
24
- require('@keystar/ui/typography');
25
- require('@keystar/ui/checkbox');
26
-
27
- const quoteBlock = api.component({
28
- preview: props => {
29
- return /*#__PURE__*/jsxRuntime.jsxs("div", {
30
- style: {
31
- borderLeft: '3px solid #CBD5E0',
32
- paddingLeft: 16
33
- },
34
- children: [/*#__PURE__*/jsxRuntime.jsx("div", {
35
- style: {
36
- fontStyle: 'italic',
37
- color: '#4A5568'
38
- },
39
- children: props.fields.content.element
40
- }), /*#__PURE__*/jsxRuntime.jsxs("div", {
41
- style: {
42
- fontWeight: 'bold',
43
- color: '#718096'
44
- },
45
- children: [/*#__PURE__*/jsxRuntime.jsx(api.NotEditable, {
46
- children: "\u2014 "
47
- }), props.fields.attribution.element]
48
- })]
49
- });
50
- },
51
- label: '内容引用',
52
- schema: {
53
- content: api.fields.child({
54
- kind: 'block',
55
- placeholder: 'Quote...',
56
- formatting: {
57
- inlineMarks: 'inherit',
58
- softBreaks: 'inherit'
59
- },
60
- links: 'inherit'
61
- }),
62
- attribution: api.fields.child({
63
- kind: 'inline',
64
- placeholder: 'Attribution...'
65
- })
66
- },
67
- chromeless: true
68
- });
69
-
70
- const carousel = api.component({
71
- label: '旋转木马',
72
- preview: function Preview(props) {
73
- return /*#__PURE__*/jsxRuntime.jsx(api.NotEditable, {
74
- children: /*#__PURE__*/jsxRuntime.jsx("div", {
75
- className: style.css({
76
- overflowY: 'scroll',
77
- display: 'flex',
78
- scrollSnapType: 'y mandatory'
79
- }),
80
- children: props.fields.items.elements.map(item => {
81
- return /*#__PURE__*/jsxRuntime.jsxs(layout.Box, {
82
- margin: "xsmall",
83
- className: style.css({
84
- minWidth: '61.8%',
85
- scrollSnapAlign: 'center',
86
- scrollSnapStop: 'always',
87
- margin: 4,
88
- padding: 8,
89
- boxSizing: 'border-box',
90
- borderRadius: 6,
91
- background: '#eff3f6'
92
- }),
93
- children: [/*#__PURE__*/jsxRuntime.jsx("img", {
94
- role: "presentation",
95
- src: item.fields.imageSrc.value,
96
- className: style.css({
97
- objectFit: 'cover',
98
- objectPosition: 'center center',
99
- height: 240,
100
- width: '100%',
101
- borderRadius: 4
102
- })
103
- }), /*#__PURE__*/jsxRuntime.jsx("h1", {
104
- className: style.css({
105
- '&&': {
106
- fontSize: '1.25rem',
107
- lineHeight: 'unset',
108
- marginTop: 8
109
- }
110
- }),
111
- children: item.fields.title.value
112
- })]
113
- }, item.key);
114
- })
115
- })
116
- });
117
- },
118
- schema: {
119
- items: api.fields.array(api.fields.object({
120
- title: api.fields.text({
121
- label: '标题'
122
- }),
123
- imageSrc: api.fields.url({
124
- label: '图片 URL',
125
- defaultValue: '/assets/images/placeholder.jpeg'
126
- })
127
- }))
128
- }
129
- });
130
-
131
- const callout = api.component({
132
- preview: function (props) {
133
- return /*#__PURE__*/jsxRuntime.jsx(callout_ui.Callout, {
134
- tone: props.fields.tone.value,
135
- children: props.fields.content.element
136
- });
137
- },
138
- label: '提示面板',
139
- chromeless: true,
140
- schema: {
141
- tone: api.fields.select({
142
- label: 'Tone',
143
- options: [{
144
- value: 'info',
145
- label: '消息'
146
- }, {
147
- value: 'caution',
148
- label: '警告'
149
- }, {
150
- value: 'positive',
151
- label: '成功'
152
- }, {
153
- value: 'critical',
154
- label: '错误'
155
- }],
156
- defaultValue: 'info'
157
- }),
158
- content: api.fields.child({
159
- kind: 'block',
160
- placeholder: '',
161
- formatting: 'inherit',
162
- dividers: 'inherit',
163
- links: 'inherit'
164
- })
165
- },
166
- toolbar({
167
- props,
168
- onRemove
169
- }) {
170
- return /*#__PURE__*/jsxRuntime.jsx(callout_ui.CalloutToolbar, {
171
- onChange: tone => {
172
- props.fields.tone.onChange(tone);
173
- },
174
- onRemove: onRemove,
175
- tone: props.fields.tone.value,
176
- tones: props.fields.tone.schema.options
177
- });
178
- }
179
- });
180
-
181
- // 上传函数
182
- async function uploadImage(albumId, file, name, altText) {
183
- const operations = {
184
- variables: {
185
- data: {
186
- name,
187
- altText,
188
- image: {
189
- upload: null
190
- },
191
- album: {
192
- connect: {
193
- id: albumId
194
- }
195
- }
196
- }
197
- },
198
- query: `mutation ($data: ImageCreateInput!) {
199
- item: createImage(data: $data) {
200
- id
201
- name
202
- image { url }
203
- album { id name }
204
- __typename
205
- }
206
- }`
207
- };
208
- const map = {
209
- '1': ['variables.data.image.upload']
210
- };
211
-
212
- // useMutation
213
- const formData = new FormData();
214
- formData.append('operations', JSON.stringify(operations));
215
- formData.append('map', JSON.stringify(map));
216
- formData.append('1', file); // 这里的 '1' 对应 map 中的键
217
-
218
- try {
219
- const response = await fetch('/api/graphql', {
220
- method: 'POST',
221
- body: formData,
222
- headers: {
223
- 'x-apollo-operation-name': 'UploadImage',
224
- 'apollo-require-preflight': 'true'
225
- }
226
- // 注意:不要手动设置 Content-Type,浏览器会自动设置正确的 boundary
227
- });
228
- const result = await response.json();
229
- if (result.errors) {
230
- throw new Error(result.errors[0].message);
231
- }
232
- return result.data.item;
233
- } catch (error) {
234
- console.log('上传失败:', error);
235
- throw error;
236
- }
237
- }
238
-
239
- const Image = api.component({
240
- label: '图片',
241
- schema: {
242
- webImageUrl: api.fields.text({
243
- label: 'Web 图片地址'
244
- }),
245
- uploadedImageUrl: api.fields.file({
246
- label: '使用上传的图片',
247
- allowedFileTypes: ['image/png', 'image/jpg', 'image/jpeg', 'image/gif', 'image/webp'],
248
- isImage: true,
249
- onUpload(file) {
250
- // console.log(file)
251
- return new Promise((resolve, reject) => {
252
- // 使用固定的 albumId:cmhepys2l0000dd2m4cxaozc8,文档相关的临时图片都存放在这儿。
253
- try {
254
- uploadImage('cmhepys2l0000dd2m4cxaozc8', file, file.name).then(ret => resolve(ret.image.url)).catch(reject);
255
- } catch (e) {
256
- reject(e);
257
- }
258
- });
259
- }
260
- }),
261
- caption: api.fields.conditional(api.fields.checkbox({
262
- label: '显示图片描述'
263
- }), {
264
- false: api.fields.empty(),
265
- true: api.fields.child({
266
- kind: 'block',
267
- placeholder: '输入图片描述',
268
- formatting: 'inherit',
269
- links: 'inherit'
270
- })
271
- })
272
- },
273
- preview: function Image(props) {
274
- const imageUrl = props.fields.webImageUrl.value || props.fields.uploadedImageUrl.value || '/assets/images/placeholder.jpeg';
275
- return /*#__PURE__*/jsxRuntime.jsxs("div", {
276
- children: [/*#__PURE__*/jsxRuntime.jsx(api.NotEditable, {
277
- children: /*#__PURE__*/jsxRuntime.jsx("img", {
278
- src: imageUrl,
279
- className: style.css({
280
- display: 'block',
281
- width: '100%',
282
- minHeight: 10
283
- })
284
- })
285
- }), props.fields.caption.discriminant ? /*#__PURE__*/jsxRuntime.jsx("div", {
286
- className: style.css({
287
- textAlign: 'center',
288
- marginTop: 5
289
- }),
290
- children: props.fields.caption.value.element
291
- }) : null]
292
- });
293
- }
294
- });
295
-
296
- const componentBlocks = {
297
- quoteBlock,
298
- carousel,
299
- callout,
300
- Image
301
- };
302
-
303
- exports.NotEditable = api.NotEditable;
304
- exports.component = api.component;
305
- exports.fields = api.fields;
306
- exports.componentBlocks = componentBlocks;
1
+ "use strict";
2
+ // this file might look strange and you might be wondering what it's for
3
+ // it's lets you import your source files by importing this entrypoint
4
+ // as you would import it if it was built with preconstruct build
5
+ // this file is slightly different to some others though
6
+ // it has a require hook which compiles your code with Babel
7
+ // this means that you don't have to set up @babel/register or anything like that
8
+ // but you can still require this module and it'll be compiled
9
+
10
+ // this bit of code imports the require hook and registers it
11
+ let unregister = require("../../../../node_modules/.pnpm/@preconstruct+hook@0.4.0/node_modules/@preconstruct/hook").___internalHook(typeof __dirname === 'undefined' ? undefined : __dirname, "../../../..", "../..");
12
+
13
+ // this re-exports the source file
14
+ module.exports = require("../../src/component-blocks.tsx");
15
+
16
+ unregister();
@@ -1,2 +1,2 @@
1
- export * from "./declarations/src/index.js";
2
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGtiLWZpZWxkcy1kb2N1bWVudC5janMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4vZGVjbGFyYXRpb25zL3NyYy9pbmRleC5kLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBIn0=
1
+ export * from "../src/index.js";
2
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGtiLWZpZWxkcy1kb2N1bWVudC5janMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSJ9