@nocobase/plugin-multi-app-share-collection 0.12.0-alpha.5 → 0.13.0-alpha.10

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,510 +1,18 @@
1
- (function(global, factory) {
2
- typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("@nocobase/client"), require("react"), require("@formily/react"), require("@nocobase/plugin-multi-app-manager/client"), require("antd"), require("@nocobase/utils/client"), require("react-i18next")) : typeof define === "function" && define.amd ? define(["exports", "@nocobase/client", "react", "@formily/react", "@nocobase/plugin-multi-app-manager/client", "antd", "@nocobase/utils/client", "react-i18next"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["@nocobase/plugin-multi-app-share-collection"] = {}, global["@nocobase/client"], global.react, global["@formily/react"], global["@nocobase/plugin-multi-app-manager"], global.antd, global["@nocobase/utils"], global["react-i18next"]));
3
- })(this, function(exports2, client, require$$0, react, client$2, antd, client$1, reactI18next) {
4
- "use strict";
5
- var jsxRuntime = { exports: {} };
6
- var reactJsxRuntime_production_min = {};
7
- /**
8
- * @license React
9
- * react-jsx-runtime.production.min.js
10
- *
11
- * Copyright (c) Facebook, Inc. and its affiliates.
12
- *
13
- * This source code is licensed under the MIT license found in the
14
- * LICENSE file in the root directory of this source tree.
15
- */
16
- var f = require$$0, k = Symbol.for("react.element"), l = Symbol.for("react.fragment"), m = Object.prototype.hasOwnProperty, n = f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, p = { key: true, ref: true, __self: true, __source: true };
17
- function q(c, a, g) {
18
- var b, d = {}, e = null, h = null;
19
- void 0 !== g && (e = "" + g);
20
- void 0 !== a.key && (e = "" + a.key);
21
- void 0 !== a.ref && (h = a.ref);
22
- for (b in a)
23
- m.call(a, b) && !p.hasOwnProperty(b) && (d[b] = a[b]);
24
- if (c && c.defaultProps)
25
- for (b in a = c.defaultProps, a)
26
- void 0 === d[b] && (d[b] = a[b]);
27
- return { $$typeof: k, type: c, key: e, ref: h, props: d, _owner: n.current };
28
- }
29
- reactJsxRuntime_production_min.Fragment = l;
30
- reactJsxRuntime_production_min.jsx = q;
31
- reactJsxRuntime_production_min.jsxs = q;
32
- {
33
- jsxRuntime.exports = reactJsxRuntime_production_min;
34
- }
35
- var jsxRuntimeExports = jsxRuntime.exports;
36
- const excludeCollections = ["users", "roles", "applications"];
37
- const useCollectionsGraph = ({ removed = [] }) => {
38
- const { collections } = client.useCollectionManager();
39
- const findAddable = require$$0.useCallback(
40
- (name) => {
41
- return client$1.CollectionsGraph.connectedNodes({
42
- collections,
43
- nodes: [name],
44
- excludes: excludeCollections
45
- }).filter((name2) => removed.includes(name2));
46
- },
47
- [removed]
48
- );
49
- const findRemovable = require$$0.useCallback(
50
- (name) => {
51
- return client$1.CollectionsGraph.connectedNodes({
52
- collections,
53
- nodes: [name],
54
- excludes: excludeCollections,
55
- direction: "reverse"
56
- }).filter((name2) => !removed.includes(name2));
57
- },
58
- [removed]
59
- );
60
- return {
61
- findAddable,
62
- findRemovable
63
- };
64
- };
65
- const useCollections = () => {
66
- var _a, _b;
67
- const record = client.useRecord();
68
- const [selected, setSelected] = require$$0.useState([]);
69
- const res1 = client.useRequest(
70
- {
71
- url: `applications/${record.name}/collectionBlacklist:list`,
72
- params: {
73
- paginate: false,
74
- params: {
75
- fields: ["name"]
76
- }
77
- }
78
- },
79
- {
80
- onSuccess(data) {
81
- var _a2;
82
- setSelected((_a2 = data.data) == null ? void 0 : _a2.map((data2) => data2.name));
83
- }
84
- }
85
- );
86
- const res2 = client.useRequest({
87
- url: `collections`,
88
- params: {
89
- fields: ["name", "title", "hidden", "category.name", "category.color", "category.sort"],
90
- sort: "sort",
91
- paginate: false
92
- }
93
- });
94
- const res3 = client.useRequest({
95
- url: `collectionCategories`,
96
- params: {
97
- sort: "sort",
98
- paginate: false
99
- }
100
- });
101
- return {
102
- loading: res1.loading || res2.loading || res3.loading,
103
- collections: (((_a = res2.data) == null ? void 0 : _a.data) || []).filter((item) => !item.hidden && !excludeCollections.includes(item.name)),
104
- removed: selected,
105
- setSelected,
106
- categories: (((_b = res3.data) == null ? void 0 : _b.data) || []).map((cat) => ({ label: cat.name, value: cat.name }))
107
- };
108
- };
109
- const includes = (text, s) => {
110
- const values = Array.isArray(s) ? s : [s];
111
- for (const val of values) {
112
- if (text.toLowerCase().includes(val)) {
113
- return true;
114
- }
115
- }
116
- return false;
117
- };
118
- const useRemovedDataSource = ({ collections, removed }) => {
119
- const [filter, setFilter] = require$$0.useState({ name: "", category: [] });
120
- const dataSource = require$$0.useMemo(() => {
121
- return collections.filter((collection) => {
122
- const { name, title, category = [] } = collection;
123
- const results = [removed.includes(collection.name)];
124
- if (filter.name) {
125
- results.push(includes(name, filter.name) || includes(title, filter.name));
126
- }
127
- if (filter.category.length > 0) {
128
- results.push(category.some((item) => includes(item.name, filter.category)));
129
- }
130
- return !results.includes(false);
131
- });
132
- }, [collections, removed, filter]);
133
- const setNameFilter = require$$0.useMemo(
134
- () => client$1.lodash.debounce((name) => {
135
- setFilter({
136
- ...filter,
137
- name
138
- });
139
- }, 300),
140
- []
141
- );
142
- return {
143
- dataSource,
144
- setNameFilter,
145
- setCategoryFilter: (category) => {
146
- setFilter({
147
- ...filter,
148
- category
149
- });
150
- }
151
- };
152
- };
153
- const useAddedDataSource = ({ collections, removed }) => {
154
- const [filter, setFilter] = require$$0.useState({ name: "", category: [] });
155
- const dataSource = collections.filter((collection) => {
156
- const { name, title, category = [] } = collection;
157
- const results = [!removed.includes(collection.name)];
158
- if (filter.name) {
159
- results.push(includes(name, filter.name) || includes(title, filter.name));
160
- }
161
- if (filter.category.length > 0) {
162
- results.push(category.some((item) => includes(item.name, filter.category)));
163
- }
164
- return !results.includes(false);
165
- });
166
- const setNameFilter = require$$0.useMemo(
167
- () => client$1.lodash.debounce((name) => {
168
- setFilter({
169
- ...filter,
170
- name
171
- });
172
- }, 300),
173
- []
174
- );
175
- return {
176
- dataSource,
177
- setNameFilter,
178
- setCategoryFilter: (category) => {
179
- setFilter({
180
- ...filter,
181
- category
182
- });
183
- }
184
- };
185
- };
186
- const TableTransfer = react.connect((props) => {
187
- const { onChange } = props;
188
- const { loading, collections, categories, removed, setSelected } = useCollections();
189
- const [selectedRowKeys1, setSelectedRowKeys1] = require$$0.useState([]);
190
- const [selectedRowKeys2, setSelectedRowKeys2] = require$$0.useState([]);
191
- const { findAddable, findRemovable } = useCollectionsGraph({ removed });
192
- const addedDataSource = useAddedDataSource({ collections, removed });
193
- const removedDataSource = useRemovedDataSource({ collections, removed });
194
- const { t } = reactI18next.useTranslation("multi-app-share-collection");
195
- const { modal } = antd.App.useApp();
196
- const { token } = client.useToken();
197
- const columns = require$$0.useMemo(
198
- () => [
199
- {
200
- title: t("Collection display name"),
201
- dataIndex: "title"
202
- },
203
- {
204
- title: t("Collection name"),
205
- dataIndex: "name"
206
- },
207
- {
208
- title: t("Collection category"),
209
- dataIndex: "category",
210
- render: (categories2) => categories2.map((category) => /* @__PURE__ */ jsxRuntimeExports.jsx(antd.Tag, { color: category.color, children: category.name }, category.name))
211
- }
212
- ],
213
- []
214
- );
215
- if (loading) {
216
- return /* @__PURE__ */ jsxRuntimeExports.jsx(antd.Spin, {});
217
- }
218
- return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: /* @__PURE__ */ jsxRuntimeExports.jsxs(
219
- antd.Row,
220
- {
221
- gutter: 24,
222
- className: client.css`
1
+ (function(o,t){typeof exports=="object"&&typeof module!="undefined"?t(exports,require("@nocobase/client"),require("react/jsx-runtime"),require("@formily/react"),require("@nocobase/plugin-multi-app-manager/client"),require("antd"),require("@nocobase/utils/client"),require("react"),require("react-i18next")):typeof define=="function"&&define.amd?define(["exports","@nocobase/client","react/jsx-runtime","@formily/react","@nocobase/plugin-multi-app-manager/client","antd","@nocobase/utils/client","react","react-i18next"],t):(o=typeof globalThis!="undefined"?globalThis:o||self,t(o["@nocobase/plugin-multi-app-share-collection"]={},o["@nocobase/client"],o.jsxRuntime,o["@formily/react"],o["@nocobase/plugin-multi-app-manager"],o.antd,o["@nocobase/utils"],o.react,o["react-i18next"]))})(this,function(o,t,e,M,y,r,C,d,S){"use strict";var R=Object.defineProperty,$=Object.defineProperties;var ee=Object.getOwnPropertyDescriptors;var O=Object.getOwnPropertySymbols;var te=Object.prototype.hasOwnProperty,oe=Object.prototype.propertyIsEnumerable;var B=(o,t,e)=>t in o?R(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,k=(o,t)=>{for(var e in t||(t={}))te.call(t,e)&&B(o,e,t[e]);if(O)for(var e of O(t))oe.call(t,e)&&B(o,e,t[e]);return o},q=(o,t)=>$(o,ee(t));var G=(o,t,e)=>new Promise((M,y)=>{var r=S=>{try{d(e.next(S))}catch(v){y(v)}},C=S=>{try{d(e.throw(S))}catch(v){y(v)}},d=S=>S.done?M(S.value):Promise.resolve(S.value).then(r,C);d((e=e.apply(o,t)).next())});const v=["users","roles","applications"],E=({removed:n=[]})=>{const{collections:a}=t.useCollectionManager(),s=d.useCallback(m=>C.CollectionsGraph.connectedNodes({collections:a,nodes:[m],excludes:v}).filter(c=>n.includes(c)),[n]),i=d.useCallback(m=>C.CollectionsGraph.connectedNodes({collections:a,nodes:[m],excludes:v,direction:"reverse"}).filter(c=>!n.includes(c)),[n]);return{findAddable:s,findRemovable:i}},W=()=>{var l,b;const n=t.useRecord(),[a,s]=d.useState([]),i=t.useRequest({url:`applications/${n.name}/collectionBlacklist:list`,params:{paginate:!1,params:{fields:["name"]}}},{onSuccess(h){var w;s((w=h.data)==null?void 0:w.map(f=>f.name))}}),m=t.useRequest({url:"collections",params:{fields:["name","title","hidden","category.name","category.color","category.sort"],sort:"sort",paginate:!1}}),c=t.useRequest({url:"collectionCategories",params:{sort:"sort",paginate:!1}});return{loading:i.loading||m.loading||c.loading,collections:(((l=m.data)==null?void 0:l.data)||[]).filter(h=>!h.hidden&&!v.includes(h.name)),removed:a,setSelected:s,categories:(((b=c.data)==null?void 0:b.data)||[]).map(h=>({label:h.name,value:h.name}))}},F=(n,a)=>{const s=Array.isArray(a)?a:[a];for(const i of s)if(n.toLowerCase().includes(i))return!0;return!1},_=({collections:n,removed:a})=>{const[s,i]=d.useState({name:"",category:[]}),m=d.useMemo(()=>n.filter(l=>{const{name:b,title:h,category:w=[]}=l,f=[a.includes(l.name)];return s.name&&f.push(F(b,s.name)||F(h,s.name)),s.category.length>0&&f.push(w.some(T=>F(T.name,s.category))),!f.includes(!1)}),[n,a,s]),c=d.useMemo(()=>C.lodash.debounce(l=>{i(q(k({},s),{name:l}))},300),[]);return{dataSource:m,setNameFilter:c,setCategoryFilter:l=>{i(q(k({},s),{category:l}))}}},U=({collections:n,removed:a})=>{const[s,i]=d.useState({name:"",category:[]}),m=n.filter(l=>{const{name:b,title:h,category:w=[]}=l,f=[!a.includes(l.name)];return s.name&&f.push(F(b,s.name)||F(h,s.name)),s.category.length>0&&f.push(w.some(T=>F(T.name,s.category))),!f.includes(!1)}),c=d.useMemo(()=>C.lodash.debounce(l=>{i(q(k({},s),{name:l}))},300),[]);return{dataSource:m,setNameFilter:c,setCategoryFilter:l=>{i(q(k({},s),{category:l}))}}},V=M.connect(n=>{const{onChange:a}=n,{loading:s,collections:i,categories:m,removed:c,setSelected:l}=W(),[b,h]=d.useState([]),[w,f]=d.useState([]),{findAddable:T,findRemovable:Y}=E({removed:c}),K=U({collections:i,removed:c}),j=_({collections:i,removed:c}),{t:g}=S.useTranslation("multi-app-share-collection"),{modal:L}=r.App.useApp(),{token:z}=t.useToken(),I=d.useMemo(()=>[{title:g("Collection display name"),dataIndex:"title"},{title:g("Collection name"),dataIndex:"name"},{title:g("Collection category"),dataIndex:"category",render:u=>u.map(p=>e.jsx(r.Tag,{color:p.color,children:p.name},p.name))}],[]);return s?e.jsx(r.Spin,{}):e.jsx("div",{children:e.jsxs(r.Row,{gutter:24,className:t.css`
223
2
  .ant-table-tbody > tr.ant-table-row:hover > td {
224
3
  background: #e6f7ff;
225
4
  cursor: pointer;
226
5
  }
227
- `,
228
- children: [
229
- /* @__PURE__ */ jsxRuntimeExports.jsxs(antd.Col, { span: 12, children: [
230
- /* @__PURE__ */ jsxRuntimeExports.jsxs(
231
- "div",
232
- {
233
- className: client.css`
6
+ `,children:[e.jsxs(r.Col,{span:12,children:[e.jsxs("div",{className:t.css`
234
7
  display: flex;
235
8
  justify-content: space-between;
236
9
  align-items: center;
237
10
  width: 100%;
238
11
  margin-bottom: 8px;
239
- `,
240
- children: [
241
- /* @__PURE__ */ jsxRuntimeExports.jsx("strong", { style: { fontSize: token.fontSizeLG, color: token.colorText }, children: t("Unshared collections") }),
242
- /* @__PURE__ */ jsxRuntimeExports.jsxs(antd.Input.Group, { compact: true, style: { width: 360 }, children: [
243
- /* @__PURE__ */ jsxRuntimeExports.jsx(
244
- antd.Select,
245
- {
246
- popupMatchSelectWidth: false,
247
- onChange: (value) => {
248
- removedDataSource.setCategoryFilter(value);
249
- },
250
- mode: "multiple",
251
- style: { width: "35%" },
252
- size: "middle",
253
- placeholder: t("All categories"),
254
- options: categories,
255
- allowClear: true
256
- }
257
- ),
258
- /* @__PURE__ */ jsxRuntimeExports.jsx(
259
- antd.Input,
260
- {
261
- onChange: (e) => removedDataSource.setNameFilter(e.target.value),
262
- style: { width: "65%" },
263
- placeholder: t("Enter name or title..."),
264
- allowClear: true
265
- }
266
- )
267
- ] })
268
- ]
269
- }
270
- ),
271
- /* @__PURE__ */ jsxRuntimeExports.jsx(
272
- antd.Table,
273
- {
274
- bordered: true,
275
- rowKey: "name",
276
- rowSelection: {
277
- type: "checkbox",
278
- selectedRowKeys: selectedRowKeys1,
279
- onChange(selectedRowKeys) {
280
- const values = removed.filter((s) => !selectedRowKeys.includes(s));
281
- setSelected(values);
282
- onChange(values);
283
- setSelectedRowKeys1([]);
284
- }
285
- },
286
- pagination: false,
287
- size: "small",
288
- columns,
289
- dataSource: removedDataSource.dataSource,
290
- scroll: { y: "calc(100vh - 260px)" },
291
- onRow: ({ name, disabled }) => ({
292
- onClick: () => {
293
- if (disabled)
294
- return;
295
- const adding = findAddable(name);
296
- const change = () => {
297
- const values = removed.filter((s) => !adding.includes(s));
298
- setSelected(values);
299
- onChange(values);
300
- };
301
- if (adding.length === 1) {
302
- return change();
303
- }
304
- modal.confirm({
305
- title: t("Are you sure to add the following collections?"),
306
- width: "60%",
307
- content: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: /* @__PURE__ */ jsxRuntimeExports.jsx(
308
- antd.Table,
309
- {
310
- size: "small",
311
- columns,
312
- dataSource: collections.filter((collection) => adding.includes(collection.name)),
313
- pagination: false,
314
- scroll: { y: "60vh" }
315
- }
316
- ) }),
317
- onOk() {
318
- change();
319
- }
320
- });
321
- }
322
- })
323
- }
324
- )
325
- ] }),
326
- /* @__PURE__ */ jsxRuntimeExports.jsxs(antd.Col, { span: 12, children: [
327
- /* @__PURE__ */ jsxRuntimeExports.jsxs(
328
- "div",
329
- {
330
- className: client.css`
12
+ `,children:[e.jsx("strong",{style:{fontSize:z.fontSizeLG,color:z.colorText},children:g("Unshared collections")}),e.jsxs(r.Input.Group,{compact:!0,style:{width:360},children:[e.jsx(r.Select,{popupMatchSelectWidth:!1,onChange:u=>{j.setCategoryFilter(u)},mode:"multiple",style:{width:"35%"},size:"middle",placeholder:g("All categories"),options:m,allowClear:!0}),e.jsx(r.Input,{onChange:u=>j.setNameFilter(u.target.value),style:{width:"65%"},placeholder:g("Enter name or title..."),allowClear:!0})]})]}),e.jsx(r.Table,{bordered:!0,rowKey:"name",rowSelection:{type:"checkbox",selectedRowKeys:b,onChange(u){const p=c.filter(x=>!u.includes(x));l(p),a(p),h([])}},pagination:!1,size:"small",columns:I,dataSource:j.dataSource,scroll:{y:"calc(100vh - 260px)"},onRow:({name:u,disabled:p})=>({onClick:()=>{if(p)return;const x=T(u),A=()=>{const N=c.filter(Z=>!x.includes(Z));l(N),a(N)};if(x.length===1)return A();L.confirm({title:g("Are you sure to add the following collections?"),width:"60%",content:e.jsx("div",{children:e.jsx(r.Table,{size:"small",columns:I,dataSource:i.filter(N=>x.includes(N.name)),pagination:!1,scroll:{y:"60vh"}})}),onOk(){A()}})}})})]}),e.jsxs(r.Col,{span:12,children:[e.jsxs("div",{className:t.css`
331
13
  display: flex;
332
14
  justify-content: space-between;
333
15
  align-items: center;
334
16
  width: 100%;
335
17
  margin-bottom: 8px;
336
- `,
337
- children: [
338
- /* @__PURE__ */ jsxRuntimeExports.jsx("strong", { style: { fontSize: token.fontSizeLG, color: token.colorText }, children: t("Shared collections") }),
339
- /* @__PURE__ */ jsxRuntimeExports.jsxs(antd.Input.Group, { compact: true, style: { width: 360 }, children: [
340
- /* @__PURE__ */ jsxRuntimeExports.jsx(
341
- antd.Select,
342
- {
343
- popupMatchSelectWidth: false,
344
- onChange: (value) => {
345
- addedDataSource.setCategoryFilter(value);
346
- },
347
- mode: "multiple",
348
- style: { width: "35%" },
349
- size: "middle",
350
- placeholder: t("All categories"),
351
- options: categories,
352
- allowClear: true
353
- }
354
- ),
355
- /* @__PURE__ */ jsxRuntimeExports.jsx(
356
- antd.Input,
357
- {
358
- onChange: (e) => addedDataSource.setNameFilter(e.target.value),
359
- style: { width: "65%" },
360
- placeholder: t("Enter name or title..."),
361
- allowClear: true
362
- }
363
- )
364
- ] })
365
- ]
366
- }
367
- ),
368
- /* @__PURE__ */ jsxRuntimeExports.jsx(
369
- antd.Table,
370
- {
371
- bordered: true,
372
- rowKey: "name",
373
- rowSelection: {
374
- type: "checkbox",
375
- selectedRowKeys: selectedRowKeys2,
376
- onChange(selectedRowKeys) {
377
- const values = client$1.lodash.uniq(removed.concat(selectedRowKeys));
378
- setSelected(values);
379
- onChange(values);
380
- setSelectedRowKeys2([]);
381
- }
382
- },
383
- pagination: false,
384
- size: "small",
385
- columns,
386
- dataSource: addedDataSource.dataSource,
387
- scroll: { y: "calc(100vh - 260px)" },
388
- onRow: ({ name }) => ({
389
- onClick: () => {
390
- const removing = findRemovable(name);
391
- const change = () => {
392
- removed.push(...removing);
393
- const values = client$1.lodash.uniq([...removed]);
394
- setSelected(values);
395
- onChange(values);
396
- };
397
- if (removing.length === 1) {
398
- return change();
399
- }
400
- modal.confirm({
401
- title: t("Are you sure to remove the following collections?"),
402
- width: "60%",
403
- content: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: /* @__PURE__ */ jsxRuntimeExports.jsx(
404
- antd.Table,
405
- {
406
- size: "small",
407
- columns,
408
- dataSource: collections.filter((collection) => removing.includes(collection.name)),
409
- pagination: false,
410
- scroll: { y: "60vh" }
411
- }
412
- ) }),
413
- onOk() {
414
- change();
415
- }
416
- });
417
- }
418
- })
419
- }
420
- )
421
- ] })
422
- ]
423
- }
424
- ) });
425
- });
426
- const i18nText = (text) => {
427
- return `{{t("${text}", { ns: 'multi-app-share-collection' })}}`;
428
- };
429
- const useShareCollectionAction = () => {
430
- const form = react.useForm();
431
- const ctx = client.useActionContext();
432
- const api = client.useAPIClient();
433
- const record = client.useRecord();
434
- return {
435
- async run() {
436
- console.log(form.values.names);
437
- await api.request({
438
- url: `applications/${record.name}/collectionBlacklist`,
439
- data: form.values.names,
440
- method: "post"
441
- });
442
- ctx.setVisible(false);
443
- form.reset();
444
- antd.message.success("Saved successfully");
445
- }
446
- };
447
- };
448
- const updateSchema = client$2.tableActionColumnSchema.properties.update;
449
- const deleteSchema = client$2.tableActionColumnSchema.properties.delete;
450
- delete client$2.tableActionColumnSchema.properties.update;
451
- delete client$2.tableActionColumnSchema.properties.delete;
452
- client$2.tableActionColumnSchema.properties["collection"] = {
453
- type: "void",
454
- title: i18nText("Share collections"),
455
- "x-component": "Action.Link",
456
- "x-component-props": {},
457
- properties: {
458
- drawer: {
459
- type: "void",
460
- "x-component": "Action.Drawer",
461
- "x-component-props": {
462
- width: "95vw"
463
- },
464
- "x-decorator": "Form",
465
- title: i18nText("Share collections"),
466
- properties: {
467
- names: {
468
- type: "array",
469
- "x-component": TableTransfer,
470
- "x-decorator": "FormItem"
471
- },
472
- footer: {
473
- type: "void",
474
- "x-component": "Action.Drawer.Footer",
475
- properties: {
476
- cancel: {
477
- title: '{{t("Cancel")}}',
478
- "x-component": "Action",
479
- "x-component-props": {
480
- useAction: "{{ cm.useCancelAction }}"
481
- }
482
- },
483
- submit: {
484
- title: '{{t("Submit")}}',
485
- "x-component": "Action",
486
- "x-component-props": {
487
- type: "primary",
488
- useAction: useShareCollectionAction
489
- }
490
- }
491
- }
492
- }
493
- }
494
- }
495
- }
496
- };
497
- client$2.tableActionColumnSchema.properties.update = updateSchema;
498
- client$2.tableActionColumnSchema.properties.delete = deleteSchema;
499
- const MultiAppShareCollectionProvider = (props) => {
500
- return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: props.children });
501
- };
502
- class MultiAppShareCollectionPlugin extends client.Plugin {
503
- async load() {
504
- this.app.use(MultiAppShareCollectionProvider);
505
- }
506
- }
507
- exports2.MultiAppShareCollectionPlugin = MultiAppShareCollectionPlugin;
508
- exports2.default = MultiAppShareCollectionPlugin;
509
- Object.defineProperties(exports2, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
510
- });
18
+ `,children:[e.jsx("strong",{style:{fontSize:z.fontSizeLG,color:z.colorText},children:g("Shared collections")}),e.jsxs(r.Input.Group,{compact:!0,style:{width:360},children:[e.jsx(r.Select,{popupMatchSelectWidth:!1,onChange:u=>{K.setCategoryFilter(u)},mode:"multiple",style:{width:"35%"},size:"middle",placeholder:g("All categories"),options:m,allowClear:!0}),e.jsx(r.Input,{onChange:u=>K.setNameFilter(u.target.value),style:{width:"65%"},placeholder:g("Enter name or title..."),allowClear:!0})]})]}),e.jsx(r.Table,{bordered:!0,rowKey:"name",rowSelection:{type:"checkbox",selectedRowKeys:w,onChange(u){const p=C.lodash.uniq(c.concat(u));l(p),a(p),f([])}},pagination:!1,size:"small",columns:I,dataSource:K.dataSource,scroll:{y:"calc(100vh - 260px)"},onRow:({name:u})=>({onClick:()=>{const p=Y(u),x=()=>{c.push(...p);const A=C.lodash.uniq([...c]);l(A),a(A)};if(p.length===1)return x();L.confirm({title:g("Are you sure to remove the following collections?"),width:"60%",content:e.jsx("div",{children:e.jsx(r.Table,{size:"small",columns:I,dataSource:i.filter(A=>p.includes(A.name)),pagination:!1,scroll:{y:"60vh"}})}),onOk(){x()}})}})})]})]})})}),D=n=>`{{t("${n}", { ns: 'multi-app-share-collection' })}}`,H=()=>{const n=M.useForm(),a=t.useActionContext(),s=t.useAPIClient(),i=t.useRecord();return{run(){return G(this,null,function*(){console.log(n.values.names),yield s.request({url:`applications/${i.name}/collectionBlacklist`,data:n.values.names,method:"post"}),a.setVisible(!1),n.reset(),r.message.success("Saved successfully")})}}},J=y.tableActionColumnSchema.properties.update,Q=y.tableActionColumnSchema.properties.delete;delete y.tableActionColumnSchema.properties.update,delete y.tableActionColumnSchema.properties.delete,y.tableActionColumnSchema.properties.collection={type:"void",title:D("Share collections"),"x-component":"Action.Link","x-component-props":{},properties:{drawer:{type:"void","x-component":"Action.Drawer","x-component-props":{width:"95vw"},"x-decorator":"Form",title:D("Share collections"),properties:{names:{type:"array","x-component":V,"x-decorator":"FormItem"},footer:{type:"void","x-component":"Action.Drawer.Footer",properties:{cancel:{title:'{{t("Cancel")}}',"x-component":"Action","x-component-props":{useAction:"{{ cm.useCancelAction }}"}},submit:{title:'{{t("Submit")}}',"x-component":"Action","x-component-props":{type:"primary",useAction:H}}}}}}}},y.tableActionColumnSchema.properties.update=J,y.tableActionColumnSchema.properties.delete=Q;const X=n=>e.jsx(e.Fragment,{children:n.children});class P extends t.Plugin{load(){return G(this,null,function*(){this.app.use(X)})}}o.MultiAppShareCollectionPlugin=P,o.default=P,Object.defineProperties(o,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
package/dist/index.js CHANGED
@@ -1,18 +1,39 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var server = require('./server');
6
-
7
-
8
-
9
- Object.defineProperty(exports, 'default', {
10
- enumerable: true,
11
- get: function () { return server__namespace.default; }
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var src_exports = {};
30
+ __export(src_exports, {
31
+ default: () => import_server.default
12
32
  });
13
- Object.keys(server).forEach(function (k) {
14
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
15
- enumerable: true,
16
- get: function () { return server[k]; }
17
- });
33
+ module.exports = __toCommonJS(src_exports);
34
+ __reExport(src_exports, require("./server"), module.exports);
35
+ var import_server = __toESM(require("./server"));
36
+ // Annotate the CommonJS export names for ESM import in node:
37
+ 0 && (module.exports = {
38
+ ...require("./server")
18
39
  });
@@ -1,5 +1,25 @@
1
- 'use strict';
2
-
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var es_ES_exports = {};
19
+ __export(es_ES_exports, {
20
+ default: () => es_ES_default
21
+ });
22
+ module.exports = __toCommonJS(es_ES_exports);
3
23
  var es_ES_default = {
4
24
  "Share collections": "Tablas compartidas",
5
25
  "Unshared collections": "Tablas no compartidas",
@@ -12,5 +32,3 @@ var es_ES_default = {
12
32
  "Collection name": "Nombre de la tabla",
13
33
  "Collection category": "Categor\xEDa de tabla"
14
34
  };
15
-
16
- module.exports = es_ES_default;
@@ -1,5 +1,25 @@
1
- 'use strict';
2
-
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var pt_BR_exports = {};
19
+ __export(pt_BR_exports, {
20
+ default: () => pt_BR_default
21
+ });
22
+ module.exports = __toCommonJS(pt_BR_exports);
3
23
  var pt_BR_default = {
4
24
  "Share collections": "Compartilhar tabelas",
5
25
  "Unshared collections": "Tabelas n\xE3o compartilhadas",
@@ -12,5 +32,3 @@ var pt_BR_default = {
12
32
  "Collection name": "Nome da tabela",
13
33
  "Collection category": "Categoria da tabela"
14
34
  };
15
-
16
- module.exports = pt_BR_default;
@@ -1,5 +1,25 @@
1
- 'use strict';
2
-
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var zh_CN_exports = {};
19
+ __export(zh_CN_exports, {
20
+ default: () => zh_CN_default
21
+ });
22
+ module.exports = __toCommonJS(zh_CN_exports);
3
23
  var zh_CN_default = {
4
24
  "Share collections": "\u5171\u4EAB\u6570\u636E\u8868",
5
25
  "Unshared collections": "\u672A\u5171\u4EAB\u7684\u6570\u636E\u8868",
@@ -12,5 +32,3 @@ var zh_CN_default = {
12
32
  "Collection name": "\u6807\u8BC6",
13
33
  "Collection category": "\u5206\u7C7B"
14
34
  };
15
-
16
- module.exports = zh_CN_default;
@@ -1,8 +1,27 @@
1
- 'use strict';
2
-
3
- var database = require('@nocobase/database');
4
-
5
- var applications_default = database.extendCollection({
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var applications_exports = {};
19
+ __export(applications_exports, {
20
+ default: () => applications_default
21
+ });
22
+ module.exports = __toCommonJS(applications_exports);
23
+ var import_database = require("@nocobase/database");
24
+ var applications_default = (0, import_database.extendCollection)({
6
25
  name: "applications",
7
26
  fields: [
8
27
  {
@@ -17,5 +36,3 @@ var applications_default = database.extendCollection({
17
36
  }
18
37
  ]
19
38
  });
20
-
21
- module.exports = applications_default;
@@ -1,8 +1,27 @@
1
- 'use strict';
2
-
3
- var database = require('@nocobase/database');
4
-
5
- var collections_default = database.extendCollection({
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var collections_exports = {};
19
+ __export(collections_exports, {
20
+ default: () => collections_default
21
+ });
22
+ module.exports = __toCommonJS(collections_exports);
23
+ var import_database = require("@nocobase/database");
24
+ var collections_default = (0, import_database.extendCollection)({
6
25
  name: "collections",
7
26
  fields: [
8
27
  {
@@ -17,5 +36,3 @@ var collections_default = database.extendCollection({
17
36
  }
18
37
  ]
19
38
  });
20
-
21
- module.exports = collections_default;
@@ -1,11 +1,33 @@
1
- 'use strict';
2
-
3
- var plugin = require('./plugin');
4
-
5
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
6
-
7
- var plugin__default = /*#__PURE__*/_interopDefault(plugin);
8
-
9
-
10
-
11
- module.exports = plugin__default.default;
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var server_exports = {};
29
+ __export(server_exports, {
30
+ default: () => import_plugin.default
31
+ });
32
+ module.exports = __toCommonJS(server_exports);
33
+ var import_plugin = __toESM(require("./plugin"));
@@ -1,9 +1,28 @@
1
- 'use strict';
2
-
3
- var server = require('@nocobase/server');
4
- var utils = require('@nocobase/utils');
5
-
6
- class update_apps_collections_default extends server.Migration {
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var update_apps_collections_exports = {};
19
+ __export(update_apps_collections_exports, {
20
+ default: () => update_apps_collections_default
21
+ });
22
+ module.exports = __toCommonJS(update_apps_collections_exports);
23
+ var import_server = require("@nocobase/server");
24
+ var import_utils = require("@nocobase/utils");
25
+ class update_apps_collections_default extends import_server.Migration {
7
26
  async up() {
8
27
  const result = await this.app.version.satisfies("<0.9.3-alpha.1");
9
28
  if (!result) {
@@ -36,7 +55,7 @@ class update_apps_collections_default extends server.Migration {
36
55
  const blackListCollections = allCollections.filter(
37
56
  (collection) => !syncedCollections.has(collection) && !["users", "roles"].includes(collection)
38
57
  );
39
- const connectedCollections = utils.CollectionsGraph.connectedNodes({
58
+ const connectedCollections = import_utils.CollectionsGraph.connectedNodes({
40
59
  collections: collectionsData,
41
60
  nodes: blackListCollections,
42
61
  direction: "reverse"
@@ -62,5 +81,3 @@ class update_apps_collections_default extends server.Migration {
62
81
  }
63
82
  }
64
83
  }
65
-
66
- module.exports = update_apps_collections_default;
@@ -4,6 +4,5 @@ export declare class MultiAppShareCollectionPlugin extends Plugin {
4
4
  beforeEnable(): Promise<void>;
5
5
  beforeLoad(): Promise<void>;
6
6
  load(): Promise<void>;
7
- requiredPlugins(): any[];
8
7
  }
9
8
  export default MultiAppShareCollectionPlugin;
@@ -1,19 +1,43 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var PluginMultiAppManager = require('@nocobase/plugin-multi-app-manager');
6
- var server = require('@nocobase/server');
7
- var lodash = require('lodash');
8
- var path = require('path');
9
-
10
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
11
-
12
- var PluginMultiAppManager__default = /*#__PURE__*/_interopDefault(PluginMultiAppManager);
13
- var lodash__default = /*#__PURE__*/_interopDefault(lodash);
14
-
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var plugin_exports = {};
29
+ __export(plugin_exports, {
30
+ MultiAppShareCollectionPlugin: () => MultiAppShareCollectionPlugin,
31
+ default: () => plugin_default
32
+ });
33
+ module.exports = __toCommonJS(plugin_exports);
34
+ var import_plugin_multi_app_manager = __toESM(require("@nocobase/plugin-multi-app-manager"));
35
+ var import_server = require("@nocobase/server");
36
+ var import_lodash = __toESM(require("lodash"));
37
+ var import_path = require("path");
15
38
  const subAppFilteredPlugins = ["multi-app-share-collection", "multi-app-manager"];
16
- class SubAppPlugin extends server.Plugin {
39
+ const unSyncPlugins = ["localization-management"];
40
+ class SubAppPlugin extends import_server.Plugin {
17
41
  beforeLoad() {
18
42
  const mainApp = this.options.mainApp;
19
43
  const subApp = this.app;
@@ -38,17 +62,19 @@ class SubAppPlugin extends server.Plugin {
38
62
  }
39
63
  }
40
64
  const sharedCollections = [...sharedCollectionGroupsCollections.flat(), "users", "users_jobs"];
65
+ subApp.on("beforeLoadPlugin", (plugin) => {
66
+ if (plugin.name === "collection-manager") {
67
+ plugin.setLoadFilter({
68
+ "name.$ne": "roles"
69
+ });
70
+ }
71
+ });
41
72
  subApp.db.on("beforeDefineCollection", (options) => {
42
73
  const name = options.name;
43
74
  if (sharedCollections.includes(name)) {
44
75
  options.schema = mainApp.db.options.schema || "public";
45
76
  }
46
77
  });
47
- subApp.db.on("beforeUpdateCollection", (collection, newOptions) => {
48
- if (collection.name === "roles") {
49
- newOptions.schema = subApp.db.options.schema;
50
- }
51
- });
52
78
  this.app.resourcer.use(async (ctx, next) => {
53
79
  const { actionName, resourceName } = ctx.action;
54
80
  if (actionName === "list" && resourceName === "applicationPlugins") {
@@ -76,6 +102,7 @@ class SubAppPlugin extends server.Plugin {
76
102
  await next();
77
103
  });
78
104
  subApp.on("beforeInstall", async () => {
105
+ await subApp.db.sync();
79
106
  const subAppPluginsCollection = subApp.db.getCollection("applicationPlugins");
80
107
  const mainAppPluginsCollection = mainApp.db.getCollection("applicationPlugins");
81
108
  await subApp.db.sequelize.query(`TRUNCATE ${subAppPluginsCollection.quotedTableName()}`);
@@ -90,44 +117,55 @@ class SubAppPlugin extends server.Plugin {
90
117
  await subApp.db.sequelize.query(`
91
118
  SELECT setval('${sequenceName[0]["pg_get_serial_sequence"]}', (SELECT max("id") FROM ${subAppPluginsCollection.quotedTableName()}));
92
119
  `);
120
+ await subApp.reload();
93
121
  console.log(`sync plugins from ${mainApp.name} app to sub app ${subApp.name}`);
94
122
  });
95
123
  }
96
124
  }
97
- class MultiAppShareCollectionPlugin extends server.Plugin {
125
+ class MultiAppShareCollectionPlugin extends import_server.Plugin {
98
126
  afterAdd() {
99
127
  }
100
128
  async beforeEnable() {
101
129
  if (!this.db.inDialect("postgres")) {
102
130
  throw new Error("multi-app-share-collection plugin only support postgres");
103
131
  }
132
+ const plugin = this.pm.get("multi-app-manager");
133
+ if (!plugin.enabled) {
134
+ throw new Error(`${this.name} plugin need multi-app-manager plugin enabled`);
135
+ }
104
136
  }
105
137
  async beforeLoad() {
106
138
  if (!this.db.inDialect("postgres")) {
107
139
  throw new Error("multi-app-share-collection plugin only support postgres");
108
140
  }
109
141
  const traverseSubApps = async (callback, options) => {
110
- if (lodash__default.default.get(options, "loadFromDatabase")) {
142
+ if (import_lodash.default.get(options, "loadFromDatabase")) {
111
143
  for (const application of await this.app.db.getCollection("applications").repository.find()) {
112
144
  const appName = application.get("name");
113
- const subApp = await this.app.appManager.getApplication(appName);
145
+ const subApp = await import_server.AppSupervisor.getInstance().getApp(appName);
114
146
  await callback(subApp);
115
147
  }
116
148
  return;
117
149
  }
118
- const subApps = [...this.app.appManager.applications.values()];
150
+ const subApps = [...import_server.AppSupervisor.getInstance().subApps()];
119
151
  for (const subApp of subApps) {
120
152
  await callback(subApp);
121
153
  }
122
154
  };
123
- this.app.on("afterSubAppAdded", (subApp) => {
124
- subApp.plugin(SubAppPlugin, { name: "sub-app", mainApp: this.app });
125
- });
155
+ const mainApp = this.app;
156
+ function addPluginToSubApp(app) {
157
+ if (app.name !== "main") {
158
+ app.plugin(SubAppPlugin, { name: "sub-app", mainApp });
159
+ }
160
+ }
161
+ if (import_server.AppSupervisor.getInstance().listeners("afterAppAdded").filter((f) => f.name == addPluginToSubApp.name).length == 0) {
162
+ import_server.AppSupervisor.getInstance().on("afterAppAdded", addPluginToSubApp);
163
+ }
126
164
  this.app.db.on("users.afterCreateWithAssociations", async (model, options) => {
127
165
  await traverseSubApps(async (subApp) => {
128
166
  const { transaction } = options;
129
167
  const repository = subApp.db.getRepository("roles");
130
- const subAppModel = await subApp.db.getCollection("users").repository.findOne({
168
+ const subAppUserModel = await subApp.db.getCollection("users").repository.findOne({
131
169
  filter: {
132
170
  id: model.get("id")
133
171
  },
@@ -139,72 +177,36 @@ class MultiAppShareCollectionPlugin extends server.Plugin {
139
177
  },
140
178
  transaction
141
179
  });
142
- if (defaultRole && await subAppModel.countRoles({ transaction }) == 0) {
143
- await subAppModel.addRoles(defaultRole, { transaction });
180
+ if (defaultRole && await subAppUserModel.countRoles({ transaction }) == 0) {
181
+ await subAppUserModel.addRoles(defaultRole, { transaction });
144
182
  }
145
183
  });
146
184
  });
147
- this.app.db.on("collection:loaded", async ({ transaction, collection }) => {
148
- await traverseSubApps(async (subApp) => {
149
- const name = collection.name;
150
- const collectionRecord = await subApp.db.getRepository("collections").findOne({
151
- filter: {
152
- name
153
- },
154
- transaction
155
- });
156
- await collectionRecord.load({ transaction });
185
+ this.app.on("__restarted", () => {
186
+ traverseSubApps((subApp) => {
187
+ subApp.runCommand("restart");
157
188
  });
158
189
  });
159
- this.app.db.on("field:loaded", async ({ transaction, fieldKey }) => {
160
- await traverseSubApps(async (subApp) => {
161
- const fieldRecord = await subApp.db.getRepository("fields").findOne({
162
- filterByTk: fieldKey,
163
- transaction
164
- });
165
- if (fieldRecord) {
166
- await fieldRecord.load({ transaction });
167
- }
168
- });
169
- });
170
- this.app.on("afterEnablePlugin", async (pluginName) => {
171
- await traverseSubApps(
172
- async (subApp) => {
190
+ this.app.on("afterEnablePlugin", (pluginNames) => {
191
+ traverseSubApps((subApp) => {
192
+ for (const pluginName of import_lodash.default.castArray(pluginNames)) {
173
193
  if (subAppFilteredPlugins.includes(pluginName))
174
194
  return;
175
- await subApp.pm.enable(pluginName);
176
- },
177
- {
178
- loadFromDatabase: true
195
+ subApp.runAsCLI(["pm", "enable", pluginName], { from: "user" });
179
196
  }
180
- );
197
+ });
181
198
  });
182
- this.app.on("afterDisablePlugin", async (pluginName) => {
183
- await traverseSubApps(
184
- async (subApp) => {
199
+ this.app.on("afterDisablePlugin", (pluginNames) => {
200
+ traverseSubApps((subApp) => {
201
+ for (const pluginName of import_lodash.default.castArray(pluginNames)) {
185
202
  if (subAppFilteredPlugins.includes(pluginName))
186
203
  return;
187
- await subApp.pm.disable(pluginName);
188
- },
189
- {
190
- loadFromDatabase: true
191
- }
192
- );
193
- });
194
- this.app.db.on("field.afterRemove", (removedField) => {
195
- const subApps = [...this.app.appManager.applications.values()];
196
- for (const subApp of subApps) {
197
- const collectionName = removedField.collection.name;
198
- const collection = subApp.db.getCollection(collectionName);
199
- if (!collection) {
200
- subApp.log.warn(`collection ${collectionName} not found in ${subApp.name}`);
201
- continue;
204
+ subApp.runAsCLI(["pm", "disable", pluginName], { from: "user" });
202
205
  }
203
- collection.removeField(removedField.name);
204
- }
206
+ });
205
207
  });
206
208
  this.app.db.on(`afterRemoveCollection`, (collection) => {
207
- const subApps = [...this.app.appManager.applications.values()];
209
+ const subApps = [...import_server.AppSupervisor.getInstance().subApps()];
208
210
  for (const subApp of subApps) {
209
211
  subApp.db.removeCollection(collection.name);
210
212
  }
@@ -217,7 +219,7 @@ class MultiAppShareCollectionPlugin extends server.Plugin {
217
219
  return;
218
220
  }
219
221
  await this.db.import({
220
- directory: path.resolve(__dirname, "collections")
222
+ directory: (0, import_path.resolve)(__dirname, "collections")
221
223
  });
222
224
  this.app.resourcer.registerActionHandlers({
223
225
  "applications:shareCollections": async (ctx, next) => {
@@ -230,16 +232,16 @@ class MultiAppShareCollectionPlugin extends server.Plugin {
230
232
  }
231
233
  });
232
234
  multiAppManager.setAppOptionsFactory((appName, mainApp) => {
233
- const mainAppDbConfig = PluginMultiAppManager__default.default.getDatabaseConfig(mainApp);
235
+ const mainAppDbConfig = import_plugin_multi_app_manager.default.getDatabaseConfig(mainApp);
234
236
  const databaseOptions = {
235
237
  ...mainAppDbConfig,
236
238
  schema: appName
237
239
  };
238
- const plugins = [...mainApp.pm.getPlugins().keys()].filter(
240
+ const plugins = [...mainApp.pm.getAliases()].filter(
239
241
  (name) => name !== "multi-app-manager" && name !== "multi-app-share-collection"
240
242
  );
241
243
  return {
242
- database: lodash__default.default.merge(databaseOptions, {
244
+ database: import_lodash.default.merge(databaseOptions, {
243
245
  dialectOptions: {
244
246
  application_name: `nocobase.${appName}`
245
247
  }
@@ -268,11 +270,9 @@ class MultiAppShareCollectionPlugin extends server.Plugin {
268
270
  await this.app.db.sequelize.query(`CREATE SCHEMA IF NOT EXISTS ${schema}`);
269
271
  });
270
272
  }
271
- requiredPlugins() {
272
- return ["multi-app-manager"];
273
- }
274
273
  }
275
274
  var plugin_default = MultiAppShareCollectionPlugin;
276
-
277
- exports.MultiAppShareCollectionPlugin = MultiAppShareCollectionPlugin;
278
- exports.default = plugin_default;
275
+ // Annotate the CommonJS export names for ESM import in node:
276
+ 0 && (module.exports = {
277
+ MultiAppShareCollectionPlugin
278
+ });
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "displayName.zh-CN": "多应用数据共享",
5
5
  "description": "multi app share collection",
6
6
  "description.zh-CN": "多应用数据共享",
7
- "version": "0.12.0-alpha.5",
7
+ "version": "0.13.0-alpha.10",
8
8
  "main": "./dist/server/index.js",
9
9
  "devDependencies": {
10
10
  "@formily/react": "2.x",
@@ -23,5 +23,5 @@
23
23
  "@nocobase/test": "0.x",
24
24
  "@nocobase/utils": "0.x"
25
25
  },
26
- "gitHead": "689cc16e83361c4d0b91907e0deac30bdb907692"
26
+ "gitHead": "5360ed81650f6895f3ed39aede2706467d55862c"
27
27
  }