@oneflowui/ui 0.4.4 → 0.5.1
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/README.en.md +1 -1
- package/README.md +70 -0
- package/dist/components/database/DatabaseView.vue.d.ts +171 -0
- package/dist/components/database/DatabaseView.vue.js +7 -0
- package/dist/components/database/DatabaseView.vue2.js +774 -0
- package/dist/components/database/index.d.ts +2 -0
- package/dist/composables/index.d.ts +2 -0
- package/dist/composables/useDatabaseView.d.ts +138 -0
- package/dist/composables/useDatabaseView.js +388 -0
- package/dist/composables/useWorkerSort.js +30 -29
- package/dist/index.d.ts +4 -0
- package/dist/index.js +178 -173
- package/dist/style.css +1 -1
- package/dist/tests/database-view.integration.spec.d.ts +1 -0
- package/dist/workers/tableWorkerSource.js +79 -0
- package/package.json +17 -17
- package/dist/assets/tableWorker-CTsbCPPP.js +0 -1
|
@@ -40,5 +40,7 @@ export { useSupabaseProvider } from './useSupabaseProvider';
|
|
|
40
40
|
export type { SupabaseQueryBuilder, SupabaseFilterBuilder, UseSupabaseProviderOptions, } from './useSupabaseProvider';
|
|
41
41
|
export { useViewPersistence, createLocalStorageBackend, createSupabaseBackend, } from './useViewPersistence';
|
|
42
42
|
export type { ViewStorageBackend, SupabaseViewBackendOptions, UseViewPersistenceOptions, } from './useViewPersistence';
|
|
43
|
+
export { useDatabaseView } from './useDatabaseView';
|
|
44
|
+
export type { DatabaseViewMode, DatabaseViewFetchParams, DatabaseViewFetchResult, DatabaseViewProvider, DatabaseSchemaEvent, DatabaseViewActions, DatabaseViewDetailOptions, DatabaseViewNavigationOptions, UseDatabaseViewOptions, UseDatabaseViewResult, } from './useDatabaseView';
|
|
43
45
|
export { useSearch } from './useSearch';
|
|
44
46
|
export type { UseSearchOptions, SearchHighlight } from './useSearch';
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
import { DataRecord, TableSchema, ViewConfig } from '../types';
|
|
3
|
+
import { SortState } from './useTable';
|
|
4
|
+
export type DatabaseViewMode = "local" | "provider";
|
|
5
|
+
export interface DatabaseViewFetchParams {
|
|
6
|
+
tableId: string;
|
|
7
|
+
schema: TableSchema | null;
|
|
8
|
+
view: ViewConfig;
|
|
9
|
+
page: number;
|
|
10
|
+
pageSize: number;
|
|
11
|
+
sort: SortState;
|
|
12
|
+
selectedRecordId: string | null;
|
|
13
|
+
}
|
|
14
|
+
export interface DatabaseViewFetchResult<T extends DataRecord = DataRecord> {
|
|
15
|
+
records?: readonly T[] | T[];
|
|
16
|
+
data?: readonly T[] | T[];
|
|
17
|
+
total?: number;
|
|
18
|
+
schema?: TableSchema | null;
|
|
19
|
+
views?: readonly ViewConfig[] | ViewConfig[] | null;
|
|
20
|
+
activeViewId?: string | null;
|
|
21
|
+
selectedRecordId?: string | null;
|
|
22
|
+
}
|
|
23
|
+
export interface DatabaseViewProvider<T extends DataRecord = DataRecord> {
|
|
24
|
+
mode?: DatabaseViewMode;
|
|
25
|
+
onFetch?: (params: DatabaseViewFetchParams) => Promise<DatabaseViewFetchResult<T>>;
|
|
26
|
+
onRefresh?: (params: DatabaseViewFetchParams) => Promise<void> | void;
|
|
27
|
+
}
|
|
28
|
+
export type DatabaseSchemaEvent = {
|
|
29
|
+
type: "schema-add-field";
|
|
30
|
+
fieldType: string;
|
|
31
|
+
} | {
|
|
32
|
+
type: "schema-rename-field";
|
|
33
|
+
fieldId: string;
|
|
34
|
+
newName: string;
|
|
35
|
+
} | {
|
|
36
|
+
type: "schema-change-field-type";
|
|
37
|
+
fieldId: string;
|
|
38
|
+
newType: string;
|
|
39
|
+
} | {
|
|
40
|
+
type: "schema-hide-field";
|
|
41
|
+
fieldId: string;
|
|
42
|
+
} | {
|
|
43
|
+
type: "schema-delete-field";
|
|
44
|
+
fieldId: string;
|
|
45
|
+
} | {
|
|
46
|
+
type: "schema-duplicate-field";
|
|
47
|
+
fieldId: string;
|
|
48
|
+
};
|
|
49
|
+
export interface DatabaseViewActions<T extends DataRecord = DataRecord> {
|
|
50
|
+
onCellEdit?: (payload: {
|
|
51
|
+
rowId: string;
|
|
52
|
+
fieldId: string;
|
|
53
|
+
value: unknown;
|
|
54
|
+
}) => Promise<void> | void;
|
|
55
|
+
onSelectRecord?: (record: T | null) => Promise<void> | void;
|
|
56
|
+
onSchemaEvent?: (event: DatabaseSchemaEvent) => Promise<void> | void;
|
|
57
|
+
onSaveView?: (view: ViewConfig) => Promise<void> | void;
|
|
58
|
+
onDeleteView?: (viewId: string) => Promise<void> | void;
|
|
59
|
+
onRefresh?: () => Promise<void> | void;
|
|
60
|
+
}
|
|
61
|
+
export interface DatabaseViewDetailOptions {
|
|
62
|
+
clearSelection?: boolean;
|
|
63
|
+
}
|
|
64
|
+
export interface DatabaseViewNavigationOptions {
|
|
65
|
+
wrap?: boolean;
|
|
66
|
+
openDetail?: boolean;
|
|
67
|
+
}
|
|
68
|
+
export interface UseDatabaseViewOptions<T extends DataRecord = DataRecord> {
|
|
69
|
+
tableId: string;
|
|
70
|
+
mode?: DatabaseViewMode;
|
|
71
|
+
schema?: Ref<TableSchema | null | undefined> | TableSchema | null | undefined;
|
|
72
|
+
records?: Ref<readonly T[] | T[] | undefined> | readonly T[] | T[] | undefined;
|
|
73
|
+
views?: Ref<readonly ViewConfig[] | ViewConfig[] | undefined> | readonly ViewConfig[] | ViewConfig[] | undefined;
|
|
74
|
+
provider?: DatabaseViewProvider<T>;
|
|
75
|
+
actions?: DatabaseViewActions<T>;
|
|
76
|
+
defaultView?: ViewConfig;
|
|
77
|
+
initialViewId?: string;
|
|
78
|
+
initialSelectedRecordId?: string | null;
|
|
79
|
+
initialDetailOpen?: boolean;
|
|
80
|
+
pageSize?: number;
|
|
81
|
+
autoLoad?: boolean;
|
|
82
|
+
}
|
|
83
|
+
export interface UseDatabaseViewResult<T extends DataRecord = DataRecord> {
|
|
84
|
+
tableId: string;
|
|
85
|
+
mode: Readonly<Ref<DatabaseViewMode>>;
|
|
86
|
+
schema: Readonly<Ref<TableSchema | null>>;
|
|
87
|
+
records: Readonly<Ref<readonly T[]>>;
|
|
88
|
+
views: Readonly<Ref<ViewConfig[]>>;
|
|
89
|
+
activeViewId: Readonly<Ref<string>>;
|
|
90
|
+
activeView: Readonly<Ref<ViewConfig>>;
|
|
91
|
+
selectedRecordId: Readonly<Ref<string | null>>;
|
|
92
|
+
selectedRecord: Readonly<Ref<T | null>>;
|
|
93
|
+
selectedRecordIndex: Readonly<Ref<number>>;
|
|
94
|
+
selectedRecordOrdinal: Readonly<Ref<number | null>>;
|
|
95
|
+
hasSelectedRecord: Readonly<Ref<boolean>>;
|
|
96
|
+
detailOpen: Readonly<Ref<boolean>>;
|
|
97
|
+
detailRecord: Readonly<Ref<T | null>>;
|
|
98
|
+
loading: Readonly<Ref<boolean>>;
|
|
99
|
+
error: Readonly<Ref<Error | null>>;
|
|
100
|
+
page: Readonly<Ref<number>>;
|
|
101
|
+
pageSize: Readonly<Ref<number>>;
|
|
102
|
+
totalCount: Readonly<Ref<number>>;
|
|
103
|
+
viewList: Readonly<Ref<{
|
|
104
|
+
id: string;
|
|
105
|
+
name: string;
|
|
106
|
+
type: ViewConfig["viewType"];
|
|
107
|
+
}[]>>;
|
|
108
|
+
isProviderMode: Readonly<Ref<boolean>>;
|
|
109
|
+
isLocalMode: Readonly<Ref<boolean>>;
|
|
110
|
+
refresh: () => Promise<void>;
|
|
111
|
+
getRecordById: (recordId: string) => T | null;
|
|
112
|
+
getRecordIndex: (recordId: string) => number;
|
|
113
|
+
selectRecord: (record: T | string | null) => void;
|
|
114
|
+
openRecordDetail: (record?: T | string | null) => void;
|
|
115
|
+
closeRecordDetail: (options?: DatabaseViewDetailOptions) => void;
|
|
116
|
+
toggleRecordDetail: (record?: T | string | null) => void;
|
|
117
|
+
selectNextRecord: (options?: DatabaseViewNavigationOptions) => void;
|
|
118
|
+
selectPreviousRecord: (options?: DatabaseViewNavigationOptions) => void;
|
|
119
|
+
switchView: (viewId: string) => void;
|
|
120
|
+
setActiveViewId: (viewId: string) => void;
|
|
121
|
+
createView: (name: string, baseConfig?: Partial<ViewConfig>) => Promise<string>;
|
|
122
|
+
saveView: (config?: Partial<ViewConfig>) => Promise<void>;
|
|
123
|
+
deleteView: (viewId: string) => Promise<void>;
|
|
124
|
+
duplicateView: (sourceViewId: string, newName: string) => Promise<string>;
|
|
125
|
+
updateActiveView: (patch: Partial<ViewConfig>) => void;
|
|
126
|
+
setSelectedRecord: (record: T | string | null) => void;
|
|
127
|
+
clearSelectedRecord: () => void;
|
|
128
|
+
setPage: (page: number) => void;
|
|
129
|
+
setPageSize: (pageSize: number) => void;
|
|
130
|
+
emitCellEdit: (payload: {
|
|
131
|
+
rowId: string;
|
|
132
|
+
fieldId: string;
|
|
133
|
+
value: unknown;
|
|
134
|
+
}) => Promise<void>;
|
|
135
|
+
emitSchemaEvent: (event: DatabaseSchemaEvent) => Promise<void>;
|
|
136
|
+
setRecords: (next: readonly T[] | T[]) => void;
|
|
137
|
+
}
|
|
138
|
+
export declare function useDatabaseView<T extends DataRecord = DataRecord>(options: UseDatabaseViewOptions<T>): UseDatabaseViewResult<T>;
|
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
import { computed as s, ref as I, shallowRef as De, watch as N } from "vue";
|
|
2
|
+
function Le(l) {
|
|
3
|
+
return !!(l && typeof l == "object" && "value" in l);
|
|
4
|
+
}
|
|
5
|
+
function G(l) {
|
|
6
|
+
if (l !== void 0)
|
|
7
|
+
return Le(l) ? l.value : l;
|
|
8
|
+
}
|
|
9
|
+
function _e(l) {
|
|
10
|
+
if (l)
|
|
11
|
+
return { ...l };
|
|
12
|
+
}
|
|
13
|
+
function z(l) {
|
|
14
|
+
var r, v, a, S;
|
|
15
|
+
return {
|
|
16
|
+
...l,
|
|
17
|
+
visibleFields: [...l.visibleFields],
|
|
18
|
+
sorts: (r = l.sorts) == null ? void 0 : r.map(_e).filter((w) => w !== void 0),
|
|
19
|
+
groups: (v = l.groups) == null ? void 0 : v.map((w) => ({ ...w })),
|
|
20
|
+
filters: (a = l.filters) == null ? void 0 : a.map((w) => ({ ...w })),
|
|
21
|
+
aggregations: (S = l.aggregations) == null ? void 0 : S.map((w) => ({ ...w })),
|
|
22
|
+
fixedColumns: l.fixedColumns ? [...l.fixedColumns] : void 0,
|
|
23
|
+
galleryCardFields: l.galleryCardFields ? [...l.galleryCardFields] : void 0
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function ue(l) {
|
|
27
|
+
return l ? {
|
|
28
|
+
...l,
|
|
29
|
+
fields: l.fields.map((r) => ({ ...r })),
|
|
30
|
+
views: (l.views ?? []).map(z)
|
|
31
|
+
} : null;
|
|
32
|
+
}
|
|
33
|
+
function H(l) {
|
|
34
|
+
return l ? l.map((r) => ({
|
|
35
|
+
...r,
|
|
36
|
+
fields: { ...r.fields }
|
|
37
|
+
})) : [];
|
|
38
|
+
}
|
|
39
|
+
function J(l) {
|
|
40
|
+
if (!l) return [];
|
|
41
|
+
const r = /* @__PURE__ */ new Set(), v = [];
|
|
42
|
+
for (const a of l)
|
|
43
|
+
!(a != null && a.viewId) || r.has(a.viewId) || (r.add(a.viewId), v.push(z(a)));
|
|
44
|
+
return v;
|
|
45
|
+
}
|
|
46
|
+
function K(l, r, v = (r == null ? void 0 : r.viewId) ?? "__default__") {
|
|
47
|
+
var w;
|
|
48
|
+
const a = r ? z(r) : void 0, S = (w = a == null ? void 0 : a.visibleFields) != null && w.length ? [...a.visibleFields] : (l == null ? void 0 : l.fields.map((p) => p.id)) ?? [];
|
|
49
|
+
return {
|
|
50
|
+
viewId: v,
|
|
51
|
+
viewType: (a == null ? void 0 : a.viewType) ?? "table",
|
|
52
|
+
name: (a == null ? void 0 : a.name) ?? (l == null ? void 0 : l.name) ?? "全部记录",
|
|
53
|
+
visibleFields: S,
|
|
54
|
+
sorts: a == null ? void 0 : a.sorts,
|
|
55
|
+
groups: a == null ? void 0 : a.groups,
|
|
56
|
+
filters: a == null ? void 0 : a.filters,
|
|
57
|
+
aggregations: a == null ? void 0 : a.aggregations,
|
|
58
|
+
fixedColumns: a == null ? void 0 : a.fixedColumns,
|
|
59
|
+
galleryCardFields: a == null ? void 0 : a.galleryCardFields
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function Ee(l, r, v, a) {
|
|
63
|
+
const S = l.filter((n) => !a.has(n.viewId)), w = /* @__PURE__ */ new Map();
|
|
64
|
+
for (const n of S)
|
|
65
|
+
w.set(n.viewId, n);
|
|
66
|
+
const p = /* @__PURE__ */ new Map();
|
|
67
|
+
for (const n of r)
|
|
68
|
+
a.has(n.viewId) || p.set(n.viewId, n);
|
|
69
|
+
const V = /* @__PURE__ */ new Map();
|
|
70
|
+
for (const n of v)
|
|
71
|
+
a.has(n.viewId) || V.set(n.viewId, n);
|
|
72
|
+
const y = [], d = /* @__PURE__ */ new Set();
|
|
73
|
+
for (const n of S) {
|
|
74
|
+
const D = V.get(n.viewId) ?? p.get(n.viewId) ?? n;
|
|
75
|
+
y.push(D), d.add(D.viewId);
|
|
76
|
+
}
|
|
77
|
+
for (const n of r)
|
|
78
|
+
a.has(n.viewId) || d.has(n.viewId) || (y.push(n), d.add(n.viewId));
|
|
79
|
+
for (const n of v)
|
|
80
|
+
a.has(n.viewId) || d.has(n.viewId) || (y.push(n), d.add(n.viewId));
|
|
81
|
+
return y;
|
|
82
|
+
}
|
|
83
|
+
function Be(l) {
|
|
84
|
+
var v;
|
|
85
|
+
const r = (v = l == null ? void 0 : l.sorts) == null ? void 0 : v[0];
|
|
86
|
+
return r ? {
|
|
87
|
+
field: r.fieldId,
|
|
88
|
+
order: r.direction
|
|
89
|
+
} : { field: null, order: null };
|
|
90
|
+
}
|
|
91
|
+
function Q(l, r) {
|
|
92
|
+
return l.some((v) => v.viewId === r);
|
|
93
|
+
}
|
|
94
|
+
function Ae(l) {
|
|
95
|
+
var ie;
|
|
96
|
+
const r = s(() => {
|
|
97
|
+
var e, t;
|
|
98
|
+
return l.mode ? l.mode : (e = l.provider) != null && e.mode ? l.provider.mode : (t = l.provider) != null && t.onFetch ? "provider" : "local";
|
|
99
|
+
}), v = s(() => ue(G(l.schema) ?? null)), a = s(() => H(G(l.records))), S = s(() => J(G(l.views))), w = I(null), p = I([]), V = I([]), y = I(/* @__PURE__ */ new Set()), d = De(a.value), n = I(!1), D = I(null), E = I(d.value.length), L = I(1), k = I(l.pageSize ?? 20), f = I(
|
|
100
|
+
l.initialSelectedRecordId !== void 0 ? l.initialSelectedRecordId : ((ie = d.value[0]) == null ? void 0 : ie.id) ?? null
|
|
101
|
+
), m = I(l.initialViewId ?? ""), $ = I(!1), B = I(0), F = I(l.initialSelectedRecordId === void 0), q = s(() => w.value ?? v.value), b = s(() => {
|
|
102
|
+
var i;
|
|
103
|
+
const e = [...((i = v.value) == null ? void 0 : i.views) ?? [], ...S.value], t = J(e);
|
|
104
|
+
return t.length > 0 ? t : [K(v.value, l.defaultView)];
|
|
105
|
+
}), g = s(
|
|
106
|
+
() => Ee(b.value, p.value, V.value, y.value)
|
|
107
|
+
), C = s(() => g.value.find((t) => t.viewId === m.value) ?? g.value[0] ?? K(q.value, l.defaultView, m.value || "__default__")), O = s(() => f.value ? d.value.find((e) => e.id === f.value) ?? null : null), T = s(() => f.value ? d.value.findIndex((e) => e.id === f.value) : -1), U = s(() => T.value >= 0), re = s(
|
|
108
|
+
() => U.value ? T.value + 1 : null
|
|
109
|
+
), h = I(!!(l.initialDetailOpen ?? l.initialSelectedRecordId)), ce = s(() => h.value ? O.value : null), de = s(
|
|
110
|
+
() => g.value.map((e) => ({
|
|
111
|
+
id: e.viewId,
|
|
112
|
+
name: e.name,
|
|
113
|
+
type: e.viewType
|
|
114
|
+
}))
|
|
115
|
+
), M = s(() => {
|
|
116
|
+
var e;
|
|
117
|
+
return r.value === "provider" && !!((e = l.provider) != null && e.onFetch);
|
|
118
|
+
}), oe = s(() => !M.value);
|
|
119
|
+
function x(e) {
|
|
120
|
+
D.value = e instanceof Error ? e : new Error(String(e));
|
|
121
|
+
}
|
|
122
|
+
function W(e) {
|
|
123
|
+
return d.value.findIndex((t) => t.id === e);
|
|
124
|
+
}
|
|
125
|
+
function ve(e) {
|
|
126
|
+
return d.value.find((t) => t.id === e) ?? null;
|
|
127
|
+
}
|
|
128
|
+
function fe(e) {
|
|
129
|
+
return W(e) >= 0;
|
|
130
|
+
}
|
|
131
|
+
function X(e) {
|
|
132
|
+
return e == null ? null : typeof e == "string" ? e : e.id;
|
|
133
|
+
}
|
|
134
|
+
function _() {
|
|
135
|
+
var e;
|
|
136
|
+
Q(g.value, m.value) || (m.value = ((e = g.value[0]) == null ? void 0 : e.viewId) ?? K(q.value, l.defaultView).viewId);
|
|
137
|
+
}
|
|
138
|
+
function P() {
|
|
139
|
+
var e;
|
|
140
|
+
F.value && (!f.value || !fe(f.value)) && (f.value = ((e = d.value[0]) == null ? void 0 : e.id) ?? null);
|
|
141
|
+
}
|
|
142
|
+
function Y(e) {
|
|
143
|
+
F.value = !1, f.value = X(e);
|
|
144
|
+
}
|
|
145
|
+
function Z(e) {
|
|
146
|
+
F.value = !1, e !== void 0 && (f.value = X(e)), h.value = !0;
|
|
147
|
+
}
|
|
148
|
+
function ee(e) {
|
|
149
|
+
h.value = !1, e != null && e.clearSelection && (F.value = !1, f.value = null);
|
|
150
|
+
}
|
|
151
|
+
function se(e) {
|
|
152
|
+
if (h.value) {
|
|
153
|
+
ee();
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
Z(e);
|
|
157
|
+
}
|
|
158
|
+
function le(e, t) {
|
|
159
|
+
const i = d.value.length;
|
|
160
|
+
if (i <= 0) return;
|
|
161
|
+
const c = T.value;
|
|
162
|
+
let o = c >= 0 ? c + e : e > 0 ? 0 : i - 1;
|
|
163
|
+
if (t != null && t.wrap)
|
|
164
|
+
o = (o + i) % i;
|
|
165
|
+
else if (o < 0 || o >= i)
|
|
166
|
+
return;
|
|
167
|
+
const u = d.value[o];
|
|
168
|
+
u && (F.value = !1, f.value = u.id, ((t == null ? void 0 : t.openDetail) ?? h.value) && (h.value = !0));
|
|
169
|
+
}
|
|
170
|
+
function we(e) {
|
|
171
|
+
le(1, e);
|
|
172
|
+
}
|
|
173
|
+
function Ie(e) {
|
|
174
|
+
le(-1, e);
|
|
175
|
+
}
|
|
176
|
+
function j(e) {
|
|
177
|
+
const t = z(e);
|
|
178
|
+
V.value = [...V.value.filter((i) => i.viewId !== t.viewId), t], y.value.delete(t.viewId), _();
|
|
179
|
+
}
|
|
180
|
+
function te(e) {
|
|
181
|
+
V.value = V.value.filter((t) => t.viewId !== e);
|
|
182
|
+
}
|
|
183
|
+
function me(e) {
|
|
184
|
+
y.value = /* @__PURE__ */ new Set([...y.value, e]), te(e);
|
|
185
|
+
}
|
|
186
|
+
async function A() {
|
|
187
|
+
var i, c, o;
|
|
188
|
+
const e = {
|
|
189
|
+
tableId: l.tableId,
|
|
190
|
+
schema: q.value,
|
|
191
|
+
view: C.value,
|
|
192
|
+
page: L.value,
|
|
193
|
+
pageSize: k.value,
|
|
194
|
+
sort: Be(C.value),
|
|
195
|
+
selectedRecordId: f.value
|
|
196
|
+
};
|
|
197
|
+
if (D.value = null, (i = l.actions) != null && i.onRefresh)
|
|
198
|
+
try {
|
|
199
|
+
await l.actions.onRefresh();
|
|
200
|
+
} catch (u) {
|
|
201
|
+
x(u);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if ((c = l.provider) != null && c.onRefresh)
|
|
205
|
+
try {
|
|
206
|
+
await l.provider.onRefresh(e);
|
|
207
|
+
} catch (u) {
|
|
208
|
+
x(u);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
if (!M.value || !((o = l.provider) != null && o.onFetch)) {
|
|
212
|
+
d.value = a.value, E.value = d.value.length, P(), _(), $.value = !1;
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
const t = B.value + 1;
|
|
216
|
+
B.value = t, n.value = !0;
|
|
217
|
+
try {
|
|
218
|
+
const u = await l.provider.onFetch(e);
|
|
219
|
+
if (B.value !== t) return;
|
|
220
|
+
const R = H(u.records ?? u.data);
|
|
221
|
+
d.value = R, E.value = u.total ?? R.length, u.schema !== void 0 && (w.value = ue(u.schema)), u.views !== void 0 && u.views !== null && (p.value = J(u.views)), u.activeViewId && (m.value = u.activeViewId), u.selectedRecordId !== void 0 && (F.value = !1, f.value = u.selectedRecordId, u.selectedRecordId === null && (h.value = !1)), $.value = !0, _(), P();
|
|
222
|
+
} catch (u) {
|
|
223
|
+
B.value === t && x(u);
|
|
224
|
+
} finally {
|
|
225
|
+
B.value === t && (n.value = !1);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
function ae(e) {
|
|
229
|
+
Q(g.value, e) && (m.value = e, L.value = 1, M.value && A());
|
|
230
|
+
}
|
|
231
|
+
function ge(e) {
|
|
232
|
+
ae(e);
|
|
233
|
+
}
|
|
234
|
+
async function he(e) {
|
|
235
|
+
var c, o;
|
|
236
|
+
const t = C.value, i = z({
|
|
237
|
+
...t,
|
|
238
|
+
...e,
|
|
239
|
+
viewId: t.viewId
|
|
240
|
+
});
|
|
241
|
+
j(i);
|
|
242
|
+
try {
|
|
243
|
+
await ((o = (c = l.actions) == null ? void 0 : c.onSaveView) == null ? void 0 : o.call(c, i));
|
|
244
|
+
} catch (u) {
|
|
245
|
+
x(u);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
async function ne(e, t) {
|
|
249
|
+
var o, u;
|
|
250
|
+
const i = `view-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 6)}`, c = z({
|
|
251
|
+
...C.value,
|
|
252
|
+
...t,
|
|
253
|
+
viewId: i,
|
|
254
|
+
name: e
|
|
255
|
+
});
|
|
256
|
+
j(c), m.value = i, L.value = 1;
|
|
257
|
+
try {
|
|
258
|
+
await ((u = (o = l.actions) == null ? void 0 : o.onSaveView) == null ? void 0 : u.call(o, c));
|
|
259
|
+
} catch (R) {
|
|
260
|
+
x(R);
|
|
261
|
+
}
|
|
262
|
+
return i;
|
|
263
|
+
}
|
|
264
|
+
async function Re(e) {
|
|
265
|
+
var c, o, u;
|
|
266
|
+
if (!Q(g.value, e)) return;
|
|
267
|
+
const t = m.value === e;
|
|
268
|
+
b.value.some((R) => R.viewId === e) ? me(e) : te(e), t && (m.value = ((c = g.value.find((R) => R.viewId !== e)) == null ? void 0 : c.viewId) ?? "", _());
|
|
269
|
+
try {
|
|
270
|
+
await ((u = (o = l.actions) == null ? void 0 : o.onDeleteView) == null ? void 0 : u.call(o, e));
|
|
271
|
+
} catch (R) {
|
|
272
|
+
x(R);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
async function Se(e, t) {
|
|
276
|
+
const i = g.value.find((c) => c.viewId === e);
|
|
277
|
+
return i ? ne(t, { ...i }) : "";
|
|
278
|
+
}
|
|
279
|
+
function ye(e) {
|
|
280
|
+
const t = z({
|
|
281
|
+
...C.value,
|
|
282
|
+
...e,
|
|
283
|
+
viewId: C.value.viewId
|
|
284
|
+
});
|
|
285
|
+
j(t);
|
|
286
|
+
}
|
|
287
|
+
function Ve(e) {
|
|
288
|
+
Y(e), f.value === null && (h.value = !1);
|
|
289
|
+
}
|
|
290
|
+
function xe() {
|
|
291
|
+
F.value = !1, f.value = null, h.value = !1;
|
|
292
|
+
}
|
|
293
|
+
function pe(e) {
|
|
294
|
+
L.value = Math.max(1, Math.floor(e) || 1), M.value && A();
|
|
295
|
+
}
|
|
296
|
+
function Fe(e) {
|
|
297
|
+
k.value = Math.max(1, Math.floor(e) || 1), L.value = 1, M.value && A();
|
|
298
|
+
}
|
|
299
|
+
async function Ce(e) {
|
|
300
|
+
var t, i;
|
|
301
|
+
try {
|
|
302
|
+
await ((i = (t = l.actions) == null ? void 0 : t.onCellEdit) == null ? void 0 : i.call(t, e));
|
|
303
|
+
} catch (c) {
|
|
304
|
+
x(c);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
async function Me(e) {
|
|
308
|
+
var t, i;
|
|
309
|
+
try {
|
|
310
|
+
await ((i = (t = l.actions) == null ? void 0 : t.onSchemaEvent) == null ? void 0 : i.call(t, e));
|
|
311
|
+
} catch (c) {
|
|
312
|
+
x(c);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
function ze(e) {
|
|
316
|
+
const t = H(e);
|
|
317
|
+
d.value = t, E.value = t.length, P();
|
|
318
|
+
}
|
|
319
|
+
return N(
|
|
320
|
+
a,
|
|
321
|
+
(e) => {
|
|
322
|
+
M.value && $.value || (d.value = e, E.value = e.length, P());
|
|
323
|
+
},
|
|
324
|
+
{ immediate: !0 }
|
|
325
|
+
), N(
|
|
326
|
+
b,
|
|
327
|
+
() => {
|
|
328
|
+
_();
|
|
329
|
+
},
|
|
330
|
+
{ immediate: !0, deep: !0 }
|
|
331
|
+
), N(
|
|
332
|
+
O,
|
|
333
|
+
() => {
|
|
334
|
+
var e, t;
|
|
335
|
+
(t = (e = l.actions) == null ? void 0 : e.onSelectRecord) == null || t.call(e, O.value);
|
|
336
|
+
},
|
|
337
|
+
{ immediate: !0, deep: !1, flush: "sync" }
|
|
338
|
+
), l.autoLoad !== !1 ? A() : (_(), P()), {
|
|
339
|
+
tableId: l.tableId,
|
|
340
|
+
mode: r,
|
|
341
|
+
schema: q,
|
|
342
|
+
records: d,
|
|
343
|
+
views: g,
|
|
344
|
+
activeViewId: m,
|
|
345
|
+
activeView: C,
|
|
346
|
+
selectedRecordId: f,
|
|
347
|
+
selectedRecord: O,
|
|
348
|
+
selectedRecordIndex: T,
|
|
349
|
+
selectedRecordOrdinal: re,
|
|
350
|
+
hasSelectedRecord: U,
|
|
351
|
+
detailOpen: h,
|
|
352
|
+
detailRecord: ce,
|
|
353
|
+
loading: n,
|
|
354
|
+
error: D,
|
|
355
|
+
page: L,
|
|
356
|
+
pageSize: k,
|
|
357
|
+
totalCount: E,
|
|
358
|
+
viewList: de,
|
|
359
|
+
isProviderMode: M,
|
|
360
|
+
isLocalMode: oe,
|
|
361
|
+
refresh: A,
|
|
362
|
+
getRecordById: ve,
|
|
363
|
+
getRecordIndex: W,
|
|
364
|
+
selectRecord: Y,
|
|
365
|
+
openRecordDetail: Z,
|
|
366
|
+
closeRecordDetail: ee,
|
|
367
|
+
toggleRecordDetail: se,
|
|
368
|
+
selectNextRecord: we,
|
|
369
|
+
selectPreviousRecord: Ie,
|
|
370
|
+
switchView: ae,
|
|
371
|
+
setActiveViewId: ge,
|
|
372
|
+
createView: ne,
|
|
373
|
+
saveView: he,
|
|
374
|
+
deleteView: Re,
|
|
375
|
+
duplicateView: Se,
|
|
376
|
+
updateActiveView: ye,
|
|
377
|
+
setSelectedRecord: Ve,
|
|
378
|
+
clearSelectedRecord: xe,
|
|
379
|
+
setPage: pe,
|
|
380
|
+
setPageSize: Fe,
|
|
381
|
+
emitCellEdit: Ce,
|
|
382
|
+
emitSchemaEvent: Me,
|
|
383
|
+
setRecords: ze
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
export {
|
|
387
|
+
Ae as useDatabaseView
|
|
388
|
+
};
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import { ref as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { ref as y, onUnmounted as L, readonly as b } from "vue";
|
|
2
|
+
import S from "../workers/tableWorkerSource.js";
|
|
3
|
+
const h = 5e3;
|
|
4
|
+
function d(p = {}) {
|
|
5
|
+
const i = y(!1);
|
|
6
|
+
let n = null, a = null;
|
|
7
|
+
function c() {
|
|
7
8
|
if (n) return n;
|
|
8
9
|
try {
|
|
9
|
-
return
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
), {
|
|
10
|
+
return a = URL.createObjectURL(
|
|
11
|
+
new Blob([S], {
|
|
12
|
+
type: "text/javascript;charset=utf-8"
|
|
13
|
+
})
|
|
14
|
+
), n = new Worker(a, {
|
|
14
15
|
type: "module"
|
|
15
16
|
}), n;
|
|
16
17
|
} catch {
|
|
@@ -19,41 +20,41 @@ function d(c = {}) {
|
|
|
19
20
|
}
|
|
20
21
|
function m(e) {
|
|
21
22
|
var s;
|
|
22
|
-
return ((s =
|
|
23
|
+
return ((s = p.enabled) == null ? void 0 : s.value) === !1 ? !1 : e >= h;
|
|
23
24
|
}
|
|
24
|
-
function
|
|
25
|
+
function v(e, s, f) {
|
|
25
26
|
if (!m(e.length))
|
|
26
27
|
return Promise.resolve(
|
|
27
|
-
[...e].sort((o,
|
|
28
|
-
const r = o[s],
|
|
29
|
-
return r == null &&
|
|
28
|
+
[...e].sort((o, l) => {
|
|
29
|
+
const r = o[s], u = l[s];
|
|
30
|
+
return r == null && u == null ? 0 : r == null ? 1 : u == null ? -1 : typeof r == "number" && typeof u == "number" ? f === "asc" ? r - u : u - r : f === "asc" ? String(r).localeCompare(String(u)) : String(u).localeCompare(String(r));
|
|
30
31
|
})
|
|
31
32
|
);
|
|
32
|
-
const t =
|
|
33
|
+
const t = c();
|
|
33
34
|
return t ? (i.value = !0, new Promise((o) => {
|
|
34
|
-
const
|
|
35
|
-
t.removeEventListener("message",
|
|
35
|
+
const l = (r) => {
|
|
36
|
+
t.removeEventListener("message", l), i.value = !1, r.data.type === "sort-result" ? o(r.data.data) : o([...e]);
|
|
36
37
|
};
|
|
37
|
-
t.addEventListener("message",
|
|
38
|
+
t.addEventListener("message", l), t.postMessage({ type: "sort", data: e, field: s, order: f });
|
|
38
39
|
})) : Promise.resolve([...e]);
|
|
39
40
|
}
|
|
40
|
-
function g(e, s,
|
|
41
|
+
function g(e, s, f = "and") {
|
|
41
42
|
if (!m(e.length))
|
|
42
43
|
return Promise.resolve(e);
|
|
43
|
-
const t =
|
|
44
|
+
const t = c();
|
|
44
45
|
return t ? (i.value = !0, new Promise((o) => {
|
|
45
|
-
const
|
|
46
|
-
t.removeEventListener("message",
|
|
46
|
+
const l = (r) => {
|
|
47
|
+
t.removeEventListener("message", l), i.value = !1, r.data.type === "filter-result" ? o(r.data.data) : o(e);
|
|
47
48
|
};
|
|
48
|
-
t.addEventListener("message",
|
|
49
|
+
t.addEventListener("message", l), t.postMessage({ type: "filter", data: e, conditions: s, logic: f });
|
|
49
50
|
})) : Promise.resolve(e);
|
|
50
51
|
}
|
|
51
|
-
return
|
|
52
|
-
n == null || n.terminate(), n = null;
|
|
52
|
+
return L(() => {
|
|
53
|
+
n == null || n.terminate(), n = null, a && (URL.revokeObjectURL(a), a = null);
|
|
53
54
|
}), {
|
|
54
|
-
requestSort:
|
|
55
|
+
requestSort: v,
|
|
55
56
|
requestFilter: g,
|
|
56
|
-
processing:
|
|
57
|
+
processing: b(i)
|
|
57
58
|
};
|
|
58
59
|
}
|
|
59
60
|
export {
|
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export { ActivityTimeline, GanttTimeline, GanttRow } from './components/timeline
|
|
|
9
9
|
export type { ActivityTimelineProps, ActivityTimelineStatus, TimelineItem, } from './components/timeline';
|
|
10
10
|
export { ContentBlock, BlockQuote, CodeBlock, RefLink, RichTextEditor } from './components/editor';
|
|
11
11
|
export { FormDesigner } from './components/form';
|
|
12
|
+
export { DatabaseView } from './components/database';
|
|
13
|
+
export type { DatabaseViewActions as DatabaseViewComponentActions, DatabaseViewSchemaEvent, DatabaseViewViewTab, DatabaseViewProps, } from './components/database';
|
|
12
14
|
export { ColorPanel, PersonPanel, FileUpload } from './components/auxiliary';
|
|
13
15
|
export { DetailLayout, PropPanel, PropRow, CommentItem } from './components/detail';
|
|
14
16
|
export { Dashboard, BarChart, PieChart, DoughnutChart, NumberCard, TableChart, } from './components/Dashboard';
|
|
@@ -66,6 +68,8 @@ export { useSupabaseProvider } from './composables/useSupabaseProvider';
|
|
|
66
68
|
export type { SupabaseQueryBuilder, SupabaseFilterBuilder, UseSupabaseProviderOptions, } from './composables/useSupabaseProvider';
|
|
67
69
|
export { useViewPersistence, createLocalStorageBackend, createSupabaseBackend, } from './composables/useViewPersistence';
|
|
68
70
|
export type { ViewStorageBackend, SupabaseViewBackendOptions, UseViewPersistenceOptions, } from './composables/useViewPersistence';
|
|
71
|
+
export { useDatabaseView } from './composables/useDatabaseView';
|
|
72
|
+
export type { DatabaseViewMode, DatabaseViewFetchParams, DatabaseViewFetchResult, DatabaseViewProvider, DatabaseSchemaEvent, DatabaseViewActions, UseDatabaseViewOptions, UseDatabaseViewResult, } from './composables/useDatabaseView';
|
|
69
73
|
export { useSearch } from './composables/useSearch';
|
|
70
74
|
export type { UseSearchOptions, SearchHighlight as SearchHighlightSegment, } from './composables/useSearch';
|
|
71
75
|
export declare const OneflowUI: {
|