@headless-adminapp/app 0.0.15-alpha.0 → 0.0.17-alpha.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.
@@ -0,0 +1,8 @@
1
+ import { FC, PropsWithChildren } from 'react';
2
+ interface AppProviderProps {
3
+ appId: string;
4
+ loadingComponent: React.ReactNode;
5
+ notFoundComponent: React.ReactNode;
6
+ }
7
+ export declare const AppProvider: FC<PropsWithChildren<AppProviderProps>>;
8
+ export {};
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.AppProvider = void 0;
13
+ const jsx_runtime_1 = require("react/jsx-runtime");
14
+ const react_query_1 = require("@tanstack/react-query");
15
+ const react_1 = require("react");
16
+ const hooks_1 = require("../metadata/hooks");
17
+ const context_1 = require("./context");
18
+ const AppProvider = ({ children, appId, loadingComponent, notFoundComponent, }) => {
19
+ const experienceStore = (0, hooks_1.useExperienceStore)();
20
+ const appStore = (0, hooks_1.useAppStore)();
21
+ const { data: schemaMetadataList } = (0, react_query_1.useQuery)({
22
+ queryKey: ['experience-schema-metadata-list'],
23
+ queryFn: () => __awaiter(void 0, void 0, void 0, function* () {
24
+ return experienceStore.getExperienceSchemaMetadatList();
25
+ }),
26
+ initialData: [],
27
+ });
28
+ const { data: app, isLoading } = (0, react_query_1.useQuery)({
29
+ queryKey: ['experience-app', appId],
30
+ queryFn: () => __awaiter(void 0, void 0, void 0, function* () {
31
+ return appStore.getApp(appId);
32
+ }),
33
+ });
34
+ const schemaMetadataDic = (0, react_1.useMemo)(() => {
35
+ var _a;
36
+ return (_a = schemaMetadataList === null || schemaMetadataList === void 0 ? void 0 : schemaMetadataList.reduce((acc, item) => {
37
+ acc[item.logicalName] = item;
38
+ return acc;
39
+ }, {})) !== null && _a !== void 0 ? _a : {};
40
+ }, [schemaMetadataList]);
41
+ if (isLoading) {
42
+ return loadingComponent;
43
+ }
44
+ if (!app) {
45
+ return notFoundComponent;
46
+ }
47
+ return ((0, jsx_runtime_1.jsx)(context_1.AppContext.Provider, { value: { app, schemaMetadataDic, schemaMetadataList }, children: children }));
48
+ };
49
+ exports.AppProvider = AppProvider;
package/app/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export { AppContext } from './context';
2
2
  export { useAppContext } from './hooks';
3
+ export { AppProvider } from './AppProvider';
package/app/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useAppContext = exports.AppContext = void 0;
3
+ exports.AppProvider = exports.useAppContext = exports.AppContext = void 0;
4
4
  var context_1 = require("./context");
5
5
  Object.defineProperty(exports, "AppContext", { enumerable: true, get: function () { return context_1.AppContext; } });
6
6
  var hooks_1 = require("./hooks");
7
7
  Object.defineProperty(exports, "useAppContext", { enumerable: true, get: function () { return hooks_1.useAppContext; } });
8
+ var AppProvider_1 = require("./AppProvider");
9
+ Object.defineProperty(exports, "AppProvider", { enumerable: true, get: function () { return AppProvider_1.AppProvider; } });
@@ -31,7 +31,7 @@ function useBaseCommandHandlerContext() {
31
31
  const queryClient = (0, react_query_1.useQueryClient)();
32
32
  const stores = (0, hooks_2.useMetadata)();
33
33
  const utility = useUtility();
34
- const [locale] = (0, locale_1.useLocale)();
34
+ const locale = (0, locale_1.useLocale)();
35
35
  return {
36
36
  dataService,
37
37
  queryClient,
@@ -24,7 +24,7 @@ const InitialValueResolver_1 = require("./InitialValueResolver");
24
24
  const ReadonlyInfoResolver_1 = require("./ReadonlyInfoResolver");
25
25
  function DataFormProvider(props) {
26
26
  const { getSchema } = (0, useMetadata_1.useMetadata)();
27
- const [{ language }] = (0, useLocale_1.useLocale)();
27
+ const { language } = (0, useLocale_1.useLocale)();
28
28
  const formValidationStrings = (0, FormValidationStringContext_1.useFormValidationStrings)();
29
29
  const [formReadOnly, setFormReadOnly] = (0, react_1.useState)(false); // A trick to provide readOnly info to formInstance
30
30
  const formInstance = (0, react_hook_form_1.useForm)({
@@ -10,7 +10,7 @@ export interface DataGridProviderProps<S extends SchemaAttributes = SchemaAttrib
10
10
  view: View<S>;
11
11
  extraFilter?: Filter;
12
12
  commands: CommandItemExperience<CommandContext>[][];
13
- onChangeView: (viewId: string) => void;
13
+ onChangeView?: (viewId: string) => void;
14
14
  isSubGrid?: boolean;
15
15
  allowViewSelection?: boolean;
16
16
  maxRecords?: number;
@@ -14,9 +14,10 @@ function DataGridProvider(props) {
14
14
  const onChangeViewRef = (0, react_1.useRef)(props.onChangeView);
15
15
  onChangeViewRef.current = props.onChangeView;
16
16
  const { schemaStore } = (0, useMetadata_1.useMetadata)();
17
- const [{ language }] = (0, useLocale_1.useLocale)();
17
+ const { language } = (0, useLocale_1.useLocale)();
18
18
  const handleViewChange = (0, react_1.useCallback)((viewId) => {
19
- onChangeViewRef.current(viewId);
19
+ var _a;
20
+ (_a = onChangeViewRef.current) === null || _a === void 0 ? void 0 : _a.call(onChangeViewRef, viewId);
20
21
  }, []);
21
22
  const contextValue = (0, context_1.useCreateContextStore)({
22
23
  schema: props.schema,
@@ -11,7 +11,7 @@ export interface GridContextState<S extends SchemaAttributes = SchemaAttributes,
11
11
  schema: Schema<S>;
12
12
  view: View<S>;
13
13
  viewLookup: LocalizedDataLookup[];
14
- onChangeView: (viewId: string) => void;
14
+ onChangeView?: (viewId: string) => void;
15
15
  extraFilter?: Filter;
16
16
  commands: CommandItemExperience<CommandContext>[][];
17
17
  maxRecords?: number;
@@ -7,6 +7,6 @@ const context_2 = require("../context");
7
7
  function useChangeView() {
8
8
  const onChangeView = (0, context_1.useContextSelector)(context_2.GridContext, (state) => state.onChangeView);
9
9
  return (0, react_1.useCallback)((viewId) => {
10
- onChangeView(viewId);
10
+ onChangeView === null || onChangeView === void 0 ? void 0 : onChangeView(viewId);
11
11
  }, [onChangeView]);
12
12
  }
@@ -79,7 +79,7 @@ function useMainGridCommandHandlerContext() {
79
79
  const queryClient = (0, react_query_1.useQueryClient)();
80
80
  const { appStore, experienceStore, schemaStore } = (0, useMetadata_1.useMetadata)();
81
81
  const utility = useUtility();
82
- const [locale] = (0, useLocale_1.useLocale)();
82
+ const locale = (0, useLocale_1.useLocale)();
83
83
  const primaryControl = useGridControlContext();
84
84
  return {
85
85
  dataService,
@@ -44,7 +44,7 @@ function useSubGridCommandHandlerContext() {
44
44
  const extraFilter = (0, useGridExtraFilter_1.useGridExtraFilter)();
45
45
  const refresh = (0, useGridRefresh_1.useGridRefresh)();
46
46
  const utility = (0, useMainGridCommands_1.useUtility)();
47
- const [locale] = (0, useLocale_1.useLocale)();
47
+ const locale = (0, useLocale_1.useLocale)();
48
48
  const mainFormHandlerContext = (0, useMainFormCommands_1.useMainFormCommandHandlerContext)();
49
49
  // console.log('mainFormHandlerContext', mainFormHandlerContext);
50
50
  return {
package/index.css ADDED
@@ -0,0 +1,4 @@
1
+ .hdl-scrollbar.rtl > div {
2
+ margin-right: 0 !important;
3
+ margin-left: -15px;
4
+ }
@@ -0,0 +1,12 @@
1
+ import { Locale } from '@headless-adminapp/core/experience/locale';
2
+ import { FC, PropsWithChildren } from 'react';
3
+ export interface LocaleProviderProps {
4
+ locale: string;
5
+ options?: {
6
+ direction?: Locale['direction'];
7
+ dateFormats?: Locale['dateFormats'];
8
+ timeFormats?: Locale['timeFormats'];
9
+ currency?: Partial<Locale['currency']>;
10
+ };
11
+ }
12
+ export declare const LocaleProvider: FC<PropsWithChildren<LocaleProviderProps>>;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LocaleProvider = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const locale_1 = require("@headless-adminapp/core/experience/locale");
6
+ const react_1 = require("react");
7
+ const context_1 = require("./context");
8
+ const LocaleProvider = ({ children, locale, options, }) => {
9
+ const localeState = (0, react_1.useMemo)(() => {
10
+ return (0, locale_1.getLocale)(locale, options);
11
+ }, [locale]);
12
+ return ((0, jsx_runtime_1.jsx)(context_1.LocaleContext.Provider, { value: localeState, children: children }));
13
+ };
14
+ exports.LocaleProvider = LocaleProvider;
@@ -1,2 +1,2 @@
1
- import { Dispatch, SetStateAction } from 'react';
2
- export declare const LocaleContext: import("react").Context<[import("@headless-adminapp/core/experience/app").Locale, Dispatch<SetStateAction<import("@headless-adminapp/core/experience/app").Locale>>] | null>;
1
+ import { Locale } from '@headless-adminapp/core/experience/locale';
2
+ export declare const LocaleContext: import("react").Context<Locale | null>;
package/locale/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { LocaleContext } from './context';
2
- export * from './types';
3
2
  export * from './useLocale';
3
+ export { type LocaleProviderProps, LocaleProvider } from './LocaleProvider';
package/locale/index.js CHANGED
@@ -14,8 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.LocaleContext = void 0;
17
+ exports.LocaleProvider = exports.LocaleContext = void 0;
18
18
  var context_1 = require("./context");
19
19
  Object.defineProperty(exports, "LocaleContext", { enumerable: true, get: function () { return context_1.LocaleContext; } });
20
- __exportStar(require("./types"), exports);
21
20
  __exportStar(require("./useLocale"), exports);
21
+ var LocaleProvider_1 = require("./LocaleProvider");
22
+ Object.defineProperty(exports, "LocaleProvider", { enumerable: true, get: function () { return LocaleProvider_1.LocaleProvider; } });
@@ -1 +1 @@
1
- export declare function useLocale(): [import("@headless-adminapp/core/experience/app").Locale, import("react").Dispatch<import("react").SetStateAction<import("@headless-adminapp/core/experience/app").Locale>>];
1
+ export declare function useLocale(): import("@headless-adminapp/core/experience/locale").Locale;
@@ -1,9 +1,8 @@
1
1
  import { IClientAppStore, ISchemaExperienceStore, ISchemaStore } from '@headless-adminapp/core/store';
2
2
  import { FC, PropsWithChildren } from 'react';
3
- interface MetadataProviderProps {
3
+ export interface MetadataProviderProps {
4
4
  schemaStore: ISchemaStore;
5
5
  experienceStore: ISchemaExperienceStore;
6
6
  appStore: IClientAppStore;
7
7
  }
8
8
  export declare const MetadataProvider: FC<PropsWithChildren<MetadataProviderProps>>;
9
- export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@headless-adminapp/app",
3
- "version": "0.0.15-alpha.0",
3
+ "version": "0.0.17-alpha.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -18,14 +18,11 @@
18
18
  },
19
19
  "scripts": {
20
20
  "build": "tsc",
21
- "copy-files": "cp package.json dist",
21
+ "ts-check": "tsc --noEmit",
22
+ "copy-files": "cp package.json dist && cp src/index.css dist",
22
23
  "prepublishOnly": "pnpm run build && pnpm run copy-files",
23
24
  "test": "echo \"Error: no test specified\" && exit 1"
24
25
  },
25
- "peerDependencies": {
26
- "@tanstack/react-query": "^5",
27
- "react-hook-form": "^7"
28
- },
29
26
  "keywords": [],
30
27
  "author": "",
31
28
  "license": "ISC",
@@ -33,5 +30,5 @@
33
30
  "clsx": "2.1.1",
34
31
  "react-custom-scrollbars-2": "^4.5.0"
35
32
  },
36
- "gitHead": "028cf2dc8cbc616b25a44fe42a2d8256b7645cf8"
33
+ "gitHead": "86b3b0f6764173ba69e71d81ef613ec570ae4a35"
37
34
  }
@@ -7,7 +7,7 @@ interface PageEntityViewProviderProps<S extends SchemaAttributes> {
7
7
  view: View<S>;
8
8
  commands: EntityMainGridCommandItemExperience[][];
9
9
  availableViews: LocalizedDataLookup[];
10
- onChangeView: (viewId: string) => void;
10
+ onChangeView?: (viewId: string) => void;
11
11
  }
12
12
  export declare function PageEntityViewProvider<S extends SchemaAttributes>({ availableViews, commands, schema, view, children, onChangeView, }: PropsWithChildren<PageEntityViewProviderProps<S>>): import("react/jsx-runtime").JSX.Element;
13
13
  export {};
@@ -3,3 +3,4 @@ export * from './useSearchParams';
3
3
  export * from './useRouter';
4
4
  export * from './useBasePath';
5
5
  export * from './useRouteResolver';
6
+ export * from './useIsRouteActive';
@@ -19,3 +19,4 @@ __exportStar(require("./useSearchParams"), exports);
19
19
  __exportStar(require("./useRouter"), exports);
20
20
  __exportStar(require("./useBasePath"), exports);
21
21
  __exportStar(require("./useRouteResolver"), exports);
22
+ __exportStar(require("./useIsRouteActive"), exports);
@@ -0,0 +1 @@
1
+ export declare function useIsRouteActive(): import("../context").InternalIsRouteActive;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useIsRouteActive = useIsRouteActive;
4
+ const react_1 = require("react");
5
+ const context_1 = require("../context");
6
+ function useIsRouteActive() {
7
+ return (0, react_1.useContext)(context_1.RouteHelperContext).isRouteActive;
8
+ }
@@ -0,0 +1,15 @@
1
+ import { Attribute, InferredAttributeType } from '@headless-adminapp/core/attributes';
2
+ interface AttributeFormattedValueStringsSet {
3
+ yes: string;
4
+ no: string;
5
+ }
6
+ export declare function getAttributeFormattedValue<A extends Attribute = Attribute>(attribute: Attribute, value: InferredAttributeType<A> | null | undefined, options?: {
7
+ maxCount?: number;
8
+ strings?: AttributeFormattedValueStringsSet;
9
+ dateFormat?: string;
10
+ locale?: string;
11
+ currency?: string;
12
+ currencySign?: 'accounting' | 'standard';
13
+ currencyDisplay?: 'symbol' | 'narrowSymbol' | 'code';
14
+ }): string | null | undefined;
15
+ export {};
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getAttributeFormattedValue = getAttributeFormattedValue;
7
+ const dayjs_1 = __importDefault(require("dayjs"));
8
+ const defaultAttributeFormattedValueStrings = {
9
+ yes: 'Yes',
10
+ no: 'No',
11
+ };
12
+ const defaultDateFormat = 'YYYY-MM-DD';
13
+ const defaultLocale = 'en-US';
14
+ const defaultCurrency = 'USD';
15
+ const defaultCurrencySign = 'accounting';
16
+ const defaultCurrencyDisplay = 'symbol';
17
+ function getAttributeFormattedValue(attribute, value, options) {
18
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
19
+ if (value === null || value === undefined) {
20
+ return null;
21
+ }
22
+ const strings = (_a = options === null || options === void 0 ? void 0 : options.strings) !== null && _a !== void 0 ? _a : defaultAttributeFormattedValueStrings;
23
+ const dateFormat = (_b = options === null || options === void 0 ? void 0 : options.dateFormat) !== null && _b !== void 0 ? _b : defaultDateFormat;
24
+ const locale = (_c = options === null || options === void 0 ? void 0 : options.locale) !== null && _c !== void 0 ? _c : defaultLocale;
25
+ const currency = (_d = options === null || options === void 0 ? void 0 : options.currency) !== null && _d !== void 0 ? _d : defaultCurrency;
26
+ const currencySign = (_e = options === null || options === void 0 ? void 0 : options.currencySign) !== null && _e !== void 0 ? _e : defaultCurrencySign;
27
+ const currencyDisplay = (_f = options === null || options === void 0 ? void 0 : options.currencyDisplay) !== null && _f !== void 0 ? _f : defaultCurrencyDisplay;
28
+ switch (attribute.type) {
29
+ case 'boolean':
30
+ return value
31
+ ? (_g = attribute.trueLabel) !== null && _g !== void 0 ? _g : strings.yes
32
+ : (_h = attribute.falseLabel) !== null && _h !== void 0 ? _h : strings.no;
33
+ case 'choice':
34
+ return ((_j = attribute.options.find((option) => option.value === value)) !== null && _j !== void 0 ? _j : {
35
+ label: '',
36
+ }).label;
37
+ case 'choices':
38
+ return value
39
+ .map((v) => {
40
+ var _a;
41
+ return ((_a = attribute.options.find((option) => option.value === v)) !== null && _a !== void 0 ? _a : {
42
+ label: '',
43
+ }).label;
44
+ })
45
+ .join(', ');
46
+ case 'date':
47
+ return (0, dayjs_1.default)(value).format(dateFormat);
48
+ case 'daterange':
49
+ if (!value)
50
+ return null;
51
+ const from = value[0];
52
+ const to = value[1];
53
+ if (!from && !to) {
54
+ return null;
55
+ }
56
+ if (from && to) {
57
+ return ((0, dayjs_1.default)(from).format(dateFormat) + ' - ' + (0, dayjs_1.default)(to).format(dateFormat));
58
+ }
59
+ if (from) {
60
+ return 'After ' + (0, dayjs_1.default)(from).format(dateFormat);
61
+ }
62
+ if (to) {
63
+ return 'Before ' + (0, dayjs_1.default)(to).format(dateFormat);
64
+ }
65
+ return null;
66
+ case 'lookup':
67
+ return value === null || value === void 0 ? void 0 : value.name;
68
+ case 'lookups':
69
+ const items = value === null || value === void 0 ? void 0 : value.map((v) => v.name);
70
+ if ((options === null || options === void 0 ? void 0 : options.maxCount) && (items === null || items === void 0 ? void 0 : items.length) > options.maxCount) {
71
+ return (items.slice(0, options.maxCount).join(', ') +
72
+ ` (+${items.length - options.maxCount})`);
73
+ }
74
+ else {
75
+ return items === null || items === void 0 ? void 0 : items.join(', ');
76
+ }
77
+ case 'money':
78
+ return new Intl.NumberFormat(locale, {
79
+ style: 'currency',
80
+ currency,
81
+ currencySign,
82
+ currencyDisplay,
83
+ }).format(value);
84
+ case 'number':
85
+ return new Intl.NumberFormat(locale).format(value);
86
+ default:
87
+ return typeof value === 'object'
88
+ ? JSON.stringify(value)
89
+ : value;
90
+ }
91
+ }
package/utils/index.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export * from './calculateColumnWidths';
2
+ export * from './getAttributeFormattedValue';
package/utils/index.js CHANGED
@@ -15,3 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./calculateColumnWidths"), exports);
18
+ __exportStar(require("./getAttributeFormattedValue"), exports);