@tachybase/plugin-field-snapshot 0.23.41 → 0.23.48

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(n,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("@tachybase/client"),require("@tachybase/schema"),require("lodash"),require("react-i18next"),require("react/jsx-runtime"),require("react"),require("antd"),require("@ant-design/icons")):typeof define=="function"&&define.amd?define(["exports","@tachybase/client","@tachybase/schema","lodash","react-i18next","react/jsx-runtime","react","antd","@ant-design/icons"],e):(n=typeof globalThis!="undefined"?globalThis:n||self,e(n["@tachybase/plugin-field-snapshot"]={},n["@tachybase/client"],n["@tachybase/schema"],n.lodash,n["react-i18next"],n.jsxRuntime,n.react,n.antd,n["@ant-design/icons"]))})(this,function(n,e,s,h,M,i,k,v,y){"use strict";var se=Object.defineProperty,ae=Object.defineProperties;var ce=Object.getOwnPropertyDescriptors;var B=Object.getOwnPropertySymbols;var V=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable;var w=(n,e,s)=>e in n?se(n,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):n[e]=s,g=(n,e)=>{for(var s in e||(e={}))V.call(e,s)&&w(n,s,e[s]);if(B)for(var s of B(e))H.call(e,s)&&w(n,s,e[s]);return n},x=(n,e)=>ae(n,ce(e));var _=(n,e)=>{var s={};for(var h in n)V.call(n,h)&&e.indexOf(h)<0&&(s[h]=n[h]);if(n!=null&&B)for(var h of B(n))e.indexOf(h)<0&&H.call(n,h)&&(s[h]=n[h]);return s};var S=(n,e,s)=>w(n,typeof e!="symbol"?e+"":e,s);var z=(n,e,s)=>new Promise((h,M)=>{var i=y=>{try{v(s.next(y))}catch(C){M(C)}},k=y=>{try{v(s.throw(y))}catch(C){M(C)}},v=y=>y.done?h(y.value):Promise.resolve(y.value).then(i,k);v((s=s.apply(n,e)).next())});const C="field-snapshot",{defaultProps:G}=e.interfacesProperties,$="appends",T="targetField",A=()=>{let t=e.useRecord();for(;t!=null&&t.__parent&&Object.keys(t.__parent).length>0;)t=t.__parent;return t};function W(){var r;const{getCollectionField:t}=e.useCollectionManager_deprecated(),c=A(),a=s.useForm().values;return(r=t(`${c.name}.${a.targetField}`))==null?void 0:r.target}function q(t,c=[]){const{getCollection:a}=e.useCollectionManager_deprecated(),r=[];return t.forEach(o=>{var l,d,u,m;if(["belongsTo","hasOne","hasMany","belongsToMany"].includes(o.type)){const P=c.filter(f=>`${f}.`.startsWith(`${o.name}.`));if(P.length){const f=a(o.target),F=P.filter(p=>p!==o.name).map(p=>p.replace(`${o.name}.`,"")).filter(p=>p);r.push({label:(d=(l=o.uiSchema)==null?void 0:l.title)!=null?d:o.name,value:o.name,children:q(f.fields,F)})}}else r.push({label:(m=(u=o.uiSchema)==null?void 0:u.title)!=null?m:o.name,value:o.name})}),r}const L={type:"void",title:"{{t('View record')}}","x-component":"RecordPicker.Viewer","x-component-props":{className:"tb-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":"popup:snapshot:addBlock",properties:{}}}}}}}};class J extends e.CollectionFieldInterface{constructor(){super(...arguments);S(this,"name","snapshot");S(this,"type","object");S(this,"group","advanced");S(this,"title",`{{t('Snapshot', {ns: '${C}'})}}`);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: '${C}'})}}`);S(this,"default",{type:"snapshot",uiSchema:{"x-component":"SnapshotRecordPicker","x-component-props":{multiple:!0,fieldNames:{label:"id",value:"id"}}}});S(this,"properties",x(g({},G),{[T]:{type:"string",title:`{{t('The association field to snapshot', {ns: '${C}'})}}`,required:!0,"x-decorator":"FormItem","x-component":"SnapshotOwnerCollectionFieldsSelect","x-disabled":"{{ !createOnly || isOverride }}","x-reactions":[{target:$,when:"{{$self.value != undefined}}",fulfill:{state:{visible:!0}},otherwise:{state:{visible:!1}}}]},[$]:{type:"string",title:`{{t("Snapshot the snapshot's association fields", {ns: "${C}"})}}`,"x-decorator":"FormItem","x-component":"AppendsTreeSelect","x-component-props":{multiple:!0,useCollection:W},"x-reactions":[{dependencies:[T],when:"{{$deps[0]}}",fulfill:{run:"{{$self.setValue($self.value)}}"}}]}}))}schemaInitialize(a,{field:r,readPretty:o,action:l,block:d}){a.properties={viewer:h.cloneDeep(L)}}initialize(a){}usePathOptions(a){const{appends:r=[],targetCollection:o}=a,{getCollection:l}=e.useCollectionManager_deprecated(),{fields:d}=l(o),u=q(d,r);return[{label:`{{t('Snapshot data', { ns: '${C}' })}}`,value:"data",children:u}]}}const K=new e.SchemaInitializer({name:"popup:snapshot:addBlock",wrap:e.gridRowColWrap,title:`{{t("Add block", { ns: "${C}" })}}`,icon:"PlusOutlined",items:[{type:"itemGroup",title:'{{t("Current record blocks")}}',name:"currentRecordBlocks",children:[{name:"details",title:'{{t("Details")}}',Component:"SnapshotBlockInitializersDetailItem",actionInitializers:"details:configureActions"}]},{type:"itemGroup",title:'{{t("Other blocks")}}',name:"otherBlocks",children:[{name:"markdown",title:'{{t("Demonstration text")}}',Component:"MarkdownBlockInitializer"}]}]}),Q=()=>{const t=A(),{getCollection:c}=e.useCollectionManager_deprecated(),a=c(t.name),r=e.useCompile();return a.fields.filter(o=>!!o.target&&!!o.interface).map(o=>{var l;return x(g({},o),{label:r((l=o.uiSchema)==null?void 0:l.title),value:o.name})})},U=t=>{const c=Q();return i.jsx(v.Select,g({popupMatchSelectWidth:!1,options:c},t))},O=t=>{const f=t,{formItemInitializers:c="details:configureFields",actionInitializers:a="details:configureActions",collection:r,association:o,resource:l,template:d}=f,u=_(f,["formItemInitializers","actionInitializers","collection","association","resource","template"]),m=l||o||r;return{type:"void","x-acl-action":`${m}:get`,"x-decorator":"SnapshotBlockProvider","x-decorator-props":g({resource:m,collection:r,association:o,readPretty:!0,action:"get",useParams:"{{ useParamsFromRecord }}"},u),"x-designer":"FormV2.ReadPrettyDesigner","x-component":"CardItem",properties:{[s.uid()]:{type:"void","x-component":"FormV2","x-read-pretty":!0,"x-use-component-props":"useFormBlockProps",properties:{grid:d||{type:"void","x-component":"Grid","x-initializer":c,properties:{}}}}}}},X=()=>{const t=e.useSchemaInitializerItem(),b=t,{onCreateBlockSchema:c,componentType:a,createBlockSchema:r,icon:o=!0,targetCollection:l}=b,d=_(b,["onCreateBlockSchema","componentType","createBlockSchema","icon","targetCollection"]),{insert:u}=e.useSchemaInitializer(),{getTemplateSchemaByMode:m}=e.useSchemaTemplateManager(),P=l||e.useCollection_deprecated(),f=e.useBlockAssociationContext(),{block:F}=e.useBlockRequestContext(),p=F!=="TableField"?t.actionInitializers||"details:configureActions":null;return k.createElement(e.SchemaInitializerItem,x(g({icon:o&&i.jsx(y.FormOutlined,{})},d),{key:"snapshotDetail",onClick:de=>z(this,[de],function*({item:I}){if(I.template){const j=yield m(I);if(I.template.componentName==="ReadPrettyFormItem"){const E=O({actionInitializers:p,association:f,collection:P.name,action:"get",useSourceId:"{{ useSourceIdFromParentRecord }}",useParams:"{{ useParamsFromRecord }}",template:j});I.mode==="reference"&&(E["x-template-key"]=I.template.key),u(E)}else u(j)}else u(O({actionInitializers:p,association:f,collection:P.name,action:"get",useSourceId:"{{ useSourceIdFromParentRecord }}",useParams:"{{ useParamsFromRecord }}"}))}),items:e.useRecordCollectionDataSourceItems("ReadPrettyFormItem")}))},Y=t=>{var m;const{action:c,readPretty:a}=t,r=s.useField(),o=k.useMemo(()=>s.createForm({readPretty:a}),[]),{resource:l,service:d}=e.useBlockRequestContext(),u=k.useRef();return d.loading?i.jsx(v.Spin,{}):i.jsx(e.FormBlockContext.Provider,{value:{action:c,form:o,field:r,service:d,resource:l,updateAssociationValues:[],formBlockRef:u},children:a?i.jsx(e.RecordProvider,{record:(m=d==null?void 0:d.data)==null?void 0:m.data,children:i.jsx("div",{ref:u,children:t.children})}):i.jsx("div",{ref:u,children:t.children})})},Z=t=>{const c=s.useField(),a=e.useBlockResource(),r={loading:!1,data:{data:e.useRecord()}},o=e.useBlockRequestContext();return i.jsx(e.BlockRequestContext_deprecated.Provider,{value:{block:t.block,props:t,field:c,service:r,resource:a,__parent:o},children:t.children})},ee=t=>{const{collection:c,association:a,dataSource:r}=t,o=e.useResource(t);return i.jsx(e.CollectionManagerProvider,{dataSource:r,children:i.jsx(e.MaybeCollectionProvider,{collection:c,children:i.jsx(e.BlockAssociationContext.Provider,{value:a,children:i.jsx(e.BlockResourceContext.Provider,{value:o,children:i.jsx(Z,x(g({},t),{children:t.children}))})})})})},te=t=>{const c=e.useRecord(),{__tableName:a}=c,{getInheritCollections:r}=e.useCollectionManager_deprecated(t.dataSource),o=r(a),{designable:l}=e.useDesignable();return!(!l&&a&&!o.includes(t.collection)&&a!==t.collection)&&i.jsx(ee,x(g({},t),{children:i.jsx(Y,g({},t))}))},oe=t=>{var P,f,F;const{collectionName:c}=t,{collections:a}=e.useCollectionManager_deprecated(),r=(P=e.useHistoryCollectionsByNames([c]))==null?void 0:P[0],o=e.useHistoryCollectionsByNames((f=r==null?void 0:r.inherits)!=null?f:[]),l=e.useHistoryCollectionsByNames((F=r==null?void 0:r.fields.filter(p=>p.interface!=="snapshot").map(p=>p.target))!=null?F:[]),d=[r,...l,...o].filter(p=>p),m=[...a.filter(p=>!d.map(b=>b.name).includes(p.name)),...d];return i.jsx(e.ExtendCollectionsProvider,{collections:m,children:i.jsx(e.CollectionManagerProvider_deprecated,{children:t.children})})},R=t=>{const c=s.useFieldSchema(),{getField:a}=e.useCollection_deprecated(),r=a(c.name);return i.jsx(oe,{collectionName:r==null?void 0:r.targetCollection,children:i.jsx(e.ReadPrettyRecordPicker,g({},t))})},ne=s.connect(R,s.mapReadPretty(R)),re=t=>{const l=t,{value:c,onChange:a}=l,r=_(l,["value","onChange"]),o=x(g({},r),{value:c==null?void 0:c.data,onChange:d=>a({data:d})});return i.jsx(ne,g({},o))},D=k.memo(t=>i.jsx(e.CollectionHistoryProvider,{children:i.jsx(e.SchemaComponentOptions,{components:{SnapshotRecordPicker:re,SnapshotBlockProvider:te,SnapshotBlockInitializersDetailItem:X,SnapshotOwnerCollectionFieldsSelect:U},children:t.children})}));D.displayName="SnapshotFieldProvider";class N extends e.Plugin{load(){return z(this,null,function*(){this.app.use(D),this.app.schemaInitializerManager.add(K),this.app.dataSourceManager.addFieldInterfaces([J])})}}n.SnapshotFieldPlugin=N,n.default=N,Object.defineProperties(n,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
1
+ (function(r,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("@tachybase/client"),require("@tachybase/schema"),require("lodash"),require("react-i18next"),require("react/jsx-runtime"),require("react"),require("antd"),require("@ant-design/icons")):typeof define=="function"&&define.amd?define(["exports","@tachybase/client","@tachybase/schema","lodash","react-i18next","react/jsx-runtime","react","antd","@ant-design/icons"],e):(r=typeof globalThis!="undefined"?globalThis:r||self,e(r["@tachybase/plugin-field-snapshot"]={},r["@tachybase/client"],r["@tachybase/schema"],r.lodash,r["react-i18next"],r.jsxRuntime,r.react,r.antd,r["@ant-design/icons"]))})(this,function(r,e,a,u,_,i,x,k,y){"use strict";var re=Object.defineProperty,se=Object.defineProperties;var ae=Object.getOwnPropertyDescriptors;var b=Object.getOwnPropertySymbols;var E=Object.prototype.hasOwnProperty,V=Object.prototype.propertyIsEnumerable;var j=(r,e,a)=>e in r?re(r,e,{enumerable:!0,configurable:!0,writable:!0,value:a}):r[e]=a,g=(r,e)=>{for(var a in e||(e={}))E.call(e,a)&&j(r,a,e[a]);if(b)for(var a of b(e))V.call(e,a)&&j(r,a,e[a]);return r},S=(r,e)=>se(r,ae(e));var B=(r,e)=>{var a={};for(var u in r)E.call(r,u)&&e.indexOf(u)<0&&(a[u]=r[u]);if(r!=null&&b)for(var u of b(r))e.indexOf(u)<0&&V.call(r,u)&&(a[u]=r[u]);return a};var M=(r,e,a)=>new Promise((u,_)=>{var i=y=>{try{k(a.next(y))}catch(C){_(C)}},x=y=>{try{k(a.throw(y))}catch(C){_(C)}},k=y=>y.done?u(y.value):Promise.resolve(y.value).then(i,x);k((a=a.apply(r,e)).next())});const C="field-snapshot",{defaultProps:H}=e.interfacesProperties,w="appends",z="targetField",$=()=>{let t=e.useRecord();for(;t!=null&&t.__parent&&Object.keys(t.__parent).length>0;)t=t.__parent;return t};function G(){var n;const{getCollectionField:t}=e.useCollectionManager_deprecated(),s=$(),c=a.useForm().values;return(n=t(`${s.name}.${c.targetField}`))==null?void 0:n.target}function T(t,s=[]){const{getCollection:c}=e.useCollectionManager_deprecated(),n=[];return t.forEach(o=>{var l,d,h,m;if(["belongsTo","hasOne","hasMany","belongsToMany"].includes(o.type)){const P=s.filter(f=>`${f}.`.startsWith(`${o.name}.`));if(P.length){const f=c(o.target),v=P.filter(p=>p!==o.name).map(p=>p.replace(`${o.name}.`,"")).filter(p=>p);n.push({label:(d=(l=o.uiSchema)==null?void 0:l.title)!=null?d:o.name,value:o.name,children:T(f.fields,v)})}}else n.push({label:(m=(h=o.uiSchema)==null?void 0:h.title)!=null?m:o.name,value:o.name})}),n}const W={type:"void",title:"{{t('View record')}}","x-component":"RecordPicker.Viewer","x-component-props":{className:"tb-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":"popup:snapshot:addBlock",properties:{}}}}}}}};class L extends e.CollectionFieldInterface{constructor(){super(...arguments),this.name="snapshot",this.type="object",this.group="advanced",this.title=`{{t('Snapshot', {ns: '${C}'})}}`,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: '${C}'})}}`,this.default={type:"snapshot",uiSchema:{"x-component":"SnapshotRecordPicker","x-component-props":{multiple:!0,fieldNames:{label:"id",value:"id"}}}},this.properties=S(g({},H),{[z]:{type:"string",title:`{{t('The association field to snapshot', {ns: '${C}'})}}`,required:!0,"x-decorator":"FormItem","x-component":"SnapshotOwnerCollectionFieldsSelect","x-disabled":"{{ !createOnly || isOverride }}","x-reactions":[{target:w,when:"{{$self.value != undefined}}",fulfill:{state:{visible:!0}},otherwise:{state:{visible:!1}}}]},[w]:{type:"string",title:`{{t("Snapshot the snapshot's association fields", {ns: "${C}"})}}`,"x-decorator":"FormItem","x-component":"AppendsTreeSelect","x-component-props":{multiple:!0,useCollection:G},"x-reactions":[{dependencies:[z],when:"{{$deps[0]}}",fulfill:{run:"{{$self.setValue($self.value)}}"}}]}})}schemaInitialize(s,{field:c,readPretty:n,action:o,block:l}){s.properties={viewer:u.cloneDeep(W)}}initialize(s){}usePathOptions(s){const{appends:c=[],targetCollection:n}=s,{getCollection:o}=e.useCollectionManager_deprecated(),{fields:l}=o(n),d=T(l,c);return[{label:`{{t('Snapshot data', { ns: '${C}' })}}`,value:"data",children:d}]}}const J=new e.SchemaInitializer({name:"popup:snapshot:addBlock",wrap:e.gridRowColWrap,title:`{{t("Add block", { ns: "${C}" })}}`,icon:"PlusOutlined",items:[{type:"itemGroup",title:'{{t("Current record blocks")}}',name:"currentRecordBlocks",children:[{name:"details",title:'{{t("Details")}}',Component:"SnapshotBlockInitializersDetailItem",actionInitializers:"details:configureActions"}]},{type:"itemGroup",title:'{{t("Other blocks")}}',name:"otherBlocks",children:[{name:"markdown",title:'{{t("Demonstration text")}}',Component:"MarkdownBlockInitializer"}]}]}),K=()=>{const t=$(),{getCollection:s}=e.useCollectionManager_deprecated(),c=s(t.name),n=e.useCompile();return c.fields.filter(o=>!!o.target&&!!o.interface).map(o=>{var l;return S(g({},o),{label:n((l=o.uiSchema)==null?void 0:l.title),value:o.name})})},Q=t=>{const s=K();return i.jsx(k.Select,g({popupMatchSelectWidth:!1,options:s},t))},A=t=>{const f=t,{formItemInitializers:s="details:configureFields",actionInitializers:c="details:configureActions",collection:n,association:o,resource:l,template:d}=f,h=B(f,["formItemInitializers","actionInitializers","collection","association","resource","template"]),m=l||o||n;return{type:"void","x-acl-action":`${m}:get`,"x-decorator":"SnapshotBlockProvider","x-decorator-props":g({resource:m,collection:n,association:o,readPretty:!0,action:"get",useParams:"{{ useParamsFromRecord }}"},h),"x-designer":"FormV2.ReadPrettyDesigner","x-component":"CardItem",properties:{[a.uid()]:{type:"void","x-component":"FormV2","x-read-pretty":!0,"x-use-component-props":"useFormBlockProps",properties:{grid:d||{type:"void","x-component":"Grid","x-initializer":s,properties:{}}}}}}},U=()=>{const t=e.useSchemaInitializerItem(),I=t,{onCreateBlockSchema:s,componentType:c,createBlockSchema:n,icon:o=!0,targetCollection:l}=I,d=B(I,["onCreateBlockSchema","componentType","createBlockSchema","icon","targetCollection"]),{insert:h}=e.useSchemaInitializer(),{getTemplateSchemaByMode:m}=e.useSchemaTemplateManager(),P=l||e.useCollection_deprecated(),f=e.useBlockAssociationContext(),{block:v}=e.useBlockRequestContext(),p=v!=="TableField"?t.actionInitializers||"details:configureActions":null;return x.createElement(e.SchemaInitializerItem,S(g({icon:o&&i.jsx(y.FormOutlined,{})},d),{key:"snapshotDetail",onClick:le=>M(this,[le],function*({item:F}){if(F.template){const D=yield m(F);if(F.template.componentName==="ReadPrettyFormItem"){const N=A({actionInitializers:p,association:f,collection:P.name,action:"get",useSourceId:"{{ useSourceIdFromParentRecord }}",useParams:"{{ useParamsFromRecord }}",template:D});F.mode==="reference"&&(N["x-template-key"]=F.template.key),h(N)}else h(D)}else h(A({actionInitializers:p,association:f,collection:P.name,action:"get",useSourceId:"{{ useSourceIdFromParentRecord }}",useParams:"{{ useParamsFromRecord }}"}))}),items:e.useRecordCollectionDataSourceItems("ReadPrettyFormItem")}))},X=t=>{var m;const{action:s,readPretty:c}=t,n=a.useField(),o=x.useMemo(()=>a.createForm({readPretty:c}),[]),{resource:l,service:d}=e.useBlockRequestContext(),h=x.useRef();return d.loading?i.jsx(k.Spin,{}):i.jsx(e.FormBlockContext.Provider,{value:{action:s,form:o,field:n,service:d,resource:l,updateAssociationValues:[],formBlockRef:h},children:c?i.jsx(e.RecordProvider,{record:(m=d==null?void 0:d.data)==null?void 0:m.data,children:i.jsx("div",{ref:h,children:t.children})}):i.jsx("div",{ref:h,children:t.children})})},Y=t=>{const s=a.useField(),c=e.useBlockResource(),n={loading:!1,data:{data:e.useRecord()}},o=e.useBlockRequestContext();return i.jsx(e.BlockRequestContext_deprecated.Provider,{value:{block:t.block,props:t,field:s,service:n,resource:c,__parent:o},children:t.children})},Z=t=>{const{collection:s,association:c,dataSource:n}=t,o=e.useResource(t);return i.jsx(e.CollectionManagerProvider,{dataSource:n,children:i.jsx(e.MaybeCollectionProvider,{collection:s,children:i.jsx(e.BlockAssociationContext.Provider,{value:c,children:i.jsx(e.BlockResourceContext.Provider,{value:o,children:i.jsx(Y,S(g({},t),{children:t.children}))})})})})},ee=t=>{const s=e.useRecord(),{__tableName:c}=s,{getInheritCollections:n}=e.useCollectionManager_deprecated(t.dataSource),o=n(c),{designable:l}=e.useDesignable();return!(!l&&c&&!o.includes(t.collection)&&c!==t.collection)&&i.jsx(Z,S(g({},t),{children:i.jsx(X,g({},t))}))},te=t=>{var P,f,v;const{collectionName:s}=t,{collections:c}=e.useCollectionManager_deprecated(),n=(P=e.useHistoryCollectionsByNames([s]))==null?void 0:P[0],o=e.useHistoryCollectionsByNames((f=n==null?void 0:n.inherits)!=null?f:[]),l=e.useHistoryCollectionsByNames((v=n==null?void 0:n.fields.filter(p=>p.interface!=="snapshot").map(p=>p.target))!=null?v:[]),d=[n,...l,...o].filter(p=>p),m=[...c.filter(p=>!d.map(I=>I.name).includes(p.name)),...d];return i.jsx(e.ExtendCollectionsProvider,{collections:m,children:i.jsx(e.CollectionManagerProvider_deprecated,{children:t.children})})},q=t=>{const s=a.useFieldSchema(),{getField:c}=e.useCollection_deprecated(),n=c(s.name);return i.jsx(te,{collectionName:n==null?void 0:n.targetCollection,children:i.jsx(e.ReadPrettyRecordPicker,g({},t))})},oe=a.connect(q,a.mapReadPretty(q)),ne=t=>{const l=t,{value:s,onChange:c}=l,n=B(l,["value","onChange"]),o=S(g({},n),{value:s==null?void 0:s.data,onChange:d=>c({data:d})});return i.jsx(oe,g({},o))},O=x.memo(t=>i.jsx(e.CollectionHistoryProvider,{children:i.jsx(e.SchemaComponentOptions,{components:{SnapshotRecordPicker:ne,SnapshotBlockProvider:ee,SnapshotBlockInitializersDetailItem:U,SnapshotOwnerCollectionFieldsSelect:Q},children:t.children})}));O.displayName="SnapshotFieldProvider";class R extends e.Plugin{load(){return M(this,null,function*(){this.app.use(O),this.app.schemaInitializerManager.add(J),this.app.dataSourceManager.addFieldInterfaces([L])})}}r.SnapshotFieldPlugin=R,r.default=R,Object.defineProperties(r,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -1,10 +1,10 @@
1
1
  module.exports = {
2
2
  "react": "18.3.1",
3
- "@tachybase/client": "0.23.41",
4
- "@tachybase/schema": "0.23.41",
3
+ "@tachybase/client": "0.23.48",
4
+ "@tachybase/schema": "0.23.48",
5
5
  "lodash": "4.17.21",
6
- "@tachybase/database": "0.23.41",
7
- "@tachybase/server": "0.23.41",
6
+ "@tachybase/database": "0.23.48",
7
+ "@tachybase/server": "0.23.48",
8
8
  "antd": "5.22.5",
9
9
  "react-i18next": "15.2.0",
10
10
  "@ant-design/icons": "5.3.7"
@@ -22,39 +22,42 @@ __export(field_snapshot_exports, {
22
22
  module.exports = __toCommonJS(field_snapshot_exports);
23
23
  var import_database = require("@tachybase/database");
24
24
  class SnapshotField extends import_database.Field {
25
+ constructor() {
26
+ super(...arguments);
27
+ this.createSnapshot = async (model, { transaction, values }) => {
28
+ const { name, targetField } = this.options;
29
+ const collectionName = this.collection.name;
30
+ const primaryKey = this.collection.model.primaryKeyAttribute;
31
+ if (!this.collection.hasField(targetField)) {
32
+ return;
33
+ }
34
+ const repository = this.database.getRepository(`${collectionName}.${targetField}`, model.get(primaryKey));
35
+ const appends = (this.options.appends || []).filter(
36
+ (appendName) => this.database.getFieldByPath(`${repository.targetCollection.name}.${appendName}`)
37
+ );
38
+ let data = await repository.find({
39
+ transaction,
40
+ appends
41
+ });
42
+ if (Array.isArray(data)) {
43
+ data = data.map((i) => i.toJSON());
44
+ } else if (data == null ? void 0 : data.toJSON) {
45
+ data = data.toJSON();
46
+ }
47
+ await model.update(
48
+ {
49
+ [name]: {
50
+ collectionName,
51
+ data
52
+ }
53
+ },
54
+ { transaction }
55
+ );
56
+ };
57
+ }
25
58
  get dataType() {
26
59
  return import_database.DataTypes.JSON;
27
60
  }
28
- createSnapshot = async (model, { transaction, values }) => {
29
- const { name, targetField } = this.options;
30
- const collectionName = this.collection.name;
31
- const primaryKey = this.collection.model.primaryKeyAttribute;
32
- if (!this.collection.hasField(targetField)) {
33
- return;
34
- }
35
- const repository = this.database.getRepository(`${collectionName}.${targetField}`, model.get(primaryKey));
36
- const appends = (this.options.appends || []).filter(
37
- (appendName) => this.database.getFieldByPath(`${repository.targetCollection.name}.${appendName}`)
38
- );
39
- let data = await repository.find({
40
- transaction,
41
- appends
42
- });
43
- if (Array.isArray(data)) {
44
- data = data.map((i) => i.toJSON());
45
- } else if (data == null ? void 0 : data.toJSON) {
46
- data = data.toJSON();
47
- }
48
- await model.update(
49
- {
50
- [name]: {
51
- collectionName,
52
- data
53
- }
54
- },
55
- { transaction }
56
- );
57
- };
58
61
  bind() {
59
62
  super.bind();
60
63
  this.on("afterCreateWithAssociations", this.createSnapshot);
@@ -25,6 +25,20 @@ var import_path = require("path");
25
25
  var import_server = require("@tachybase/server");
26
26
  var import_field_snapshot = require("./fields/field-snapshot");
27
27
  class SnapshotFieldPlugin extends import_server.Plugin {
28
+ constructor() {
29
+ super(...arguments);
30
+ this.autoFillTargetCollection = async (model) => {
31
+ const { collectionName, targetField } = model.get();
32
+ const collection = this.db.getCollection(collectionName);
33
+ if (!collection) {
34
+ return;
35
+ }
36
+ const field = collection.getField(targetField);
37
+ if (field == null ? void 0 : field.target) {
38
+ model.set("targetCollection", field.target);
39
+ }
40
+ };
41
+ }
28
42
  afterAdd() {
29
43
  }
30
44
  async beforeLoad() {
@@ -73,17 +87,6 @@ class SnapshotFieldPlugin extends import_server.Plugin {
73
87
  this.app.db.on("fields.afterCreateWithAssociations", fieldHandler);
74
88
  this.app.db.on("fields.beforeCreate", this.autoFillTargetCollection);
75
89
  }
76
- autoFillTargetCollection = async (model) => {
77
- const { collectionName, targetField } = model.get();
78
- const collection = this.db.getCollection(collectionName);
79
- if (!collection) {
80
- return;
81
- }
82
- const field = collection.getField(targetField);
83
- if (field == null ? void 0 : field.target) {
84
- model.set("targetCollection", field.target);
85
- }
86
- };
87
90
  async load() {
88
91
  await this.importCollections((0, import_path.resolve)(__dirname, "collections"));
89
92
  this.app.db.registerFieldTypes({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tachybase/plugin-field-snapshot",
3
3
  "displayName": "Collection field: Snapshot",
4
- "version": "0.23.41",
4
+ "version": "0.23.48",
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
  "keywords": [
7
7
  "Collection fields"
@@ -16,14 +16,14 @@
16
16
  "rc-tree-select": "5.25.0",
17
17
  "react": "~18.3.1",
18
18
  "react-i18next": "^15.2.0",
19
- "@tachybase/schema": "0.23.41"
19
+ "@tachybase/schema": "0.23.48"
20
20
  },
21
21
  "peerDependencies": {
22
- "@tachybase/client": "0.23.41",
23
- "@tachybase/server": "0.23.41",
24
- "@tachybase/database": "0.23.41",
25
- "@tachybase/test": "0.23.41",
26
- "@tachybase/utils": "0.23.41"
22
+ "@tachybase/client": "0.23.48",
23
+ "@tachybase/database": "0.23.48",
24
+ "@tachybase/server": "0.23.48",
25
+ "@tachybase/utils": "0.23.48",
26
+ "@tachybase/test": "0.23.48"
27
27
  },
28
28
  "description.zh-CN": "在添加数据时,为它的关系数据创建快照,并保存在当前的数据中。关系数据更新时,快照不会更新。",
29
29
  "displayName.zh-CN": "数据表字段:关系快照",