@tachybase/plugin-block-comments 0.23.20 → 0.23.35

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,3 +1,3 @@
1
- (function(c,n){typeof exports=="object"&&typeof module!="undefined"?n(exports,require("react"),require("@tachybase/client"),require("react-i18next"),require("@tachybase/schema"),require("@ant-design/icons"),require("react/jsx-runtime"),require("lodash"),require("antd"),require("dayjs")):typeof define=="function"&&define.amd?define(["exports","react","@tachybase/client","react-i18next","@tachybase/schema","@ant-design/icons","react/jsx-runtime","lodash","antd","dayjs"],n):(c=typeof globalThis!="undefined"?globalThis:c||self,n(c["@tachybase/plugin-block-comments"]={},c.react,c["@tachybase/client"],c["react-i18next"],c["@tachybase/schema"],c["@ant-design/icons"],c.jsxRuntime,c.lodash,c.antd,c.dayjs))})(this,function(c,n,t,T,u,L,r,F,x,B){"use strict";var re=Object.defineProperty,se=Object.defineProperties;var ie=Object.getOwnPropertyDescriptors;var Q=Object.getOwnPropertySymbols;var ce=Object.prototype.hasOwnProperty,le=Object.prototype.propertyIsEnumerable;var N=(c,n,t)=>n in c?re(c,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):c[n]=t,b=(c,n)=>{for(var t in n||(n={}))ce.call(n,t)&&N(c,t,n[t]);if(Q)for(var t of Q(n))le.call(n,t)&&N(c,t,n[t]);return c},v=(c,n)=>se(c,ie(n));var A=(c,n,t)=>N(c,typeof n!="symbol"?n+"":n,t);var D=(c,n,t)=>new Promise((T,u)=>{var L=x=>{try{F(t.next(x))}catch(B){u(B)}},r=x=>{try{F(t.throw(x))}catch(B){u(B)}},F=x=>x.done?T(x.value):Promise.resolve(x.value).then(L,r);F((t=t.apply(c,n)).next())});function M(e){return t.tval(e,{ns:E})}const E="block-comments";function z(){return T.useTranslation(E)}const U=new t.SchemaInitializer({name:"comment:configureItemActions",title:'{{t("Configure actions")}}',icon:"SettingOutlined",items:[{type:"itemGroup",name:"enableActions",title:'{{t("Enable actions")}}',children:[{name:"edit",title:'{{t("Edit")}}',Component:"UpdateCommentActionInitializer",schema:{"x-action":"update","x-decorator":"ACLActionProvider","x-align":"left"},useVisible(){const e=t.useCollection_deprecated();return(e.template!=="view"||(e==null?void 0:e.writableView))&&e.template!=="sql"}},{name:"delete",title:'{{t("Delete")}}',Component:"DestroyActionInitializer",schema:{"x-component":"Action.Link","x-action":"destroy","x-decorator":"ACLActionProvider","x-align":"left"},useVisible(){return t.useCollection_deprecated().template!=="sql"}},{name:"reply",title:M("Quote Reply"),Component:"QuoteReplyCommentActionInitializer",schema:{"x-action":"create","x-decorator":"ACLActionProvider","x-align":"left"},useVisible(){return t.useCollection_deprecated().template!=="sql"}}]}]}),_=({collectionName:e,dataSource:o,association:a,rowKey:l})=>({type:"void","x-acl-action":`${a||e}:view`,"x-decorator":"Comment.Decorator","x-use-decorator-props":"useCommentBlockDecoratorProps","x-decorator-props":{collection:e,dataSource:o,association:a,readPretty:!0,action:"list",runWhenParamsChanged:!0},"x-component":"CardItem","x-toolbar":"BlockSchemaToolbar","x-settings":"blockSettings:comment",properties:{list:{type:"array","x-component":"Comment.List",properties:{item:{type:"object","x-component":"Comment.Item","x-read-pretty":!0,properties:{actionBar:{type:"void","x-align":"left","x-initializer":"comment:configureItemActions","x-component":"ActionBar","x-component-props":{layout:"one-column"}}}}}},submit:{type:"string","x-component":"Comment.Submit","x-acl-action":`${a||e}:create`,"x-decorator":"ACLCollectionProvider","x-decorator-props":{collection:e,dataSource:o,association:a}}}}),H=({filterCollections:e,filterOtherRecordsCollection:o,onlyCurrentDataSource:a,hideSearch:l,showAssociationFields:C,hideOtherRecordsInPopup:h})=>{const{insert:s}=t.useSchemaInitializer(),i=t.useSchemaInitializerItem();n.useContext(u.SchemaOptionsContext);const{getCollection:d}=t.useCollectionManager_deprecated();return r.jsx(t.DataBlockInitializer,v(b({},i),{componentType:"Comment",icon:r.jsx(L.CommentOutlined,{}),onlyCurrentDataSource:a,hideSearch:l,filter:e,filterOtherRecordsCollection:o,showAssociationFields:C,hideOtherRecordsInPopup:h,onCreateBlockSchema:w=>D(this,[w],function*({item:f,fromOthersInPopup:m}){const P=d(f.name,f.dataSource),k=f.associationField;s(_(k&&!m?{dataSource:f.dataSource,rowKey:P.filterTargetKey||"id",association:`${k.collectionName}.${k.name}`}:{collectionName:f.name,dataSource:f.dataSource,rowKey:P.filterTargetKey||"id"}))})}))},V=n.createContext({});function O(){return n.useContext(V)}const K=new t.SchemaSettings({name:"blockSettings:comment",items:[{name:"title",Component:t.SchemaSettingsBlockTitleItem},{name:"SetTheDataScope",Component:t.SchemaSettingsDataScope,useComponentProps(){var h,s;const{name:e}=t.useCollection_deprecated(),o=u.useFieldSchema(),{form:a}=t.useFormBlockContext(),l=u.useField(),{dn:C}=t.useDesignable();return{collectionName:e,defaultFilter:((s=(h=o==null?void 0:o["x-decorator-props"])==null?void 0:h.params)==null?void 0:s.filter)||{},form:a,onSubmit:({filter:i})=>{i=t.removeNullCondition(i),F.set(o,"x-decorator-props.params.filter",i),l.decoratorProps.params=v(b({},o["x-decorator-props"].params),{page:1}),C.emit("patch",{schema:{"x-uid":o["x-uid"],"x-decorator-props":o["x-decorator-props"]}})}}}},{name:"divider",type:"divider"},{name:"EnableCreate",type:"switch",useComponentProps(){const{setCreateAble:e,createAble:o}=O(),{t:a}=z();return{title:a("Enable Create"),checked:o,onChange:e}}},{name:"remove",type:"remove",componentProps:{removeParentsIfNoChildren:!0,breakRemoveOn:{"x-component":"Grid"}}}]});class W extends t.CollectionTemplate{constructor(){super(...arguments);A(this,"name","comment");A(this,"title",M("Comment Collection"));A(this,"order",2);A(this,"color","orange");A(this,"default",{fields:[{name:"content",type:"text",length:"long",interface:"vditor",deletable:!1,uiSchema:{type:"string",title:M("Comment Content"),interface:"vditor","x-component":"MarkdownVditor"}}]});A(this,"presetFieldsDisabled",!0);A(this,"configurableProperties",t.getConfigurableProperties("title","name","inherits","category","description","presetFields"))}}const G=t.withDynamicSchemaProps(e=>{let o;return r.jsx(Y,v(b({},e),{children:r.jsx(t.List.Decorator,v(b({},e),{children:r.jsx(t.CollectionManagerProvider,{dataSource:e.dataSource,children:r.jsx(t.CollectionProvider,{name:`${(o=e.association)!=null?o:e.collection}`,children:e.children})})}))}))});function Y(e){u.useField();const o=u.useFieldSchema(),[a,l]=n.useState(!1),{dn:C}=t.useDesignable();n.useEffect(()=>{var d;const i=(d=C.current["x-component-props"])==null?void 0:d.createAble;l(i===void 0?!0:i)},[]);const h=n.useCallback(i=>{const d=Object.assign({},o["x-component-props"],i);o["x-component-props"]=d,C.emit("patch",{schema:{"x-uid":o["x-uid"],"x-component-props":o["x-component-props"]}}),C.refresh()},[C,o]),s=n.useCallback(i=>{h({createAble:i}),l(i)},[l,h]);return r.jsx(V.Provider,{value:{createAble:a,setCreateAble:s},children:e.children})}const q=t.genStyleHook("tb-comment",e=>{const{componentCls:o}=e;return{[o]:{[`${o}-item-container-container`]:{"&:first-child":{border:"5px solid #d0d7deb3",position:"relative",zIndex:1,borderRadius:8}},[`${o}-item-container-border`]:{border:"1px solid #d0d7deb3",position:"relative",zIndex:1,borderRadius:8},[`${o}-item-container-line`]:{position:"absolute",top:0,bottom:0,content:"",display:"block",width:2,left:16,backgroundColor:"#d0d7deb3",zIndex:0},".ant-list-pagination":{marginTop:e.marginXS},".ant-card-head":{padding:"0 !important",fontWeight:"normal",backgroundColor:"#f6f8fa"},[`${o}-item-title`]:{color:"#636c76",display:"flex",alignItems:"center",paddingLeft:16,borderRadius:"8px 8px 0 0 ",justifyContent:"space-between",flexWrap:"wrap",[`${o}-item-title-left`]:{backgroundColor:"#f6f8fa",color:"#636c76",display:"flex",alignItems:"center",columnGap:6,"span:first-child":{fontWeight:"bold",fontSize:14},"span:not(:first-child)":{fontWeight:"normal",fontSize:14}},[`${o}-item-title-right`]:{marginRight:16,flexShrink:0}},[`${o}-item-editor`]:{position:"relative",zIndex:2,backgroundColor:"white",borderRadius:"0 0 8px 8px",[`${o}-item-editor-button-area`]:{marginTop:10,display:"flex",columnGap:5}}}}}),X=u.observer(({editing:e,setEditing:o,children:a})=>{var S,g;let l,C,h;const s=u.useField(),{t:i}=z(),{componentCls:d}=q(),f=t.useCollectionParentRecordData(),{resource:m,service:w}=t.useBlockRequestContext(),P=n.useCallback(()=>()=>D(this,null,function*(){var p,y;yield m.update({filterByTk:(p=s.value)==null?void 0:p.id,values:{content:(y=s==null?void 0:s.value)==null?void 0:y.content}}),w.refresh()}),[m,w,s.value]),k=t.useCollectionFields(),I=n.useMemo(()=>{let p,y;return(y=(p=k.find(j=>j.name==="content"))==null?void 0:p.uiSchema)==null?void 0:y["x-component-props"]},[k]);return r.jsx(t.RecordProvider,{record:s.value,parent:f,children:r.jsxs("div",{className:`${d}-item-container`,children:[r.jsx("div",{className:`${d}-item-container-line`}),r.jsx(x.Card,{size:"small",title:r.jsxs("div",{className:`${d}-item-title`,children:[r.jsxs("div",{className:`${d}-item-title-left`,children:[r.jsx("span",{children:(C=(l=s==null?void 0:s.value)==null?void 0:l.createdBy)==null?void 0:C.nickname}),r.jsx("span",{children:i("commented")}),r.jsx(x.Tooltip,{title:B((h=s==null?void 0:s.value)==null?void 0:h.createdAt).format("YYYY-MM-DD HH:mm:ss"),children:r.jsx("span",{children:B((S=s==null?void 0:s.value)==null?void 0:S.createdAt).fromNow()})})]}),r.jsx("div",{className:`${d}-item-title-right`,children:a})]}),children:r.jsxs("div",{className:`${d}-item-editor`,children:[r.jsx(u.RecursionField,{basePath:s.address,name:"content",schema:{type:"string",name:"content","x-component":"MarkdownVditor","x-component-props":v(b({},I),{value:(g=s==null?void 0:s.value)==null?void 0:g.content}),"x-read-pretty":!0}}),e&&r.jsxs("div",{className:`${d}-item-editor-button-area`,children:[r.jsx(x.Button,{onClick:()=>{s.form.setFieldState(`${s.address}.content`,p=>{p.pattern="readPretty"}),o(!1)},children:i("Cancel")}),r.jsx(x.Button,{type:"primary",onClick:()=>{o(!1),P(),s.form.setFieldState(`${s.address}.content`,p=>{p.pattern="readPretty"})},children:i("Update Comment")})]})]})})]})})}),J=t.withDynamicSchemaProps(e=>{var k,I;const o=u.useFieldSchema(),a=u.useField(),[l]=n.useState(new Map),{wrapSSR:C,hashId:h,componentCls:s}=q();u.useForm();const{service:i}=t.useBlockRequestContext(),{run:d,params:f}=i,m=(k=i==null?void 0:i.data)==null?void 0:k.meta,w=n.useCallback(S=>(l.has(S)||l.set(S,new u.Schema({type:"object",properties:{[S]:o.properties.item}})),l.get(S)),[o.properties,l]),P=n.useCallback((S,g)=>{d(v(b({},f==null?void 0:f[0]),{page:S,pageSize:g}))},[d,f]);return i!=null&&i.loading?r.jsx("div",{style:{display:"flex",justifyContent:"center"},children:r.jsx(x.Spin,{spinning:!0})}):C(r.jsx("div",{className:`${s} ${h}`,children:r.jsx(x.List,v(b({},e),{pagination:!m||m.count<=m.pageSize?!1:{onChange:P,total:(m==null?void 0:m.count)||0,pageSize:(m==null?void 0:m.pageSize)||10,current:(m==null?void 0:m.page)||1},children:r.jsx("div",{style:{display:"flex",flexDirection:"column"},children:(I=a.value)!=null&&I.length?a.value.map((S,g)=>{const p=g===0,y=g===a.value.length-1;return r.jsx("div",{style:{position:"relative",padding:`${p?0:"10px"} 0 ${y?0:"10px"} 0`},children:r.jsx(u.RecursionField,{basePath:a.address,name:g,onlyRenderProperties:!0,schema:w(g)})},g)}):null})}))}))});function Z(){var g;const e=u.useField(),o=n.useCallback(p=>{e.setValue(v(b({},e.value),{content:p}))},[e]),{t:a}=z(),{wrapSSR:l,componentCls:C,hashId:h}=q(),s=n.useMemo(()=>{var p,y;return((y=(p=e.value)==null?void 0:p.content)==null?void 0:y.trim().length)>0},[e.value]),{resource:i,service:d}=t.useBlockRequestContext(),f=n.useCallback(()=>D(this,null,function*(){yield i.create({values:e.value}),o(""),d.refresh()}),[i,e,d,o]),{createAble:m}=O(),w=t.useACLActionParamsContext(),{designable:P}=t.useDesignable(),k=!P&&(((g=e==null?void 0:e.data)==null?void 0:g.hidden)||!w),I=t.useCollectionFields(),S=n.useMemo(()=>{var p,y;return(y=(p=I.find(j=>j.name==="content"))==null?void 0:p.uiSchema)==null?void 0:y["x-component-props"]},[I]);return!m||k?null:l(r.jsxs("div",{style:{marginTop:10},className:`${C} ${h}`,children:[r.jsx(u.RecursionField,{basePath:e.address,name:"content",schema:{type:"string","x-component":"MarkdownVditor","x-component-props":v(b({},S),{onChange:p=>{o(p)}}),"x-read-pretty":!1,"x-read-only":!1,name:"content"}}),r.jsx(x.Button,{disabled:!s,onClick:f,type:"primary",style:{marginTop:10},children:a("Comment")})]}))}function R(){var h;const e=u.useField(),{t:o}=z(),a=t.useACLActionParamsContext(),{designable:l}=t.useDesignable(),C=n.useCallback(()=>{var f;const s=e.address.slice(0,e.address.length-4).concat("submit.content"),i=e.address.slice(0,e.address.length-2).concat("content"),d=(f=e.form.getValuesIn(i))!=null?f:"";e.form.setValuesIn(s,`${d.split(`
1
+ (function(c,n){typeof exports=="object"&&typeof module!="undefined"?n(exports,require("react"),require("@tachybase/client"),require("react-i18next"),require("@tachybase/schema"),require("@ant-design/icons"),require("react/jsx-runtime"),require("lodash"),require("antd"),require("dayjs")):typeof define=="function"&&define.amd?define(["exports","react","@tachybase/client","react-i18next","@tachybase/schema","@ant-design/icons","react/jsx-runtime","lodash","antd","dayjs"],n):(c=typeof globalThis!="undefined"?globalThis:c||self,n(c["@tachybase/plugin-block-comments"]={},c.react,c["@tachybase/client"],c["react-i18next"],c["@tachybase/schema"],c["@ant-design/icons"],c.jsxRuntime,c.lodash,c.antd,c.dayjs))})(this,function(c,n,t,T,u,L,r,F,x,B){"use strict";var re=Object.defineProperty,se=Object.defineProperties;var ie=Object.getOwnPropertyDescriptors;var Q=Object.getOwnPropertySymbols;var ce=Object.prototype.hasOwnProperty,le=Object.prototype.propertyIsEnumerable;var N=(c,n,t)=>n in c?re(c,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):c[n]=t,b=(c,n)=>{for(var t in n||(n={}))ce.call(n,t)&&N(c,t,n[t]);if(Q)for(var t of Q(n))le.call(n,t)&&N(c,t,n[t]);return c},v=(c,n)=>se(c,ie(n));var A=(c,n,t)=>N(c,typeof n!="symbol"?n+"":n,t);var D=(c,n,t)=>new Promise((T,u)=>{var L=x=>{try{F(t.next(x))}catch(B){u(B)}},r=x=>{try{F(t.throw(x))}catch(B){u(B)}},F=x=>x.done?T(x.value):Promise.resolve(x.value).then(L,r);F((t=t.apply(c,n)).next())});function M(e){return t.tval(e,{ns:E})}const E="block-comments";function z(){return T.useTranslation(E)}const U=new t.SchemaInitializer({name:"comment:configureItemActions",title:'{{t("Configure actions")}}',icon:"SettingOutlined",items:[{type:"itemGroup",name:"enableActions",title:'{{t("Enable actions")}}',children:[{name:"edit",title:'{{t("Edit")}}',Component:"UpdateCommentActionInitializer",schema:{"x-action":"update","x-decorator":"ACLActionProvider","x-align":"left"},useVisible(){const e=t.useCollection_deprecated();return(e.template!=="view"||(e==null?void 0:e.writableView))&&e.template!=="sql"}},{name:"delete",title:'{{t("Delete")}}',Component:"DestroyActionInitializer",schema:{"x-component":"Action.Link","x-action":"destroy","x-decorator":"ACLActionProvider","x-align":"left"},useVisible(){return t.useCollection_deprecated().template!=="sql"}},{name:"reply",title:M("Quote Reply"),Component:"QuoteReplyCommentActionInitializer",schema:{"x-action":"create","x-decorator":"ACLActionProvider","x-align":"left"},useVisible(){return t.useCollection_deprecated().template!=="sql"}}]}]}),_=({collectionName:e,dataSource:o,association:a,rowKey:l})=>({type:"void","x-acl-action":`${a||e}:view`,"x-decorator":"Comment.Decorator","x-use-decorator-props":"useCommentBlockDecoratorProps","x-decorator-props":{collection:e,dataSource:o,association:a,readPretty:!0,action:"list",runWhenParamsChanged:!0},"x-component":"CardItem","x-toolbar":"BlockSchemaToolbar","x-settings":"blockSettings:comment",properties:{list:{type:"array","x-component":"Comment.List",properties:{item:{type:"object","x-component":"Comment.Item","x-read-pretty":!0,properties:{actionBar:{type:"void","x-align":"left","x-initializer":"comment:configureItemActions","x-component":"ActionBar","x-component-props":{layout:"one-column"}}}}}},submit:{type:"string","x-component":"Comment.Submit","x-acl-action":`${a||e}:create`,"x-decorator":"ACLCollectionProvider","x-decorator-props":{collection:e,dataSource:o,association:a}}}}),H=({filterCollections:e,filterOtherRecordsCollection:o,onlyCurrentDataSource:a,hideSearch:l,showAssociationFields:C,hideOtherRecordsInPopup:h})=>{const{insert:s}=t.useSchemaInitializer(),i=t.useSchemaInitializerItem();n.useContext(u.SchemaOptionsContext);const{getCollection:d}=t.useCollectionManager_deprecated();return r.jsx(t.DataBlockInitializer,v(b({},i),{componentType:"Comment",icon:r.jsx(L.CommentOutlined,{}),onlyCurrentDataSource:a,hideSearch:l,filter:e,filterOtherRecordsCollection:o,showAssociationFields:C,hideOtherRecordsInPopup:h,onCreateBlockSchema:w=>D(this,[w],function*({item:f,fromOthersInPopup:m}){const P=d(f.name,f.dataSource),k=f.associationField;s(_(k&&!m?{dataSource:f.dataSource,rowKey:P.filterTargetKey||"id",association:`${k.collectionName}.${k.name}`}:{collectionName:f.name,dataSource:f.dataSource,rowKey:P.filterTargetKey||"id"}))})}))},V=n.createContext({});function O(){return n.useContext(V)}const K=new t.SchemaSettings({name:"blockSettings:comment",items:[{name:"title",Component:t.SchemaSettingsBlockTitleItem},{name:"SetTheDataScope",Component:t.SchemaSettingsDataScope,useComponentProps(){var h,s;const{name:e}=t.useCollection_deprecated(),o=u.useFieldSchema(),{form:a}=t.useFormBlockContext(),l=u.useField(),{dn:C}=t.useDesignable();return{collectionName:e,defaultFilter:((s=(h=o==null?void 0:o["x-decorator-props"])==null?void 0:h.params)==null?void 0:s.filter)||{},form:a,onSubmit:({filter:i})=>{i=t.removeNullCondition(i),F.set(o,"x-decorator-props.params.filter",i),l.decoratorProps.params=v(b({},o["x-decorator-props"].params),{page:1}),C.emit("patch",{schema:{"x-uid":o["x-uid"],"x-decorator-props":o["x-decorator-props"]}})}}}},{name:"divider",type:"divider"},{name:"EnableCreate",type:"switch",useComponentProps(){const{setCreateAble:e,createAble:o}=O(),{t:a}=z();return{title:a("Enable Create"),checked:o,onChange:e}}},{name:"remove",type:"remove",componentProps:{removeParentsIfNoChildren:!0,breakRemoveOn:{"x-component":"Grid"}}}]});class W extends t.CollectionTemplate{constructor(){super(...arguments);A(this,"name","comment");A(this,"title",M("Comment Collection"));A(this,"order",2);A(this,"color","orange");A(this,"default",{fields:[{name:"content",type:"text",length:"long",interface:"vditor",deletable:!1,uiSchema:{type:"string",title:M("Comment Content"),interface:"vditor","x-component":"MarkdownVditor"}}]});A(this,"presetFieldsDisabled",!0);A(this,"configurableProperties",t.getConfigurableProperties("title","name","inherits","category","description","presetFields"))}}const G=t.withDynamicSchemaProps(e=>{let o;return r.jsx(Y,v(b({},e),{children:r.jsx(t.List.Decorator,v(b({},e),{children:r.jsx(t.CollectionManagerProvider,{dataSource:e.dataSource,children:r.jsx(t.CollectionProvider,{name:`${(o=e.association)!=null?o:e.collection}`,children:e.children})})}))}))});function Y(e){u.useField();const o=u.useFieldSchema(),[a,l]=n.useState(!1),{dn:C}=t.useDesignable();n.useEffect(()=>{var d;const i=(d=C.current["x-component-props"])==null?void 0:d.createAble;l(i===void 0?!0:i)},[]);const h=n.useCallback(i=>{const d=Object.assign({},o["x-component-props"],i);o["x-component-props"]=d,C.emit("patch",{schema:{"x-uid":o["x-uid"],"x-component-props":o["x-component-props"]}}),C.refresh()},[C,o]),s=n.useCallback(i=>{h({createAble:i}),l(i)},[l,h]);return r.jsx(V.Provider,{value:{createAble:a,setCreateAble:s},children:e.children})}const q=t.genStyleHook("tb-comment",e=>{const{componentCls:o}=e;return{[o]:{[`${o}-item-container-container`]:{"&:first-child":{border:"5px solid #d0d7deb3",position:"relative",zIndex:1,borderRadius:8}},[`${o}-item-container-border`]:{border:"1px solid #d0d7deb3",position:"relative",zIndex:1,borderRadius:8},[`${o}-item-container-line`]:{position:"absolute",top:0,bottom:0,content:"",display:"block",width:2,left:16,backgroundColor:"#d0d7deb3",zIndex:0},".ant-list-pagination":{marginTop:e.marginXS},".ant-card-head":{padding:"0 !important",fontWeight:"normal",backgroundColor:"#f6f8fa"},[`${o}-item-title`]:{color:"#636c76",display:"flex",alignItems:"center",paddingLeft:16,borderRadius:"8px 8px 0 0 ",justifyContent:"space-between",flexWrap:"wrap",[`${o}-item-title-left`]:{backgroundColor:"#f6f8fa",color:"#636c76",display:"flex",alignItems:"center",columnGap:6,"span:first-child":{fontWeight:"bold",fontSize:14},"span:not(:first-child)":{fontWeight:"normal",fontSize:14}},[`${o}-item-title-right`]:{marginRight:16,flexShrink:0}},[`${o}-item-editor`]:{position:"relative",zIndex:2,backgroundColor:"white",borderRadius:"0 0 8px 8px",[`${o}-item-editor-button-area`]:{marginTop:10,display:"flex",columnGap:5}}}}}),X=u.observer(({editing:e,setEditing:o,children:a})=>{var S,g;let l,C,h;const s=u.useField(),{t:i}=z(),{componentCls:d}=q(),f=t.useCollectionParentRecordData(),{resource:m,service:w}=t.useBlockRequestContext(),P=n.useCallback(()=>D(this,null,function*(){var p,y;yield m.update({filterByTk:(p=s.value)==null?void 0:p.id,values:{content:(y=s==null?void 0:s.value)==null?void 0:y.content}}),w.refresh()}),[m,w,s.value]),k=t.useCollectionFields(),I=n.useMemo(()=>{let p,y;return(y=(p=k.find(j=>j.name==="content"))==null?void 0:p.uiSchema)==null?void 0:y["x-component-props"]},[k]);return r.jsx(t.RecordProvider,{record:s.value,parent:f,children:r.jsxs("div",{className:`${d}-item-container`,children:[r.jsx("div",{className:`${d}-item-container-line`}),r.jsx(x.Card,{size:"small",title:r.jsxs("div",{className:`${d}-item-title`,children:[r.jsxs("div",{className:`${d}-item-title-left`,children:[r.jsx("span",{children:(C=(l=s==null?void 0:s.value)==null?void 0:l.createdBy)==null?void 0:C.nickname}),r.jsx("span",{children:i("commented")}),r.jsx(x.Tooltip,{title:B((h=s==null?void 0:s.value)==null?void 0:h.createdAt).format("YYYY-MM-DD HH:mm:ss"),children:r.jsx("span",{children:B((S=s==null?void 0:s.value)==null?void 0:S.createdAt).fromNow()})})]}),r.jsx("div",{className:`${d}-item-title-right`,children:a})]}),children:r.jsxs("div",{className:`${d}-item-editor`,children:[r.jsx(u.RecursionField,{basePath:s.address,name:"content",schema:{type:"string",name:"content","x-component":"MarkdownVditor","x-component-props":v(b({},I),{value:(g=s==null?void 0:s.value)==null?void 0:g.content}),"x-read-pretty":!0}}),e&&r.jsxs("div",{className:`${d}-item-editor-button-area`,children:[r.jsx(x.Button,{onClick:()=>{s.form.setFieldState(`${s.address}.content`,p=>{p.pattern="readPretty"}),o(!1)},children:i("Cancel")}),r.jsx(x.Button,{type:"primary",onClick:()=>{o(!1),P(),s.form.setFieldState(`${s.address}.content`,p=>{p.pattern="readPretty"})},children:i("Update Comment")})]})]})})]})})}),J=t.withDynamicSchemaProps(e=>{var k,I;const o=u.useFieldSchema(),a=u.useField(),[l]=n.useState(new Map),{wrapSSR:C,hashId:h,componentCls:s}=q();u.useForm();const{service:i}=t.useBlockRequestContext(),{run:d,params:f}=i,m=(k=i==null?void 0:i.data)==null?void 0:k.meta,w=n.useCallback(S=>(l.has(S)||l.set(S,new u.Schema({type:"object",properties:{[S]:o.properties.item}})),l.get(S)),[o.properties,l]),P=n.useCallback((S,g)=>{d(v(b({},f==null?void 0:f[0]),{page:S,pageSize:g}))},[d,f]);return i!=null&&i.loading?r.jsx("div",{style:{display:"flex",justifyContent:"center"},children:r.jsx(x.Spin,{spinning:!0})}):C(r.jsx("div",{className:`${s} ${h}`,children:r.jsx(x.List,v(b({},e),{pagination:!m||m.count<=m.pageSize?!1:{onChange:P,total:(m==null?void 0:m.count)||0,pageSize:(m==null?void 0:m.pageSize)||10,current:(m==null?void 0:m.page)||1},children:r.jsx("div",{style:{display:"flex",flexDirection:"column"},children:(I=a.value)!=null&&I.length?a.value.map((S,g)=>{const p=g===0,y=g===a.value.length-1;return r.jsx("div",{style:{position:"relative",padding:`${p?0:"10px"} 0 ${y?0:"10px"} 0`},children:r.jsx(u.RecursionField,{basePath:a.address,name:g,onlyRenderProperties:!0,schema:w(g)})},g)}):null})}))}))});function Z(){var g;const e=u.useField(),o=n.useCallback(p=>{e.setValue(v(b({},e.value),{content:p}))},[e]),{t:a}=z(),{wrapSSR:l,componentCls:C,hashId:h}=q(),s=n.useMemo(()=>{var p,y;return((y=(p=e.value)==null?void 0:p.content)==null?void 0:y.trim().length)>0},[e.value]),{resource:i,service:d}=t.useBlockRequestContext(),f=n.useCallback(()=>D(this,null,function*(){yield i.create({values:e.value}),o(""),d.refresh()}),[i,e,d,o]),{createAble:m}=O(),w=t.useACLActionParamsContext(),{designable:P}=t.useDesignable(),k=!P&&(((g=e==null?void 0:e.data)==null?void 0:g.hidden)||!w),I=t.useCollectionFields(),S=n.useMemo(()=>{var p,y;return(y=(p=I.find(j=>j.name==="content"))==null?void 0:p.uiSchema)==null?void 0:y["x-component-props"]},[I]);return!m||k?null:l(r.jsxs("div",{style:{marginTop:10},className:`${C} ${h}`,children:[r.jsx(u.RecursionField,{basePath:e.address,name:"content",schema:{type:"string","x-component":"MarkdownVditor","x-component-props":v(b({},S),{onChange:p=>{o(p)}}),"x-read-pretty":!1,"x-read-only":!1,name:"content"}}),r.jsx(x.Button,{disabled:!s,onClick:f,type:"primary",style:{marginTop:10},children:a("Comment")})]}))}function R(){var h;const e=u.useField(),{t:o}=z(),a=t.useACLActionParamsContext(),{designable:l}=t.useDesignable(),C=n.useCallback(()=>{var f;const s=e.address.slice(0,e.address.length-4).concat("submit.content"),i=e.address.slice(0,e.address.length-2).concat("content"),d=(f=e.form.getValuesIn(i))!=null?f:"";e.form.setValuesIn(s,`${d.split(`
2
2
  `).map(m=>`> ${m}`).join(`
3
3
  `)}`)},[e.address,e.form]);return!l&&((h=e==null?void 0:e.data)!=null&&h.hidden||!a)?null:r.jsx("a",{style:{fontSize:14},onClick:C,children:o("Quote Reply")})}function ee(e){const{t:o}=z(),a={type:"void",title:o("Quote Reply"),"x-component":"QuoteReplyCommentActionButton"};return r.jsx(t.ActionInitializer,v(b({},e),{schema:a}))}function te(){var s;const e=u.useField(),{t:o}=z(),[a,l]=n.useState(!1),C=t.useACLActionParamsContext(),{designable:h}=t.useDesignable();return n.useEffect(()=>{const i=e.address.slice(0,e.address.length-2);e.form.setFieldState(i.concat("content"),d=>{d.pattern=a?"editable":"readPretty"}),e.form.setFieldState(i,d=>{d.componentProps=v(b({},d.componentProps),{editing:a,setEditing:l})})},[a,e.address,e.form]),!h&&((s=e==null?void 0:e.data)!=null&&s.hidden||!C)?null:r.jsx("a",{style:{fontSize:14},onClick:()=>{l(!0)},children:o("Edit")})}function oe(e){const o={type:"void",title:'{{t("Edit")}}',"x-component":"UpdateCommentActionButton"};return r.jsx(t.ActionInitializer,v(b({},e),{schema:o}))}function ne(e){let o;return e.association&&(o=t.useParentRecordCommon(e.association)),{parentRecord:o,params:{pageSize:100,appends:["createdBy"],sort:["createdAt"]}}}const $=()=>null;$.ActionBar=t.ActionBar,$.List=J,$.Item=X,$.Decorator=G,$.Submit=Z;class ae extends t.Plugin{load(){return D(this,null,function*(){this.app.dataSourceManager.addCollectionTemplates([W]),this.app.schemaInitializerManager.addItem("page:addBlock","dataBlocks.comment",{title:M("Comment"),Component:"CommentBlockInitializer",useComponentProps(){return{filterCollections({collection:o}){return o.template==="comment"}}}}),this.app.schemaInitializerManager.addItem("popup:common:addBlock","dataBlocks.comment",{title:M("Comment"),Component:"CommentBlockInitializer",useVisible(){const o=t.useCollection();return n.useMemo(()=>o.fields.some(a=>t.canMakeAssociationBlock(a)&&["hasMany","belongsToMany"].includes(a.type)),[o.fields])},useComponentProps(){const o=t.useCollectionManager();return{onlyCurrentDataSource:!0,filterCollections({associationField:a}){if(a){if(!["hasMany","belongsToMany"].includes(a.type))return!1;const l=o.getCollection(a.target);return(l==null?void 0:l.template)==="comment"}return!1},filterOtherRecordsCollection(a){return(a==null?void 0:a.template)==="comment"},showAssociationFields:!0,hideOtherRecordsInPopup:!1,hideSearch:!0}}}),this.app.addComponents({CommentBlockInitializer:H,Comment:$,UpdateCommentActionInitializer:oe,UpdateCommentActionButton:te,QuoteReplyCommentActionButton:R,QuoteReplyCommentActionInitializer:ee}),this.app.addScopes({useCommentBlockDecoratorProps:ne}),this.schemaSettingsManager.add(K),this.schemaInitializerManager.add(U)})}}c.default=ae,Object.defineProperties(c,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -1,11 +1,11 @@
1
1
  module.exports = {
2
- "@tachybase/client": "0.23.20",
2
+ "@tachybase/client": "0.23.35",
3
3
  "react": "18.3.1",
4
- "@tachybase/schema": "0.23.20",
4
+ "@tachybase/schema": "0.23.35",
5
5
  "@ant-design/icons": "5.3.7",
6
6
  "lodash": "4.17.21",
7
7
  "antd": "5.22.5",
8
8
  "dayjs": "1.11.13",
9
9
  "react-i18next": "15.2.0",
10
- "@tachybase/server": "0.23.20"
10
+ "@tachybase/server": "0.23.35"
11
11
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tachybase/plugin-block-comments",
3
- "version": "0.23.20",
3
+ "version": "0.23.35",
4
4
  "main": "dist/server/index.js",
5
5
  "dependencies": {},
6
6
  "devDependencies": {
@@ -9,13 +9,13 @@
9
9
  "dayjs": "1.11.13",
10
10
  "lodash": "^4.17.21",
11
11
  "react-i18next": "^15.2.0",
12
- "@tachybase/components": "0.23.20",
13
- "@tachybase/schema": "0.23.20"
12
+ "@tachybase/schema": "0.23.35",
13
+ "@tachybase/components": "0.23.35"
14
14
  },
15
15
  "peerDependencies": {
16
- "@tachybase/client": "0.23.20",
17
- "@tachybase/server": "0.23.20",
18
- "@tachybase/test": "0.23.20"
16
+ "@tachybase/client": "0.23.35",
17
+ "@tachybase/server": "0.23.35",
18
+ "@tachybase/test": "0.23.35"
19
19
  },
20
20
  "description.zh-CN": "评论",
21
21
  "displayName.zh-CN": "评论",