@headless-adminapp/app 1.4.0 → 1.4.6
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/datagrid/DataGridProvider/utils.d.ts +1 -0
- package/datagrid/DataGridProvider/utils.js +17 -0
- package/metadata/MetadataProvider.d.ts +2 -1
- package/metadata/MetadataProvider.js +3 -1
- package/metadata/context.d.ts +2 -0
- package/metadata/hooks/useMetadata.d.ts +2 -0
- package/metadata/hooks/useMetadata.js +3 -1
- package/metadata/hooks/useRecentItemStore.d.ts +2 -0
- package/metadata/hooks/useRecentItemStore.js +8 -0
- package/package.json +2 -2
- package/store/RecentItemStore.d.ts +25 -0
- package/store/RecentItemStore.js +63 -0
- package/store/index.d.ts +1 -1
- package/store/index.js +1 -1
- package/store/HistoryState.d.ts +0 -7
- package/store/HistoryState.js +0 -32
|
@@ -5,6 +5,7 @@ import { Filter } from '@headless-adminapp/core/transport';
|
|
|
5
5
|
import { TransformedViewColumn } from '../context';
|
|
6
6
|
export declare function transformColumnFilter<S extends SchemaAttributes = SchemaAttributes>(filter: Partial<Record<string, ColumnCondition>>, schema: Schema<S>, schemaStore: ISchemaStore): Record<string, ColumnCondition> | null;
|
|
7
7
|
export declare function mergeConditions<S extends SchemaAttributes = SchemaAttributes>(schema: Schema<S>, filter: Filter | null | undefined, extraFilter: Filter | null | undefined, quickFilterResults: Filter | null | undefined, columnFilters: Partial<Record<string, ColumnCondition>> | undefined, schemaStore: ISchemaStore): Filter | null;
|
|
8
|
+
export declare function mergeFilters(...filters: Array<Filter | null | undefined>): Filter | null;
|
|
8
9
|
export declare function simplyfyFilter(filter: Filter): Filter | null;
|
|
9
10
|
export declare function collectExpandedKeys(columns: TransformedViewColumn<SchemaAttributes>[]): Record<string, string[]>;
|
|
10
11
|
export declare function collectGridColumns<S extends SchemaAttributes = SchemaAttributes>({ gridColumns, schema, }: {
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.transformColumnFilter = transformColumnFilter;
|
|
7
7
|
exports.mergeConditions = mergeConditions;
|
|
8
|
+
exports.mergeFilters = mergeFilters;
|
|
8
9
|
exports.simplyfyFilter = simplyfyFilter;
|
|
9
10
|
exports.collectExpandedKeys = collectExpandedKeys;
|
|
10
11
|
exports.collectGridColumns = collectGridColumns;
|
|
@@ -116,6 +117,22 @@ function mergeConditions(schema, filter, extraFilter, quickFilterResults, column
|
|
|
116
117
|
filters: filters,
|
|
117
118
|
});
|
|
118
119
|
}
|
|
120
|
+
function mergeFilters(...filters) {
|
|
121
|
+
if (filters.length === 0) {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
const nonNullFilters = filters.filter((f) => !!f);
|
|
125
|
+
if (nonNullFilters.length === 0) {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
if (nonNullFilters.length === 1) {
|
|
129
|
+
return nonNullFilters[0];
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
type: 'and',
|
|
133
|
+
filters: nonNullFilters,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
119
136
|
function simplyfyFilter(filter) {
|
|
120
137
|
const conditions = filter.conditions ?? [];
|
|
121
138
|
const filters = [];
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { AppExperience } from '@headless-adminapp/core/experience/app';
|
|
2
2
|
import { ISchemaExperienceStore, ISchemaStore, SchemaStore } from '@headless-adminapp/core/store';
|
|
3
3
|
import { FC, PropsWithChildren } from 'react';
|
|
4
|
-
import { SchemaExperienceStore } from '../store';
|
|
4
|
+
import { IRecentItemStore, SchemaExperienceStore } from '../store';
|
|
5
5
|
export interface MetadataProviderProps {
|
|
6
6
|
schemaStore?: ISchemaStore;
|
|
7
7
|
experienceStore?: ISchemaExperienceStore;
|
|
8
8
|
appExperience?: AppExperience;
|
|
9
|
+
recentItemStore?: IRecentItemStore;
|
|
9
10
|
}
|
|
10
11
|
export declare const defaultSchemaStore: SchemaStore<import("@headless-adminapp/core/schema").SchemaAttributes>;
|
|
11
12
|
export declare const defaultExperienceStore: SchemaExperienceStore;
|
|
@@ -24,11 +24,13 @@ const defaultApp = {
|
|
|
24
24
|
},
|
|
25
25
|
logo: {},
|
|
26
26
|
};
|
|
27
|
-
const
|
|
27
|
+
const defaultRecentItemStore = new store_2.RecentItemStore();
|
|
28
|
+
const MetadataProvider = ({ children, experienceStore = exports.defaultExperienceStore, schemaStore = exports.defaultSchemaStore, appExperience = defaultApp, recentItemStore = defaultRecentItemStore, }) => {
|
|
28
29
|
const contextValue = (0, context_1.useCreateContextStore)({
|
|
29
30
|
experienceStore,
|
|
30
31
|
schemaStore,
|
|
31
32
|
appExperience,
|
|
33
|
+
recentItemStore,
|
|
32
34
|
});
|
|
33
35
|
return ((0, jsx_runtime_1.jsx)(context_2.MetadataContext.Provider, { value: contextValue, children: children }));
|
|
34
36
|
};
|
package/metadata/context.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { AppExperience } from '@headless-adminapp/core/experience/app';
|
|
2
2
|
import type { ISchemaExperienceStore, ISchemaStore } from '@headless-adminapp/core/store';
|
|
3
|
+
import { IRecentItemStore } from '../store';
|
|
3
4
|
export interface MetadataContextState {
|
|
4
5
|
schemaStore: ISchemaStore;
|
|
5
6
|
experienceStore: ISchemaExperienceStore;
|
|
6
7
|
appExperience: AppExperience;
|
|
8
|
+
recentItemStore: IRecentItemStore;
|
|
7
9
|
}
|
|
8
10
|
export declare const MetadataContext: import("react").Context<import("../mutable/context").ContextValue<MetadataContextState>>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IRecentItemStore } from '@headless-adminapp/app/store';
|
|
1
2
|
import type { AppExperience } from '@headless-adminapp/core/experience/app';
|
|
2
3
|
import type { Schema, SchemaAttributes } from '@headless-adminapp/core/schema';
|
|
3
4
|
import type { ISchemaExperienceStore, ISchemaStore } from '@headless-adminapp/core/store';
|
|
@@ -6,6 +7,7 @@ interface UseMetadataResult {
|
|
|
6
7
|
schemaStore: ISchemaStore<SchemaAttributes>;
|
|
7
8
|
appExperience: AppExperience;
|
|
8
9
|
experienceStore: ISchemaExperienceStore;
|
|
10
|
+
recentItemStore: IRecentItemStore;
|
|
9
11
|
}
|
|
10
12
|
export declare function useMetadata(): UseMetadataResult;
|
|
11
13
|
export {};
|
|
@@ -8,11 +8,13 @@ function useMetadata() {
|
|
|
8
8
|
const schemaStore = (0, context_1.useContextSelector)(context_2.MetadataContext, (state) => state.schemaStore);
|
|
9
9
|
const appExperience = (0, context_1.useContextSelector)(context_2.MetadataContext, (state) => state.appExperience);
|
|
10
10
|
const experienceStore = (0, context_1.useContextSelector)(context_2.MetadataContext, (state) => state.experienceStore);
|
|
11
|
+
const recentItemStore = (0, context_1.useContextSelector)(context_2.MetadataContext, (state) => state.recentItemStore);
|
|
11
12
|
const schemas = schemaStore.getAllSchema();
|
|
12
13
|
return (0, react_1.useMemo)(() => ({
|
|
13
14
|
schemas,
|
|
14
15
|
schemaStore,
|
|
15
16
|
appExperience,
|
|
16
17
|
experienceStore,
|
|
17
|
-
|
|
18
|
+
recentItemStore,
|
|
19
|
+
}), [schemas, schemaStore, appExperience, experienceStore, recentItemStore]);
|
|
18
20
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useRecentItemStore = useRecentItemStore;
|
|
4
|
+
const context_1 = require("../../mutable/context");
|
|
5
|
+
const context_2 = require("../context");
|
|
6
|
+
function useRecentItemStore() {
|
|
7
|
+
return (0, context_1.useContextSelector)(context_2.MetadataContext, (state) => state.recentItemStore);
|
|
8
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@headless-adminapp/app",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"uuid": "11.0.3",
|
|
39
39
|
"yup": "^1.4.0"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "89d91fe63da3aae42fc34482cc90c1e12963810b"
|
|
42
42
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Id } from '@headless-adminapp/core';
|
|
2
|
+
export interface IRecentItemStore {
|
|
3
|
+
getItems: <T = unknown>(cacheKey: string, limit?: number) => RecentItem<T>[];
|
|
4
|
+
addItem: <T = unknown>(cacheKey: string, id: Id, value: T, limit?: number) => void;
|
|
5
|
+
addListener: (cacheKey: string, listener: (items: RecentItem<unknown>[]) => void) => void;
|
|
6
|
+
removeListener: (cacheKey: string, listener: (items: RecentItem<unknown>[]) => void) => void;
|
|
7
|
+
}
|
|
8
|
+
export type RecentItem<T> = {
|
|
9
|
+
timestamp: number;
|
|
10
|
+
id: Id;
|
|
11
|
+
value: T;
|
|
12
|
+
};
|
|
13
|
+
export declare class RecentItemStore implements IRecentItemStore {
|
|
14
|
+
private data;
|
|
15
|
+
private readonly storageKey;
|
|
16
|
+
private readonly maxItems;
|
|
17
|
+
private listeners;
|
|
18
|
+
constructor();
|
|
19
|
+
private init;
|
|
20
|
+
private sync;
|
|
21
|
+
getItems<T = unknown>(cacheKey: string, limit?: number): RecentItem<T>[];
|
|
22
|
+
addItem<T = unknown>(cacheKey: string, id: Id, value: T, limit?: number): void;
|
|
23
|
+
addListener(cacheKey: string, listener: (items: RecentItem<unknown>[]) => void): void;
|
|
24
|
+
removeListener(cacheKey: string, listener: (items: RecentItem<unknown>[]) => void): void;
|
|
25
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RecentItemStore = void 0;
|
|
4
|
+
class RecentItemStore {
|
|
5
|
+
data = {};
|
|
6
|
+
storageKey = 'recent_items';
|
|
7
|
+
maxItems = 5;
|
|
8
|
+
listeners = {};
|
|
9
|
+
constructor() {
|
|
10
|
+
this.init();
|
|
11
|
+
}
|
|
12
|
+
init() {
|
|
13
|
+
const _data = localStorage.getItem(this.storageKey);
|
|
14
|
+
if (_data) {
|
|
15
|
+
this.data = JSON.parse(_data);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
this.data = {};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
sync() {
|
|
22
|
+
localStorage.setItem(this.storageKey, JSON.stringify(this.data));
|
|
23
|
+
}
|
|
24
|
+
getItems(cacheKey, limit) {
|
|
25
|
+
if (!this.data[cacheKey]) {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
if (limit) {
|
|
29
|
+
return this.data[cacheKey].slice(0, limit);
|
|
30
|
+
}
|
|
31
|
+
return this.data[cacheKey];
|
|
32
|
+
}
|
|
33
|
+
addItem(cacheKey, id, value, limit) {
|
|
34
|
+
if (!this.data[cacheKey]) {
|
|
35
|
+
this.data[cacheKey] = [];
|
|
36
|
+
}
|
|
37
|
+
const timestamp = Date.now();
|
|
38
|
+
if (this.data[cacheKey].some((item) => item.id === id)) {
|
|
39
|
+
// Remove existing item with the same ID
|
|
40
|
+
this.data[cacheKey] = this.data[cacheKey].filter((item) => item.id !== id);
|
|
41
|
+
}
|
|
42
|
+
const newItem = { timestamp, id, value };
|
|
43
|
+
this.data[cacheKey].unshift(newItem);
|
|
44
|
+
this.data[cacheKey] = this.data[cacheKey].slice(0, limit ?? this.maxItems); // Limit to max items
|
|
45
|
+
this.sync();
|
|
46
|
+
for (const listener of this.listeners[cacheKey] || []) {
|
|
47
|
+
listener(this.data[cacheKey]);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
addListener(cacheKey, listener) {
|
|
51
|
+
if (!this.listeners[cacheKey]) {
|
|
52
|
+
this.listeners[cacheKey] = [];
|
|
53
|
+
}
|
|
54
|
+
this.listeners[cacheKey].push(listener);
|
|
55
|
+
}
|
|
56
|
+
removeListener(cacheKey, listener) {
|
|
57
|
+
if (!this.listeners[cacheKey]) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
this.listeners[cacheKey] = this.listeners[cacheKey].filter((l) => l !== listener);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.RecentItemStore = RecentItemStore;
|
package/store/index.d.ts
CHANGED
package/store/index.js
CHANGED
|
@@ -17,4 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./ComponentStore"), exports);
|
|
18
18
|
__exportStar(require("./EventManager"), exports);
|
|
19
19
|
__exportStar(require("./SchemaExperienceStore"), exports);
|
|
20
|
-
__exportStar(require("./
|
|
20
|
+
__exportStar(require("./RecentItemStore"), exports);
|
package/store/HistoryState.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export interface HistoryStatePlugin {
|
|
2
|
-
getter: () => Record<string, Record<string, unknown>>;
|
|
3
|
-
setter: (value: Record<string, Record<string, unknown>>) => void;
|
|
4
|
-
}
|
|
5
|
-
export declare function registerHistoryStatePlugin(plugin: HistoryStatePlugin): void;
|
|
6
|
-
export declare function getHistoryState<T extends Record<string, unknown> = Record<string, unknown>>(key: string): Partial<T>;
|
|
7
|
-
export declare function setHistoryState(key: string, value: Record<string, unknown>): void;
|
package/store/HistoryState.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.registerHistoryStatePlugin = registerHistoryStatePlugin;
|
|
4
|
-
exports.getHistoryState = getHistoryState;
|
|
5
|
-
exports.setHistoryState = setHistoryState;
|
|
6
|
-
let historyStatePlugin = null;
|
|
7
|
-
function registerHistoryStatePlugin(plugin) {
|
|
8
|
-
historyStatePlugin = plugin;
|
|
9
|
-
}
|
|
10
|
-
function getHistoryState(key) {
|
|
11
|
-
if (!historyStatePlugin) {
|
|
12
|
-
return {};
|
|
13
|
-
}
|
|
14
|
-
if (!key || typeof key !== 'string' || key.startsWith('~')) {
|
|
15
|
-
return {};
|
|
16
|
-
}
|
|
17
|
-
const state = historyStatePlugin.getter();
|
|
18
|
-
return (state[key] || {});
|
|
19
|
-
}
|
|
20
|
-
function setHistoryState(key, value) {
|
|
21
|
-
if (!historyStatePlugin) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
const currentState = historyStatePlugin.getter();
|
|
25
|
-
historyStatePlugin.setter({
|
|
26
|
-
...currentState,
|
|
27
|
-
[key]: {
|
|
28
|
-
...currentState[key],
|
|
29
|
-
...value,
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
}
|