@nocobase/plugin-snapshot-field 0.19.0-alpha.9 → 0.20.0-alpha.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.
@@ -1,5 +1,13 @@
1
1
  import { SelectProps } from 'antd';
2
2
  import React from 'react';
3
3
  export type SnapshotOwnerCollectionFieldsSelectProps = Omit<SelectProps, 'options'>;
4
- export declare const useSnapshotOwnerCollectionFields: () => any[];
4
+ export declare const useSnapshotOwnerCollectionFields: () => {
5
+ label: any;
6
+ value: any;
7
+ name?: any;
8
+ collectionName?: string;
9
+ sourceKey?: string;
10
+ uiSchema?: any;
11
+ target?: string;
12
+ }[];
5
13
  export declare const SnapshotOwnerCollectionFieldsSelect: React.FC<SnapshotOwnerCollectionFieldsSelectProps>;
@@ -1 +1 @@
1
- (function(n,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("@nocobase/client"),require("react/jsx-runtime"),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/jsx-runtime","react","antd","@formily/react","lodash","react-i18next","@ant-design/icons","@formily/shared","@formily/core"],e):(n=typeof globalThis!="undefined"?globalThis:n||self,e(n["@nocobase/plugin-snapshot-field"]={},n["@nocobase/client"],n.jsxRuntime,n.react,n.antd,n["@formily/react"],n.lodash,n["react-i18next"],n["@ant-design/icons"],n["@formily/shared"],n["@formily/core"]))})(this,function(n,e,r,l,v,P,M,b,C,I,W){"use strict";var ae=Object.defineProperty,ce=Object.defineProperties;var le=Object.getOwnPropertyDescriptors;var w=Object.getOwnPropertySymbols;var H=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable;var V=(n,e,r)=>e in n?ae(n,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):n[e]=r,m=(n,e)=>{for(var r in e||(e={}))H.call(e,r)&&V(n,r,e[r]);if(w)for(var r of w(e))G.call(e,r)&&V(n,r,e[r]);return n},x=(n,e)=>ce(n,le(e));var B=(n,e)=>{var r={};for(var l in n)H.call(n,l)&&e.indexOf(l)<0&&(r[l]=n[l]);if(n!=null&&w)for(var l of w(n))e.indexOf(l)<0&&G.call(n,l)&&(r[l]=n[l]);return r};var T=(n,e,r)=>new Promise((l,v)=>{var P=C=>{try{b(r.next(C))}catch(I){v(I)}},M=C=>{try{b(r.throw(C))}catch(I){v(I)}},b=C=>C.done?l(C.value):Promise.resolve(C.value).then(P,M);b((r=r.apply(n,e)).next())});const S="snapshot-field",{defaultProps:L}=e.interfacesProperties,q="appends",A="targetField",$=()=>{let o=e.useRecord();for(;o&&Object.keys(o.__parent).length>0;)o=o.__parent;return o};function J(){var s;const{getCollectionField:o}=e.useCollectionManager(),i=$(),a=P.useForm().values;return(s=o(`${i.name}.${a.targetField}`))==null?void 0:s.target}function R(o,i=[]){const{getCollection:a}=e.useCollectionManager(),s=[];return o.forEach(t=>{var c,d,u,f;if(["belongsTo","hasOne","hasMany","belongsToMany"].includes(t.type)){const g=i.filter(h=>`${h}.`.startsWith(`${t.name}.`));if(g.length){const h=a(t.target),k=g.filter(y=>y!==t.name).map(y=>y.replace(`${t.name}.`,"")).filter(y=>y);s.push({label:(d=(c=t.uiSchema)==null?void 0:c.title)!=null?d:t.name,value:t.name,children:R(h.fields,k)})}}else s.push({label:(f=(u=t.uiSchema)==null?void 0:u.title)!=null?f:t.name,value:t.name})}),s}const K={type:"void",title:"{{t('View record')}}","x-component":"RecordPicker.Viewer","x-component-props":{className:"nb-action-popup"},properties:{tabs:{type:"void","x-component":"Tabs","x-component-props":{},properties:{tab1:{type:"void",title:"{{t('Detail')}}","x-component":"Tabs.TabPane","x-designer":"Tabs.Designer","x-component-props":{},properties:{grid:{type:"void","x-component":"Grid","x-initializer":"SnapshotBlockInitializers",properties:{}}}}}}}},z={name:"snapshot",type:"object",group:"advanced",title:`{{t('Snapshot', {ns: '${S}'})}}`,description:`{{t('When adding a new record, create a snapshot for its relational record and save in the new record. The snapshot will not be updated when the relational record is updated.', {ns: '${S}'})}}`,default:{type:"snapshot",uiSchema:{"x-component":"SnapshotRecordPicker","x-component-props":{multiple:!0,fieldNames:{label:"id",value:"id"}}}},schemaInitialize(o,{field:i,readPretty:a,action:s,block:t}){o.properties={viewer:M.cloneDeep(K)}},initialize:o=>{},usePathOptions(o){const{appends:i=[],targetCollection:a}=o,{getCollection:s}=e.useCollectionManager(),{fields:t}=s(a),c=R(t,i);return[{label:`{{t('Snapshot data', { ns: '${S}' })}}`,value:"data",children:c}]},properties:x(m({},L),{[A]:{type:"string",title:`{{t('The association field to snapshot', {ns: '${S}'})}}`,required:!0,"x-decorator":"FormItem","x-component":"SnapshotOwnerCollectionFieldsSelect","x-disabled":"{{ !createOnly || isOverride }}","x-reactions":[{target:q,when:"{{$self.value != undefined}}",fulfill:{state:{visible:!0}},otherwise:{state:{visible:!1}}}]},[q]:{type:"string",title:`{{t("Snapshot the snapshot's association fields", {ns: "${S}"})}}`,"x-decorator":"FormItem","x-component":"AppendsTreeSelect","x-component-props":{multiple:!0,useCollection:J},"x-reactions":[{dependencies:[A],when:"{{$deps[0]}}",fulfill:{run:"{{$self.setValue($self.value)}}"}}]}})},Q=()=>{const o=$(),{getCollection:i}=e.useCollectionManager(),a=i(o.name),s=e.useCompile();return a.fields.filter(t=>!!t.target&&!!t.interface).map(t=>{var c;return x(m({},t),{label:s((c=t.uiSchema)==null?void 0:c.title),value:t.name})})},U=o=>{const i=Q();return r.jsx(v.Select,m({popupMatchSelectWidth:!1,options:i},o))},O=o=>{const h=o,{formItemInitializers:i="ReadPrettyFormItemInitializers",actionInitializers:a="ReadPrettyFormActionInitializers",collection:s,association:t,resource:c,template:d}=h,u=B(h,["formItemInitializers","actionInitializers","collection","association","resource","template"]),f=c||t||s;return{type:"void","x-acl-action":`${f}:get`,"x-decorator":"SnapshotBlockProvider","x-decorator-props":m({resource:f,collection:s,association:t,readPretty:!0,action:"get",useParams:"{{ useParamsFromRecord }}"},u),"x-designer":"FormV2.ReadPrettyDesigner","x-component":"CardItem",properties:{[I.uid()]:{type:"void","x-component":"FormV2","x-read-pretty":!0,"x-component-props":{useProps:"{{ useFormBlockProps }}"},properties:{grid:d||{type:"void","x-component":"Grid","x-initializer":i,properties:{}}}}}}},X=()=>{const o=e.useSchemaInitializerItem(),F=o,{onCreateBlockSchema:i,componentType:a,createBlockSchema:s,icon:t=!0,targetCollection:c}=F,d=B(F,["onCreateBlockSchema","componentType","createBlockSchema","icon","targetCollection"]),{insert:u}=e.useSchemaInitializer(),{getTemplateSchemaByMode:f}=e.useSchemaTemplateManager(),g=c||e.useCollection(),h=e.useBlockAssociationContext(),{block:k}=e.useBlockRequestContext(),y=k!=="TableField"?o.actionInitializers||"ReadPrettyFormActionInitializers":null;return l.createElement(e.SchemaInitializerItem,x(m({icon:t&&r.jsx(C.FormOutlined,{})},d),{key:"snapshotDetail",onClick:ie=>T(this,[ie],function*({item:p}){if(p.template){const j=yield f(p);if(p.template.componentName==="ReadPrettyFormItem"){const E=O({actionInitializers:y,association:h,collection:g.name,action:"get",useSourceId:"{{ useSourceIdFromParentRecord }}",useParams:"{{ useParamsFromRecord }}",template:j});p.mode==="reference"&&(E["x-template-key"]=p.template.key),u(E)}else u(j)}else u(O({actionInitializers:y,association:h,collection:g.name,action:"get",useSourceId:"{{ useSourceIdFromParentRecord }}",useParams:"{{ useParamsFromRecord }}"}))}),items:e.useRecordCollectionDataSourceItems("ReadPrettyFormItem")}))},Y=o=>{var f;const{action:i,readPretty:a}=o,s=P.useField(),t=l.useMemo(()=>W.createForm({readPretty:a}),[]),{resource:c,service:d}=e.useBlockRequestContext(),u=l.useRef();return d.loading?r.jsx(v.Spin,{}):r.jsx(e.FormBlockContext.Provider,{value:{action:i,form:t,field:s,service:d,resource:c,updateAssociationValues:[],formBlockRef:u},children:a?r.jsx(e.RecordProvider,{record:(f=d==null?void 0:d.data)==null?void 0:f.data,children:r.jsx("div",{ref:u,children:o.children})}):r.jsx("div",{ref:u,children:o.children})})},Z=o=>{const i=P.useField(),a=e.useBlockResource(),s={loading:!1,data:{data:e.useRecord()}},t=l.useContext(e.BlockRequestContext);return r.jsx(e.BlockRequestContext.Provider,{value:{block:o.block,props:o,field:i,service:s,resource:a,__parent:t},children:o.children})},ee=o=>{const{collection:i,association:a}=o,s=e.useResource(o);return r.jsx(e.MaybeCollectionProvider,{collection:i,children:r.jsx(e.BlockAssociationContext.Provider,{value:a,children:r.jsx(e.BlockResourceContext.Provider,{value:s,children:r.jsx(Z,x(m({},o),{children:o.children}))})})})},oe=o=>{const i=e.useRecord(),{__tableName:a}=i,{getInheritCollections:s}=e.useCollectionManager(),t=s(a),{designable:c}=e.useDesignable();return!(!c&&a&&!t.includes(o.collection)&&a!==o.collection)&&r.jsx(ee,x(m({},o),{children:r.jsx(Y,m({},o))}))},te=o=>{var k,y,F;const{collectionName:i}=o,h=l.useContext(e.CollectionManagerContext),{collections:a}=h,s=B(h,["collections"]),t=(k=e.useHistoryCollectionsByNames([i]))==null?void 0:k[0],c=e.useHistoryCollectionsByNames((y=t==null?void 0:t.inherits)!=null?y:[]),d=e.useHistoryCollectionsByNames((F=t==null?void 0:t.fields.filter(p=>p.interface!=="snapshot").map(p=>p.target))!=null?F:[]),u=[t,...d,...c].filter(p=>p),g=[...a.filter(p=>!u.map(ie=>ie.name).includes(p.name)),...u];return r.jsx(e.CollectionManagerContext.Provider,{value:x(m({},s),{collections:g}),children:o.children})},N=o=>{const i=P.useFieldSchema(),{getField:a}=e.useCollection(),s=a(i.name);return r.jsx(te,{collectionName:s==null?void 0:s.targetCollection,children:r.jsx(e.ReadPrettyRecordPicker,m({},o))})},re=P.connect(N,P.mapReadPretty(N)),ne=o=>{const c=o,{value:i,onChange:a}=c,s=B(c,["value","onChange"]),t=x(m({},s),{value:i==null?void 0:i.data,onChange:d=>a({data:d})});return r.jsx(re,m({},t))},D=l.memo(o=>(l.useEffect(()=>{e.registerField(z.group,z.name,z)},[]),r.jsx(e.CollectionManagerProvider,{interfaces:{snapshot:z},children:r.jsx(e.CollectionHistoryProvider,{children:r.jsx(e.SchemaComponentOptions,{components:{SnapshotRecordPicker:ne,SnapshotBlockProvider:oe,SnapshotBlockInitializersDetailItem:X,SnapshotOwnerCollectionFieldsSelect:U},children:o.children})})})));D.displayName="SnapshotFieldProvider";const se=new e.SchemaInitializer({name:"SnapshotBlockInitializers",wrap:e.gridRowColWrap,title:`{{t("Add block", { ns: "${S}" })}}`,icon:"PlusOutlined",items:[{type:"itemGroup",title:'{{t("Current record blocks")}}',name:"currentRecordBlocks",children:[{name:"details",title:'{{t("Details")}}',Component:"SnapshotBlockInitializersDetailItem",actionInitializers:"CalendarFormActionInitializers"}]},{type:"itemGroup",title:'{{t("Other blocks")}}',name:"otherBlocks",children:[{name:"markdown",title:'{{t("Markdown")}}',Component:"MarkdownBlockInitializer"}]}]});class _ extends e.Plugin{load(){return T(this,null,function*(){this.app.use(D),this.app.schemaInitializerManager.add(se)})}}n.SnapshotFieldPlugin=_,n.default=_,Object.defineProperties(n,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
1
+ (function(r,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("@nocobase/client"),require("react/jsx-runtime"),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/jsx-runtime","react","antd","@formily/react","lodash","react-i18next","@ant-design/icons","@formily/shared","@formily/core"],e):(r=typeof globalThis!="undefined"?globalThis:r||self,e(r["@nocobase/plugin-snapshot-field"]={},r["@nocobase/client"],r.jsxRuntime,r.react,r.antd,r["@formily/react"],r.lodash,r["react-i18next"],r["@ant-design/icons"],r["@formily/shared"],r["@formily/core"]))})(this,function(r,e,o,d,v,C,_,B,y,I,W){"use strict";var ie=Object.defineProperty,ce=Object.defineProperties;var le=Object.getOwnPropertyDescriptors;var z=Object.getOwnPropertySymbols;var H=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable;var w=(r,e,o)=>e in r?ie(r,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):r[e]=o,f=(r,e)=>{for(var o in e||(e={}))H.call(e,o)&&w(r,o,e[o]);if(z)for(var o of z(e))G.call(e,o)&&w(r,o,e[o]);return r},g=(r,e)=>ce(r,le(e));var M=(r,e)=>{var o={};for(var d in r)H.call(r,d)&&e.indexOf(d)<0&&(o[d]=r[d]);if(r!=null&&z)for(var d of z(r))e.indexOf(d)<0&&G.call(r,d)&&(o[d]=r[d]);return o};var S=(r,e,o)=>(w(r,typeof e!="symbol"?e+"":e,o),o);var q=(r,e,o)=>new Promise((d,v)=>{var C=y=>{try{B(o.next(y))}catch(I){v(I)}},_=y=>{try{B(o.throw(y))}catch(I){v(I)}},B=y=>y.done?d(y.value):Promise.resolve(y.value).then(C,_);B((o=o.apply(r,e)).next())});const x="snapshot-field",{defaultProps:L}=e.interfacesProperties,R="appends",T="targetField",A=()=>{let t=e.useRecord();for(;t&&Object.keys(t.__parent).length>0;)t=t.__parent;return t};function J(){var s;const{getCollectionField:t}=e.useCollectionManager_deprecated(),i=A(),a=C.useForm().values;return(s=t(`${i.name}.${a.targetField}`))==null?void 0:s.target}function $(t,i=[]){const{getCollection:a}=e.useCollectionManager_deprecated(),s=[];return t.forEach(n=>{var c,l,u,m;if(["belongsTo","hasOne","hasMany","belongsToMany"].includes(n.type)){const P=i.filter(h=>`${h}.`.startsWith(`${n.name}.`));if(P.length){const h=a(n.target),k=P.filter(p=>p!==n.name).map(p=>p.replace(`${n.name}.`,"")).filter(p=>p);s.push({label:(l=(c=n.uiSchema)==null?void 0:c.title)!=null?l:n.name,value:n.name,children:$(h.fields,k)})}}else s.push({label:(m=(u=n.uiSchema)==null?void 0:u.title)!=null?m:n.name,value:n.name})}),s}const K={type:"void",title:"{{t('View record')}}","x-component":"RecordPicker.Viewer","x-component-props":{className:"nb-action-popup"},properties:{tabs:{type:"void","x-component":"Tabs","x-component-props":{},properties:{tab1:{type:"void",title:"{{t('Detail')}}","x-component":"Tabs.TabPane","x-designer":"Tabs.Designer","x-component-props":{},properties:{grid:{type:"void","x-component":"Grid","x-initializer":"SnapshotBlockInitializers",properties:{}}}}}}}};class Q extends e.CollectionFieldInterface{constructor(){super(...arguments);S(this,"name","snapshot");S(this,"type","object");S(this,"group","advanced");S(this,"title",`{{t('Snapshot', {ns: '${x}'})}}`);S(this,"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: '${x}'})}}`);S(this,"default",{type:"snapshot",uiSchema:{"x-component":"SnapshotRecordPicker","x-component-props":{multiple:!0,fieldNames:{label:"id",value:"id"}}}});S(this,"properties",g(f({},L),{[T]:{type:"string",title:`{{t('The association field to snapshot', {ns: '${x}'})}}`,required:!0,"x-decorator":"FormItem","x-component":"SnapshotOwnerCollectionFieldsSelect","x-disabled":"{{ !createOnly || isOverride }}","x-reactions":[{target:R,when:"{{$self.value != undefined}}",fulfill:{state:{visible:!0}},otherwise:{state:{visible:!1}}}]},[R]:{type:"string",title:`{{t("Snapshot the snapshot's association fields", {ns: "${x}"})}}`,"x-decorator":"FormItem","x-component":"AppendsTreeSelect","x-component-props":{multiple:!0,useCollection_deprecated:J},"x-reactions":[{dependencies:[T],when:"{{$deps[0]}}",fulfill:{run:"{{$self.setValue($self.value)}}"}}]}}))}schemaInitialize(a,{field:s,readPretty:n,action:c,block:l}){a.properties={viewer:_.cloneDeep(K)}}initialize(a){}usePathOptions(a){const{appends:s=[],targetCollection:n}=a,{getCollection:c}=e.useCollectionManager_deprecated(),{fields:l}=c(n),u=$(l,s);return[{label:`{{t('Snapshot data', { ns: '${x}' })}}`,value:"data",children:u}]}}const U=()=>{const t=A(),{getCollection:i}=e.useCollectionManager_deprecated(),a=i(t.name),s=e.useCompile();return a.fields.filter(n=>!!n.target&&!!n.interface).map(n=>{var c;return g(f({},n),{label:s((c=n.uiSchema)==null?void 0:c.title),value:n.name})})},X=t=>{const i=U();return o.jsx(v.Select,f({popupMatchSelectWidth:!1,options:i},t))},O=t=>{const h=t,{formItemInitializers:i="ReadPrettyFormItemInitializers",actionInitializers:a="ReadPrettyFormActionInitializers",collection:s,association:n,resource:c,template:l}=h,u=M(h,["formItemInitializers","actionInitializers","collection","association","resource","template"]),m=c||n||s;return{type:"void","x-acl-action":`${m}:get`,"x-decorator":"SnapshotBlockProvider","x-decorator-props":f({resource:m,collection:s,association:n,readPretty:!0,action:"get",useParams:"{{ useParamsFromRecord }}"},u),"x-designer":"FormV2.ReadPrettyDesigner","x-component":"CardItem",properties:{[I.uid()]:{type:"void","x-component":"FormV2","x-read-pretty":!0,"x-component-props":{useProps:"{{ useFormBlockProps }}"},properties:{grid:l||{type:"void","x-component":"Grid","x-initializer":i,properties:{}}}}}}},Y=()=>{const t=e.useSchemaInitializerItem(),b=t,{onCreateBlockSchema:i,componentType:a,createBlockSchema:s,icon:n=!0,targetCollection:c}=b,l=M(b,["onCreateBlockSchema","componentType","createBlockSchema","icon","targetCollection"]),{insert:u}=e.useSchemaInitializer(),{getTemplateSchemaByMode:m}=e.useSchemaTemplateManager(),P=c||e.useCollection_deprecated(),h=e.useBlockAssociationContext(),{block:k}=e.useBlockRequestContext(),p=k!=="TableField"?t.actionInitializers||"ReadPrettyFormActionInitializers":null;return d.createElement(e.SchemaInitializerItem,g(f({icon:n&&o.jsx(y.FormOutlined,{})},l),{key:"snapshotDetail",onClick:ue=>q(this,[ue],function*({item:F}){if(F.template){const E=yield m(F);if(F.template.componentName==="ReadPrettyFormItem"){const V=O({actionInitializers:p,association:h,collection:P.name,action:"get",useSourceId:"{{ useSourceIdFromParentRecord }}",useParams:"{{ useParamsFromRecord }}",template:E});F.mode==="reference"&&(V["x-template-key"]=F.template.key),u(V)}else u(E)}else u(O({actionInitializers:p,association:h,collection:P.name,action:"get",useSourceId:"{{ useSourceIdFromParentRecord }}",useParams:"{{ useParamsFromRecord }}"}))}),items:e.useRecordCollectionDataSourceItems("ReadPrettyFormItem")}))},Z=t=>{var m;const{action:i,readPretty:a}=t,s=C.useField(),n=d.useMemo(()=>W.createForm({readPretty:a}),[]),{resource:c,service:l}=e.useBlockRequestContext(),u=d.useRef();return l.loading?o.jsx(v.Spin,{}):o.jsx(e.FormBlockContext.Provider,{value:{action:i,form:n,field:s,service:l,resource:c,updateAssociationValues:[],formBlockRef:u},children:a?o.jsx(e.RecordProvider,{record:(m=l==null?void 0:l.data)==null?void 0:m.data,children:o.jsx("div",{ref:u,children:t.children})}):o.jsx("div",{ref:u,children:t.children})})},ee=t=>{const i=C.useField(),a=e.useBlockResource(),s={loading:!1,data:{data:e.useRecord()}},n=e.useBlockRequestContext();return o.jsx(e.BlockRequestContext_deprecated.Provider,{value:{block:t.block,props:t,field:i,service:s,resource:a,__parent:n},children:t.children})},te=t=>{const{collection:i,association:a,dataSource:s}=t,n=e.useResource(t);return o.jsx(e.CollectionManagerProvider,{dataSource:s,children:o.jsx(e.MaybeCollectionProvider,{collection:i,children:o.jsx(e.BlockAssociationContext.Provider,{value:a,children:o.jsx(e.BlockResourceContext.Provider,{value:n,children:o.jsx(ee,g(f({},t),{children:t.children}))})})})})},oe=t=>{const i=e.useRecord(),{__tableName:a}=i,{getInheritCollections:s}=e.useCollectionManager_deprecated(t.dataSource),n=s(a),{designable:c}=e.useDesignable();return!(!c&&a&&!n.includes(t.collection)&&a!==t.collection)&&o.jsx(te,g(f({},t),{children:o.jsx(Z,f({},t))}))},re=t=>{var P,h,k;const{collectionName:i}=t,{collections:a}=e.useCollectionManager_deprecated(),s=(P=e.useHistoryCollectionsByNames([i]))==null?void 0:P[0],n=e.useHistoryCollectionsByNames((h=s==null?void 0:s.inherits)!=null?h:[]),c=e.useHistoryCollectionsByNames((k=s==null?void 0:s.fields.filter(p=>p.interface!=="snapshot").map(p=>p.target))!=null?k:[]),l=[s,...c,...n].filter(p=>p),m=[...a.filter(p=>!l.map(b=>b.name).includes(p.name)),...l];return o.jsx(e.ExtendCollectionsProvider,{collections:m,children:o.jsx(e.CollectionManagerProvider_deprecated,{children:t.children})})},N=t=>{const i=C.useFieldSchema(),{getField:a}=e.useCollection_deprecated(),s=a(i.name);return o.jsx(re,{collectionName:s==null?void 0:s.targetCollection,children:o.jsx(e.ReadPrettyRecordPicker,f({},t))})},ne=C.connect(N,C.mapReadPretty(N)),se=t=>{const c=t,{value:i,onChange:a}=c,s=M(c,["value","onChange"]),n=g(f({},s),{value:i==null?void 0:i.data,onChange:l=>a({data:l})});return o.jsx(ne,f({},n))},D=d.memo(t=>o.jsx(e.CollectionHistoryProvider,{children:o.jsx(e.SchemaComponentOptions,{components:{SnapshotRecordPicker:se,SnapshotBlockProvider:oe,SnapshotBlockInitializersDetailItem:Y,SnapshotOwnerCollectionFieldsSelect:X},children:t.children})}));D.displayName="SnapshotFieldProvider";const ae=new e.SchemaInitializer({name:"SnapshotBlockInitializers",wrap:e.gridRowColWrap,title:`{{t("Add block", { ns: "${x}" })}}`,icon:"PlusOutlined",items:[{type:"itemGroup",title:'{{t("Current record blocks")}}',name:"currentRecordBlocks",children:[{name:"details",title:'{{t("Details")}}',Component:"SnapshotBlockInitializersDetailItem",actionInitializers:"CalendarFormActionInitializers"}]},{type:"itemGroup",title:'{{t("Other blocks")}}',name:"otherBlocks",children:[{name:"markdown",title:'{{t("Markdown")}}',Component:"MarkdownBlockInitializer"}]}]});class j extends e.Plugin{load(){return q(this,null,function*(){this.app.use(D),this.app.schemaInitializerManager.add(ae),this.app.dataSourceManager.addFieldInterfaces([Q])})}}r.SnapshotFieldPlugin=j,r.default=j,Object.defineProperties(r,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -1,3 +1,95 @@
1
- import { IField } from '@nocobase/client';
1
+ import { ISchema } from '@formily/react';
2
+ import { CollectionFieldInterface } from '@nocobase/client';
2
3
  export declare const useTopRecord: () => any;
3
- export declare const snapshot: IField;
4
+ declare function useRecordCollection(): any;
5
+ export declare class SnapshotFieldInterface extends CollectionFieldInterface {
6
+ name: string;
7
+ type: string;
8
+ group: string;
9
+ title: string;
10
+ description: string;
11
+ default: {
12
+ type: string;
13
+ uiSchema: {
14
+ 'x-component': string;
15
+ 'x-component-props': {
16
+ multiple: boolean;
17
+ fieldNames: {
18
+ label: string;
19
+ value: string;
20
+ };
21
+ };
22
+ };
23
+ };
24
+ schemaInitialize(schema: ISchema, { field, readPretty, action, block }: {
25
+ field: any;
26
+ readPretty: any;
27
+ action: any;
28
+ block: any;
29
+ }): void;
30
+ initialize(values: any): void;
31
+ usePathOptions(field: any): {
32
+ label: string;
33
+ value: string;
34
+ children: any[];
35
+ }[];
36
+ properties: {
37
+ targetField: {
38
+ type: string;
39
+ title: string;
40
+ required: boolean;
41
+ 'x-decorator': string;
42
+ 'x-component': string;
43
+ 'x-disabled': string;
44
+ 'x-reactions': {
45
+ target: string;
46
+ when: string;
47
+ fulfill: {
48
+ state: {
49
+ visible: boolean;
50
+ };
51
+ };
52
+ otherwise: {
53
+ state: {
54
+ visible: boolean;
55
+ };
56
+ };
57
+ }[];
58
+ };
59
+ appends: {
60
+ type: string;
61
+ title: string;
62
+ 'x-decorator': string;
63
+ 'x-component': string;
64
+ 'x-component-props': {
65
+ multiple: boolean;
66
+ useCollection_deprecated: typeof useRecordCollection;
67
+ };
68
+ 'x-reactions': {
69
+ dependencies: string[];
70
+ when: string;
71
+ fulfill: {
72
+ run: string;
73
+ };
74
+ }[];
75
+ };
76
+ 'uiSchema.title': {
77
+ type: string;
78
+ title: string;
79
+ required: boolean;
80
+ 'x-decorator': string;
81
+ 'x-component': string;
82
+ };
83
+ name: {
84
+ type: string;
85
+ title: string;
86
+ required: boolean;
87
+ 'x-disabled': string;
88
+ 'x-decorator': string;
89
+ 'x-component': string;
90
+ 'x-validator': string;
91
+ description: string;
92
+ };
93
+ };
94
+ }
95
+ export {};
@@ -1,11 +1,11 @@
1
1
  module.exports = {
2
- "@nocobase/client": "0.19.0-alpha.9",
2
+ "@nocobase/client": "0.20.0-alpha.1",
3
3
  "react": "18.2.0",
4
4
  "@formily/react": "2.3.0",
5
5
  "@formily/core": "2.3.0",
6
6
  "lodash": "4.17.21",
7
- "@nocobase/database": "0.19.0-alpha.9",
8
- "@nocobase/server": "0.19.0-alpha.9",
7
+ "@nocobase/database": "0.20.0-alpha.1",
8
+ "@nocobase/server": "0.20.0-alpha.1",
9
9
  "antd": "5.12.8",
10
10
  "react-i18next": "11.18.6",
11
11
  "@ant-design/icons": "5.2.6",
@@ -47,10 +47,6 @@ class SnapshotFieldPlugin extends import_server.Plugin {
47
47
  values: collectionDoc,
48
48
  transaction
49
49
  });
50
- await fieldsHistoryRepository.createMany({
51
- records: collectionDoc.fields ?? [],
52
- transaction
53
- });
54
50
  };
55
51
  this.app.db.on("collections.afterCreateWithAssociations", collectionHandler);
56
52
  const deleteField = async (field, transaction) => {
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "displayName.zh-CN": "数据表字段:关系快照",
5
5
  "description": "When adding a new record, create a snapshot for its relational record and save in the new record. The snapshot will not be updated when the relational record is updated.",
6
6
  "description.zh-CN": "在添加数据时,为它的关系数据创建快照,并保存在当前的数据中。关系数据更新时,快照不会更新。",
7
- "version": "0.19.0-alpha.9",
7
+ "version": "0.20.0-alpha.1",
8
8
  "license": "AGPL-3.0",
9
9
  "main": "./dist/server/index.js",
10
10
  "homepage": "https://docs.nocobase.com/plugins/snapshot-field",
@@ -26,7 +26,7 @@
26
26
  "@nocobase/test": "0.x",
27
27
  "@nocobase/utils": "0.x"
28
28
  },
29
- "gitHead": "975f9c58a1995df6a8d7a4d191a0dc4a9769ebc5",
29
+ "gitHead": "516c0b1470d77ff499f533ae6b57e4c084450ff5",
30
30
  "keywords": [
31
31
  "Collection fields"
32
32
  ]