@tachybase/plugin-block-comments 0.23.47 → 0.23.58

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.
@@ -5,4 +5,4 @@ export declare const CommentBlockInitializer: ({ filterCollections, filterOtherR
5
5
  hideSearch: any;
6
6
  showAssociationFields: any;
7
7
  hideOtherRecordsInPopup: any;
8
- }) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
8
+ }) => import("react/jsx-runtime").JSX.Element;
@@ -1,2 +1,4 @@
1
1
  export declare const CommentDecorator: import("react").FunctionComponent<any>;
2
- export declare function H(e: any): import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
2
+ export declare const ProviderCommentContext: ({ children }: {
3
+ children: any;
4
+ }) => import("react/jsx-runtime").JSX.Element;
@@ -1,2 +1 @@
1
- import react from 'react';
2
- export declare const CommentItem: react.MemoExoticComponent<import("@tachybase/schema").ReactFC<Omit<any, "ref">>>;
1
+ export declare const CommentItem: import("react").MemoExoticComponent<import("@tachybase/schema").ReactFC<Omit<any, "ref">>>;
@@ -1,5 +1 @@
1
- import { Plugin } from '@tachybase/client';
2
- declare class PluginComments extends Plugin {
3
- load(): Promise<void>;
4
- }
5
- export default PluginComments;
1
+ export { default } from './plugin';
@@ -1,3 +1,3 @@
1
- (function(c,a){typeof exports=="object"&&typeof module!="undefined"?a(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"],a):(c=typeof globalThis!="undefined"?globalThis:c||self,a(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,a,t,D,u,T,r,w,x,I){"use strict";var ae=Object.defineProperty,re=Object.defineProperties;var se=Object.getOwnPropertyDescriptors;var V=Object.getOwnPropertySymbols;var ie=Object.prototype.hasOwnProperty,ce=Object.prototype.propertyIsEnumerable;var O=(c,a,t)=>a in c?ae(c,a,{enumerable:!0,configurable:!0,writable:!0,value:t}):c[a]=t,b=(c,a)=>{for(var t in a||(a={}))ie.call(a,t)&&O(c,t,a[t]);if(V)for(var t of V(a))ce.call(a,t)&&O(c,t,a[t]);return c},v=(c,a)=>re(c,se(a));var M=(c,a,t)=>new Promise((D,u)=>{var T=x=>{try{w(t.next(x))}catch(I){u(I)}},r=x=>{try{w(t.throw(x))}catch(I){u(I)}},w=x=>x.done?D(x.value):Promise.resolve(x.value).then(T,r);w((t=t.apply(c,a)).next())});function F(e){return t.tval(e,{ns:j})}const j="block-comments";function B(){return D.useTranslation(j)}const Q=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:F("Quote Reply"),Component:"QuoteReplyCommentActionInitializer",schema:{"x-action":"create","x-decorator":"ACLActionProvider","x-align":"left"},useVisible(){return t.useCollection_deprecated().template!=="sql"}}]}]}),U=({collectionName:e,dataSource:o,association:n,rowKey:l})=>({type:"void","x-acl-action":`${n||e}:view`,"x-decorator":"Comment.Decorator","x-use-decorator-props":"useCommentBlockDecoratorProps","x-decorator-props":{collection:e,dataSource:o,association:n,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":`${n||e}:create`,"x-decorator":"ACLCollectionProvider","x-decorator-props":{collection:e,dataSource:o,association:n}}}}),_=({filterCollections:e,filterOtherRecordsCollection:o,onlyCurrentDataSource:n,hideSearch:l,showAssociationFields:h,hideOtherRecordsInPopup:C})=>{const{insert:s}=t.useSchemaInitializer(),i=t.useSchemaInitializerItem();a.useContext(u.SchemaOptionsContext);const{getCollection:d}=t.useCollectionManager_deprecated();return r.jsx(t.DataBlockInitializer,v(b({},i),{componentType:"Comment",icon:r.jsx(T.CommentOutlined,{}),onlyCurrentDataSource:n,hideSearch:l,filter:e,filterOtherRecordsCollection:o,showAssociationFields:h,hideOtherRecordsInPopup:C,onCreateBlockSchema:$=>M(this,[$],function*({item:f,fromOthersInPopup:m}){const P=d(f.name,f.dataSource),k=f.associationField;s(U(k&&!m?{dataSource:f.dataSource,rowKey:P.filterTargetKey||"id",association:`${k.collectionName}.${k.name}`}:{collectionName:f.name,dataSource:f.dataSource,rowKey:P.filterTargetKey||"id"}))})}))},N=a.createContext({});function E(){return a.useContext(N)}const H=new t.SchemaSettings({name:"blockSettings:comment",items:[{name:"title",Component:t.SchemaSettingsBlockTitleItem},{name:"SetTheDataScope",Component:t.SchemaSettingsDataScope,useComponentProps(){var C,s;const{name:e}=t.useCollection_deprecated(),o=u.useFieldSchema(),{form:n}=t.useFormBlockContext(),l=u.useField(),{dn:h}=t.useDesignable();return{collectionName:e,defaultFilter:((s=(C=o==null?void 0:o["x-decorator-props"])==null?void 0:C.params)==null?void 0:s.filter)||{},form:n,onSubmit:({filter:i})=>{i=t.removeNullCondition(i),w.set(o,"x-decorator-props.params.filter",i),l.decoratorProps.params=v(b({},o["x-decorator-props"].params),{page:1}),h.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}=E(),{t:n}=B();return{title:n("Enable Create"),checked:o,onChange:e}}},{name:"remove",type:"remove",componentProps:{removeParentsIfNoChildren:!0,breakRemoveOn:{"x-component":"Grid"}}}]});class K extends t.CollectionTemplate{constructor(){super(...arguments),this.name="comment",this.title=F("Comment Collection"),this.order=2,this.color="orange",this.default={fields:[{name:"content",type:"text",length:"long",interface:"vditor",deletable:!1,uiSchema:{type:"string",title:F("Comment Content"),interface:"vditor","x-component":"MarkdownVditor"}}]},this.presetFieldsDisabled=!0,this.configurableProperties=t.getConfigurableProperties("title","name","inherits","category","description","presetFields")}}const W=t.withDynamicSchemaProps(e=>{let o;return r.jsx(G,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 G(e){u.useField();const o=u.useFieldSchema(),[n,l]=a.useState(!1),{dn:h}=t.useDesignable();a.useEffect(()=>{var d;const i=(d=h.current["x-component-props"])==null?void 0:d.createAble;l(i===void 0?!0:i)},[]);const C=a.useCallback(i=>{const d=Object.assign({},o["x-component-props"],i);o["x-component-props"]=d,h.emit("patch",{schema:{"x-uid":o["x-uid"],"x-component-props":o["x-component-props"]}}),h.refresh()},[h,o]),s=a.useCallback(i=>{C({createAble:i}),l(i)},[l,C]);return r.jsx(N.Provider,{value:{createAble:n,setCreateAble:s},children:e.children})}const L=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}}}}}),Y=u.observer(({editing:e,setEditing:o,children:n})=>{var S,g;let l,h,C;const s=u.useField(),{t:i}=B(),{componentCls:d}=L(),f=t.useCollectionParentRecordData(),{resource:m,service:$}=t.useBlockRequestContext(),P=a.useCallback(()=>M(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}}),$.refresh()}),[m,$,s.value]),k=t.useCollectionFields(),A=a.useMemo(()=>{let p,y;return(y=(p=k.find(q=>q.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:(h=(l=s==null?void 0:s.value)==null?void 0:l.createdBy)==null?void 0:h.nickname}),r.jsx("span",{children:i("commented")}),r.jsx(x.Tooltip,{title:I((C=s==null?void 0:s.value)==null?void 0:C.createdAt).format("YYYY-MM-DD HH:mm:ss"),children:r.jsx("span",{children:I((S=s==null?void 0:s.value)==null?void 0:S.createdAt).fromNow()})})]}),r.jsx("div",{className:`${d}-item-title-right`,children:n})]}),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({},A),{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")})]})]})})]})})}),X=t.withDynamicSchemaProps(e=>{var k,A;const o=u.useFieldSchema(),n=u.useField(),[l]=a.useState(new Map),{wrapSSR:h,hashId:C,componentCls:s}=L();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,$=a.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=a.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})}):h(r.jsx("div",{className:`${s} ${C}`,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:(A=n.value)!=null&&A.length?n.value.map((S,g)=>{const p=g===0,y=g===n.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:n.address,name:g,onlyRenderProperties:!0,schema:$(g)})},g)}):null})}))}))});function J(){var g;const e=u.useField(),o=a.useCallback(p=>{e.setValue(v(b({},e.value),{content:p}))},[e]),{t:n}=B(),{wrapSSR:l,componentCls:h,hashId:C}=L(),s=a.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=a.useCallback(()=>M(this,null,function*(){yield i.create({values:e.value}),o(""),d.refresh()}),[i,e,d,o]),{createAble:m}=E(),$=t.useACLActionParamsContext(),{designable:P}=t.useDesignable(),k=!P&&(((g=e==null?void 0:e.data)==null?void 0:g.hidden)||!$),A=t.useCollectionFields(),S=a.useMemo(()=>{var p,y;return(y=(p=A.find(q=>q.name==="content"))==null?void 0:p.uiSchema)==null?void 0:y["x-component-props"]},[A]);return!m||k?null:l(r.jsxs("div",{style:{marginTop:10},className:`${h} ${C}`,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:n("Comment")})]}))}function Z(){var C;const e=u.useField(),{t:o}=B(),n=t.useACLActionParamsContext(),{designable:l}=t.useDesignable(),h=a.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
- `).map(m=>`> ${m}`).join(`
3
- `)}`)},[e.address,e.form]);return!l&&((C=e==null?void 0:e.data)!=null&&C.hidden||!n)?null:r.jsx("a",{style:{fontSize:14},onClick:h,children:o("Quote Reply")})}function R(e){const{t:o}=B(),n={type:"void",title:o("Quote Reply"),"x-component":"QuoteReplyCommentActionButton"};return r.jsx(t.ActionInitializer,v(b({},e),{schema:n}))}function ee(){var s;const e=u.useField(),{t:o}=B(),[n,l]=a.useState(!1),h=t.useACLActionParamsContext(),{designable:C}=t.useDesignable();return a.useEffect(()=>{const i=e.address.slice(0,e.address.length-2);e.form.setFieldState(i.concat("content"),d=>{d.pattern=n?"editable":"readPretty"}),e.form.setFieldState(i,d=>{d.componentProps=v(b({},d.componentProps),{editing:n,setEditing:l})})},[n,e.address,e.form]),!C&&((s=e==null?void 0:e.data)!=null&&s.hidden||!h)?null:r.jsx("a",{style:{fontSize:14},onClick:()=>{l(!0)},children:o("Edit")})}function te(e){const o={type:"void",title:'{{t("Edit")}}',"x-component":"UpdateCommentActionButton"};return r.jsx(t.ActionInitializer,v(b({},e),{schema:o}))}function oe(e){let o;return e.association&&(o=t.useParentRecordCommon(e.association)),{parentRecord:o,params:{pageSize:100,appends:["createdBy"],sort:["createdAt"]}}}const z=()=>null;z.ActionBar=t.ActionBar,z.List=X,z.Item=Y,z.Decorator=W,z.Submit=J;class ne extends t.Plugin{load(){return M(this,null,function*(){this.app.dataSourceManager.addCollectionTemplates([K]),this.app.schemaInitializerManager.addItem("page:addBlock","dataBlocks.comment",{title:F("Comment"),Component:"CommentBlockInitializer",useComponentProps(){return{filterCollections({collection:o}){return o.template==="comment"}}}}),this.app.schemaInitializerManager.addItem("popup:common:addBlock","dataBlocks.comment",{title:F("Comment"),Component:"CommentBlockInitializer",useVisible(){const o=t.useCollection();return a.useMemo(()=>o.fields.some(n=>t.canMakeAssociationBlock(n)&&["hasMany","belongsToMany"].includes(n.type)),[o.fields])},useComponentProps(){const o=t.useCollectionManager();return{onlyCurrentDataSource:!0,filterCollections({associationField:n}){if(n){if(!["hasMany","belongsToMany"].includes(n.type))return!1;const l=o.getCollection(n.target);return(l==null?void 0:l.template)==="comment"}return!1},filterOtherRecordsCollection(n){return(n==null?void 0:n.template)==="comment"},showAssociationFields:!0,hideOtherRecordsInPopup:!1,hideSearch:!0}}}),this.app.addComponents({CommentBlockInitializer:_,Comment:z,UpdateCommentActionInitializer:te,UpdateCommentActionButton:ee,QuoteReplyCommentActionButton:Z,QuoteReplyCommentActionInitializer:R}),this.app.addScopes({useCommentBlockDecoratorProps:oe}),this.schemaSettingsManager.add(H),this.schemaInitializerManager.add(Q)})}}c.default=ne,Object.defineProperties(c,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
1
+ (function(c,a){typeof exports=="object"&&typeof module!="undefined"?a(exports,require("react"),require("@tachybase/client"),require("react-i18next"),require("react/jsx-runtime"),require("@tachybase/schema"),require("@ant-design/icons"),require("lodash"),require("antd"),require("dayjs")):typeof define=="function"&&define.amd?define(["exports","react","@tachybase/client","react-i18next","react/jsx-runtime","@tachybase/schema","@ant-design/icons","lodash","antd","dayjs"],a):(c=typeof globalThis!="undefined"?globalThis:c||self,a(c["@tachybase/plugin-block-comments"]={},c.react,c["@tachybase/client"],c["react-i18next"],c.jsxRuntime,c["@tachybase/schema"],c["@ant-design/icons"],c.lodash,c.antd,c.dayjs))})(this,function(c,a,t,T,s,C,D,$,g,I){"use strict";var ae=Object.defineProperty,se=Object.defineProperties;var ie=Object.getOwnPropertyDescriptors;var E=Object.getOwnPropertySymbols;var ce=Object.prototype.hasOwnProperty,le=Object.prototype.propertyIsEnumerable;var V=(c,a,t)=>a in c?ae(c,a,{enumerable:!0,configurable:!0,writable:!0,value:t}):c[a]=t,x=(c,a)=>{for(var t in a||(a={}))ce.call(a,t)&&V(c,t,a[t]);if(E)for(var t of E(a))le.call(a,t)&&V(c,t,a[t]);return c},b=(c,a)=>se(c,ie(a));var M=(c,a,t)=>new Promise((T,s)=>{var C=g=>{try{$(t.next(g))}catch(I){s(I)}},D=g=>{try{$(t.throw(g))}catch(I){s(I)}},$=g=>g.done?T(g.value):Promise.resolve(g.value).then(C,D);$((t=t.apply(c,a)).next())});const L="block-comments";function w(e){return t.tval(e,{ns:L})}function B(){return T.useTranslation(L)}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:w("Quote Reply"),Component:"QuoteReplyCommentActionInitializer",schema:{"x-action":"create","x-decorator":"ACLActionProvider","x-align":"left"},useVisible(){return t.useCollection_deprecated().template!=="sql"}}]}]}),O=({collectionName:e,dataSource:o,association:r,rowKey:n})=>({type:"void","x-acl-action":`${r||e}:view`,"x-decorator":"Comment.Decorator","x-use-decorator-props":"useCommentBlockDecoratorProps","x-decorator-props":{collection:e,dataSource:o,association:r,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":`${r||e}:create`,"x-decorator":"ACLCollectionProvider","x-decorator-props":{collection:e,dataSource:o,association:r}}}}),Q=({filterCollections:e,filterOtherRecordsCollection:o,onlyCurrentDataSource:r,hideSearch:n,showAssociationFields:p,hideOtherRecordsInPopup:d})=>{const{insert:f}=t.useSchemaInitializer(),i=t.useSchemaInitializerItem();a.useContext(C.SchemaOptionsContext);const{getCollection:u}=t.useCollectionManager_deprecated(),y=F=>M(this,[F],function*({item:m,fromOthersInPopup:k}){const v=u(m.name,m.dataSource),S=m.associationField;f(O(S&&!k?{dataSource:m.dataSource,rowKey:v.filterTargetKey||"id",association:`${S.collectionName}.${S.name}`}:{collectionName:m.name,dataSource:m.dataSource,rowKey:v.filterTargetKey||"id"}))});return s.jsx(t.DataBlockInitializer,b(x({},i),{componentType:"Comment",icon:s.jsx(D.CommentOutlined,{}),onlyCurrentDataSource:r,hideSearch:n,filter:e,filterOtherRecordsCollection:o,showAssociationFields:p,hideOtherRecordsInPopup:d,onCreateBlockSchema:y}))},j=a.createContext({});function N(){return a.useContext(j)}const _=new t.SchemaSettings({name:"blockSettings:comment",items:[{name:"title",Component:t.SchemaSettingsBlockTitleItem},{name:"SetTheDataScope",Component:t.SchemaSettingsDataScope,useComponentProps(){var d,f;const{name:e}=t.useCollection_deprecated(),o=C.useFieldSchema(),{form:r}=t.useFormBlockContext(),n=C.useField(),{dn:p}=t.useDesignable();return{collectionName:e,defaultFilter:((f=(d=o==null?void 0:o["x-decorator-props"])==null?void 0:d.params)==null?void 0:f.filter)||{},form:r,onSubmit:({filter:i})=>{i=t.removeNullCondition(i),$.set(o,"x-decorator-props.params.filter",i),n.decoratorProps.params=b(x({},o["x-decorator-props"].params),{page:1}),p.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}=N(),{t:r}=B();return{title:r("Enable Create"),checked:o,onChange:e}}},{name:"remove",type:"remove",componentProps:{removeParentsIfNoChildren:!0,breakRemoveOn:{"x-component":"Grid"}}}]});class K extends t.CollectionTemplate{constructor(){super(...arguments),this.name="comment",this.title=w("Comment Collection"),this.order=2,this.color="orange",this.default={fields:[{name:"content",type:"text",length:"long",interface:"vditor",deletable:!1,uiSchema:{type:"string",title:w("Comment Content"),interface:"vditor","x-component":"MarkdownVditor"}}]},this.presetFieldsDisabled=!0,this.configurableProperties=t.getConfigurableProperties("title","name","inherits","category","description","presetFields")}}const W=t.withDynamicSchemaProps(e=>{const{dataSource:o,association:r,collection:n,children:p}=e,d=`${r||n}`;return s.jsx(G,b(x({},e),{children:s.jsx(t.List.Decorator,b(x({},e),{children:s.jsx(t.CollectionManagerProvider,{dataSource:o,children:s.jsx(t.CollectionProvider,{name:d,children:p})})}))}))}),G=({children:e})=>{const o=C.useFieldSchema(),[r,n]=a.useState(!1),{dn:p}=t.useDesignable(),d=a.useCallback(i=>{const u=x(x({},o["x-component-props"]),i);o["x-component-props"]=u,p.emit("patch",{schema:{"x-uid":o["x-uid"],"x-component-props":o["x-component-props"]}}),p.refresh()},[p,o]),f=a.useCallback(i=>{d({createAble:i}),n(i)},[n,d]);return a.useEffect(()=>{var u;const i=(u=p.current["x-component-props"])==null?void 0:u.createAble;n(i!=null?i:!0)},[]),s.jsx(j.Provider,{value:{createAble:r,setCreateAble:f},children:e})},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}}}}}),H=C.observer(({editing:e,setEditing:o,children:r})=>{var v,S,P;const n=C.useField(),{t:p}=B(),{componentCls:d}=q(),f=t.useCollectionParentRecordData(),{resource:i,service:u}=t.useBlockRequestContext(),y=a.useCallback(()=>M(this,null,function*(){var h,l;yield i.update({filterByTk:(h=n.value)==null?void 0:h.id,values:{content:(l=n==null?void 0:n.value)==null?void 0:l.content}}),u.refresh()}),[i,u,n.value]),m=t.useCollectionFields(),k=a.useMemo(()=>{var l;const h=m.find(A=>A.name==="content");return(l=h==null?void 0:h.uiSchema)==null?void 0:l["x-component-props"]},[m]),F=()=>{o(!1),y(),n.form.setFieldState(`${n.address}.content`,h=>{h.pattern="readPretty"})};return s.jsx(t.RecordProvider,{record:n.value,parent:f,children:s.jsxs("div",{className:`${d}-item-container`,children:[s.jsx("div",{className:`${d}-item-container-line`}),s.jsxs(g.Card,{size:"small",title:s.jsxs("div",{className:`${d}-item-title`,children:[s.jsxs("div",{className:`${d}-item-title-left`,children:[s.jsx("span",{children:p("commented")}),s.jsx(g.Tooltip,{title:I((v=n==null?void 0:n.value)==null?void 0:v.createdAt).format("YYYY-MM-DD HH:mm:ss"),children:s.jsx("span",{children:I((S=n==null?void 0:n.value)==null?void 0:S.createdAt).fromNow()})})]}),s.jsx("div",{className:`${d}-item-title-right`,children:r})]}),children:[s.jsx(C.RecursionField,{name:"content",basePath:n.address,schema:{type:"string",name:"content","x-component":"MarkdownVditor","x-component-props":b(x({},k),{value:(P=n==null?void 0:n.value)==null?void 0:P.content}),"x-read-pretty":!0}}),e&&s.jsxs("div",{className:`${d}-item-editor-button-area`,children:[s.jsx(g.Button,{onClick:()=>{n.form.setFieldState(`${n.address}.content`,h=>{h.pattern="readPretty"}),o(!1)},children:p("Cancel")}),s.jsx(g.Button,{type:"primary",onClick:F,children:p("Update Comment")})]})]})]})})}),Y=t.withDynamicSchemaProps(e=>{var S,P;const o=C.useFieldSchema(),r=C.useField(),[n]=a.useState(new Map),{wrapSSR:p,hashId:d,componentCls:f}=q(),{service:i}=t.useBlockRequestContext(),{run:u,params:y}=i,m=(S=i==null?void 0:i.data)==null?void 0:S.meta,k=a.useCallback(h=>{if(n.has(h))return n.get(h);const l=new C.Schema({type:"object",properties:{[h]:o.properties.item}});return n.set(h,l),l},[o.properties,n]),F=a.useCallback((h,l)=>{u(b(x({},y==null?void 0:y[0]),{page:h,pageSize:l}))},[u,y]),v=!m||m.count<=m.pageSize?!1:{onChange:F,total:(m==null?void 0:m.count)||0,pageSize:(m==null?void 0:m.pageSize)||10,current:(m==null?void 0:m.page)||1};return i!=null&&i.loading?s.jsx("div",{style:{display:"flex",justifyContent:"center"},children:s.jsx(g.Spin,{spinning:!0})}):p(s.jsx("div",{className:`${f} ${d}`,children:s.jsx(g.List,b(x({},e),{pagination:v,children:s.jsx("div",{style:{display:"flex",flexDirection:"column"},children:(P=r.value)!=null&&P.length?r.value.map((h,l)=>s.jsx("div",{style:{position:"relative",padding:`${l===0?0:"10px"} 0 ${l===r.value.length-1?0:"10px"} 0`},children:s.jsx(C.RecursionField,{basePath:r.address,name:l,onlyRenderProperties:!0,schema:k(l)})},l)):null})}))}))});function X(){var h;const e=C.useField(),o=a.useCallback(l=>{e.setValue(b(x({},e.value),{content:l}))},[e]),{t:r}=B(),{wrapSSR:n,componentCls:p,hashId:d}=q(),f=a.useMemo(()=>{var l,A;return((A=(l=e.value)==null?void 0:l.content)==null?void 0:A.trim().length)>0},[e.value]),{resource:i,service:u}=t.useBlockRequestContext(),y=a.useCallback(()=>M(this,null,function*(){yield i.create({values:e.value}),o(""),u.refresh()}),[i,e,u,o]),{createAble:m}=N(),k=t.useACLActionParamsContext(),{designable:F}=t.useDesignable(),v=!F&&(((h=e==null?void 0:e.data)==null?void 0:h.hidden)||!k),S=t.useCollectionFields(),P=a.useMemo(()=>{var l,A;return(A=(l=S.find(re=>re.name==="content"))==null?void 0:l.uiSchema)==null?void 0:A["x-component-props"]},[S]);return!m||v?null:n(s.jsxs("div",{style:{marginTop:10},className:`${p} ${d}`,children:[s.jsx(C.RecursionField,{basePath:e.address,name:"content",schema:{name:"content",type:"string","x-component":"MarkdownVditor","x-component-props":b(x({},P),{onChange:l=>{o(l)}}),"x-read-pretty":!1,"x-read-only":!1}}),s.jsx(g.Button,{style:{marginTop:10},type:"primary",disabled:!f,onClick:y,children:r("Comment")})]}))}function J(){var d;const e=C.useField(),{t:o}=B(),r=t.useACLActionParamsContext(),{designable:n}=t.useDesignable(),p=a.useCallback(()=>{var y;const f=e.address.slice(0,e.address.length-4).concat("submit.content"),i=e.address.slice(0,e.address.length-2).concat("content"),u=(y=e.form.getValuesIn(i))!=null?y:"";e.form.setValuesIn(f,Z(u))},[e.address,e.form]);return!n&&((d=e==null?void 0:e.data)!=null&&d.hidden||!r)?null:s.jsx("a",{style:{fontSize:14},onClick:p,children:o("Quote Reply")})}function Z(e){return e.split(`
2
+ `).map(o=>`> ${o}`).join(`
3
+ `)}function R(e){const{t:o}=B(),r={type:"void",title:o("Quote Reply"),"x-component":"QuoteReplyCommentActionButton"};return s.jsx(t.ActionInitializer,b(x({},e),{schema:r}))}function ee(){var f;const e=C.useField(),{t:o}=B(),[r,n]=a.useState(!1),p=t.useACLActionParamsContext(),{designable:d}=t.useDesignable();return a.useEffect(()=>{const i=e.address.slice(0,e.address.length-2);e.form.setFieldState(i.concat("content"),u=>{u.pattern=r?"editable":"readPretty"}),e.form.setFieldState(i,u=>{u.componentProps=b(x({},u.componentProps),{editing:r,setEditing:n})})},[r,e.address,e.form]),!d&&((f=e==null?void 0:e.data)!=null&&f.hidden||!p)?null:s.jsx("a",{style:{fontSize:14},onClick:()=>{n(!0)},children:o("Edit")})}function te(e){const o={type:"void",title:'{{t("Edit")}}',"x-component":"UpdateCommentActionButton"};return s.jsx(t.ActionInitializer,b(x({},e),{schema:o}))}function oe(e){const{association:o}=e;return{parentRecord:t.useParentRecordCommon(o),params:{pageSize:100,appends:["createdBy"],sort:["createdAt"]}}}const z=()=>null;z.ActionBar=t.ActionBar,z.List=Y,z.Item=H,z.Decorator=W,z.Submit=X;class ne extends t.Plugin{load(){return M(this,null,function*(){this.app.dataSourceManager.addCollectionTemplates([K]),this.app.schemaInitializerManager.addItem("page:addBlock","dataBlocks.comment",{title:w("Comment"),Component:"CommentBlockInitializer",useComponentProps(){return{filterCollections({collection:o}){return o.template==="comment"}}}}),this.app.schemaInitializerManager.addItem("popup:common:addBlock","dataBlocks.comment",{title:w("Comment"),Component:"CommentBlockInitializer",useVisible(){const o=t.useCollection();return a.useMemo(()=>o.fields.some(r=>t.canMakeAssociationBlock(r)&&["hasMany","belongsToMany"].includes(r.type)),[o.fields])},useComponentProps(){const o=t.useCollectionManager();return{onlyCurrentDataSource:!0,filterCollections({associationField:r}){if(r){if(!["hasMany","belongsToMany"].includes(r.type))return!1;const n=o.getCollection(r.target);return(n==null?void 0:n.template)==="comment"}return!1},filterOtherRecordsCollection(r){return(r==null?void 0:r.template)==="comment"},showAssociationFields:!0,hideOtherRecordsInPopup:!1,hideSearch:!0}}}),this.app.addComponents({CommentBlockInitializer:Q,Comment:z,UpdateCommentActionInitializer:te,UpdateCommentActionButton:ee,QuoteReplyCommentActionButton:J,QuoteReplyCommentActionInitializer:R}),this.app.addScopes({useCommentBlockDecoratorProps:oe}),this.schemaSettingsManager.add(_),this.schemaInitializerManager.add(U)})}}c.default=ne,Object.defineProperties(c,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -1,3 +1,3 @@
1
- export declare function tval(e: any): string;
2
1
  export declare const NAMESPACE = "block-comments";
2
+ export declare function tval(str: any): string;
3
3
  export declare function useTranslation(): import("react-i18next").UseTranslationResponse<"block-comments", undefined>;
@@ -0,0 +1,5 @@
1
+ import { Plugin } from '@tachybase/client';
2
+ declare class PluginComments extends Plugin {
3
+ load(): Promise<void>;
4
+ }
5
+ export default PluginComments;
@@ -1,11 +1,11 @@
1
1
  module.exports = {
2
- "@tachybase/client": "0.23.47",
2
+ "@tachybase/client": "0.23.58",
3
3
  "react": "18.3.1",
4
- "@tachybase/schema": "0.23.47",
4
+ "@tachybase/schema": "0.23.58",
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.47"
10
+ "@tachybase/server": "0.23.58"
11
11
  };
@@ -1,13 +1,13 @@
1
1
  declare const _default: {
2
2
  Comment: string;
3
- "Comment Collection": string;
4
- "Comment Content": string;
3
+ 'Comment Collection': string;
4
+ 'Comment Content': string;
5
5
  Cancel: string;
6
- "Update Comment": string;
6
+ 'Update Comment': string;
7
7
  commented: string;
8
- "Quote Reply": string;
8
+ 'Quote Reply': string;
9
9
  Delete: string;
10
10
  Edit: string;
11
- "Enable Create": string;
11
+ 'Enable Create': string;
12
12
  };
13
13
  export default _default;
@@ -21,14 +21,14 @@ __export(en_US_exports, {
21
21
  });
22
22
  module.exports = __toCommonJS(en_US_exports);
23
23
  var en_US_default = {
24
- "Comment": "Comment",
24
+ Comment: "Comment",
25
25
  "Comment Collection": "Comment collection",
26
26
  "Comment Content": "Content",
27
- "Cancel": "Cancel",
27
+ Cancel: "Cancel",
28
28
  "Update Comment": "Update comment",
29
- "commented": "commented",
29
+ commented: "commented",
30
30
  "Quote Reply": "Quote reply",
31
- "Delete": "Delete",
32
- "Edit": "Edit",
31
+ Delete: "Delete",
32
+ Edit: "Edit",
33
33
  "Enable Create": "Allow adding comments"
34
34
  };
@@ -1,13 +1,13 @@
1
1
  declare const _default: {
2
2
  Comment: string;
3
- "Comment Collection": string;
4
- "Comment Content": string;
3
+ 'Comment Collection': string;
4
+ 'Comment Content': string;
5
5
  Cancel: string;
6
- "Update Comment": string;
6
+ 'Update Comment': string;
7
7
  commented: string;
8
- "Quote Reply": string;
8
+ 'Quote Reply': string;
9
9
  Delete: string;
10
10
  Edit: string;
11
- "Enable Create": string;
11
+ 'Enable Create': string;
12
12
  };
13
13
  export default _default;
@@ -21,14 +21,14 @@ __export(ko_KR_exports, {
21
21
  });
22
22
  module.exports = __toCommonJS(ko_KR_exports);
23
23
  var ko_KR_default = {
24
- "Comment": "\uB313\uAE00",
24
+ Comment: "\uB313\uAE00",
25
25
  "Comment Collection": "\uB313\uAE00 \uBAA8\uC74C",
26
26
  "Comment Content": "\uB313\uAE00 \uB0B4\uC6A9",
27
- "Cancel": "\uCDE8\uC18C",
27
+ Cancel: "\uCDE8\uC18C",
28
28
  "Update Comment": "\uB313\uAE00 \uC5C5\uB370\uC774\uD2B8",
29
- "commented": "\uB313\uAE00 \uB0A8\uAE40",
29
+ commented: "\uB313\uAE00 \uB0A8\uAE40",
30
30
  "Quote Reply": "\uC778\uC6A9 \uBC0F \uB2F5\uC7A5",
31
- "Delete": "\uC0AD\uC81C",
32
- "Edit": "\uD3B8\uC9D1",
31
+ Delete: "\uC0AD\uC81C",
32
+ Edit: "\uD3B8\uC9D1",
33
33
  "Enable Create": "\uC758\uACAC \uCD94\uAC00 \uD5C8\uC6A9"
34
34
  };
@@ -1,13 +1,13 @@
1
1
  declare const _default: {
2
2
  Comment: string;
3
- "Comment Collection": string;
4
- "Comment Content": string;
3
+ 'Comment Collection': string;
4
+ 'Comment Content': string;
5
5
  Cancel: string;
6
- "Update Comment": string;
6
+ 'Update Comment': string;
7
7
  commented: string;
8
- "Quote Reply": string;
8
+ 'Quote Reply': string;
9
9
  Delete: string;
10
10
  Edit: string;
11
- "Enable Create": string;
11
+ 'Enable Create': string;
12
12
  };
13
13
  export default _default;
@@ -21,14 +21,14 @@ __export(zh_CN_exports, {
21
21
  });
22
22
  module.exports = __toCommonJS(zh_CN_exports);
23
23
  var zh_CN_default = {
24
- "Comment": "\u8BC4\u8BBA",
24
+ Comment: "\u8BC4\u8BBA",
25
25
  "Comment Collection": "\u8BC4\u8BBA\u8868",
26
26
  "Comment Content": "\u8BC4\u8BBA\u5185\u5BB9",
27
- "Cancel": "\u53D6\u6D88",
27
+ Cancel: "\u53D6\u6D88",
28
28
  "Update Comment": "\u66F4\u65B0\u8BC4\u8BBA",
29
- "commented": "\u8BC4\u8BBA\u4E8E",
29
+ commented: "\u8BC4\u8BBA\u4E8E",
30
30
  "Quote Reply": "\u5F15\u7528\u5E76\u56DE\u590D",
31
- "Delete": "\u5220\u9664",
32
- "Edit": "\u7F16\u8F91",
31
+ Delete: "\u5220\u9664",
32
+ Edit: "\u7F16\u8F91",
33
33
  "Enable Create": "\u5141\u8BB8\u589E\u52A0\u8BC4\u8BBA"
34
34
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tachybase/plugin-block-comments",
3
- "version": "0.23.47",
3
+ "version": "0.23.58",
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.47",
13
- "@tachybase/schema": "0.23.47"
12
+ "@tachybase/components": "0.23.58",
13
+ "@tachybase/schema": "0.23.58"
14
14
  },
15
15
  "peerDependencies": {
16
- "@tachybase/client": "0.23.47",
17
- "@tachybase/server": "0.23.47",
18
- "@tachybase/test": "0.23.47"
16
+ "@tachybase/client": "0.23.58",
17
+ "@tachybase/server": "0.23.58",
18
+ "@tachybase/test": "0.23.58"
19
19
  },
20
20
  "description.zh-CN": "评论",
21
21
  "displayName.zh-CN": "评论",