@headless-adminapp/app 1.4.3 → 1.4.8

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.
@@ -119,9 +119,6 @@ var FormCommandBuilder;
119
119
  if (!recordId) {
120
120
  return;
121
121
  }
122
- // if (typeof stringSet === 'function') {
123
- // stringSet = stringSet(context);
124
- // }
125
122
  const localizeSelector = (0, utils_1.createLocalizedSelector)(stringSet, localizedStringSet, context.locale.language);
126
123
  try {
127
124
  const confirmResult = await context.utility.openConfirmDialog({
@@ -76,7 +76,7 @@ function getIsFieldDisabled({ attribute, isFormReadonly, disabledFields, control
76
76
  else if ('disabled' in control && control.disabled !== undefined) {
77
77
  disabled = control.disabled;
78
78
  }
79
- else if (attribute && attribute.readonly !== undefined) {
79
+ else if (attribute?.readonly !== undefined) {
80
80
  disabled = attribute.readonly;
81
81
  }
82
82
  }
@@ -39,21 +39,23 @@ function useFormSave() {
39
39
  const saveRecord = (0, context_1.useContextSelector)(context_2.DataFormContext, (state) => state.saveRecordFn);
40
40
  const client = (0, react_query_1.useQueryClient)();
41
41
  const router = (0, route_1.useRouter)();
42
- function showMessageAfterSave({ isCreatedMode }) {
42
+ function showMessageAfterSave({ mode }) {
43
43
  // Show notification
44
- if (!isCreatedMode) {
45
- openToastNotification({
46
- type: 'success',
47
- title: 'Record updated',
48
- text: 'Record updated successfully',
49
- });
50
- }
51
- else {
52
- openToastNotification({
53
- type: 'success',
54
- title: 'Record created',
55
- text: 'Record created successfully',
56
- });
44
+ switch (mode) {
45
+ case 'create':
46
+ openToastNotification({
47
+ type: 'success',
48
+ title: 'Record created',
49
+ text: 'Record created successfully',
50
+ });
51
+ break;
52
+ case 'update':
53
+ openToastNotification({
54
+ type: 'success',
55
+ title: 'Record updated',
56
+ text: 'Record updated successfully',
57
+ });
58
+ break;
57
59
  }
58
60
  }
59
61
  const _save = async (mode) => {
@@ -107,7 +109,7 @@ function useFormSave() {
107
109
  queryKey: ['data', 'retriveRecords'],
108
110
  });
109
111
  showMessageAfterSave({
110
- isCreatedMode: !record,
112
+ mode: record ? 'update' : 'create',
111
113
  });
112
114
  }
113
115
  catch (err) {
@@ -19,9 +19,7 @@ function useLoadFormGridPage(logicalName, formId) {
19
19
  queryKey: ['experience-schema-form-commands', logicalName],
20
20
  queryFn: async () => {
21
21
  let commands = await experienceStore.getFormCommands(logicalName);
22
- if (!commands) {
23
- commands = formCommands;
24
- }
22
+ commands ??= formCommands;
25
23
  return commands ?? [];
26
24
  },
27
25
  initialData: [],
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getModifiedValues = getModifiedValues;
4
4
  exports.saveRecord = saveRecord;
5
5
  exports.saveEditableGridControl = saveEditableGridControl;
6
- const utils_1 = require("../../dataform/DataFormProvider/utils");
6
+ const utils_1 = require("../DataFormProvider/utils");
7
7
  function getModifiedValues(initialValues, values, exclude) {
8
8
  const keys = Object.keys(values);
9
9
  return keys.reduce((p, c) => {
@@ -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 = [];
@@ -3,22 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useDebouncedValue = useDebouncedValue;
4
4
  const react_1 = require("react");
5
5
  function useDebouncedValue(value, wait, options = { leading: false }) {
6
- const [_value, setValue] = (0, react_1.useState)(value);
6
+ const [internalValue, setInternalValue] = (0, react_1.useState)(value);
7
7
  const mountedRef = (0, react_1.useRef)(false);
8
- const timeoutRef = (0, react_1.useRef)(null);
8
+ const timeoutRef = (0, react_1.useRef)();
9
9
  const cooldownRef = (0, react_1.useRef)(false);
10
10
  const cancel = () => window.clearTimeout(timeoutRef.current);
11
11
  (0, react_1.useEffect)(() => {
12
12
  if (mountedRef.current) {
13
13
  if (!cooldownRef.current && options.leading) {
14
14
  cooldownRef.current = true;
15
- setValue(value);
15
+ setInternalValue(value);
16
16
  }
17
17
  else {
18
18
  cancel();
19
19
  timeoutRef.current = window.setTimeout(() => {
20
20
  cooldownRef.current = false;
21
- setValue(value);
21
+ setInternalValue(value);
22
22
  }, wait);
23
23
  }
24
24
  }
@@ -27,5 +27,5 @@ function useDebouncedValue(value, wait, options = { leading: false }) {
27
27
  mountedRef.current = true;
28
28
  return cancel;
29
29
  }, []);
30
- return [_value, cancel];
30
+ return [internalValue, cancel];
31
31
  }
@@ -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;
@@ -5,6 +5,7 @@ const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const app_1 = require("@headless-adminapp/core/experience/app");
6
6
  const store_1 = require("@headless-adminapp/core/store");
7
7
  const icons_1 = require("@headless-adminapp/icons");
8
+ const react_1 = require("react");
8
9
  const context_1 = require("../mutable/context");
9
10
  const store_2 = require("../store");
10
11
  const context_2 = require("./context");
@@ -24,12 +25,21 @@ const defaultApp = {
24
25
  },
25
26
  logo: {},
26
27
  };
27
- const MetadataProvider = ({ children, experienceStore = exports.defaultExperienceStore, schemaStore = exports.defaultSchemaStore, appExperience = defaultApp, }) => {
28
+ const defaultRecentItemStore = new store_2.RecentItemStore();
29
+ const MetadataProvider = ({ children, experienceStore = exports.defaultExperienceStore, schemaStore = exports.defaultSchemaStore, appExperience = defaultApp, recentItemStore = defaultRecentItemStore, }) => {
28
30
  const contextValue = (0, context_1.useCreateContextStore)({
29
31
  experienceStore,
30
32
  schemaStore,
31
33
  appExperience,
34
+ recentItemStore,
32
35
  });
36
+ (0, react_1.useEffect)(() => {
37
+ contextValue.setValue({
38
+ appExperience,
39
+ experienceStore,
40
+ schemaStore,
41
+ });
42
+ }, [contextValue, appExperience, experienceStore, schemaStore]);
33
43
  return ((0, jsx_runtime_1.jsx)(context_2.MetadataContext.Provider, { value: contextValue, children: children }));
34
44
  };
35
45
  exports.MetadataProvider = MetadataProvider;
@@ -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>>;
@@ -12,9 +12,7 @@ function useExperienceViewCommands(logicalName) {
12
12
  queryKey: ['experience-schema-view-commands', logicalName],
13
13
  queryFn: async () => {
14
14
  let commands = await experienceStore.getViewCommands(logicalName);
15
- if (!commands) {
16
- commands = viewCommands;
17
- }
15
+ commands ??= viewCommands;
18
16
  return commands ?? [];
19
17
  },
20
18
  initialData: [],
@@ -12,9 +12,7 @@ function useExperienceViewSubgridCommands(logicalName) {
12
12
  queryKey: ['experience-schema-view-subgrid-commands', logicalName],
13
13
  queryFn: async () => {
14
14
  let commands = await experienceStore.getSubgridCommands(logicalName);
15
- if (!commands) {
16
- commands = subgridCommands;
17
- }
15
+ commands ??= subgridCommands;
18
16
  return commands ?? [];
19
17
  },
20
18
  initialData: [],
@@ -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
- }), [schemas, schemaStore, appExperience, experienceStore]);
18
+ recentItemStore,
19
+ }), [schemas, schemaStore, appExperience, experienceStore, recentItemStore]);
18
20
  }
@@ -0,0 +1,2 @@
1
+ import { IRecentItemStore } from '../../store/RecentItemStore';
2
+ export declare function useRecentItemStore(): IRecentItemStore;
@@ -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
+ }
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useOpenForm = useOpenForm;
4
4
  const app_1 = require("@headless-adminapp/core/experience/app");
5
5
  const react_1 = require("react");
6
- const hooks_1 = require("../../route/hooks/");
6
+ const hooks_1 = require("../../route/hooks");
7
7
  const useRouteResolver_1 = require("../../route/hooks/useRouteResolver");
8
8
  function useOpenForm() {
9
9
  const routeResolver = (0, useRouteResolver_1.useRouteResolver)();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@headless-adminapp/app",
3
- "version": "1.4.3",
3
+ "version": "1.4.8",
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": "5c5739c442d4690430997c7f375fed5966cde046"
41
+ "gitHead": "f25faf823d592f7d9c0356c1ca238e9019b8e7c0"
42
42
  }
@@ -13,12 +13,10 @@ const ProgressIndicatorProvider = ({ children, }) => {
13
13
  setOverlayVisible(true);
14
14
  setMessage(message);
15
15
  if (delay) {
16
- if (!showTimeoutRef.current) {
17
- showTimeoutRef.current = setTimeout(() => {
18
- setVisible(true);
19
- showTimeoutRef.current = undefined;
20
- }, delay);
21
- }
16
+ showTimeoutRef.current ??= setTimeout(() => {
17
+ setVisible(true);
18
+ showTimeoutRef.current = undefined;
19
+ }, delay);
22
20
  }
23
21
  else {
24
22
  if (showTimeoutRef.current) {
@@ -1,7 +1,7 @@
1
- import { SchemaAttributes } from '@headless-adminapp/core/schema';
1
+ import { InferredSchemaType, SchemaAttributes } from '@headless-adminapp/core/schema';
2
2
  export declare function useRecordSetResult(): {
3
3
  isLoading: boolean;
4
- data: import("@headless-adminapp/core/transport").Data<SchemaAttributes>[] | undefined;
4
+ data: import("@headless-adminapp/core/transport").Data<InferredSchemaType<SchemaAttributes>>[] | undefined;
5
5
  cardView: import("@headless-adminapp/core/experience/view").CardView | null;
6
6
  schema: import("@headless-adminapp/core/schema").Schema<SchemaAttributes> | null;
7
7
  };
@@ -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;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SchemaExperienceStore = void 0;
4
4
  exports.getDefaultCardView = getDefaultCardView;
5
+ const utils_1 = require("@headless-adminapp/core/utils");
5
6
  function getDefaultCardView(schema) {
6
7
  return {
7
8
  primaryColumn: schema.primaryAttribute,
@@ -71,9 +72,7 @@ class SchemaExperienceStore {
71
72
  if (!validViewIds.length) {
72
73
  validViewIds = [experience.defaultViewId];
73
74
  }
74
- if (!viewId) {
75
- viewId = experience.defaultViewId;
76
- }
75
+ viewId = (0, utils_1.stringWithDefault)(viewId, experience.defaultViewId);
77
76
  if (!validViewIds.includes(viewId)) {
78
77
  viewId = validViewIds[0];
79
78
  }
@@ -103,9 +102,7 @@ class SchemaExperienceStore {
103
102
  if (!validViewIds.length) {
104
103
  validViewIds = [experience.defaultViewId];
105
104
  }
106
- if (!viewId) {
107
- viewId = experience.defaultAssociatedViewId;
108
- }
105
+ viewId = (0, utils_1.stringWithDefault)(viewId, experience.defaultAssociatedViewId);
109
106
  if (!validViewIds.includes(viewId)) {
110
107
  viewId = validViewIds[0];
111
108
  }
@@ -130,9 +127,7 @@ class SchemaExperienceStore {
130
127
  }
131
128
  async getViewLookupV2(logicalName, viewId) {
132
129
  const experience = await this.getExperience(logicalName);
133
- if (!viewId) {
134
- viewId = experience.defaultLookupId;
135
- }
130
+ viewId = (0, utils_1.stringWithDefault)(viewId, experience.defaultLookupId);
136
131
  const view = experience.lookups.find((v) => v.id === viewId);
137
132
  if (!view) {
138
133
  throw new Error(`Lookup ${viewId} not found`);
package/store/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export * from './ComponentStore';
2
2
  export * from './EventManager';
3
3
  export * from './SchemaExperienceStore';
4
- export * from './HistoryState';
4
+ export * from './RecentItemStore';
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("./HistoryState"), exports);
20
+ __exportStar(require("./RecentItemStore"), exports);
@@ -3,9 +3,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FileServiceContext = exports.DataServiceContext = void 0;
4
4
  const react_1 = require("react");
5
5
  exports.DataServiceContext = (0, react_1.createContext)(undefined);
6
- // export const noopFileService = {
7
- // uploadFile: async () => {
8
- // throw new Error('File service not implemented');
9
- // },
10
- // } as IFileService;
11
6
  exports.FileServiceContext = (0, react_1.createContext)(null);
package/utils/phone.js CHANGED
@@ -21,7 +21,7 @@ function parsePhoneNumber(input, defaultCountry) {
21
21
  uri: phoneNumber.getURI(),
22
22
  };
23
23
  }
24
- catch (error) {
24
+ catch {
25
25
  return {
26
26
  formattedInternationalValue: input,
27
27
  formattedNationalValue: input,
@@ -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;
@@ -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
- }