@nocobase/client 1.2.23-alpha → 1.2.25-alpha

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.
package/es/index.mjs CHANGED
@@ -61,7 +61,7 @@ import { Outlet, UNSAFE_RouteContext, UNSAFE_LocationContext, useRoutes, HashRou
61
61
  import * as nocobaseSDK from "@nocobase/sdk";
62
62
  import { APIClient as APIClient$1, getSubAppName } from "@nocobase/sdk";
63
63
  import * as antd from "antd";
64
- import { notification, Spin, message, Tag, Select as Select$1, theme, App, ConfigProvider, Popover, Menu as Menu$1, Switch, Divider, Button, Result, Tooltip, Input as Input$3, Empty, Modal, Typography, Image, Slider, Space as Space$1, Card, Collapse, Badge, Tree as Tree$2, Dropdown, Alert, Cascader as Cascader$1, Radio as Radio$1, Drawer as Drawer$1, Flex, InputNumber as InputNumber$1, DatePicker as DatePicker$1, Tabs as Tabs$1, TreeSelect as TreeSelect$2, Upload as Upload$1, Progress, Table as Table$2, Skeleton, AutoComplete as AutoComplete$1, Checkbox as Checkbox$1, ColorPicker as ColorPicker$1, List as List$1, Col, QRCode, Pagination as Pagination$1, TimePicker as TimePicker$1, Row, Popconfirm, Layout } from "antd";
64
+ import { notification, Spin, message, Tag, Result, Button, Select as Select$1, theme, App, ConfigProvider, Popover, Menu as Menu$1, Switch, Divider, Tooltip, Input as Input$3, Empty, Modal, Typography, Image, Slider, Space as Space$1, Card, Collapse, Badge, Tree as Tree$2, Dropdown, Alert, Cascader as Cascader$1, Radio as Radio$1, Drawer as Drawer$1, Flex, InputNumber as InputNumber$1, DatePicker as DatePicker$1, Tabs as Tabs$1, TreeSelect as TreeSelect$2, Upload as Upload$1, Progress, Table as Table$2, Skeleton, AutoComplete as AutoComplete$1, Checkbox as Checkbox$1, ColorPicker as ColorPicker$1, List as List$1, Col, QRCode, Pagination as Pagination$1, TimePicker as TimePicker$1, Row, Popconfirm, Layout } from "antd";
65
65
  import * as formilyShared from "@formily/shared";
66
66
  import { merge, uid, isArr, isFn, applyMiddleware, isNum as isNum$1, isStr, isBool, toArr as toArr$3, isValid, isReactElement, each } from "@formily/shared";
67
67
  import * as ahooks from "ahooks";
@@ -84,7 +84,7 @@ import ReactDOM__default, { createPortal } from "react-dom";
84
84
  import * as antdCssinjs from "@ant-design/cssinjs";
85
85
  import { useStyleRegister } from "@ant-design/cssinjs";
86
86
  import * as antIcons from "@ant-design/icons";
87
- import antIcons__default, { createFromIconfontCN, RightOutlined, LoadingOutlined, HighlightOutlined, PlusOutlined, TableOutlined, DragOutlined, MenuOutlined, CopyOutlined, CloseCircleOutlined, UserOutlined, CloseCircleFilled, CloseOutlined, InboxOutlined, DownloadOutlined, DeleteOutlined, EditOutlined, DownOutlined, CheckOutlined, RightSquareOutlined, SyncOutlined, ExclamationCircleFilled, ApiOutlined, SettingOutlined, ReadOutlined, ReloadOutlined, QuestionCircleOutlined, SearchOutlined, FormOutlined, OrderedListOutlined, DisconnectOutlined } from "@ant-design/icons";
87
+ import antIcons__default, { LoadingOutlined, createFromIconfontCN, RightOutlined, HighlightOutlined, PlusOutlined, TableOutlined, DragOutlined, MenuOutlined, CopyOutlined, CloseCircleOutlined, UserOutlined, CloseCircleFilled, CloseOutlined, InboxOutlined, DownloadOutlined, DeleteOutlined, EditOutlined, DownOutlined, CheckOutlined, RightSquareOutlined, SyncOutlined, ExclamationCircleFilled, ApiOutlined, SettingOutlined, ReadOutlined, ReloadOutlined, QuestionCircleOutlined, SearchOutlined, FormOutlined, OrderedListOutlined, DisconnectOutlined } from "@ant-design/icons";
88
88
  import { useHotkeys } from "react-hotkeys-hook";
89
89
  import * as antdStyle from "antd-style";
90
90
  import { createStyles, useAntdToken, createGlobalStyle } from "antd-style";
@@ -3965,7 +3965,7 @@ function addAppVersion(e, t) {
3965
3965
  addAppVersion((n = e.properties) == null ? void 0 : n[o], t);
3966
3966
  }), e;
3967
3967
  }
3968
- const name = "@nocobase/client", version$1 = "1.2.23-alpha", license = "AGPL-3.0", main = "lib/index.js", module = "es/index.mjs", types = "es/index.d.ts", dependencies = {
3968
+ const name = "@nocobase/client", version$1 = "1.2.25-alpha", license = "AGPL-3.0", main = "lib/index.js", module = "es/index.mjs", types = "es/index.d.ts", dependencies = {
3969
3969
  "@ahooksjs/use-url-state": "3.5.1",
3970
3970
  "@ant-design/cssinjs": "^1.11.1",
3971
3971
  "@ant-design/icons": "^5.1.4",
@@ -3986,9 +3986,9 @@ const name = "@nocobase/client", version$1 = "1.2.23-alpha", license = "AGPL-3.0
3986
3986
  "@formily/reactive-react": "^2.2.27",
3987
3987
  "@formily/shared": "^2.2.27",
3988
3988
  "@formily/validator": "^2.2.27",
3989
- "@nocobase/evaluators": "1.2.23-alpha",
3990
- "@nocobase/sdk": "1.2.23-alpha",
3991
- "@nocobase/utils": "1.2.23-alpha",
3989
+ "@nocobase/evaluators": "1.2.25-alpha",
3990
+ "@nocobase/sdk": "1.2.25-alpha",
3991
+ "@nocobase/utils": "1.2.25-alpha",
3992
3992
  ahooks: "^3.7.2",
3993
3993
  antd: "^5.12.8",
3994
3994
  "antd-style": "3.4.5",
@@ -4937,6 +4937,512 @@ function SetDataLoadingMode() {
4937
4937
  }
4938
4938
  );
4939
4939
  }
4940
+ const DataSourceManagerContext = createContext(null);
4941
+ DataSourceManagerContext.displayName = "DataSourceManagerContext";
4942
+ const DataSourceManagerProvider = ({ children: e, dataSourceManager: t }) => /* @__PURE__ */ jsx(DataSourceManagerContext.Provider, { value: t, children: e });
4943
+ function useDataSourceManager() {
4944
+ return useContext(DataSourceManagerContext);
4945
+ }
4946
+ const DataSourceContext = createContext(null);
4947
+ DataSourceContext.displayName = "DataSourceContext";
4948
+ const DataSourceProvider = ({ children: e, dataSource: t }) => {
4949
+ const o = useDataSourceManager(), { t: n } = useTranslation(), { refresh: r } = useSchemaComponentContext(), [i, a] = React.useState(0), l = o == null ? void 0 : o.getDataSource(t);
4950
+ return l ? l.status === "loading-failed" ? /* @__PURE__ */ jsx(
4951
+ CollectionDeletedPlaceholder,
4952
+ {
4953
+ type: "Data Source",
4954
+ name: l.displayName || t,
4955
+ message: l.errorMessage || "loading failed"
4956
+ }
4957
+ ) : l.status === "loading" || l.status === "reloading" ? /* @__PURE__ */ jsx(CardItem, { children: /* @__PURE__ */ jsx(
4958
+ Result,
4959
+ {
4960
+ icon: /* @__PURE__ */ jsx(LoadingOutlined, {}),
4961
+ title: `${l.displayName || t} ${n("data source")} ${n("loading")}...`,
4962
+ extra: /* @__PURE__ */ jsx(
4963
+ Button,
4964
+ {
4965
+ type: "primary",
4966
+ onClick: () => l.reload().then(() => {
4967
+ r(), a(Math.random());
4968
+ }),
4969
+ children: n("Refresh")
4970
+ }
4971
+ )
4972
+ }
4973
+ ) }) : /* @__PURE__ */ jsx(DataSourceContext.Provider, { value: l, children: e }) : /* @__PURE__ */ jsx(CollectionDeletedPlaceholder, { type: "Data Source", name: t });
4974
+ };
4975
+ function useDataSource() {
4976
+ return useContext(DataSourceContext);
4977
+ }
4978
+ function useDataSourceKey() {
4979
+ const e = useContext(DataSourceContext);
4980
+ return e == null ? void 0 : e.key;
4981
+ }
4982
+ const ExtendCollectionsContext = createContext(null);
4983
+ ExtendCollectionsContext.displayName = "ExtendCollectionsContext";
4984
+ const ExtendCollectionsProvider = ({ children: e, collections: t }) => {
4985
+ const o = useExtendCollections(), n = useMemo(() => o ? [...o, ...t] : t, [o, t]), r = useDataSourceKey();
4986
+ return /* @__PURE__ */ jsx(ExtendCollectionsContext.Provider, { value: n, children: /* @__PURE__ */ jsx(CollectionManagerProvider, { dataSource: r, children: e }) });
4987
+ };
4988
+ function useExtendCollections() {
4989
+ return useContext(ExtendCollectionsContext);
4990
+ }
4991
+ const CollectionManagerContext = createContext(null);
4992
+ CollectionManagerContext.displayName = "CollectionManagerContext";
4993
+ const CollectionManagerProviderInner = ({ instance: e, children: t }) => {
4994
+ const o = useDataSource(), n = useExtendCollections(), r = useMemo(() => {
4995
+ const i = e || (o == null ? void 0 : o.collectionManager);
4996
+ return n != null && n.length ? i.clone(n) : i;
4997
+ }, [e, n, o]);
4998
+ return /* @__PURE__ */ jsx(CollectionManagerContext.Provider, { value: r, children: t });
4999
+ }, CollectionManagerProvider = ({ instance: e, dataSource: t, children: o }) => /* @__PURE__ */ jsx(DataSourceProvider, { dataSource: t, children: /* @__PURE__ */ jsx(CollectionManagerProviderInner, { instance: e, children: o }) });
5000
+ function useCollectionManager() {
5001
+ return useContext(CollectionManagerContext);
5002
+ }
5003
+ const useCollections = (e) => {
5004
+ const t = useCollectionManager();
5005
+ return useMemo(() => t.getCollections(e), [t, e]);
5006
+ }, useSourceKey = (e) => useCollectionManager().getSourceKeyByAssociation(e);
5007
+ class CollectionRecord {
5008
+ constructor(t) {
5009
+ P(this, "data");
5010
+ P(this, "parentRecord");
5011
+ P(this, "isNew");
5012
+ const { data: o, parentRecord: n, isNew: r } = t;
5013
+ this.isNew = r, this.data = o, this.parentRecord = n;
5014
+ }
5015
+ setData(t) {
5016
+ this.data = t;
5017
+ }
5018
+ setParentRecord(t) {
5019
+ this.parentRecord = t;
5020
+ }
5021
+ }
5022
+ const CollectionRecordContext = createContext(null);
5023
+ CollectionRecordContext.displayName = "CollectionRecordContext";
5024
+ const CollectionRecordProvider = ({
5025
+ isNew: e,
5026
+ record: t,
5027
+ parentRecord: o,
5028
+ children: n
5029
+ }) => {
5030
+ const r = useMemo(() => {
5031
+ if (o)
5032
+ return o instanceof CollectionRecord ? o : new CollectionRecord({ data: o });
5033
+ if (t instanceof CollectionRecord)
5034
+ return t.parentRecord;
5035
+ }, [o, t]), i = useMemo(() => {
5036
+ let a;
5037
+ return t ? t instanceof CollectionRecord ? (a = t, a.isNew = t.isNew || e) : a = new CollectionRecord({ data: t, isNew: e }) : a = new CollectionRecord({ isNew: e }), a.setParentRecord(r), a;
5038
+ }, [t, r, e]);
5039
+ return /* @__PURE__ */ jsx(CollectionRecordContext.Provider, { value: i, children: n });
5040
+ };
5041
+ function useCollectionRecord() {
5042
+ return useContext(CollectionRecordContext);
5043
+ }
5044
+ function useCollectionRecordData() {
5045
+ const e = useCollectionRecord();
5046
+ return e == null ? void 0 : e.data;
5047
+ }
5048
+ function useCollectionParentRecord() {
5049
+ const e = useCollectionRecord();
5050
+ return e == null ? void 0 : e.parentRecord;
5051
+ }
5052
+ function useCollectionParentRecordData() {
5053
+ var t;
5054
+ const e = useCollectionRecord();
5055
+ return (t = e == null ? void 0 : e.parentRecord) == null ? void 0 : t.data;
5056
+ }
5057
+ class DataSource {
5058
+ constructor(t, o) {
5059
+ P(this, "collectionManager");
5060
+ P(this, "reloadCallbacks", []);
5061
+ this.options = t, this.dataSourceManager = o, this.collectionManager = new CollectionManager(t.collections, this);
5062
+ }
5063
+ get app() {
5064
+ return this.dataSourceManager.app;
5065
+ }
5066
+ get key() {
5067
+ return this.options.key;
5068
+ }
5069
+ get displayName() {
5070
+ return this.options.displayName;
5071
+ }
5072
+ get status() {
5073
+ return this.options.status;
5074
+ }
5075
+ get errorMessage() {
5076
+ return this.options.errorMessage;
5077
+ }
5078
+ get collections() {
5079
+ return this.collectionManager.getCollections() || [];
5080
+ }
5081
+ getOptions() {
5082
+ return this.options;
5083
+ }
5084
+ setOptions(t) {
5085
+ Object.assign(this.options, t);
5086
+ }
5087
+ getOption(t) {
5088
+ return this.options[t];
5089
+ }
5090
+ addReloadCallback(t) {
5091
+ this.reloadCallbacks.includes(t) || this.reloadCallbacks.push(t);
5092
+ }
5093
+ removeReloadCallback(t) {
5094
+ this.reloadCallbacks = this.reloadCallbacks.filter((o) => o !== t);
5095
+ }
5096
+ reload() {
5097
+ return V(this, null, function* () {
5098
+ const t = yield this.getDataSource();
5099
+ return this.setOptions(t), this.collectionManager.setCollections(t.collections || []), this.reloadCallbacks.forEach((o) => o(t.collections)), this.options;
5100
+ });
5101
+ }
5102
+ }
5103
+ class LocalDataSource extends DataSource {
5104
+ getDataSource() {
5105
+ return {
5106
+ collections: this.collections
5107
+ };
5108
+ }
5109
+ }
5110
+ class CollectionTemplate {
5111
+ constructor(t) {
5112
+ P(this, "name");
5113
+ P(this, "Collection");
5114
+ P(this, "title");
5115
+ P(this, "color");
5116
+ /** Sorting */
5117
+ P(this, "order");
5118
+ /** Default configuration */
5119
+ P(this, "default");
5120
+ P(this, "events");
5121
+ /** UI configurable CollectionOptions parameters (fields for adding or editing Collection forms) */
5122
+ P(this, "configurableProperties");
5123
+ /** Available field types for the current template */
5124
+ P(this, "availableFieldInterfaces");
5125
+ /** Whether it is a divider */
5126
+ P(this, "divider");
5127
+ /** Template description */
5128
+ P(this, "description");
5129
+ /** Configure buttons in the configuration fields */
5130
+ P(this, "configureActions");
5131
+ // Whether to prohibit deleting fields
5132
+ P(this, "forbidDeletion");
5133
+ P(this, "supportDataSourceType");
5134
+ P(this, "notSupportDataSourceType");
5135
+ this.collectionTemplateManager = t;
5136
+ }
5137
+ }
5138
+ class CollectionTemplateManager {
5139
+ constructor(t, o) {
5140
+ P(this, "collectionTemplateInstances", {});
5141
+ this.dataSourceManager = o, this.addCollectionTemplates(t);
5142
+ }
5143
+ addCollectionTemplates(t = []) {
5144
+ const o = t.reduce((n, r) => {
5145
+ const i = new r(this);
5146
+ return n[i.name] = i, n;
5147
+ }, {});
5148
+ return Object.assign(this.collectionTemplateInstances, o), this.dataSourceManager.getDataSources().forEach((n) => {
5149
+ const r = n.collectionManager.getCollections((i) => o[i.template]);
5150
+ n.collectionManager.reAddCollections(r);
5151
+ }), o;
5152
+ }
5153
+ getCollectionTemplate(t) {
5154
+ return this.collectionTemplateInstances[t];
5155
+ }
5156
+ getCollectionTemplates(t) {
5157
+ return Object.values(this.collectionTemplateInstances).filter((o) => {
5158
+ var n, r;
5159
+ if (!t || !o.supportDataSourceType && !o.notSupportDataSourceType)
5160
+ return !0;
5161
+ if (o.supportDataSourceType)
5162
+ return (n = o.supportDataSourceType) == null ? void 0 : n.includes(t);
5163
+ if (o.notSupportDataSourceType)
5164
+ return !((r = o.notSupportDataSourceType) != null && r.includes(t));
5165
+ }).sort((o, n) => (o.order || 0) - (n.order || 0));
5166
+ }
5167
+ }
5168
+ class CollectionFieldInterface {
5169
+ constructor(t) {
5170
+ P(this, "name");
5171
+ P(this, "group");
5172
+ P(this, "title");
5173
+ P(this, "description");
5174
+ P(this, "order");
5175
+ P(this, "default");
5176
+ P(this, "sortable");
5177
+ P(this, "availableTypes");
5178
+ P(this, "supportDataSourceType");
5179
+ P(this, "notSupportDataSourceType");
5180
+ P(this, "hasDefaultValue");
5181
+ P(this, "isAssociation");
5182
+ P(this, "operators");
5183
+ /**
5184
+ * - 如果该值为空,则在 Filter 组件中该字段会被过滤掉
5185
+ * - 如果该值为空,则不会在变量列表中看到该字段
5186
+ */
5187
+ P(this, "filterable");
5188
+ P(this, "titleUsable");
5189
+ P(this, "hidden");
5190
+ this.collectionFieldInterfaceManager = t;
5191
+ }
5192
+ }
5193
+ class CollectionFieldInterfaceManager {
5194
+ constructor(t, o, n) {
5195
+ P(this, "collectionFieldInterfaceInstances", {});
5196
+ P(this, "collectionFieldGroups", {});
5197
+ this.dataSourceManager = n, this.addFieldInterfaces(t), this.addFieldInterfaceGroups(o);
5198
+ }
5199
+ addFieldInterfaces(t = []) {
5200
+ const o = t.reduce((n, r) => {
5201
+ const i = new r(this);
5202
+ return n[i.name] = i, n;
5203
+ }, {});
5204
+ Object.assign(this.collectionFieldInterfaceInstances, o);
5205
+ }
5206
+ getFieldInterface(t) {
5207
+ return this.collectionFieldInterfaceInstances[t];
5208
+ }
5209
+ getFieldInterfaces(t) {
5210
+ return Object.values(this.collectionFieldInterfaceInstances).filter((o) => {
5211
+ var n, r;
5212
+ if (!t || !o.supportDataSourceType && !o.notSupportDataSourceType)
5213
+ return !0;
5214
+ if (o.supportDataSourceType)
5215
+ return (n = o.supportDataSourceType) == null ? void 0 : n.includes(t);
5216
+ if (o.notSupportDataSourceType)
5217
+ return !((r = o.notSupportDataSourceType) != null && r.includes(t));
5218
+ });
5219
+ }
5220
+ addFieldInterfaceGroups(t) {
5221
+ Object.assign(this.collectionFieldGroups, t);
5222
+ }
5223
+ getFieldInterfaceGroups() {
5224
+ return this.collectionFieldGroups;
5225
+ }
5226
+ getFieldInterfaceGroup(t) {
5227
+ return this.collectionFieldGroups[t];
5228
+ }
5229
+ }
5230
+ const DEFAULT_DATA_SOURCE_KEY = "main", DEFAULT_DATA_SOURCE_TITLE = '{{t("Main")}}';
5231
+ class DataSourceManager {
5232
+ constructor(t = {}, o) {
5233
+ P(this, "dataSourceInstancesMap", {});
5234
+ P(this, "multiDataSources", []);
5235
+ P(this, "collectionMixins", []);
5236
+ P(this, "collectionTemplateManager");
5237
+ P(this, "collectionFieldInterfaceManager");
5238
+ this.options = t, this.app = o, this.collectionTemplateManager = new CollectionTemplateManager(t.collectionTemplates, this), this.collectionFieldInterfaceManager = new CollectionFieldInterfaceManager(
5239
+ t.fieldInterfaces,
5240
+ t.fieldInterfaceGroups,
5241
+ this
5242
+ ), this.collectionMixins.push(...t.collectionMixins || []), this.addDataSource(LocalDataSource, {
5243
+ key: DEFAULT_DATA_SOURCE_KEY,
5244
+ displayName: DEFAULT_DATA_SOURCE_TITLE,
5245
+ collections: t.collections || []
5246
+ }), (t.dataSources || []).forEach((n) => {
5247
+ this.addDataSource(LocalDataSource, n);
5248
+ });
5249
+ }
5250
+ addCollectionMixins(t = []) {
5251
+ const o = t.filter((n) => !this.collectionMixins.includes(n));
5252
+ o.length && (this.collectionMixins.push(...o), this.getDataSources().forEach((n) => n.collectionManager.reAddCollections()));
5253
+ }
5254
+ getDataSources(t) {
5255
+ const o = Object.values(this.dataSourceInstancesMap);
5256
+ return t ? _.filter(o, t) : o;
5257
+ }
5258
+ getDataSource(t) {
5259
+ return t ? this.dataSourceInstancesMap[t] : this.dataSourceInstancesMap[DEFAULT_DATA_SOURCE_KEY];
5260
+ }
5261
+ removeDataSources(t) {
5262
+ t.forEach((o) => {
5263
+ delete this.dataSourceInstancesMap[o];
5264
+ });
5265
+ }
5266
+ addDataSource(t, o) {
5267
+ const n = new t(o, this);
5268
+ return this.dataSourceInstancesMap[n.key] = n, n;
5269
+ }
5270
+ addDataSources(t, o) {
5271
+ return V(this, null, function* () {
5272
+ this.multiDataSources.some(([n, r]) => n === t && r === o) || this.multiDataSources.push([t, o]);
5273
+ });
5274
+ }
5275
+ getAllCollections(t = {}) {
5276
+ const { filterCollection: o, filterDataSource: n } = t;
5277
+ return this.getDataSources(n).reduce(
5278
+ (r, i) => (r.push(F(g({}, i.getOptions()), {
5279
+ collections: i.collectionManager.getCollections(o)
5280
+ })), r),
5281
+ []
5282
+ );
5283
+ }
5284
+ addFieldInterfaceGroups(t) {
5285
+ this.collectionFieldInterfaceManager.addFieldInterfaceGroups(t);
5286
+ }
5287
+ addCollectionTemplates(t = []) {
5288
+ this.collectionTemplateManager.addCollectionTemplates(t);
5289
+ }
5290
+ addFieldInterfaces(t = []) {
5291
+ this.collectionFieldInterfaceManager.addFieldInterfaces(t);
5292
+ }
5293
+ reload() {
5294
+ return V(this, null, function* () {
5295
+ return yield Promise.all(
5296
+ this.multiDataSources.map((n) => V(this, [n], function* ([t, o]) {
5297
+ (yield t()).map((i) => this.addDataSource(o, i));
5298
+ }))
5299
+ ), Promise.all(this.getDataSources().map((t) => t.reload()));
5300
+ });
5301
+ }
5302
+ }
5303
+ const HEADERS_DATA_SOURCE_KEY = "x-data-source", isTitleField = (e, t) => {
5304
+ var o;
5305
+ return (o = e.collectionFieldInterfaceManager.getFieldInterface(t.interface)) == null ? void 0 : o.titleUsable;
5306
+ }, useDataSourceHeaders = (e) => useMemo(() => {
5307
+ if (e && e !== DEFAULT_DATA_SOURCE_KEY)
5308
+ return { [HEADERS_DATA_SOURCE_KEY]: e };
5309
+ }, [e]), getDataSourceHeaders = (e) => e && e !== DEFAULT_DATA_SOURCE_KEY ? { [HEADERS_DATA_SOURCE_KEY]: e } : {}, DataBlockResourceContext = createContext(null);
5310
+ DataBlockResourceContext.displayName = "DataBlockResourceContext";
5311
+ const DataBlockResourceProvider = ({ children: e }) => {
5312
+ const t = useDataBlockProps(), o = useCollectionManager(), { association: n, collection: r, dataSource: i, sourceId: a, parentRecord: l } = t, c = useAPIClient(), u = useDataSourceHeaders(i), d = useMemo(() => typeof r == "string" ? r : r == null ? void 0 : r.name, [r]), p = useMemo(() => {
5313
+ if (a)
5314
+ return a;
5315
+ if (n && l) {
5316
+ const h = o.getSourceKeyByAssociation(n);
5317
+ return (l instanceof CollectionRecord ? l.data : l)[h];
5318
+ }
5319
+ }, [n, a, l]), m = useMemo(() => n ? c.resource(n, p, u) : c.resource(d, void 0, u), [c, n, r, p, u]);
5320
+ return /* @__PURE__ */ jsx(DataBlockResourceContext.Provider, { value: m, children: e });
5321
+ };
5322
+ function useDataBlockResource() {
5323
+ const e = useContext(DataBlockResourceContext);
5324
+ if (!e)
5325
+ throw new Error("useDataBlockResource() must be used within a DataBlockResourceProvider");
5326
+ return e;
5327
+ }
5328
+ const DataBlockContext = createContext({});
5329
+ DataBlockContext.displayName = "DataBlockContext";
5330
+ const AssociationOrCollectionProvider = (e) => {
5331
+ const { collection: t, association: o, allowNull: n = !1 } = e, r = useMemo(() => o ? {
5332
+ Component: AssociationProvider,
5333
+ name: o
5334
+ } : {
5335
+ Component: SanitizedCollectionProvider,
5336
+ name: t
5337
+ }, [t, o]);
5338
+ return /* @__PURE__ */ jsx(r.Component, { name: r.name, allowNull: n, children: e.children });
5339
+ }, DataBlockProvider = withDynamicSchemaProps(
5340
+ (e) => {
5341
+ const c = e, { collection: t, association: o, dataSource: n, children: r, hidden: i } = c, a = H(c, ["collection", "association", "dataSource", "children", "hidden"]), { dn: l } = useDesignable();
5342
+ return i ? null : /* @__PURE__ */ jsx(
5343
+ DataBlockContext.Provider,
5344
+ {
5345
+ value: {
5346
+ dn: l,
5347
+ props: F(g({}, a), { collection: t, association: o, dataSource: n })
5348
+ },
5349
+ children: /* @__PURE__ */ jsx(CollectionManagerProvider, { dataSource: n, children: /* @__PURE__ */ jsx(AssociationOrCollectionProvider, { collection: t, association: o, children: /* @__PURE__ */ jsx(ACLCollectionProvider, { children: /* @__PURE__ */ jsx(DataBlockResourceProvider, { children: /* @__PURE__ */ jsx(BlockRequestProvider, { children: /* @__PURE__ */ jsx(DataBlockCollector, { params: e.params, children: r }) }) }) }) }) })
5350
+ }
5351
+ );
5352
+ },
5353
+ { displayName: "DataBlockProvider" }
5354
+ ), useDataBlock = () => {
5355
+ const e = useContext(DataBlockContext);
5356
+ if (!e)
5357
+ throw new Error("useDataBlock() must be used within a DataBlockProvider");
5358
+ return e;
5359
+ }, useDataBlockProps = () => useDataBlock().props, BlockRequestContext = createContext(null);
5360
+ BlockRequestContext.displayName = "BlockRequestContext";
5361
+ function useCurrentRequest(e) {
5362
+ const t = useDataLoadingMode(), o = useDataBlockResource(), { action: n, params: r = {}, record: i, requestService: a, requestOptions: l } = e, c = useMemo(() => a || ((d) => {
5363
+ if (i)
5364
+ return Promise.resolve({ data: i });
5365
+ if (!n)
5366
+ throw new Error(
5367
+ "[nocobase]: The 'action' parameter is missing in the 'DataBlockRequestProvider' component"
5368
+ );
5369
+ const p = r.filterByTk === void 0 ? _.omit(r, "filterByTk") : r;
5370
+ return o[n](g(g({}, p), d)).then((m) => m.data);
5371
+ }), [o, n, JSON.stringify(r), JSON.stringify(i), a]);
5372
+ return useRequest(c, F(g({}, l), {
5373
+ manual: t === "manual",
5374
+ ready: !!n,
5375
+ refreshDeps: [n, JSON.stringify(r), JSON.stringify(i), o]
5376
+ }));
5377
+ }
5378
+ function requestParentRecordData(a) {
5379
+ return V(this, arguments, function* ({
5380
+ sourceId: e,
5381
+ association: t,
5382
+ parentRecord: o,
5383
+ api: n,
5384
+ headers: r,
5385
+ sourceKey: i
5386
+ }) {
5387
+ if (o)
5388
+ return Promise.resolve({ data: o });
5389
+ if (!t || !i || !e)
5390
+ return Promise.resolve({ data: void 0 });
5391
+ const c = `${t.split(".")[0]}:get?filter[${i}]=${e}`;
5392
+ return (yield n.request({ url: c, headers: r })).data;
5393
+ });
5394
+ }
5395
+ function useParentRequest(e) {
5396
+ const { sourceId: t, association: o, parentRecord: n } = e, r = useAPIClient(), i = useDataBlockProps(), a = useDataSourceHeaders(i.dataSource), l = useSourceKey(o);
5397
+ return useRequest(
5398
+ () => requestParentRecordData({ sourceId: t, association: o, parentRecord: n, api: r, headers: a, sourceKey: l }),
5399
+ {
5400
+ refreshDeps: [o, n, t]
5401
+ }
5402
+ );
5403
+ }
5404
+ const BlockRequestProvider = ({ children: e }) => {
5405
+ var x, C;
5406
+ const t = useDataBlockProps(), {
5407
+ action: o,
5408
+ filterByTk: n,
5409
+ sourceId: r,
5410
+ params: i = {},
5411
+ association: a,
5412
+ collection: l,
5413
+ record: c,
5414
+ parentRecord: u,
5415
+ requestOptions: d,
5416
+ requestService: p
5417
+ } = t, m = useCurrentRequest({
5418
+ action: o,
5419
+ sourceId: r,
5420
+ record: c,
5421
+ association: a,
5422
+ collection: l,
5423
+ requestOptions: d,
5424
+ requestService: p,
5425
+ params: F(g({}, i), {
5426
+ filterByTk: n || i.filterByTk
5427
+ })
5428
+ }), h = useParentRequest({
5429
+ sourceId: r,
5430
+ association: a,
5431
+ parentRecord: u
5432
+ }), f = useMemo(() => {
5433
+ var S, b;
5434
+ return ((S = h.data) == null ? void 0 : S.data) && new CollectionRecord({ isNew: !1, data: (b = h.data) == null ? void 0 : b.data });
5435
+ }, [(x = h.data) == null ? void 0 : x.data]);
5436
+ return /* @__PURE__ */ jsx(BlockRequestContext.Provider, { value: m, children: o !== "list" ? /* @__PURE__ */ jsx(
5437
+ CollectionRecordProvider,
5438
+ {
5439
+ isNew: o == null,
5440
+ record: (C = m.data) == null ? void 0 : C.data,
5441
+ parentRecord: f,
5442
+ children: e
5443
+ }
5444
+ ) : /* @__PURE__ */ jsx(CollectionRecordProvider, { isNew: !1, record: null, parentRecord: f, children: e }) });
5445
+ }, useDataBlockRequest = () => useContext(BlockRequestContext);
4940
5446
  var FilterBlockType = /* @__PURE__ */ ((e) => (e[e.FORM = 0] = "FORM", e[e.TABLE = 1] = "TABLE", e[e.TREE = 2] = "TREE", e[e.COLLAPSE = 3] = "COLLAPSE", e))(FilterBlockType || {});
4941
5447
  const mergeFilter = (e, t = "$and") => {
4942
5448
  const o = e.filter((n) => {
@@ -4955,7 +5461,7 @@ const mergeFilter = (e, t = "$and") => {
4955
5461
  (r) => r.type !== "belongsTo" && r.foreignKey === n.name
4956
5462
  ));
4957
5463
  }, useSupportedBlocks = (e) => {
4958
- const { getDataBlocks: t } = useFilterBlock(), o = useFieldSchema(), n = useCollection_deprecated(), { getAllCollectionsInheritChain: r } = useCollectionManager_deprecated();
5464
+ const { getDataBlocks: t } = useFilterBlock(), o = useFieldSchema(), n = useCollection(), { getAllCollectionsInheritChain: r } = useCollectionManager_deprecated();
4959
5465
  if (e === 0 || e === 3)
4960
5466
  return t().filter((i) => isSameCollection(i.collection, n));
4961
5467
  if (e === 1 || e === 2)
@@ -5062,32 +5568,33 @@ const FilterBlockProvider = ({ children: e }) => {
5062
5568
  children: e,
5063
5569
  params: t
5064
5570
  }) => {
5065
- const o = useCollection_deprecated(), { recordDataBlocks: n } = useFilterBlock(), { service: r } = useBlockRequestContext(), i = useField(), a = useFieldSchema(), l = useAssociatedFields(), c = useRef(null), u = useDataLoadingMode(), d = i.decoratorType !== "FilterFormBlockProvider" && i.decoratorType !== "FormBlockProvider" && i.decoratorProps.blockType !== "filter", p = useCallback(() => {
5571
+ var m;
5572
+ const o = useCollection(), { recordDataBlocks: n } = useFilterBlock(), r = useDataBlockRequest(), i = useField(), a = useFieldSchema(), l = useAssociatedFields(), c = useRef(null), u = useDataLoadingMode(), d = i && i.decoratorType !== "FilterFormBlockProvider" && i.decoratorType !== "FormBlockProvider" && i.decoratorProps.blockType !== "filter", p = useCallback(() => {
5066
5573
  n({
5067
5574
  uid: a["x-uid"],
5068
5575
  title: i.componentProps.title,
5069
5576
  doFilter: r.runAsync,
5070
5577
  collection: o,
5071
5578
  associatedFields: l,
5072
- foreignKeyFields: o.foreignKeyFields,
5579
+ foreignKeyFields: o.getFields("isForeignKey"),
5073
5580
  defaultFilter: (t == null ? void 0 : t.filter) || {},
5074
5581
  service: r,
5075
5582
  dom: c.current,
5076
5583
  dataLoadingMode: u,
5077
- clearFilter(m) {
5078
- var C, S, b;
5079
- const h = ((C = this.service.params) == null ? void 0 : C[0]) || {}, f = ((b = (S = this.service.params) == null ? void 0 : S[1]) == null ? void 0 : b.filters) || {};
5080
- delete f[m];
5081
- const x = mergeFilter([
5082
- ...Object.values(f).map((y) => removeNullCondition(y)),
5584
+ clearFilter(h) {
5585
+ var S, b, y;
5586
+ const f = ((S = this.service.params) == null ? void 0 : S[0]) || {}, x = ((y = (b = this.service.params) == null ? void 0 : b[1]) == null ? void 0 : y.filters) || {};
5587
+ delete x[h];
5588
+ const C = mergeFilter([
5589
+ ...Object.values(x).map((v) => removeNullCondition(v)),
5083
5590
  (t == null ? void 0 : t.filter) || {}
5084
5591
  ]);
5085
5592
  this.service.run(
5086
- F(g({}, h), {
5593
+ F(g({}, f), {
5087
5594
  page: 1,
5088
- filter: x
5595
+ filter: C
5089
5596
  }),
5090
- { filters: f }
5597
+ { filters: x }
5091
5598
  );
5092
5599
  },
5093
5600
  clearData() {
@@ -5098,7 +5605,7 @@ const FilterBlockProvider = ({ children: e }) => {
5098
5605
  l,
5099
5606
  o,
5100
5607
  u,
5101
- i.componentProps.title,
5608
+ (m = i == null ? void 0 : i.componentProps) == null ? void 0 : m.title,
5102
5609
  a,
5103
5610
  t == null ? void 0 : t.filter,
5104
5611
  n,
@@ -8471,319 +8978,7 @@ https://requirejs.org/docs/errors.html#` + e);
8471
8978
  define
8472
8979
  };
8473
8980
  }
8474
- const DataSourceManagerContext = createContext(null);
8475
- DataSourceManagerContext.displayName = "DataSourceManagerContext";
8476
- const DataSourceManagerProvider = ({ children: e, dataSourceManager: t }) => /* @__PURE__ */ jsx(DataSourceManagerContext.Provider, { value: t, children: e });
8477
- function useDataSourceManager() {
8478
- return useContext(DataSourceManagerContext);
8479
- }
8480
- const DataSourceContext = createContext(null);
8481
- DataSourceContext.displayName = "DataSourceContext";
8482
- const DataSourceProvider = ({ children: e, dataSource: t }) => {
8483
- const o = useDataSourceManager(), { t: n } = useTranslation(), { refresh: r } = useSchemaComponentContext(), [i, a] = React.useState(0), l = o == null ? void 0 : o.getDataSource(t);
8484
- return l ? l.status === "loading-failed" ? /* @__PURE__ */ jsx(
8485
- CollectionDeletedPlaceholder,
8486
- {
8487
- type: "Data Source",
8488
- name: l.displayName || t,
8489
- message: l.errorMessage || "loading failed"
8490
- }
8491
- ) : l.status === "loading" || l.status === "reloading" ? /* @__PURE__ */ jsx(CardItem, { children: /* @__PURE__ */ jsx(
8492
- Result,
8493
- {
8494
- icon: /* @__PURE__ */ jsx(LoadingOutlined, {}),
8495
- title: `${l.displayName || t} ${n("data source")} ${n("loading")}...`,
8496
- extra: /* @__PURE__ */ jsx(
8497
- Button,
8498
- {
8499
- type: "primary",
8500
- onClick: () => l.reload().then(() => {
8501
- r(), a(Math.random());
8502
- }),
8503
- children: n("Refresh")
8504
- }
8505
- )
8506
- }
8507
- ) }) : /* @__PURE__ */ jsx(DataSourceContext.Provider, { value: l, children: e }) : /* @__PURE__ */ jsx(CollectionDeletedPlaceholder, { type: "Data Source", name: t });
8508
- };
8509
- function useDataSource() {
8510
- return useContext(DataSourceContext);
8511
- }
8512
- function useDataSourceKey() {
8513
- const e = useContext(DataSourceContext);
8514
- return e == null ? void 0 : e.key;
8515
- }
8516
- class DataSource {
8517
- constructor(t, o) {
8518
- P(this, "collectionManager");
8519
- P(this, "reloadCallbacks", []);
8520
- this.options = t, this.dataSourceManager = o, this.collectionManager = new CollectionManager(t.collections, this);
8521
- }
8522
- get app() {
8523
- return this.dataSourceManager.app;
8524
- }
8525
- get key() {
8526
- return this.options.key;
8527
- }
8528
- get displayName() {
8529
- return this.options.displayName;
8530
- }
8531
- get status() {
8532
- return this.options.status;
8533
- }
8534
- get errorMessage() {
8535
- return this.options.errorMessage;
8536
- }
8537
- get collections() {
8538
- return this.collectionManager.getCollections() || [];
8539
- }
8540
- getOptions() {
8541
- return this.options;
8542
- }
8543
- setOptions(t) {
8544
- Object.assign(this.options, t);
8545
- }
8546
- getOption(t) {
8547
- return this.options[t];
8548
- }
8549
- addReloadCallback(t) {
8550
- this.reloadCallbacks.includes(t) || this.reloadCallbacks.push(t);
8551
- }
8552
- removeReloadCallback(t) {
8553
- this.reloadCallbacks = this.reloadCallbacks.filter((o) => o !== t);
8554
- }
8555
- reload() {
8556
- return V(this, null, function* () {
8557
- const t = yield this.getDataSource();
8558
- return this.setOptions(t), this.collectionManager.setCollections(t.collections || []), this.reloadCallbacks.forEach((o) => o(t.collections)), this.options;
8559
- });
8560
- }
8561
- }
8562
- class LocalDataSource extends DataSource {
8563
- getDataSource() {
8564
- return {
8565
- collections: this.collections
8566
- };
8567
- }
8568
- }
8569
- class CollectionTemplate {
8570
- constructor(t) {
8571
- P(this, "name");
8572
- P(this, "Collection");
8573
- P(this, "title");
8574
- P(this, "color");
8575
- /** Sorting */
8576
- P(this, "order");
8577
- /** Default configuration */
8578
- P(this, "default");
8579
- P(this, "events");
8580
- /** UI configurable CollectionOptions parameters (fields for adding or editing Collection forms) */
8581
- P(this, "configurableProperties");
8582
- /** Available field types for the current template */
8583
- P(this, "availableFieldInterfaces");
8584
- /** Whether it is a divider */
8585
- P(this, "divider");
8586
- /** Template description */
8587
- P(this, "description");
8588
- /** Configure buttons in the configuration fields */
8589
- P(this, "configureActions");
8590
- // Whether to prohibit deleting fields
8591
- P(this, "forbidDeletion");
8592
- P(this, "supportDataSourceType");
8593
- P(this, "notSupportDataSourceType");
8594
- this.collectionTemplateManager = t;
8595
- }
8596
- }
8597
- class CollectionTemplateManager {
8598
- constructor(t, o) {
8599
- P(this, "collectionTemplateInstances", {});
8600
- this.dataSourceManager = o, this.addCollectionTemplates(t);
8601
- }
8602
- addCollectionTemplates(t = []) {
8603
- const o = t.reduce((n, r) => {
8604
- const i = new r(this);
8605
- return n[i.name] = i, n;
8606
- }, {});
8607
- return Object.assign(this.collectionTemplateInstances, o), this.dataSourceManager.getDataSources().forEach((n) => {
8608
- const r = n.collectionManager.getCollections((i) => o[i.template]);
8609
- n.collectionManager.reAddCollections(r);
8610
- }), o;
8611
- }
8612
- getCollectionTemplate(t) {
8613
- return this.collectionTemplateInstances[t];
8614
- }
8615
- getCollectionTemplates(t) {
8616
- return Object.values(this.collectionTemplateInstances).filter((o) => {
8617
- var n, r;
8618
- if (!t || !o.supportDataSourceType && !o.notSupportDataSourceType)
8619
- return !0;
8620
- if (o.supportDataSourceType)
8621
- return (n = o.supportDataSourceType) == null ? void 0 : n.includes(t);
8622
- if (o.notSupportDataSourceType)
8623
- return !((r = o.notSupportDataSourceType) != null && r.includes(t));
8624
- }).sort((o, n) => (o.order || 0) - (n.order || 0));
8625
- }
8626
- }
8627
- class CollectionFieldInterface {
8628
- constructor(t) {
8629
- P(this, "name");
8630
- P(this, "group");
8631
- P(this, "title");
8632
- P(this, "description");
8633
- P(this, "order");
8634
- P(this, "default");
8635
- P(this, "sortable");
8636
- P(this, "availableTypes");
8637
- P(this, "supportDataSourceType");
8638
- P(this, "notSupportDataSourceType");
8639
- P(this, "hasDefaultValue");
8640
- P(this, "isAssociation");
8641
- P(this, "operators");
8642
- /**
8643
- * - 如果该值为空,则在 Filter 组件中该字段会被过滤掉
8644
- * - 如果该值为空,则不会在变量列表中看到该字段
8645
- */
8646
- P(this, "filterable");
8647
- P(this, "titleUsable");
8648
- P(this, "hidden");
8649
- this.collectionFieldInterfaceManager = t;
8650
- }
8651
- }
8652
- class CollectionFieldInterfaceManager {
8653
- constructor(t, o, n) {
8654
- P(this, "collectionFieldInterfaceInstances", {});
8655
- P(this, "collectionFieldGroups", {});
8656
- this.dataSourceManager = n, this.addFieldInterfaces(t), this.addFieldInterfaceGroups(o);
8657
- }
8658
- addFieldInterfaces(t = []) {
8659
- const o = t.reduce((n, r) => {
8660
- const i = new r(this);
8661
- return n[i.name] = i, n;
8662
- }, {});
8663
- Object.assign(this.collectionFieldInterfaceInstances, o);
8664
- }
8665
- getFieldInterface(t) {
8666
- return this.collectionFieldInterfaceInstances[t];
8667
- }
8668
- getFieldInterfaces(t) {
8669
- return Object.values(this.collectionFieldInterfaceInstances).filter((o) => {
8670
- var n, r;
8671
- if (!t || !o.supportDataSourceType && !o.notSupportDataSourceType)
8672
- return !0;
8673
- if (o.supportDataSourceType)
8674
- return (n = o.supportDataSourceType) == null ? void 0 : n.includes(t);
8675
- if (o.notSupportDataSourceType)
8676
- return !((r = o.notSupportDataSourceType) != null && r.includes(t));
8677
- });
8678
- }
8679
- addFieldInterfaceGroups(t) {
8680
- Object.assign(this.collectionFieldGroups, t);
8681
- }
8682
- getFieldInterfaceGroups() {
8683
- return this.collectionFieldGroups;
8684
- }
8685
- getFieldInterfaceGroup(t) {
8686
- return this.collectionFieldGroups[t];
8687
- }
8688
- }
8689
- const DEFAULT_DATA_SOURCE_KEY = "main", DEFAULT_DATA_SOURCE_TITLE = '{{t("Main")}}';
8690
- class DataSourceManager {
8691
- constructor(t = {}, o) {
8692
- P(this, "dataSourceInstancesMap", {});
8693
- P(this, "multiDataSources", []);
8694
- P(this, "collectionMixins", []);
8695
- P(this, "collectionTemplateManager");
8696
- P(this, "collectionFieldInterfaceManager");
8697
- this.options = t, this.app = o, this.collectionTemplateManager = new CollectionTemplateManager(t.collectionTemplates, this), this.collectionFieldInterfaceManager = new CollectionFieldInterfaceManager(
8698
- t.fieldInterfaces,
8699
- t.fieldInterfaceGroups,
8700
- this
8701
- ), this.collectionMixins.push(...t.collectionMixins || []), this.addDataSource(LocalDataSource, {
8702
- key: DEFAULT_DATA_SOURCE_KEY,
8703
- displayName: DEFAULT_DATA_SOURCE_TITLE,
8704
- collections: t.collections || []
8705
- }), (t.dataSources || []).forEach((n) => {
8706
- this.addDataSource(LocalDataSource, n);
8707
- });
8708
- }
8709
- addCollectionMixins(t = []) {
8710
- const o = t.filter((n) => !this.collectionMixins.includes(n));
8711
- o.length && (this.collectionMixins.push(...o), this.getDataSources().forEach((n) => n.collectionManager.reAddCollections()));
8712
- }
8713
- getDataSources(t) {
8714
- const o = Object.values(this.dataSourceInstancesMap);
8715
- return t ? _.filter(o, t) : o;
8716
- }
8717
- getDataSource(t) {
8718
- return t ? this.dataSourceInstancesMap[t] : this.dataSourceInstancesMap[DEFAULT_DATA_SOURCE_KEY];
8719
- }
8720
- removeDataSources(t) {
8721
- t.forEach((o) => {
8722
- delete this.dataSourceInstancesMap[o];
8723
- });
8724
- }
8725
- addDataSource(t, o) {
8726
- const n = new t(o, this);
8727
- return this.dataSourceInstancesMap[n.key] = n, n;
8728
- }
8729
- addDataSources(t, o) {
8730
- return V(this, null, function* () {
8731
- this.multiDataSources.some(([n, r]) => n === t && r === o) || this.multiDataSources.push([t, o]);
8732
- });
8733
- }
8734
- getAllCollections(t = {}) {
8735
- const { filterCollection: o, filterDataSource: n } = t;
8736
- return this.getDataSources(n).reduce(
8737
- (r, i) => (r.push(F(g({}, i.getOptions()), {
8738
- collections: i.collectionManager.getCollections(o)
8739
- })), r),
8740
- []
8741
- );
8742
- }
8743
- addFieldInterfaceGroups(t) {
8744
- this.collectionFieldInterfaceManager.addFieldInterfaceGroups(t);
8745
- }
8746
- addCollectionTemplates(t = []) {
8747
- this.collectionTemplateManager.addCollectionTemplates(t);
8748
- }
8749
- addFieldInterfaces(t = []) {
8750
- this.collectionFieldInterfaceManager.addFieldInterfaces(t);
8751
- }
8752
- reload() {
8753
- return V(this, null, function* () {
8754
- return yield Promise.all(
8755
- this.multiDataSources.map((n) => V(this, [n], function* ([t, o]) {
8756
- (yield t()).map((i) => this.addDataSource(o, i));
8757
- }))
8758
- ), Promise.all(this.getDataSources().map((t) => t.reload()));
8759
- });
8760
- }
8761
- }
8762
- const ExtendCollectionsContext = createContext(null);
8763
- ExtendCollectionsContext.displayName = "ExtendCollectionsContext";
8764
- const ExtendCollectionsProvider = ({ children: e, collections: t }) => {
8765
- const o = useExtendCollections(), n = useMemo(() => o ? [...o, ...t] : t, [o, t]), r = useDataSourceKey();
8766
- return /* @__PURE__ */ jsx(ExtendCollectionsContext.Provider, { value: n, children: /* @__PURE__ */ jsx(CollectionManagerProvider, { dataSource: r, children: e }) });
8767
- };
8768
- function useExtendCollections() {
8769
- return useContext(ExtendCollectionsContext);
8770
- }
8771
- const CollectionManagerContext = createContext(null);
8772
- CollectionManagerContext.displayName = "CollectionManagerContext";
8773
- const CollectionManagerProviderInner = ({ instance: e, children: t }) => {
8774
- const o = useDataSource(), n = useExtendCollections(), r = useMemo(() => {
8775
- const i = e || (o == null ? void 0 : o.collectionManager);
8776
- return n != null && n.length ? i.clone(n) : i;
8777
- }, [e, n, o]);
8778
- return /* @__PURE__ */ jsx(CollectionManagerContext.Provider, { value: r, children: t });
8779
- }, CollectionManagerProvider = ({ instance: e, dataSource: t, children: o }) => /* @__PURE__ */ jsx(DataSourceProvider, { dataSource: t, children: /* @__PURE__ */ jsx(CollectionManagerProviderInner, { instance: e, children: o }) });
8780
- function useCollectionManager() {
8781
- return useContext(CollectionManagerContext);
8782
- }
8783
- const useCollections = (e) => {
8784
- const t = useCollectionManager();
8785
- return useMemo(() => t.getCollections(e), [t, e]);
8786
- }, useCollectionManager_deprecated = (e) => {
8981
+ const useCollectionManager_deprecated = (e) => {
8787
8982
  const t = useDataSourceManager(), o = useDataSource(), n = useCollectionManager(), r = e || (o == null ? void 0 : o.key) || void 0, [i, a] = useState(uid()), { refresh: l } = useSchemaComponentContext(), c = useMemo(
8788
8983
  () => {
8789
8984
  var R;
@@ -9042,200 +9237,7 @@ const DataSourceApplicationProvider = (n) => {
9042
9237
  "dataSourceManager"
9043
9238
  ]);
9044
9239
  return /* @__PURE__ */ jsx(DataSourceManagerProvider, { dataSourceManager: t, children: /* @__PURE__ */ jsx(CollectionManagerProvider, F(g({}, o), { children: e })) });
9045
- }, useSourceKey = (e) => useCollectionManager().getSourceKeyByAssociation(e);
9046
- class CollectionRecord {
9047
- constructor(t) {
9048
- P(this, "data");
9049
- P(this, "parentRecord");
9050
- P(this, "isNew");
9051
- const { data: o, parentRecord: n, isNew: r } = t;
9052
- this.isNew = r, this.data = o, this.parentRecord = n;
9053
- }
9054
- setData(t) {
9055
- this.data = t;
9056
- }
9057
- setParentRecord(t) {
9058
- this.parentRecord = t;
9059
- }
9060
- }
9061
- const CollectionRecordContext = createContext(null);
9062
- CollectionRecordContext.displayName = "CollectionRecordContext";
9063
- const CollectionRecordProvider = ({
9064
- isNew: e,
9065
- record: t,
9066
- parentRecord: o,
9067
- children: n
9068
- }) => {
9069
- const r = useMemo(() => {
9070
- if (o)
9071
- return o instanceof CollectionRecord ? o : new CollectionRecord({ data: o });
9072
- if (t instanceof CollectionRecord)
9073
- return t.parentRecord;
9074
- }, [o, t]), i = useMemo(() => {
9075
- let a;
9076
- return t ? t instanceof CollectionRecord ? (a = t, a.isNew = t.isNew || e) : a = new CollectionRecord({ data: t, isNew: e }) : a = new CollectionRecord({ isNew: e }), a.setParentRecord(r), a;
9077
- }, [t, r, e]);
9078
- return /* @__PURE__ */ jsx(CollectionRecordContext.Provider, { value: i, children: n });
9079
- };
9080
- function useCollectionRecord() {
9081
- return useContext(CollectionRecordContext);
9082
- }
9083
- function useCollectionRecordData() {
9084
- const e = useCollectionRecord();
9085
- return e == null ? void 0 : e.data;
9086
- }
9087
- function useCollectionParentRecord() {
9088
- const e = useCollectionRecord();
9089
- return e == null ? void 0 : e.parentRecord;
9090
- }
9091
- function useCollectionParentRecordData() {
9092
- var t;
9093
- const e = useCollectionRecord();
9094
- return (t = e == null ? void 0 : e.parentRecord) == null ? void 0 : t.data;
9095
- }
9096
- const HEADERS_DATA_SOURCE_KEY = "x-data-source", isTitleField = (e, t) => {
9097
- var o;
9098
- return (o = e.collectionFieldInterfaceManager.getFieldInterface(t.interface)) == null ? void 0 : o.titleUsable;
9099
- }, useDataSourceHeaders = (e) => useMemo(() => {
9100
- if (e && e !== DEFAULT_DATA_SOURCE_KEY)
9101
- return { [HEADERS_DATA_SOURCE_KEY]: e };
9102
- }, [e]), getDataSourceHeaders = (e) => e && e !== DEFAULT_DATA_SOURCE_KEY ? { [HEADERS_DATA_SOURCE_KEY]: e } : {}, DataBlockResourceContext = createContext(null);
9103
- DataBlockResourceContext.displayName = "DataBlockResourceContext";
9104
- const DataBlockResourceProvider = ({ children: e }) => {
9105
- const t = useDataBlockProps(), o = useCollectionManager(), { association: n, collection: r, dataSource: i, sourceId: a, parentRecord: l } = t, c = useAPIClient(), u = useDataSourceHeaders(i), d = useMemo(() => typeof r == "string" ? r : r == null ? void 0 : r.name, [r]), p = useMemo(() => {
9106
- if (a)
9107
- return a;
9108
- if (n && l) {
9109
- const h = o.getSourceKeyByAssociation(n);
9110
- return (l instanceof CollectionRecord ? l.data : l)[h];
9111
- }
9112
- }, [n, a, l]), m = useMemo(() => n ? c.resource(n, p, u) : c.resource(d, void 0, u), [c, n, r, p, u]);
9113
- return /* @__PURE__ */ jsx(DataBlockResourceContext.Provider, { value: m, children: e });
9114
- };
9115
- function useDataBlockResource() {
9116
- const e = useContext(DataBlockResourceContext);
9117
- if (!e)
9118
- throw new Error("useDataBlockResource() must be used within a DataBlockResourceProvider");
9119
- return e;
9120
- }
9121
- const BlockRequestContext = createContext(null);
9122
- BlockRequestContext.displayName = "BlockRequestContext";
9123
- function useCurrentRequest(e) {
9124
- const t = useDataLoadingMode(), o = useDataBlockResource(), { action: n, params: r = {}, record: i, requestService: a, requestOptions: l } = e, c = useMemo(() => a || ((d) => {
9125
- if (i)
9126
- return Promise.resolve({ data: i });
9127
- if (!n)
9128
- throw new Error(
9129
- "[nocobase]: The 'action' parameter is missing in the 'DataBlockRequestProvider' component"
9130
- );
9131
- const p = r.filterByTk === void 0 ? _.omit(r, "filterByTk") : r;
9132
- return o[n](g(g({}, p), d)).then((m) => m.data);
9133
- }), [o, n, JSON.stringify(r), JSON.stringify(i), a]);
9134
- return useRequest(c, F(g({}, l), {
9135
- manual: t === "manual",
9136
- ready: !!n,
9137
- refreshDeps: [n, JSON.stringify(r), JSON.stringify(i), o]
9138
- }));
9139
- }
9140
- function requestParentRecordData(a) {
9141
- return V(this, arguments, function* ({
9142
- sourceId: e,
9143
- association: t,
9144
- parentRecord: o,
9145
- api: n,
9146
- headers: r,
9147
- sourceKey: i
9148
- }) {
9149
- if (o)
9150
- return Promise.resolve({ data: o });
9151
- if (!t || !i || !e)
9152
- return Promise.resolve({ data: void 0 });
9153
- const c = `${t.split(".")[0]}:get?filter[${i}]=${e}`;
9154
- return (yield n.request({ url: c, headers: r })).data;
9155
- });
9156
- }
9157
- function useParentRequest(e) {
9158
- const { sourceId: t, association: o, parentRecord: n } = e, r = useAPIClient(), i = useDataBlockProps(), a = useDataSourceHeaders(i.dataSource), l = useSourceKey(o);
9159
- return useRequest(
9160
- () => requestParentRecordData({ sourceId: t, association: o, parentRecord: n, api: r, headers: a, sourceKey: l }),
9161
- {
9162
- refreshDeps: [o, n, t]
9163
- }
9164
- );
9165
- }
9166
- const BlockRequestProvider = ({ children: e }) => {
9167
- var x, C;
9168
- const t = useDataBlockProps(), {
9169
- action: o,
9170
- filterByTk: n,
9171
- sourceId: r,
9172
- params: i = {},
9173
- association: a,
9174
- collection: l,
9175
- record: c,
9176
- parentRecord: u,
9177
- requestOptions: d,
9178
- requestService: p
9179
- } = t, m = useCurrentRequest({
9180
- action: o,
9181
- sourceId: r,
9182
- record: c,
9183
- association: a,
9184
- collection: l,
9185
- requestOptions: d,
9186
- requestService: p,
9187
- params: F(g({}, i), {
9188
- filterByTk: n || i.filterByTk
9189
- })
9190
- }), h = useParentRequest({
9191
- sourceId: r,
9192
- association: a,
9193
- parentRecord: u
9194
- }), f = useMemo(() => {
9195
- var S, b;
9196
- return ((S = h.data) == null ? void 0 : S.data) && new CollectionRecord({ isNew: !1, data: (b = h.data) == null ? void 0 : b.data });
9197
- }, [(x = h.data) == null ? void 0 : x.data]);
9198
- return /* @__PURE__ */ jsx(BlockRequestContext.Provider, { value: m, children: o !== "list" ? /* @__PURE__ */ jsx(
9199
- CollectionRecordProvider,
9200
- {
9201
- isNew: o == null,
9202
- record: (C = m.data) == null ? void 0 : C.data,
9203
- parentRecord: f,
9204
- children: e
9205
- }
9206
- ) : /* @__PURE__ */ jsx(CollectionRecordProvider, { isNew: !1, record: null, parentRecord: f, children: e }) });
9207
- }, useDataBlockRequest = () => useContext(BlockRequestContext), DataBlockContext = createContext({});
9208
- DataBlockContext.displayName = "DataBlockContext";
9209
- const AssociationOrCollectionProvider = (e) => {
9210
- const { collection: t, association: o, allowNull: n = !1 } = e, r = useMemo(() => o ? {
9211
- Component: AssociationProvider,
9212
- name: o
9213
- } : {
9214
- Component: SanitizedCollectionProvider,
9215
- name: t
9216
- }, [t, o]);
9217
- return /* @__PURE__ */ jsx(r.Component, { name: r.name, allowNull: n, children: e.children });
9218
- }, DataBlockProvider = withDynamicSchemaProps(
9219
- (e) => {
9220
- const c = e, { collection: t, association: o, dataSource: n, children: r, hidden: i } = c, a = H(c, ["collection", "association", "dataSource", "children", "hidden"]), { dn: l } = useDesignable();
9221
- return i ? null : /* @__PURE__ */ jsx(
9222
- DataBlockContext.Provider,
9223
- {
9224
- value: {
9225
- dn: l,
9226
- props: F(g({}, a), { collection: t, association: o, dataSource: n })
9227
- },
9228
- children: /* @__PURE__ */ jsx(CollectionManagerProvider, { dataSource: n, children: /* @__PURE__ */ jsx(AssociationOrCollectionProvider, { collection: t, association: o, children: /* @__PURE__ */ jsx(ACLCollectionProvider, { children: /* @__PURE__ */ jsx(DataBlockResourceProvider, { children: /* @__PURE__ */ jsx(BlockRequestProvider, { children: r }) }) }) }) })
9229
- }
9230
- );
9231
- },
9232
- { displayName: "DataBlockProvider" }
9233
- ), useDataBlock = () => {
9234
- const e = useContext(DataBlockContext);
9235
- if (!e)
9236
- throw new Error("useDataBlock() must be used within a DataBlockProvider");
9237
- return e;
9238
- }, useDataBlockProps = () => useDataBlock().props, DesignableSwitch = () => {
9240
+ }, DesignableSwitch = () => {
9239
9241
  const { designable: e, setDesignable: t } = useDesignable(), { t: o } = useTranslation(), { token: n } = useToken$1(), r = {};
9240
9242
  return e && (r.backgroundColor = "var(--colorSettings)"), useHotkeys("Ctrl+Shift+U", () => t(!e), [e]), /* @__PURE__ */ jsx(Tooltip, { title: o("UI Editor"), children: /* @__PURE__ */ jsx(
9241
9243
  Button,
@@ -12338,7 +12340,7 @@ function SchemaSettingsBlockTitleItem() {
12338
12340
  }
12339
12341
  const getTargetKey = (e) => (e == null ? void 0 : e.targetKey) || "id";
12340
12342
  function SchemaSettingsConnectDataBlocks(e) {
12341
- const { type: t, emptyDescription: o } = e, n = useFieldSchema(), { dn: r } = useDesignable(), { t: i } = useTranslation(), a = useCollection_deprecated(), { inProvider: l } = useFilterBlock(), c = useSupportedBlocks(t);
12343
+ const { type: t, emptyDescription: o } = e, n = useFieldSchema(), { dn: r } = useDesignable(), { t: i } = useTranslation(), a = useCollection(), { inProvider: l } = useFilterBlock(), c = useSupportedBlocks(t);
12342
12344
  let { targets: u = [], uid: d } = findFilterTargets(n);
12343
12345
  const p = useCompile(), { getAllCollectionsInheritChain: m } = useCollectionManager_deprecated();
12344
12346
  if (!l)
@@ -16467,8 +16469,8 @@ const useFormItemInitializerFields = (e) => {
16467
16469
  exists: !!c,
16468
16470
  remove() {
16469
16471
  r == null || r(c.name), i == null || i.query(new RegExp(`${c.parent.name}.${c.name}$`)).forEach((u) => {
16470
- var d;
16471
- (d = u.setValue) == null || d.call(u, void 0);
16472
+ var d, p;
16473
+ (d = u.setValue) == null || d.call(u, void 0), (p = u.setInitialValue) == null || p.call(u, void 0);
16472
16474
  }), c && n(c, l);
16473
16475
  }
16474
16476
  };
@@ -19014,8 +19016,8 @@ const SchemaSettingsProvider = (e) => {
19014
19016
  breakRemoveOn: n
19015
19017
  };
19016
19018
  l != null && l.required && (l.required = !1, c.required = !1), i && i.uid === c["x-uid"] && (u != null && u.dn) ? yield u == null ? void 0 : u.dn.remove(null, x) : yield r.remove(null, x), yield (C = t == null ? void 0 : t.onOk) == null ? void 0 : C.call(t), delete d.values[c.name], m == null || m(c.name), d == null || d.query(new RegExp(`${c.parent.name}.${c.name}$`)).forEach((S) => {
19017
- var b;
19018
- (b = S.setValue) == null || b.call(S, void 0);
19019
+ var b, y;
19020
+ (b = S.setValue) == null || b.call(S, void 0), (y = S.setInitialValue) == null || y.call(S, void 0);
19019
19021
  }), h(c["x-uid"]);
19020
19022
  });
19021
19023
  }
@@ -30288,7 +30290,7 @@ function flatData$1(e, t) {
30288
30290
  return o;
30289
30291
  }
30290
30292
  function getCurrentOptions(e, t, o) {
30291
- const n = flatData$1(t, o), r = castArray(e).filter((a) => a != null).map((a) => isPlainObject(a) ? a[o.value] : a);
30293
+ const n = flatData$1(t, o), r = castArray(e).map((a) => isPlainObject(a) ? a[o.value] : a);
30292
30294
  function i(a) {
30293
30295
  if (!a)
30294
30296
  return [];
@@ -30307,13 +30309,8 @@ function getCurrentOptions(e, t, o) {
30307
30309
  const ReadPretty$c = observer$1(
30308
30310
  (e) => {
30309
30311
  var a;
30310
- const t = g(g({}, defaultFieldNames$1), e.fieldNames), o = useField();
30311
- if (!isValid(e.value))
30312
- return /* @__PURE__ */ jsx("div", {});
30313
- if (isArrayField(o) && ((a = o == null ? void 0 : o.value) == null ? void 0 : a.length) === 0)
30314
- return /* @__PURE__ */ jsx("div", {});
30315
- const n = useCollectionField(), r = o.dataSource || e.options || (n == null ? void 0 : n.uiSchema.enum) || [], i = getCurrentOptions(o.value, r, t);
30316
- return /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(EllipsisWithTooltip, { ellipsis: e.ellipsis, children: i.map((l, c) => /* @__PURE__ */ jsx(Tag, { color: l[t.color], icon: l.icon, children: l[t.label] }, c)) }) });
30312
+ const t = g(g({}, defaultFieldNames$1), e.fieldNames), o = useField(), n = useCollectionField(), r = o.dataSource || e.options || (n == null ? void 0 : n.uiSchema.enum) || [], i = getCurrentOptions(o.value, r, t);
30313
+ return !isValid(e.value) && !i.length ? /* @__PURE__ */ jsx("div", {}) : isArrayField(o) && ((a = o == null ? void 0 : o.value) == null ? void 0 : a.length) === 0 ? /* @__PURE__ */ jsx("div", {}) : /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(EllipsisWithTooltip, { ellipsis: e.ellipsis, children: i.map((l, c) => /* @__PURE__ */ jsx(Tag, { color: l[t.color], icon: l.icon, children: l[t.label] }, c)) }) });
30317
30314
  },
30318
30315
  { displayName: "ReadPretty" }
30319
30316
  ), isEmptyObject = (e) => !isValid(e) || typeof e == "object" && Object.keys(e).length === 0, ObjectSelect = (e) => {
@@ -30871,7 +30868,11 @@ function getSubscriber(e, t, o, n, r) {
30871
30868
  let a = t.stateOfLinkageRules[i];
30872
30869
  a = yield Promise.all(a), a = a.filter((u) => u.condition);
30873
30870
  const l = a[a.length - 1];
30874
- i === "value" ? a.length > 1 && (t.value = l.value) : (t[i] = l == null ? void 0 : l.value, i === "display" && (l == null ? void 0 : l.value) === "none" && (t.value = null)), t.stateOfLinkageRules[i] = null;
30871
+ i === "value" ? a.length > 1 && (t.value = l.value) : (t[i] = l == null ? void 0 : l.value, requestAnimationFrame(() => {
30872
+ t.setState((u) => {
30873
+ u[i] = l == null ? void 0 : l.value;
30874
+ });
30875
+ }), i === "display" && (l == null ? void 0 : l.value) === "none" && (t.value = null)), t.stateOfLinkageRules[i] = null;
30875
30876
  }));
30876
30877
  };
30877
30878
  }
@@ -34566,9 +34567,9 @@ const useTableColumns$1 = (e) => {
34566
34567
  initialInView: Z || !1 || X.length <= 10,
34567
34568
  skip: Z || !1
34568
34569
  });
34569
- return /* @__PURE__ */ jsx("td", F(g({}, ee), { ref: ne, className: cls(ee.className, cellClass), children: ie || Z ? ee.children : /* @__PURE__ */ jsx(Skeleton.Button, { style: { height: "100%" } }) }));
34570
+ return /* @__PURE__ */ jsx("td", F(g({}, ee), { ref: ne, className: cls(ee.className, cellClass), children: S.isSubTable || ie || Z ? ee.children : /* @__PURE__ */ jsx(Skeleton.Button, { style: { height: "100%" } }) }));
34570
34571
  },
34571
- [X.length]
34572
+ [X.length, S.isSubTable]
34572
34573
  ), te = useMemo(() => ({
34573
34574
  header: {
34574
34575
  wrapper: HeaderWrapperComponent,
@@ -45248,7 +45249,7 @@ const string = [
45248
45249
  ];
45249
45250
  return useEffect(() => {
45250
45251
  const u = {
45251
- autoGenId: !0,
45252
+ autoGenId: !1,
45252
45253
  createdAt: !0,
45253
45254
  createdBy: !0,
45254
45255
  updatedAt: !0,
@@ -45286,7 +45287,7 @@ const string = [
45286
45287
  onChange: (u, d) => {
45287
45288
  var h;
45288
45289
  const p = getDefaultCollectionFields(d, o.values), m = {
45289
- autoGenId: !!p.find((f) => f.name === "id"),
45290
+ autoGenId: !1,
45290
45291
  createdAt: !!p.find((f) => f.name === "createdAt"),
45291
45292
  createdBy: !!p.find((f) => f.name === "createdBy"),
45292
45293
  updatedAt: !!p.find((f) => f.name === "updatedAt"),
@@ -49301,7 +49302,7 @@ const useBlockContext = () => useContext(BlockContext), useCompatDataBlockParent
49301
49302
  var m;
49302
49303
  return (m = e.params) != null && m.appends ? g(g({}, e.params), a) : g(F(g({}, e.params), { appends: c }), a);
49303
49304
  }, [c, a, e.params]), p = useMemo(() => ({ name: t }), [t]);
49304
- return /* @__PURE__ */ jsx(BlockContext.Provider, { value: p, children: /* @__PURE__ */ jsx(DataBlockProvider, F(g({}, e), { params: d, parentRecord: r || i, children: /* @__PURE__ */ jsx(BlockRequestProvider_deprecated, F(g({}, e), { updateAssociationValues: u, params: d, children: /* @__PURE__ */ jsx(DataBlockCollector, F(g({}, e), { params: d, children: e.children })) })) })) });
49305
+ return /* @__PURE__ */ jsx(BlockContext.Provider, { value: p, children: /* @__PURE__ */ jsx(DataBlockProvider, F(g({}, e), { params: d, parentRecord: r || i, children: /* @__PURE__ */ jsx(BlockRequestProvider_deprecated, F(g({}, e), { updateAssociationValues: u, params: d, children: e.children })) })) });
49305
49306
  }, useBlockAssociationContext = () => {
49306
49307
  const { association: e } = useDataBlockProps();
49307
49308
  return useContext(BlockAssociationContext) || e;