@nocobase/plugin-snapshot-field 0.11.1-alpha.5 → 0.12.0-alpha.2

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 (106) hide show
  1. package/client.d.ts +2 -3
  2. package/client.js +1 -1
  3. package/dist/client/index.js +510 -0
  4. package/{lib → dist}/index.d.ts +1 -0
  5. package/dist/index.js +18 -0
  6. package/dist/locale/en-US.js +15 -0
  7. package/dist/locale/es-ES.js +15 -0
  8. package/dist/locale/fr-FR.js +15 -0
  9. package/dist/locale/ja-JP.js +5 -0
  10. package/dist/locale/pt-BR.js +15 -0
  11. package/dist/locale/ru-RU.js +5 -0
  12. package/dist/locale/tr-TR.js +5 -0
  13. package/dist/locale/zh-CN.js +17 -0
  14. package/dist/server/collections/collectionsHistory.js +59 -0
  15. package/dist/server/collections/fieldsHistory.js +77 -0
  16. package/dist/server/fields/snapshot-field.js +49 -0
  17. package/dist/server/index.js +11 -0
  18. package/dist/server/plugin.js +112 -0
  19. package/package.json +18 -27
  20. package/server.d.ts +2 -3
  21. package/server.js +1 -1
  22. package/lib/client/SnapshotBlock/SnapshotBlockInitializers/SnapshotBlockInitializers.js +0 -56
  23. package/lib/client/SnapshotBlock/SnapshotBlockInitializers/SnapshotBlockInitializersDetailItem.js +0 -157
  24. package/lib/client/SnapshotBlock/SnapshotBlockProvider.js +0 -126
  25. package/lib/client/SnapshotFieldProvider.js +0 -51
  26. package/lib/client/SnapshotHistoryCollectionProvider.js +0 -55
  27. package/lib/client/SnapshotRecordPicker.js +0 -60
  28. package/lib/client/components/SnapshotOwnerCollectionFieldsSelect.js +0 -57
  29. package/lib/client/index.js +0 -27
  30. package/lib/client/interface.js +0 -208
  31. package/lib/client/locale/index.js +0 -37
  32. package/lib/index.js +0 -13
  33. package/lib/locale/en-US.js +0 -18
  34. package/lib/locale/es-ES.js +0 -18
  35. package/lib/locale/fr-FR.js +0 -18
  36. package/lib/locale/ja-JP.js +0 -8
  37. package/lib/locale/pt-BR.js +0 -18
  38. package/lib/locale/ru-RU.js +0 -8
  39. package/lib/locale/tr-TR.js +0 -8
  40. package/lib/locale/zh-CN.js +0 -20
  41. package/lib/server/collections/collectionsHistory.js +0 -54
  42. package/lib/server/collections/fieldsHistory.js +0 -70
  43. package/lib/server/fields/snapshot-field.js +0 -72
  44. package/lib/server/index.js +0 -13
  45. package/lib/server/plugin.js +0 -171
  46. package/src/__tests__/data/field_linkto.ts +0 -12
  47. package/src/__tests__/data/field_m2m.ts +0 -15
  48. package/src/__tests__/data/field_o2m.ts +0 -14
  49. package/src/__tests__/data/field_o2o.ts +0 -14
  50. package/src/__tests__/data/snap_linkto.ts +0 -12
  51. package/src/__tests__/data/snap_m2m.ts +0 -12
  52. package/src/__tests__/data/snap_o2m.ts +0 -12
  53. package/src/__tests__/data/snap_o2o.ts +0 -13
  54. package/src/__tests__/data/table_a.ts +0 -37
  55. package/src/__tests__/data/table_b.ts +0 -37
  56. package/src/__tests__/data/table_m2m.ts +0 -37
  57. package/src/__tests__/fieldsHistory.test.ts +0 -62
  58. package/src/__tests__/snapshots.test.ts +0 -155
  59. package/src/client/SnapshotBlock/SnapshotBlockInitializers/SnapshotBlockInitializers.tsx +0 -44
  60. package/src/client/SnapshotBlock/SnapshotBlockInitializers/SnapshotBlockInitializersDetailItem.tsx +0 -121
  61. package/src/client/SnapshotBlock/SnapshotBlockProvider.tsx +0 -105
  62. package/src/client/SnapshotFieldProvider.tsx +0 -48
  63. package/src/client/SnapshotHistoryCollectionProvider.tsx +0 -42
  64. package/src/client/SnapshotRecordPicker.tsx +0 -33
  65. package/src/client/components/SnapshotOwnerCollectionFieldsSelect.tsx +0 -22
  66. package/src/client/index.tsx +0 -10
  67. package/src/client/interface.ts +0 -185
  68. package/src/client/locale/index.ts +0 -18
  69. package/src/index.ts +0 -1
  70. package/src/locale/en-US.ts +0 -12
  71. package/src/locale/es-ES.ts +0 -11
  72. package/src/locale/fr-FR.ts +0 -12
  73. package/src/locale/ja-JP.ts +0 -1
  74. package/src/locale/pt-BR.ts +0 -13
  75. package/src/locale/ru-RU.ts +0 -1
  76. package/src/locale/tr-TR.ts +0 -1
  77. package/src/locale/zh-CN.ts +0 -14
  78. package/src/server/collections/.gitkeep +0 -0
  79. package/src/server/collections/collectionsHistory.ts +0 -57
  80. package/src/server/collections/fieldsHistory.ts +0 -75
  81. package/src/server/fields/snapshot-field.ts +0 -60
  82. package/src/server/index.ts +0 -1
  83. package/src/server/plugin.ts +0 -124
  84. /package/{lib → dist}/client/SnapshotBlock/SnapshotBlockInitializers/SnapshotBlockInitializers.d.ts +0 -0
  85. /package/{lib → dist}/client/SnapshotBlock/SnapshotBlockInitializers/SnapshotBlockInitializersDetailItem.d.ts +0 -0
  86. /package/{lib → dist}/client/SnapshotBlock/SnapshotBlockProvider.d.ts +0 -0
  87. /package/{lib → dist}/client/SnapshotFieldProvider.d.ts +0 -0
  88. /package/{lib → dist}/client/SnapshotHistoryCollectionProvider.d.ts +0 -0
  89. /package/{lib → dist}/client/SnapshotRecordPicker.d.ts +0 -0
  90. /package/{lib → dist}/client/components/SnapshotOwnerCollectionFieldsSelect.d.ts +0 -0
  91. /package/{lib → dist}/client/index.d.ts +0 -0
  92. /package/{lib → dist}/client/interface.d.ts +0 -0
  93. /package/{lib → dist}/client/locale/index.d.ts +0 -0
  94. /package/{lib → dist}/locale/en-US.d.ts +0 -0
  95. /package/{lib → dist}/locale/es-ES.d.ts +0 -0
  96. /package/{lib → dist}/locale/fr-FR.d.ts +0 -0
  97. /package/{lib → dist}/locale/ja-JP.d.ts +0 -0
  98. /package/{lib → dist}/locale/pt-BR.d.ts +0 -0
  99. /package/{lib → dist}/locale/ru-RU.d.ts +0 -0
  100. /package/{lib → dist}/locale/tr-TR.d.ts +0 -0
  101. /package/{lib → dist}/locale/zh-CN.d.ts +0 -0
  102. /package/{lib → dist}/server/collections/collectionsHistory.d.ts +0 -0
  103. /package/{lib → dist}/server/collections/fieldsHistory.d.ts +0 -0
  104. /package/{lib → dist}/server/fields/snapshot-field.d.ts +0 -0
  105. /package/{lib → dist}/server/index.d.ts +0 -0
  106. /package/{lib → dist}/server/plugin.d.ts +0 -0
package/client.d.ts CHANGED
@@ -1,3 +1,2 @@
1
- export * from './src/client';
2
- export { default } from './src/client';
3
-
1
+ export * from './dist/client';
2
+ export { default } from './dist/client';
package/client.js CHANGED
@@ -1 +1 @@
1
- module.exports = require('./lib/client/index.js');
1
+ module.exports = require('./dist/client/index.js');
@@ -0,0 +1,510 @@
1
+ (function(global, factory) {
2
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("@nocobase/client"), require("react"), require("antd"), require("@formily/react"), require("lodash"), require("react-i18next"), require("@ant-design/icons"), require("@formily/shared"), require("@formily/core")) : typeof define === "function" && define.amd ? define(["exports", "@nocobase/client", "react", "antd", "@formily/react", "lodash", "react-i18next", "@ant-design/icons", "@formily/shared", "@formily/core"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["@nocobase/plugin-snapshot-field"] = {}, global["@nocobase/client"], global.react, global.antd, global["@formily/react"], global.lodash, global["react-i18next"], global["@ant-design/icons"], global["@formily/shared"], global["@formily/core"]));
3
+ })(this, function(exports2, client, require$$0, antd, react, lodash, reactI18next, icons, shared, core) {
4
+ "use strict";
5
+ var jsxRuntime = { exports: {} };
6
+ var reactJsxRuntime_production_min = {};
7
+ /**
8
+ * @license React
9
+ * react-jsx-runtime.production.min.js
10
+ *
11
+ * Copyright (c) Facebook, Inc. and its affiliates.
12
+ *
13
+ * This source code is licensed under the MIT license found in the
14
+ * LICENSE file in the root directory of this source tree.
15
+ */
16
+ var f = require$$0, k = Symbol.for("react.element"), l = Symbol.for("react.fragment"), m = Object.prototype.hasOwnProperty, n = f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, p = { key: true, ref: true, __self: true, __source: true };
17
+ function q(c, a, g) {
18
+ var b, d = {}, e = null, h = null;
19
+ void 0 !== g && (e = "" + g);
20
+ void 0 !== a.key && (e = "" + a.key);
21
+ void 0 !== a.ref && (h = a.ref);
22
+ for (b in a)
23
+ m.call(a, b) && !p.hasOwnProperty(b) && (d[b] = a[b]);
24
+ if (c && c.defaultProps)
25
+ for (b in a = c.defaultProps, a)
26
+ void 0 === d[b] && (d[b] = a[b]);
27
+ return { $$typeof: k, type: c, key: e, ref: h, props: d, _owner: n.current };
28
+ }
29
+ reactJsxRuntime_production_min.Fragment = l;
30
+ reactJsxRuntime_production_min.jsx = q;
31
+ reactJsxRuntime_production_min.jsxs = q;
32
+ {
33
+ jsxRuntime.exports = reactJsxRuntime_production_min;
34
+ }
35
+ var jsxRuntimeExports = jsxRuntime.exports;
36
+ const NAMESPACE = "snapshot-field";
37
+ function useSnapshotTranslation() {
38
+ return reactI18next.useTranslation(NAMESPACE);
39
+ }
40
+ const { defaultProps } = client.interfacesProperties;
41
+ const APPENDS = "appends";
42
+ const TARGET_FIELD = "targetField";
43
+ const useTopRecord = () => {
44
+ let record = client.useRecord();
45
+ while (record && Object.keys(record.__parent).length > 0) {
46
+ record = record.__parent;
47
+ }
48
+ return record;
49
+ };
50
+ function useRecordCollection() {
51
+ var _a;
52
+ const { getCollectionField } = client.useCollectionManager();
53
+ const record = useTopRecord();
54
+ const formValues = react.useForm().values;
55
+ return (_a = getCollectionField(`${record.name}.${formValues.targetField}`)) == null ? void 0 : _a.target;
56
+ }
57
+ function MakeFieldsPathOptions(fields, appends = []) {
58
+ const { getCollection } = client.useCollectionManager();
59
+ const options = [];
60
+ fields.forEach((field) => {
61
+ var _a, _b;
62
+ if (["belongsTo", "hasOne", "hasMany", "belongsToMany"].includes(field.type)) {
63
+ const currentAppends = appends.filter((key) => `${key}.`.startsWith(`${field.name}.`));
64
+ if (currentAppends.length) {
65
+ const nextCollection = getCollection(field.target);
66
+ const nextAppends = currentAppends.filter((key) => key !== field.name).map((key) => key.replace(`${field.name}.`, "")).filter((key) => key);
67
+ options.push({
68
+ label: ((_a = field.uiSchema) == null ? void 0 : _a.title) ?? field.name,
69
+ value: field.name,
70
+ children: MakeFieldsPathOptions(nextCollection.fields, nextAppends)
71
+ });
72
+ }
73
+ } else {
74
+ options.push({
75
+ label: ((_b = field.uiSchema) == null ? void 0 : _b.title) ?? field.name,
76
+ value: field.name
77
+ });
78
+ }
79
+ });
80
+ return options;
81
+ }
82
+ const recordPickerViewer = {
83
+ type: "void",
84
+ title: `{{t('View record')}}`,
85
+ "x-component": "RecordPicker.Viewer",
86
+ "x-component-props": {
87
+ className: "nb-action-popup"
88
+ },
89
+ properties: {
90
+ tabs: {
91
+ type: "void",
92
+ "x-component": "Tabs",
93
+ "x-component-props": {},
94
+ // 'x-initializer': 'TabPaneInitializers',
95
+ properties: {
96
+ tab1: {
97
+ type: "void",
98
+ title: `{{t('Detail')}}`,
99
+ "x-component": "Tabs.TabPane",
100
+ "x-designer": "Tabs.Designer",
101
+ "x-component-props": {},
102
+ properties: {
103
+ grid: {
104
+ type: "void",
105
+ "x-component": "Grid",
106
+ "x-initializer": "SnapshotBlockInitializers",
107
+ properties: {}
108
+ }
109
+ }
110
+ }
111
+ }
112
+ }
113
+ }
114
+ };
115
+ const snapshot = {
116
+ name: "snapshot",
117
+ type: "object",
118
+ group: "advanced",
119
+ title: `{{t('Snapshot', {ns: '${NAMESPACE}'})}}`,
120
+ description: `{{t('When adding a new record, create a snapshot for its relational record and save in the current record. The snapshot is not updated when the record is subsequently updated.', {ns: '${NAMESPACE}'})}}`,
121
+ default: {
122
+ type: "snapshot",
123
+ // name,
124
+ uiSchema: {
125
+ // title,
126
+ "x-component": "SnapshotRecordPicker",
127
+ "x-component-props": {
128
+ multiple: true,
129
+ fieldNames: {
130
+ label: "id",
131
+ value: "id"
132
+ }
133
+ }
134
+ }
135
+ },
136
+ schemaInitialize(schema, { field, readPretty, action, block }) {
137
+ schema["properties"] = {
138
+ viewer: lodash.cloneDeep(recordPickerViewer)
139
+ };
140
+ },
141
+ initialize: (values) => {
142
+ },
143
+ usePathOptions(field) {
144
+ const { appends = [], targetCollection } = field;
145
+ const { getCollection } = client.useCollectionManager();
146
+ const { fields } = getCollection(targetCollection);
147
+ const result = MakeFieldsPathOptions(fields, appends);
148
+ return [
149
+ {
150
+ label: `{{t('Snapshot data', { ns: '${NAMESPACE}' })}}`,
151
+ value: "data",
152
+ children: result
153
+ }
154
+ ];
155
+ },
156
+ properties: {
157
+ ...defaultProps,
158
+ [TARGET_FIELD]: {
159
+ type: "string",
160
+ title: `{{t('The association field to snapshot', {ns: '${NAMESPACE}'})}}`,
161
+ required: true,
162
+ "x-decorator": "FormItem",
163
+ "x-component": "SnapshotOwnerCollectionFieldsSelect",
164
+ "x-disabled": "{{ !createOnly || isOverride }}",
165
+ "x-reactions": [
166
+ {
167
+ target: APPENDS,
168
+ when: "{{$self.value != undefined}}",
169
+ fulfill: {
170
+ state: {
171
+ visible: true
172
+ }
173
+ },
174
+ otherwise: {
175
+ state: {
176
+ visible: false
177
+ }
178
+ }
179
+ }
180
+ ]
181
+ },
182
+ [APPENDS]: {
183
+ type: "string",
184
+ title: `{{t("Snapshot the snapshot's association fields", {ns: "${NAMESPACE}"})}}`,
185
+ "x-decorator": "FormItem",
186
+ "x-component": "AppendsTreeSelect",
187
+ "x-component-props": {
188
+ useCollection: useRecordCollection
189
+ },
190
+ "x-reactions": [
191
+ {
192
+ dependencies: [TARGET_FIELD],
193
+ when: "{{$deps[0]}}",
194
+ fulfill: {
195
+ run: "{{$self.setValue($self.value)}}"
196
+ }
197
+ }
198
+ ]
199
+ }
200
+ }
201
+ };
202
+ const useSnapshotOwnerCollectionFields = () => {
203
+ const record = useTopRecord();
204
+ const { getCollection } = client.useCollectionManager();
205
+ const collection = getCollection(record.name);
206
+ const compile = client.useCompile();
207
+ return collection.fields.filter((i) => !!i.target && !!i.interface).map((i) => {
208
+ var _a;
209
+ return { ...i, label: compile((_a = i.uiSchema) == null ? void 0 : _a.title), value: i.name };
210
+ });
211
+ };
212
+ const SnapshotOwnerCollectionFieldsSelect = (props) => {
213
+ const options = useSnapshotOwnerCollectionFields();
214
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(antd.Select, { popupMatchSelectWidth: false, options, ...props });
215
+ };
216
+ const SnapshotBlockInitializers = (props) => {
217
+ const { t } = useSnapshotTranslation();
218
+ const { insertPosition, component } = props;
219
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(
220
+ client.SchemaInitializer.Button,
221
+ {
222
+ wrap: client.gridRowColWrap,
223
+ insertPosition,
224
+ component,
225
+ title: component ? null : t("Add block"),
226
+ icon: "PlusOutlined",
227
+ items: [
228
+ {
229
+ type: "itemGroup",
230
+ title: '{{t("Current record blocks")}}',
231
+ children: [
232
+ {
233
+ key: "details",
234
+ type: "item",
235
+ title: '{{t("Details")}}',
236
+ component: "SnapshotBlockInitializersDetailItem",
237
+ actionInitializers: "CalendarFormActionInitializers"
238
+ }
239
+ ]
240
+ },
241
+ {
242
+ type: "itemGroup",
243
+ title: '{{t("Other blocks")}}',
244
+ children: [
245
+ {
246
+ key: "markdown",
247
+ type: "item",
248
+ title: '{{t("Markdown")}}',
249
+ component: "MarkdownBlockInitializer"
250
+ }
251
+ ]
252
+ }
253
+ ]
254
+ }
255
+ );
256
+ };
257
+ const createSnapshotBlockSchema = (options) => {
258
+ const {
259
+ formItemInitializers = "ReadPrettyFormItemInitializers",
260
+ actionInitializers = "ReadPrettyFormActionInitializers",
261
+ collection,
262
+ association,
263
+ resource,
264
+ template,
265
+ ...others
266
+ } = options;
267
+ const resourceName = resource || association || collection;
268
+ const schema = {
269
+ type: "void",
270
+ "x-acl-action": `${resourceName}:get`,
271
+ "x-decorator": "SnapshotBlockProvider",
272
+ "x-decorator-props": {
273
+ resource: resourceName,
274
+ collection,
275
+ association,
276
+ readPretty: true,
277
+ action: "get",
278
+ useParams: "{{ useParamsFromRecord }}",
279
+ ...others
280
+ },
281
+ "x-designer": "FormV2.ReadPrettyDesigner",
282
+ "x-component": "CardItem",
283
+ properties: {
284
+ [shared.uid()]: {
285
+ type: "void",
286
+ "x-component": "FormV2",
287
+ "x-read-pretty": true,
288
+ "x-component-props": {
289
+ useProps: "{{ useFormBlockProps }}"
290
+ },
291
+ properties: {
292
+ grid: template || {
293
+ type: "void",
294
+ "x-component": "Grid",
295
+ "x-initializer": formItemInitializers,
296
+ properties: {}
297
+ }
298
+ }
299
+ }
300
+ }
301
+ };
302
+ console.log(JSON.stringify(schema, null, 2));
303
+ return schema;
304
+ };
305
+ const SnapshotBlockInitializersDetailItem = (props) => {
306
+ const {
307
+ onCreateBlockSchema,
308
+ componentType,
309
+ createBlockSchema,
310
+ insert,
311
+ icon = true,
312
+ targetCollection,
313
+ ...others
314
+ } = props;
315
+ const { getTemplateSchemaByMode } = client.useSchemaTemplateManager();
316
+ const collection = targetCollection || client.useCollection();
317
+ const association = client.useBlockAssociationContext();
318
+ const { block } = client.useBlockRequestContext();
319
+ const actionInitializers = block !== "TableField" ? props.actionInitializers || "ReadPrettyFormActionInitializers" : null;
320
+ return /* @__PURE__ */ require$$0.createElement(
321
+ client.SchemaInitializer.Item,
322
+ {
323
+ icon: icon && /* @__PURE__ */ jsxRuntimeExports.jsx(icons.FormOutlined, {}),
324
+ ...others,
325
+ key: "snapshotDetail",
326
+ onClick: async ({ item }) => {
327
+ if (item.template) {
328
+ const s = await getTemplateSchemaByMode(item);
329
+ if (item.template.componentName === "ReadPrettyFormItem") {
330
+ const blockSchema = createSnapshotBlockSchema({
331
+ actionInitializers,
332
+ association,
333
+ collection: collection.name,
334
+ action: "get",
335
+ useSourceId: "{{ useSourceIdFromParentRecord }}",
336
+ useParams: "{{ useParamsFromRecord }}",
337
+ template: s
338
+ });
339
+ if (item.mode === "reference") {
340
+ blockSchema["x-template-key"] = item.template.key;
341
+ }
342
+ insert(blockSchema);
343
+ } else {
344
+ insert(s);
345
+ }
346
+ } else {
347
+ insert(
348
+ createSnapshotBlockSchema({
349
+ actionInitializers,
350
+ association,
351
+ collection: collection.name,
352
+ action: "get",
353
+ useSourceId: "{{ useSourceIdFromParentRecord }}",
354
+ useParams: "{{ useParamsFromRecord }}"
355
+ })
356
+ );
357
+ }
358
+ },
359
+ items: client.useRecordCollectionDataSourceItems("ReadPrettyFormItem")
360
+ }
361
+ );
362
+ };
363
+ const InternalFormBlockProvider = (props) => {
364
+ var _a;
365
+ const { action, readPretty } = props;
366
+ const field = react.useField();
367
+ const form = require$$0.useMemo(
368
+ () => core.createForm({
369
+ readPretty
370
+ }),
371
+ []
372
+ );
373
+ const { resource, service } = client.useBlockRequestContext();
374
+ const formBlockRef = require$$0.useRef();
375
+ if (service.loading) {
376
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(antd.Spin, {});
377
+ }
378
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(
379
+ client.FormBlockContext.Provider,
380
+ {
381
+ value: {
382
+ action,
383
+ form,
384
+ field,
385
+ service,
386
+ resource,
387
+ updateAssociationValues: [],
388
+ formBlockRef
389
+ },
390
+ children: readPretty ? /* @__PURE__ */ jsxRuntimeExports.jsx(client.RecordProvider, { record: (_a = service == null ? void 0 : service.data) == null ? void 0 : _a.data, children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { ref: formBlockRef, children: props.children }) }) : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { ref: formBlockRef, children: props.children })
391
+ }
392
+ );
393
+ };
394
+ const BlockRequestProvider = (props) => {
395
+ const field = react.useField();
396
+ const resource = client.useBlockResource();
397
+ const service = {
398
+ loading: false,
399
+ data: {
400
+ data: client.useRecord()
401
+ }
402
+ };
403
+ const __parent = require$$0.useContext(client.BlockRequestContext);
404
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(client.BlockRequestContext.Provider, { value: { block: props.block, props, field, service, resource, __parent }, children: props.children });
405
+ };
406
+ const BlockProvider = (props) => {
407
+ const { collection, association } = props;
408
+ const resource = client.useResource(props);
409
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(client.MaybeCollectionProvider, { collection, children: /* @__PURE__ */ jsxRuntimeExports.jsx(client.BlockAssociationContext.Provider, { value: association, children: /* @__PURE__ */ jsxRuntimeExports.jsx(client.BlockResourceContext.Provider, { value: resource, children: /* @__PURE__ */ jsxRuntimeExports.jsx(BlockRequestProvider, { ...props, children: props.children }) }) }) });
410
+ };
411
+ const SnapshotBlockProvider = (props) => {
412
+ const record = client.useRecord();
413
+ const { __tableName } = record;
414
+ const { getInheritCollections } = client.useCollectionManager();
415
+ const inheritCollections = getInheritCollections(__tableName);
416
+ const { designable } = client.useDesignable();
417
+ const flag = !designable && __tableName && !inheritCollections.includes(props.collection) && __tableName !== props.collection;
418
+ return !flag && /* @__PURE__ */ jsxRuntimeExports.jsx(BlockProvider, { ...props, children: /* @__PURE__ */ jsxRuntimeExports.jsx(InternalFormBlockProvider, { ...props }) });
419
+ };
420
+ const SnapshotHistoryCollectionProvider = (props) => {
421
+ var _a;
422
+ const { collectionName } = props;
423
+ const { collections: allCollections, ...rest } = require$$0.useContext(client.CollectionManagerContext);
424
+ const snapshotTargetCollection = (_a = client.useHistoryCollectionsByNames([collectionName])) == null ? void 0 : _a[0];
425
+ const inheritCollections = client.useHistoryCollectionsByNames((snapshotTargetCollection == null ? void 0 : snapshotTargetCollection.inherits) ?? []);
426
+ const associationFieldTargetCollections = client.useHistoryCollectionsByNames(
427
+ (snapshotTargetCollection == null ? void 0 : snapshotTargetCollection.fields.filter((i) => i.interface !== "snapshot").map((i) => i.target)) ?? []
428
+ );
429
+ const finallyHistoryCollecionts = [
430
+ snapshotTargetCollection,
431
+ ...associationFieldTargetCollections,
432
+ ...inheritCollections
433
+ ].filter((i) => i);
434
+ const filterdAllCollection = allCollections.filter(
435
+ (c) => !finallyHistoryCollecionts.map((i) => i.name).includes(c.name)
436
+ );
437
+ const overridedCollections = [...filterdAllCollection, ...finallyHistoryCollecionts];
438
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(
439
+ client.CollectionManagerContext.Provider,
440
+ {
441
+ value: {
442
+ ...rest,
443
+ collections: overridedCollections
444
+ },
445
+ children: props.children
446
+ }
447
+ );
448
+ };
449
+ const ReadPrettyRecordPickerWrapper = (props) => {
450
+ const fieldSchema = react.useFieldSchema();
451
+ const { getField } = client.useCollection();
452
+ const collectionField = getField(fieldSchema.name);
453
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(SnapshotHistoryCollectionProvider, { collectionName: collectionField == null ? void 0 : collectionField.targetCollection, children: /* @__PURE__ */ jsxRuntimeExports.jsx(client.ReadPrettyRecordPicker, { ...props }) });
454
+ };
455
+ const SnapshotRecordPickerInner = react.connect(
456
+ ReadPrettyRecordPickerWrapper,
457
+ react.mapReadPretty(ReadPrettyRecordPickerWrapper)
458
+ );
459
+ const SnapshotRecordPicker = (props) => {
460
+ const { value, onChange, ...restProps } = props;
461
+ const newProps = {
462
+ ...restProps,
463
+ value: value == null ? void 0 : value.data,
464
+ onChange: (value2) => onChange({ data: value2 })
465
+ };
466
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(SnapshotRecordPickerInner, { ...newProps });
467
+ };
468
+ const SnapshotFieldProvider = require$$0.memo((props) => {
469
+ require$$0.useEffect(() => {
470
+ client.registerField(snapshot.group, snapshot.name, snapshot);
471
+ }, []);
472
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(
473
+ client.CollectionManagerProvider,
474
+ {
475
+ interfaces: {
476
+ snapshot
477
+ },
478
+ children: /* @__PURE__ */ jsxRuntimeExports.jsx(client.CollectionHistoryProvider, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(
479
+ client.SchemaInitializerProvider,
480
+ {
481
+ initializers: {
482
+ SnapshotBlockInitializers
483
+ },
484
+ children: /* @__PURE__ */ jsxRuntimeExports.jsx(
485
+ client.SchemaComponentOptions,
486
+ {
487
+ components: {
488
+ SnapshotRecordPicker,
489
+ SnapshotBlockProvider,
490
+ SnapshotBlockInitializersDetailItem,
491
+ SnapshotOwnerCollectionFieldsSelect
492
+ },
493
+ children: props.children
494
+ }
495
+ )
496
+ }
497
+ ) })
498
+ }
499
+ );
500
+ });
501
+ SnapshotFieldProvider.displayName = "SnapshotFieldProvider";
502
+ class SnapshotFieldPlugin extends client.Plugin {
503
+ async load() {
504
+ this.app.use(SnapshotFieldProvider);
505
+ }
506
+ }
507
+ exports2.SnapshotFieldPlugin = SnapshotFieldPlugin;
508
+ exports2.default = SnapshotFieldPlugin;
509
+ Object.defineProperties(exports2, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
510
+ });
@@ -1 +1,2 @@
1
+ export * from './server';
1
2
  export { default } from './server';
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var server = require('./server');
6
+
7
+
8
+
9
+ Object.defineProperty(exports, 'default', {
10
+ enumerable: true,
11
+ get: function () { return server__namespace.default; }
12
+ });
13
+ Object.keys(server).forEach(function (k) {
14
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
15
+ enumerable: true,
16
+ get: function () { return server[k]; }
17
+ });
18
+ });
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ var en_US_default = {
4
+ Detail: "Detail",
5
+ Snapshot: "Snapshot",
6
+ "View record": "View record",
7
+ "Add block": "Add block",
8
+ "Allow linking to multiple records": "Allow linking to multiple records",
9
+ "When adding a new record, create a snapshot for its relational record and save in the current record. The snapshot is not updated when the record is subsequently updated.": "When adding a new record, create a snapshot for its relational record and save in the current record. The snapshot is not updated when the record is subsequently updated.",
10
+ "The association field to snapshot": "The association field to snapshot",
11
+ "Snapshot the snapshot's association fields": "Snapshot the snapshot's association fields",
12
+ "Please select": "Please select"
13
+ };
14
+
15
+ module.exports = en_US_default;
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ var es_ES_default = {
4
+ "Detail": "Detalle",
5
+ "Snapshot": "Snapshot",
6
+ "View record": "Ver registro",
7
+ "Add block": "A\xF1adir bloque",
8
+ "Allow linking to multiple records": "Permitir enlace a m\xFAltiples registros",
9
+ "When adding a new record, create a snapshot for its relational record and save in the current record. The snapshot is not updated when the record is subsequently updated.": "Al a\xF1adir un nuevo registro, crear una snapshot para su registro relacional y guardar en el registro actual. La snapshot no se actualiza cuando el registro se actualiza posteriormente.",
10
+ "The association field to snapshot": "El campo de asociaci\xF3n a la snapshot",
11
+ "Snapshot the snapshot's association fields": "Snapshot los campos de asociaci\xF3n de la snapshot",
12
+ "Please select": "Por favor, seleccione"
13
+ };
14
+
15
+ module.exports = es_ES_default;
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ var fr_FR_default = {
4
+ Detail: "D\xE9tail",
5
+ Snapshot: "Snapshot",
6
+ "View record": "Voir l'enregistrement",
7
+ "Add block": "Ajouter un bloc",
8
+ "Allow linking to multiple records": "Autoriser la liaison \xE0 plusieurs enregistrements",
9
+ "When adding a new record, create a snapshot for its relational record and save in the current record. The snapshot is not updated when the record is subsequently updated.": "Lors de l'ajout d'un nouvel enregistrement, cr\xE9ez un snapshot pour son enregistrement relationnel et enregistrez-le dans l'enregistrement actuel. Le snapshot n'est pas mis \xE0 jour lorsque l'enregistrement est ult\xE9rieurement modifi\xE9.",
10
+ "The association field to snapshot": "Le champ d'association \xE0 un snapshot",
11
+ "Snapshot the snapshot's association fields": "Snapshot des champs d'association du snapshot",
12
+ "Please select": "Veuillez s\xE9lectionner"
13
+ };
14
+
15
+ module.exports = fr_FR_default;
@@ -0,0 +1,5 @@
1
+ 'use strict';
2
+
3
+ var ja_JP_default = {};
4
+
5
+ module.exports = ja_JP_default;
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ var pt_BR_default = {
4
+ Detail: "Detalhes",
5
+ Snapshot: "Fotografia",
6
+ "View record": "Visualizar registro",
7
+ "Add block": "Adicionar bloco",
8
+ "Allow linking to multiple records": "Permitir vincula\xE7\xE3o a v\xE1rios registros",
9
+ "When adding a new record, create a snapshot for its relational record and save in the current record. The snapshot is not updated when the record is subsequently updated.": "Ao adicionar um novo registro, crie uma imagem instant\xE2nea para o registro relacionado e salve no registro atual. A imagem instant\xE2nea n\xE3o \xE9 atualizada quando o registro \xE9 posteriormente atualizado.",
10
+ "The association field to snapshot": "O campo de associa\xE7\xE3o para criar imagem instant\xE2nea",
11
+ "Snapshot the snapshot's association fields": "Criar imagem instant\xE2nea para os campos de associa\xE7\xE3o da imagem instant\xE2nea",
12
+ "Please select": "Por favor, selecione"
13
+ };
14
+
15
+ module.exports = pt_BR_default;
@@ -0,0 +1,5 @@
1
+ 'use strict';
2
+
3
+ var ru_RU_default = {};
4
+
5
+ module.exports = ru_RU_default;
@@ -0,0 +1,5 @@
1
+ 'use strict';
2
+
3
+ var tr_TR_default = {};
4
+
5
+ module.exports = tr_TR_default;
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ var zh_CN_default = {
4
+ Detail: "\u8BE6\u60C5",
5
+ Snapshot: "\u5FEB\u7167",
6
+ "Add block": "\u521B\u5EFA\u533A\u5757",
7
+ "When adding a new record, create a snapshot for its relational record and save in the current record. The snapshot is not updated when the record is subsequently updated.": "\u5728\u6DFB\u52A0\u6570\u636E\u65F6\uFF0C\u4E3A\u5B83\u7684\u5173\u7CFB\u6570\u636E\u521B\u5EFA\u5FEB\u7167\uFF0C\u5E76\u4FDD\u5B58\u5728\u5F53\u524D\u7684\u6570\u636E\u4E2D\u3002\u540E\u7EED\u66F4\u65B0\u6570\u636E\u65F6\uFF0C\u5FEB\u7167\u4E0D\u518D\u66F4\u65B0\u3002",
8
+ "View record": "\u67E5\u770B\u6570\u636E",
9
+ "Allow linking to multiple records": "\u5141\u8BB8\u5173\u8054\u591A\u6761\u8BB0\u5F55",
10
+ "The association field to snapshot": "\u5FEB\u7167\u76EE\u6807\u5173\u7CFB\u5B57\u6BB5",
11
+ "Snapshot the snapshot's association fields": "\u4E3A\u5FEB\u7167\u7684\u5173\u7CFB\u6570\u636E\u521B\u5EFA\u5FEB\u7167",
12
+ "Please select": "\u8BF7\u9009\u62E9",
13
+ "When a record is created, association data is backed up in a snapshot": "\u521B\u5EFA\u8BB0\u5F55\u65F6\uFF0C\u5173\u7CFB\u6570\u636E\u4F1A\u5907\u4EFD\u5230\u5FEB\u7167\u91CC",
14
+ "Snapshot data": "\u5FEB\u7167\u6570\u636E"
15
+ };
16
+
17
+ module.exports = zh_CN_default;