@nocobase/client 2.0.29 → 2.0.31

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.
@@ -0,0 +1,25 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ import type { FlowModel } from '@nocobase/flow-engine';
10
+ import type { HookAPI } from 'antd/es/modal/useModal';
11
+ type PopupBeforeClosePayload = {
12
+ result?: any;
13
+ force?: boolean;
14
+ ignoredDirtyFormModelUids?: string[];
15
+ };
16
+ type PopupViewLike = {
17
+ beforeClose?: (payload: PopupBeforeClosePayload) => Promise<boolean | void> | boolean | void;
18
+ };
19
+ export declare function bindPopupSubTableBeforeClose({ view, model, modal, t, }: {
20
+ view: PopupViewLike;
21
+ model?: FlowModel | null;
22
+ modal: Pick<HookAPI, 'confirm'>;
23
+ t: (key: string) => string;
24
+ }): () => void;
25
+ export {};
package/es/index.mjs CHANGED
@@ -9964,7 +9964,7 @@ function addAppVersion(e, t) {
9964
9964
  addAppVersion((n = e.properties) == null ? void 0 : n[o], t);
9965
9965
  }), e;
9966
9966
  }
9967
- const name = "@nocobase/client", version = "2.0.29", license = "Apache-2.0", main = "lib/index.js", module = "es/index.mjs", types = "es/index.d.ts", dependencies = {
9967
+ const name = "@nocobase/client", version = "2.0.31", license = "Apache-2.0", main = "lib/index.js", module = "es/index.mjs", types = "es/index.d.ts", dependencies = {
9968
9968
  "@ahooksjs/use-url-state": "3.5.1",
9969
9969
  "@ant-design/cssinjs": "^1.11.1",
9970
9970
  "@ant-design/icons": "^5.6.1",
@@ -9987,10 +9987,10 @@ const name = "@nocobase/client", version = "2.0.29", license = "Apache-2.0", mai
9987
9987
  "@formily/reactive-react": "^2.2.27",
9988
9988
  "@formily/shared": "^2.2.27",
9989
9989
  "@formily/validator": "^2.2.27",
9990
- "@nocobase/evaluators": "2.0.29",
9991
- "@nocobase/flow-engine": "2.0.29",
9992
- "@nocobase/sdk": "2.0.29",
9993
- "@nocobase/utils": "2.0.29",
9990
+ "@nocobase/evaluators": "2.0.31",
9991
+ "@nocobase/flow-engine": "2.0.31",
9992
+ "@nocobase/sdk": "2.0.31",
9993
+ "@nocobase/utils": "2.0.31",
9994
9994
  "@tanstack/react-table": "^8.21.3",
9995
9995
  "@types/tabulator-tables": "^6.2.6",
9996
9996
  "acorn-jsx": "^5.3.2",
@@ -83703,7 +83703,12 @@ const CustomWidth = ({ setOpen: e, t, handleChange: o, defaultValue: n }) => {
83703
83703
  ] })
83704
83704
  }
83705
83705
  );
83706
- }, Ze = class Ze extends DisplayItemModel {
83706
+ };
83707
+ function getSavedAssociationTitleField(e) {
83708
+ var t, o, n;
83709
+ return ((o = (t = e.getStepParams) == null ? void 0 : t.call(e, "tableColumnSettings", "fieldNames")) == null ? void 0 : o.label) || ((n = e.props) == null ? void 0 : n.titleField);
83710
+ }
83711
+ const Ze = class Ze extends DisplayItemModel {
83707
83712
  afterAddAsSubModel() {
83708
83713
  return L(this, null, function* () {
83709
83714
  yield Ne(Ze.prototype, this, "afterAddAsSubModel").call(this), yield this.dispatchEvent("beforeRender");
@@ -83865,8 +83870,12 @@ TableColumnModel.registerFlow({
83865
83870
  init: {
83866
83871
  handler(e, t) {
83867
83872
  return L(this, null, function* () {
83873
+ var i, a, l, c;
83868
83874
  const o = e.model.context.collectionField;
83869
- o && (e.model.setProps("title", o.title), e.model.setProps("dataIndex", o.name), yield e.model.applySubModelsBeforeRenderFlows("field"), e.model.setProps(x({}, o.getComponentProps())));
83875
+ if (!o)
83876
+ return;
83877
+ const n = getSavedAssociationTitleField(e.model), r = o.isAssociationField() && n ? x(x({}, o.getComponentProps()), (c = (l = (a = (i = o.targetCollection) == null ? void 0 : i.getField) == null ? void 0 : a.call(i, n)) == null ? void 0 : l.getComponentProps) == null ? void 0 : c.call(l)) : o.getComponentProps();
83878
+ e.model.setProps("title", o.title), e.model.setProps("dataIndex", o.name), yield e.model.applySubModelsBeforeRenderFlows("field"), e.model.setProps(x({}, r));
83870
83879
  });
83871
83880
  }
83872
83881
  },
@@ -84019,7 +84028,7 @@ TableColumnModel.registerFlow({
84019
84028
  defaultParams: (e) => {
84020
84029
  const t = e.model.context.collectionField.targetCollectionTitleFieldName;
84021
84030
  return {
84022
- label: e.model.props.titleField || t
84031
+ label: getSavedAssociationTitleField(e.model) || t
84023
84032
  };
84024
84033
  },
84025
84034
  handler(e, t) {
@@ -86387,6 +86396,66 @@ EditableItemModel.bindModelToInterface("CascadeSelectListFieldModel", ["m2m", "o
86387
86396
  isDefault: !0,
86388
86397
  order: 60
86389
86398
  });
86399
+ const POPUP_BEFORE_CLOSE_NEXT = Symbol("popupBeforeCloseNext");
86400
+ function visitModelTree(e, t) {
86401
+ const o = e ? [e] : [], n = /* @__PURE__ */ new Set();
86402
+ for (; o.length; ) {
86403
+ const r = o.pop();
86404
+ !(r != null && r.uid) || n.has(r.uid) || (n.add(r.uid), t(r), Object.values(r.subModels || {}).forEach((i) => {
86405
+ Array.isArray(i) ? o.push(...i) : i && typeof i == "object" && o.push(i);
86406
+ }));
86407
+ }
86408
+ }
86409
+ function unlinkBeforeClose(e, t) {
86410
+ let o, n = e.beforeClose;
86411
+ for (; n; ) {
86412
+ if (n === t) {
86413
+ o ? o[POPUP_BEFORE_CLOSE_NEXT] = n[POPUP_BEFORE_CLOSE_NEXT] : e.beforeClose = n[POPUP_BEFORE_CLOSE_NEXT];
86414
+ break;
86415
+ }
86416
+ if (!(POPUP_BEFORE_CLOSE_NEXT in n))
86417
+ break;
86418
+ o = n, n = n[POPUP_BEFORE_CLOSE_NEXT];
86419
+ }
86420
+ }
86421
+ function bindPopupSubTableBeforeClose({
86422
+ view: e,
86423
+ model: t,
86424
+ modal: o,
86425
+ t: n
86426
+ }) {
86427
+ const r = (l = []) => {
86428
+ const c = [], u = l.length ? new Set(l) : null;
86429
+ return visitModelTree(t, (d) => {
86430
+ var p, m;
86431
+ d.uid && ((m = (p = d.getUserModifiedFields) == null ? void 0 : p.call(d)) != null && m.size) && !(u != null && u.has(d.uid)) && c.push(d.uid);
86432
+ }), c;
86433
+ }, i = (l) => {
86434
+ if (!l.length)
86435
+ return;
86436
+ const c = new Set(l);
86437
+ visitModelTree(t, (u) => {
86438
+ var d;
86439
+ u.uid && c.has(u.uid) && ((d = u.resetUserModifiedFields) == null || d.call(u));
86440
+ });
86441
+ }, a = (l) => L(this, null, function* () {
86442
+ const c = l.force ? [] : r(l.ignoredDirtyFormModelUids);
86443
+ if (c.length && !(yield o.confirm({
86444
+ title: n("Unsaved changes"),
86445
+ content: n("Are you sure you don't want to save?"),
86446
+ okText: n("Confirm"),
86447
+ cancelText: n("Cancel")
86448
+ })))
86449
+ return !1;
86450
+ const u = a[POPUP_BEFORE_CLOSE_NEXT], d = c.length ? Array.from(/* @__PURE__ */ new Set([...l.ignoredDirtyFormModelUids || [], ...c])) : l.ignoredDirtyFormModelUids;
86451
+ return (yield u == null ? void 0 : u(A(x({}, l), {
86452
+ ignoredDirtyFormModelUids: d
86453
+ }))) !== !1 ? (c.length && i(c), !0) : !1;
86454
+ });
86455
+ return a[POPUP_BEFORE_CLOSE_NEXT] = e.beforeClose, e.beforeClose = a, () => {
86456
+ unlinkBeforeClose(e, a);
86457
+ };
86458
+ }
86390
86459
  function FieldWithoutPermissionPlaceholder({ targetModel: e, children: t }) {
86391
86460
  const o = e.context.t, n = e, r = n.context.collectionField.collection, i = r.dataSource, a = n.context.collectionField.name, l = useMemo(() => {
86392
86461
  const d = `${o(i.displayName || i.key)} > `, p = r ? `${o(r.title) || r.name || r.tableName} > ` : "";
@@ -86416,7 +86485,15 @@ function RemoteModelRenderer({ options: e, fieldModel: t }) {
86416
86485
  refreshDeps: [o, e]
86417
86486
  }
86418
86487
  );
86419
- return r || !(n != null && n.uid) ? /* @__PURE__ */ jsx(SkeletonFallback, { style: { margin: 16 } }) : /* @__PURE__ */ jsx(FlowModelRenderer, { model: n, fallback: /* @__PURE__ */ jsx(SkeletonFallback, { style: { margin: 16 } }) });
86488
+ return useEffect(() => {
86489
+ if (n != null && n.uid)
86490
+ return bindPopupSubTableBeforeClose({
86491
+ view: o.view,
86492
+ model: n,
86493
+ modal: o.modal,
86494
+ t: o.t
86495
+ });
86496
+ }, [o, n]), r || !(n != null && n.uid) ? /* @__PURE__ */ jsx(SkeletonFallback, { style: { margin: 16 } }) : /* @__PURE__ */ jsx(FlowModelRenderer, { model: n, fallback: /* @__PURE__ */ jsx(SkeletonFallback, { style: { margin: 16 } }) });
86420
86497
  }
86421
86498
  function EditFormContent({ model: e, scene: t = "update" }) {
86422
86499
  const o = useFlowContext(), { Header: n, type: r } = o.view;
@@ -87775,17 +87852,18 @@ PopupSubTableFormSubmitActionModel.registerFlow({
87775
87852
  save: {
87776
87853
  handler(e, t) {
87777
87854
  return L(this, null, function* () {
87855
+ var d;
87778
87856
  const o = e.blockModel, n = o.context.associationModel, r = n.context.resource, a = o.resource.getUpdateAssociationValues(), l = n.context.collectionField.name, c = r.getUpdateAssociationValues(), u = matchPath(c, l);
87779
87857
  try {
87780
- const d = e != null && e.flowSettingsEnabled ? getValidationNamePathsExcludingHiddenModels(o) : null;
87781
- Array.isArray(d) ? d.length && (yield o.form.validateFields(d)) : yield o.form.validateFields();
87782
- const p = o.form.getFieldsValue(!0), m = omitHiddenModelValuesFromSubmit(p, o);
87858
+ const p = e != null && e.flowSettingsEnabled ? getValidationNamePathsExcludingHiddenModels(o) : null;
87859
+ Array.isArray(p) ? p.length && (yield o.form.validateFields(p)) : yield o.form.validateFields();
87860
+ const m = o.form.getFieldsValue(!0), h = omitHiddenModelValuesFromSubmit(m, o);
87783
87861
  n.dispatchEvent("updateRow", {
87784
- updatedRecord: m
87862
+ updatedRecord: h
87785
87863
  });
87786
- const h = a.map((g) => `${u}.${g}`);
87787
- r.addUpdateAssociationValues(h);
87788
- } catch (d) {
87864
+ const g = a.map((f) => `${u}.${f}`);
87865
+ r.addUpdateAssociationValues(g), (d = o.resetUserModifiedFields) == null || d.call(o);
87866
+ } catch (p) {
87789
87867
  return;
87790
87868
  }
87791
87869
  e.view && e.view.close();
@@ -95737,47 +95815,64 @@ const models = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProper
95737
95815
  transformNestedData,
95738
95816
  transformRowsToSingleColumn
95739
95817
  }, Symbol.toStringTag, { value: "Module" }));
95740
- function collectDirtyFormModelUids(e) {
95818
+ function collectDirtyFormModelUids(e, t = []) {
95741
95819
  if (!e)
95742
95820
  return [];
95743
- const t = /* @__PURE__ */ new Set(), o = [], n = (r) => {
95744
- var a;
95745
- if (!(r != null && r.uid) || t.has(r.uid))
95821
+ const o = /* @__PURE__ */ new Set(), n = [], r = t.length ? new Set(t) : null, i = (a) => {
95822
+ var c;
95823
+ if (!(a != null && a.uid) || o.has(a.uid))
95746
95824
  return;
95747
- t.add(r.uid);
95748
- const i = (a = r.getUserModifiedFields) == null ? void 0 : a.call(r);
95749
- i != null && i.size && o.push(r.uid), Object.values(r.subModels || {}).forEach((l) => {
95750
- _.castArray(l).forEach((c) => {
95751
- c && typeof c == "object" && n(c);
95825
+ o.add(a.uid);
95826
+ const l = (c = a.getUserModifiedFields) == null ? void 0 : c.call(a);
95827
+ l != null && l.size && !(r != null && r.has(a.uid)) && n.push(a.uid), Object.values(a.subModels || {}).forEach((u) => {
95828
+ _.castArray(u).forEach((d) => {
95829
+ d && typeof d == "object" && i(d);
95752
95830
  });
95753
95831
  });
95754
95832
  };
95755
- return n(e), o;
95833
+ return i(e), n;
95756
95834
  }
95757
- function createBeforeCloseDirtyState(e) {
95758
- const t = collectDirtyFormModelUids(e);
95835
+ function createBeforeCloseDirtyState(e, t = []) {
95836
+ const o = collectDirtyFormModelUids(e, t);
95759
95837
  return {
95760
- hasDirtyForms: t.length > 0,
95761
- formModelUids: t
95838
+ hasDirtyForms: o.length > 0,
95839
+ formModelUids: o
95762
95840
  };
95763
95841
  }
95842
+ function resetDirtyFormModels(e, t = []) {
95843
+ if (!e || !t.length)
95844
+ return;
95845
+ const o = /* @__PURE__ */ new Set(), n = new Set(t), r = (i) => {
95846
+ var a;
95847
+ !(i != null && i.uid) || o.has(i.uid) || (o.add(i.uid), n.has(i.uid) && ((a = i.resetUserModifiedFields) == null || a.call(i)), Object.values(i.subModels || {}).forEach((l) => {
95848
+ _.castArray(l).forEach((c) => {
95849
+ c && typeof c == "object" && r(c);
95850
+ });
95851
+ }));
95852
+ };
95853
+ r(e);
95854
+ }
95764
95855
  function createViewBeforeCloseHandler(e) {
95765
- return (n) => L(this, [n], function* ({ result: t, force: o }) {
95856
+ return (r) => L(this, [r], function* ({
95857
+ result: t,
95858
+ force: o,
95859
+ ignoredDirtyFormModelUids: n
95860
+ }) {
95766
95861
  if (o)
95767
95862
  return !0;
95768
- const r = createBeforeCloseDirtyState(e);
95769
- let i = !1;
95770
- const a = yield e.dispatchEvent("close", {
95863
+ const i = createBeforeCloseDirtyState(e, n);
95864
+ let a = !1;
95865
+ const l = yield e.dispatchEvent("close", {
95771
95866
  result: t,
95772
95867
  force: !1,
95773
- dirty: r,
95868
+ dirty: i,
95774
95869
  controller: {
95775
95870
  prevent() {
95776
- i = !0;
95871
+ a = !0;
95777
95872
  }
95778
95873
  }
95779
- }), l = (a == null ? void 0 : a.__abortedByExitAll) === !0 || (Array.isArray(a) ? a.some((c) => c instanceof FlowExitAllException) : !1);
95780
- return !i && !l;
95874
+ }), c = (l == null ? void 0 : l.__abortedByExitAll) === !0 || (Array.isArray(l) ? l.some((d) => d instanceof FlowExitAllException) : !1), u = !a && !c;
95875
+ return u && i.hasDirtyForms && resetDirtyFormModels(e, i.formModelUids), u;
95781
95876
  });
95782
95877
  }
95783
95878
  const openView = defineAction({
@@ -95868,9 +95963,9 @@ const openView = defineAction({
95868
95963
  const se = typeof (o == null ? void 0 : o[ne]) != "undefined", re = a.includes(ne);
95869
95964
  return se && !re ? o[ne] : typeof (t == null ? void 0 : t[ne]) != "undefined" ? t[ne] : se ? o[ne] : i == null ? void 0 : i[ne];
95870
95965
  }, c = (() => {
95871
- var se;
95966
+ var se, re;
95872
95967
  const ne = l("filterByTk");
95873
- return Array.isArray((se = e.collection) == null ? void 0 : se.filterTargetKey) && e.collection.filterTargetKey.length === 1 && ne != null && typeof ne != "object" ? { [e.collection.filterTargetKey[0]]: ne } : ne;
95968
+ return ((se = e.collection) == null ? void 0 : se.template) === "sql" && Array.isArray((re = e.collection) == null ? void 0 : re.filterTargetKey) && e.collection.filterTargetKey.length === 1 && ne != null && typeof ne != "object" ? { [e.collection.filterTargetKey[0]]: ne } : ne;
95874
95969
  })(), u = l("sourceId"), d = typeof (o == null ? void 0 : o.dataSourceKey) != "undefined" ? o.dataSourceKey : t == null ? void 0 : t.dataSourceKey, p = typeof (o == null ? void 0 : o.collectionName) != "undefined" ? o.collectionName : t == null ? void 0 : t.collectionName, m = typeof (o == null ? void 0 : o.associationName) != "undefined" ? o.associationName : t == null ? void 0 : t.associationName, h = typeof o.tabUid != "undefined" ? o.tabUid : t.tabUid, g = (z = e.inputArgs) != null && z.isMobileLayout ? "embed" : ((U = e.inputArgs) == null ? void 0 : U.mode) || t.mode || "drawer";
95875
95970
  let f = typeof o.navigation != "undefined" ? o.navigation : t.navigation;
95876
95971
  if ((n || r) && (f = !1), f !== !1 && e.isNavigationEnabled !== !1 && !e.inputArgs.navigation && (K = e.view) != null && K.navigation) {