@nocobase/plugin-snapshot-field 0.14.0-alpha.7 → 0.15.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 +1 @@
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,n,l,v,g,w,F,C,I,W){"use strict";var ce=Object.defineProperty,le=Object.defineProperties;var de=Object.getOwnPropertyDescriptors;var M=Object.getOwnPropertySymbols;var H=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable;var V=(r,e,n)=>e in r?ce(r,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):r[e]=n,m=(r,e)=>{for(var n in e||(e={}))H.call(e,n)&&V(r,n,e[n]);if(M)for(var n of M(e))G.call(e,n)&&V(r,n,e[n]);return r},S=(r,e)=>le(r,de(e));var B=(r,e)=>{var n={};for(var l in r)H.call(r,l)&&e.indexOf(l)<0&&(n[l]=r[l]);if(r!=null&&M)for(var l of M(r))e.indexOf(l)<0&&G.call(r,l)&&(n[l]=r[l]);return n};var T=(r,e,n)=>new Promise((l,v)=>{var g=C=>{try{F(n.next(C))}catch(I){v(I)}},w=C=>{try{F(n.throw(C))}catch(I){v(I)}},F=C=>C.done?l(C.value):Promise.resolve(C.value).then(g,w);F((n=n.apply(r,e)).next())});const x="snapshot-field";function J(){return F.useTranslation(x)}const{defaultProps:L}=e.interfacesProperties,q="appends",A="targetField",O=()=>{let o=e.useRecord();for(;o&&Object.keys(o.__parent).length>0;)o=o.__parent;return o};function K(){var s;const{getCollectionField:o}=e.useCollectionManager(),i=O(),a=g.useForm().values;return(s=o(`${i.name}.${a.targetField}`))==null?void 0:s.target}function $(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 P=i.filter(h=>`${h}.`.startsWith(`${t.name}.`));if(P.length){const h=a(t.target),k=P.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:$(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 Q={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: '${x}'})}}`,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}'})}}`,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:w.cloneDeep(Q)}},initialize:o=>{},usePathOptions(o){const{appends:i=[],targetCollection:a}=o,{getCollection:s}=e.useCollectionManager(),{fields:t}=s(a),c=$(t,i);return[{label:`{{t('Snapshot data', { ns: '${x}' })}}`,value:"data",children:c}]},properties:S(m({},L),{[A]:{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: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: "${x}"})}}`,"x-decorator":"FormItem","x-component":"AppendsTreeSelect","x-component-props":{multiple:!0,useCollection:K},"x-reactions":[{dependencies:[A],when:"{{$deps[0]}}",fulfill:{run:"{{$self.setValue($self.value)}}"}}]}})},U=()=>{const o=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 S(m({},t),{label:s((c=t.uiSchema)==null?void 0:c.title),value:t.name})})},X=o=>{const i=U();return n.jsx(v.Select,m({"data-testid":"antd-select",popupMatchSelectWidth:!1,options:i},o))},Y=o=>{const{t:i}=J(),{insertPosition:a,component:s}=o;return n.jsx(e.SchemaInitializer.Button,{"data-testid":"add-block-button-in-snapshot-block",wrap:e.gridRowColWrap,insertPosition:a,component:s,title:s?null:i("Add block"),icon:"PlusOutlined",items:[{type:"itemGroup",title:'{{t("Current record blocks")}}',children:[{key:"details",type:"item",title:'{{t("Details")}}',component:"SnapshotBlockInitializersDetailItem",actionInitializers:"CalendarFormActionInitializers"}]},{type:"itemGroup",title:'{{t("Other blocks")}}',children:[{key:"markdown",type:"item",title:'{{t("Markdown")}}',component:"MarkdownBlockInitializer"}]}]})},N=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,P={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:{}}}}}};return console.log(JSON.stringify(P,null,2)),P},Z=o=>{const b=o,{onCreateBlockSchema:i,componentType:a,createBlockSchema:s,insert:t,icon:c=!0,targetCollection:d}=b,u=B(b,["onCreateBlockSchema","componentType","createBlockSchema","insert","icon","targetCollection"]),{getTemplateSchemaByMode:f}=e.useSchemaTemplateManager(),P=d||e.useCollection(),h=e.useBlockAssociationContext(),{block:k}=e.useBlockRequestContext(),y=k!=="TableField"?o.actionInitializers||"ReadPrettyFormActionInitializers":null;return l.createElement(e.SchemaInitializer.Item,S(m({icon:c&&n.jsx(C.FormOutlined,{})},u),{key:"snapshotDetail",onClick:ae=>T(this,[ae],function*({item:p}){if(p.template){const j=yield f(p);if(p.template.componentName==="ReadPrettyFormItem"){const E=N({actionInitializers:y,association:h,collection:P.name,action:"get",useSourceId:"{{ useSourceIdFromParentRecord }}",useParams:"{{ useParamsFromRecord }}",template:j});p.mode==="reference"&&(E["x-template-key"]=p.template.key),t(E)}else t(j)}else t(N({actionInitializers:y,association:h,collection:P.name,action:"get",useSourceId:"{{ useSourceIdFromParentRecord }}",useParams:"{{ useParamsFromRecord }}"}))}),items:e.useRecordCollectionDataSourceItems("ReadPrettyFormItem")}))},ee=o=>{var f;const{action:i,readPretty:a}=o,s=g.useField(),t=l.useMemo(()=>W.createForm({readPretty:a}),[]),{resource:c,service:d}=e.useBlockRequestContext(),u=l.useRef();return d.loading?n.jsx(v.Spin,{}):n.jsx(e.FormBlockContext.Provider,{value:{action:i,form:t,field:s,service:d,resource:c,updateAssociationValues:[],formBlockRef:u},children:a?n.jsx(e.RecordProvider,{record:(f=d==null?void 0:d.data)==null?void 0:f.data,children:n.jsx("div",{ref:u,children:o.children})}):n.jsx("div",{ref:u,children:o.children})})},oe=o=>{const i=g.useField(),a=e.useBlockResource(),s={loading:!1,data:{data:e.useRecord()}},t=l.useContext(e.BlockRequestContext);return n.jsx(e.BlockRequestContext.Provider,{value:{block:o.block,props:o,field:i,service:s,resource:a,__parent:t},children:o.children})},te=o=>{const{collection:i,association:a}=o,s=e.useResource(o);return n.jsx(e.MaybeCollectionProvider,{collection:i,children:n.jsx(e.BlockAssociationContext.Provider,{value:a,children:n.jsx(e.BlockResourceContext.Provider,{value:s,children:n.jsx(oe,S(m({},o),{children:o.children}))})})})},ne=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)&&n.jsx(te,S(m({},o),{children:n.jsx(ee,m({},o))}))},re=o=>{var k,y,b;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((b=t==null?void 0:t.fields.filter(p=>p.interface!=="snapshot").map(p=>p.target))!=null?b:[]),u=[t,...d,...c].filter(p=>p),P=[...a.filter(p=>!u.map(ae=>ae.name).includes(p.name)),...u];return n.jsx(e.CollectionManagerContext.Provider,{value:S(m({},s),{collections:P}),children:o.children})},D=o=>{const i=g.useFieldSchema(),{getField:a}=e.useCollection(),s=a(i.name);return n.jsx(re,{collectionName:s==null?void 0:s.targetCollection,children:n.jsx(e.ReadPrettyRecordPicker,m({},o))})},se=g.connect(D,g.mapReadPretty(D)),ie=o=>{const c=o,{value:i,onChange:a}=c,s=B(c,["value","onChange"]),t=S(m({},s),{value:i==null?void 0:i.data,onChange:d=>a({data:d})});return n.jsx(se,m({},t))},R=l.memo(o=>(l.useEffect(()=>{e.registerField(z.group,z.name,z)},[]),n.jsx(e.CollectionManagerProvider,{interfaces:{snapshot:z},children:n.jsx(e.CollectionHistoryProvider,{children:n.jsx(e.SchemaInitializerProvider,{initializers:{SnapshotBlockInitializers:Y},children:n.jsx(e.SchemaComponentOptions,{components:{SnapshotRecordPicker:ie,SnapshotBlockProvider:ne,SnapshotBlockInitializersDetailItem:Z,SnapshotOwnerCollectionFieldsSelect:X},children:o.children})})})})));R.displayName="SnapshotFieldProvider";class _ extends e.Plugin{load(){return T(this,null,function*(){this.app.use(R)})}}r.SnapshotFieldPlugin=_,r.default=_,Object.defineProperties(r,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
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,g,w,F,C,I,W){"use strict";var ce=Object.defineProperty,le=Object.defineProperties;var de=Object.getOwnPropertyDescriptors;var M=Object.getOwnPropertySymbols;var H=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable;var V=(n,e,r)=>e in n?ce(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(M)for(var r of M(e))G.call(e,r)&&V(n,r,e[r]);return n},S=(n,e)=>le(n,de(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&&M)for(var l of M(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 g=C=>{try{F(r.next(C))}catch(I){v(I)}},w=C=>{try{F(r.throw(C))}catch(I){v(I)}},F=C=>C.done?l(C.value):Promise.resolve(C.value).then(g,w);F((r=r.apply(n,e)).next())});const x="snapshot-field";function J(){return F.useTranslation(x)}const{defaultProps:L}=e.interfacesProperties,q="appends",A="targetField",O=()=>{let o=e.useRecord();for(;o&&Object.keys(o.__parent).length>0;)o=o.__parent;return o};function K(){var s;const{getCollectionField:o}=e.useCollectionManager(),i=O(),a=g.useForm().values;return(s=o(`${i.name}.${a.targetField}`))==null?void 0:s.target}function $(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 P=i.filter(h=>`${h}.`.startsWith(`${t.name}.`));if(P.length){const h=a(t.target),k=P.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:$(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 Q={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: '${x}'})}}`,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}'})}}`,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:w.cloneDeep(Q)}},initialize:o=>{},usePathOptions(o){const{appends:i=[],targetCollection:a}=o,{getCollection:s}=e.useCollectionManager(),{fields:t}=s(a),c=$(t,i);return[{label:`{{t('Snapshot data', { ns: '${x}' })}}`,value:"data",children:c}]},properties:S(m({},L),{[A]:{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: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: "${x}"})}}`,"x-decorator":"FormItem","x-component":"AppendsTreeSelect","x-component-props":{multiple:!0,useCollection:K},"x-reactions":[{dependencies:[A],when:"{{$deps[0]}}",fulfill:{run:"{{$self.setValue($self.value)}}"}}]}})},U=()=>{const o=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 S(m({},t),{label:s((c=t.uiSchema)==null?void 0:c.title),value:t.name})})},X=o=>{const i=U();return r.jsx(v.Select,m({popupMatchSelectWidth:!1,options:i},o))},Y=o=>{const{t:i}=J(),{insertPosition:a,component:s}=o;return r.jsx(e.SchemaInitializer.Button,{wrap:e.gridRowColWrap,insertPosition:a,component:s,title:s?null:i("Add block"),icon:"PlusOutlined",items:[{type:"itemGroup",title:'{{t("Current record blocks")}}',children:[{key:"details",type:"item",title:'{{t("Details")}}',component:"SnapshotBlockInitializersDetailItem",actionInitializers:"CalendarFormActionInitializers"}]},{type:"itemGroup",title:'{{t("Other blocks")}}',children:[{key:"markdown",type:"item",title:'{{t("Markdown")}}',component:"MarkdownBlockInitializer"}]}]})},N=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,P={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:{}}}}}};return console.log(JSON.stringify(P,null,2)),P},Z=o=>{const b=o,{onCreateBlockSchema:i,componentType:a,createBlockSchema:s,insert:t,icon:c=!0,targetCollection:d}=b,u=B(b,["onCreateBlockSchema","componentType","createBlockSchema","insert","icon","targetCollection"]),{getTemplateSchemaByMode:f}=e.useSchemaTemplateManager(),P=d||e.useCollection(),h=e.useBlockAssociationContext(),{block:k}=e.useBlockRequestContext(),y=k!=="TableField"?o.actionInitializers||"ReadPrettyFormActionInitializers":null;return l.createElement(e.SchemaInitializer.Item,S(m({icon:c&&r.jsx(C.FormOutlined,{})},u),{key:"snapshotDetail",onClick:ae=>T(this,[ae],function*({item:p}){if(p.template){const j=yield f(p);if(p.template.componentName==="ReadPrettyFormItem"){const E=N({actionInitializers:y,association:h,collection:P.name,action:"get",useSourceId:"{{ useSourceIdFromParentRecord }}",useParams:"{{ useParamsFromRecord }}",template:j});p.mode==="reference"&&(E["x-template-key"]=p.template.key),t(E)}else t(j)}else t(N({actionInitializers:y,association:h,collection:P.name,action:"get",useSourceId:"{{ useSourceIdFromParentRecord }}",useParams:"{{ useParamsFromRecord }}"}))}),items:e.useRecordCollectionDataSourceItems("ReadPrettyFormItem")}))},ee=o=>{var f;const{action:i,readPretty:a}=o,s=g.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})})},oe=o=>{const i=g.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})},te=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(oe,S(m({},o),{children:o.children}))})})})},re=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(te,S(m({},o),{children:r.jsx(ee,m({},o))}))},ne=o=>{var k,y,b;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((b=t==null?void 0:t.fields.filter(p=>p.interface!=="snapshot").map(p=>p.target))!=null?b:[]),u=[t,...d,...c].filter(p=>p),P=[...a.filter(p=>!u.map(ae=>ae.name).includes(p.name)),...u];return r.jsx(e.CollectionManagerContext.Provider,{value:S(m({},s),{collections:P}),children:o.children})},D=o=>{const i=g.useFieldSchema(),{getField:a}=e.useCollection(),s=a(i.name);return r.jsx(ne,{collectionName:s==null?void 0:s.targetCollection,children:r.jsx(e.ReadPrettyRecordPicker,m({},o))})},se=g.connect(D,g.mapReadPretty(D)),ie=o=>{const c=o,{value:i,onChange:a}=c,s=B(c,["value","onChange"]),t=S(m({},s),{value:i==null?void 0:i.data,onChange:d=>a({data:d})});return r.jsx(se,m({},t))},R=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.SchemaInitializerProvider,{initializers:{SnapshotBlockInitializers:Y},children:r.jsx(e.SchemaComponentOptions,{components:{SnapshotRecordPicker:ie,SnapshotBlockProvider:re,SnapshotBlockInitializersDetailItem:Z,SnapshotOwnerCollectionFieldsSelect:X},children:o.children})})})})));R.displayName="SnapshotFieldProvider";class _ extends e.Plugin{load(){return T(this,null,function*(){this.app.use(R)})}}n.SnapshotFieldPlugin=_,n.default=_,Object.defineProperties(n,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -1,11 +1,11 @@
1
1
  module.exports = {
2
- "@nocobase/client": "0.14.0-alpha.7",
2
+ "@nocobase/client": "0.15.0-alpha.1",
3
3
  "react": "18.2.0",
4
4
  "@formily/react": "2.2.27",
5
5
  "@formily/core": "2.2.27",
6
6
  "lodash": "4.17.21",
7
- "@nocobase/database": "0.14.0-alpha.7",
8
- "@nocobase/server": "0.14.0-alpha.7",
7
+ "@nocobase/database": "0.15.0-alpha.1",
8
+ "@nocobase/server": "0.15.0-alpha.1",
9
9
  "antd": "5.8.6",
10
10
  "react-i18next": "11.18.6",
11
11
  "@ant-design/icons": "5.1.4",
@@ -35,7 +35,8 @@ class SnapshotFieldPlugin extends import_server.Plugin {
35
35
  const existCollection = await collectionsHistoryRepository.findOne({
36
36
  filter: {
37
37
  name: collectionDoc.name
38
- }
38
+ },
39
+ transaction
39
40
  });
40
41
  if (existCollection) {
41
42
  await existCollection.destroy({
@@ -52,19 +53,21 @@ class SnapshotFieldPlugin extends import_server.Plugin {
52
53
  });
53
54
  };
54
55
  this.app.db.on("collections.afterCreateWithAssociations", collectionHandler);
55
- const fieldHandler = async (model, { transaction }) => {
56
- const fieldDoc = model.get();
56
+ const deleteField = async (field, transaction) => {
57
57
  const fieldsHistoryRepository = this.app.db.getRepository("fieldsHistory");
58
- const existField = await fieldsHistoryRepository.findOne({
59
- filter: {
60
- name: fieldDoc.name,
61
- collectionName: fieldDoc.collectionName
62
- }
58
+ const { name, collectionName } = field;
59
+ await fieldsHistoryRepository.destroy({
60
+ filter: { name, collectionName },
61
+ transaction
63
62
  });
64
- if (existField) {
65
- await existField.destroy({
66
- transaction
67
- });
63
+ };
64
+ const fieldHandler = async (model, { transaction }) => {
65
+ const fieldsHistoryRepository = this.app.db.getRepository("fieldsHistory");
66
+ const fieldDoc = model.get();
67
+ await deleteField(fieldDoc, transaction);
68
+ const reverseField = fieldDoc.reverseField;
69
+ if (reverseField) {
70
+ await deleteField(reverseField, transaction);
68
71
  }
69
72
  await fieldsHistoryRepository.create({
70
73
  values: JSON.parse(JSON.stringify(fieldDoc)),
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "displayName.zh-CN": "关系快照字段",
5
5
  "description": "",
6
6
  "description.zh-CN": "",
7
- "version": "0.14.0-alpha.7",
7
+ "version": "0.15.0-alpha.1",
8
8
  "license": "AGPL-3.0",
9
9
  "main": "./dist/server/index.js",
10
10
  "devDependencies": {
@@ -24,5 +24,5 @@
24
24
  "@nocobase/test": "0.x",
25
25
  "@nocobase/utils": "0.x"
26
26
  },
27
- "gitHead": "dc958417d27ed0753439bcef192be91a03dfc30f"
27
+ "gitHead": "8bbeab858a818fbe0a1f954ecf1f61337d06c065"
28
28
  }