@react-pakistan/util-functions 1.25.32 → 1.25.33
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/factory/generic-component-factory.d.ts +66 -0
- package/factory/generic-component-factory.js +119 -0
- package/factory/generic-module-factory.d.ts +65 -0
- package/factory/generic-module-factory.js +159 -0
- package/factory/index.d.ts +2 -0
- package/factory/index.js +18 -0
- package/hooks/use-rtl.d.ts +44 -0
- package/hooks/use-rtl.js +75 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +3 -1
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic Component Factory
|
|
3
|
+
*
|
|
4
|
+
* Reusable UI components for CRUD modules with customizable configuration.
|
|
5
|
+
* Generates tables, forms, drawers, and other common UI patterns.
|
|
6
|
+
*/
|
|
7
|
+
import React, { FC } from 'react';
|
|
8
|
+
import { COMPONENT_TYPE, HeaderAction, TableColumn } from '@appcorp/shadcn/components/enhanced-table';
|
|
9
|
+
export declare const DRAWER_TYPES: {
|
|
10
|
+
FORM_DRAWER: string;
|
|
11
|
+
FILTER_DRAWER: string;
|
|
12
|
+
VIEW_DRAWER: string;
|
|
13
|
+
MORE_ACTIONS_DRAWER: string;
|
|
14
|
+
};
|
|
15
|
+
export interface ComponentConfig {
|
|
16
|
+
cancelLabel?: string;
|
|
17
|
+
drawerDescription?: string;
|
|
18
|
+
drawerTitle: string;
|
|
19
|
+
filterContent: React.ReactNode;
|
|
20
|
+
filterDrawerValue?: string;
|
|
21
|
+
formContent: React.ReactNode;
|
|
22
|
+
formDrawerValue?: string;
|
|
23
|
+
moduleName: string;
|
|
24
|
+
moreActionsContent: React.ReactNode;
|
|
25
|
+
saveLabel?: string;
|
|
26
|
+
searchPlaceholder: string;
|
|
27
|
+
size?: 'small' | 'medium' | 'large' | 'full';
|
|
28
|
+
tableColumns: TableColumn[];
|
|
29
|
+
tableDescription: string;
|
|
30
|
+
tableTitle: string;
|
|
31
|
+
viewContent: React.ReactNode;
|
|
32
|
+
viewDrawerValue?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface TableBodyCol {
|
|
35
|
+
key?: string | string[];
|
|
36
|
+
componentType: COMPONENT_TYPE | string;
|
|
37
|
+
textFormatter?: (value: unknown, row: unknown) => React.ReactNode;
|
|
38
|
+
}
|
|
39
|
+
interface GenericTableProps {
|
|
40
|
+
config: ComponentConfig;
|
|
41
|
+
context: any;
|
|
42
|
+
tableBodyCols: TableBodyCol[];
|
|
43
|
+
headerActions?: HeaderAction[];
|
|
44
|
+
rowActions?: any[];
|
|
45
|
+
iconMap?: Record<string, any>;
|
|
46
|
+
}
|
|
47
|
+
export declare const GenericTable: FC<GenericTableProps>;
|
|
48
|
+
interface GenericDrawerProps {
|
|
49
|
+
config: ComponentConfig;
|
|
50
|
+
context: any;
|
|
51
|
+
formContent?: React.ReactNode;
|
|
52
|
+
viewContent?: React.ReactNode;
|
|
53
|
+
filterContent?: React.ReactNode;
|
|
54
|
+
moreActionsContent?: React.ReactNode;
|
|
55
|
+
}
|
|
56
|
+
export declare const GenericDrawer: FC<GenericDrawerProps>;
|
|
57
|
+
interface GenericModulePageProps {
|
|
58
|
+
config: ComponentConfig;
|
|
59
|
+
context: any;
|
|
60
|
+
tableBodyCols: TableBodyCol[];
|
|
61
|
+
headerActions?: HeaderAction[];
|
|
62
|
+
rowActions?: any[];
|
|
63
|
+
iconMap?: Record<string, any>;
|
|
64
|
+
}
|
|
65
|
+
export declare const createGenericModulePage: (config: ComponentConfig) => React.FC<GenericModulePageProps>;
|
|
66
|
+
export {};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic Component Factory
|
|
3
|
+
*
|
|
4
|
+
* Reusable UI components for CRUD modules with customizable configuration.
|
|
5
|
+
* Generates tables, forms, drawers, and other common UI patterns.
|
|
6
|
+
*/
|
|
7
|
+
'use client';
|
|
8
|
+
"use strict";
|
|
9
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
12
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
13
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
14
|
+
}
|
|
15
|
+
Object.defineProperty(o, k2, desc);
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
+
}) : function(o, v) {
|
|
23
|
+
o["default"] = v;
|
|
24
|
+
});
|
|
25
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
26
|
+
var ownKeys = function(o) {
|
|
27
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
28
|
+
var ar = [];
|
|
29
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
30
|
+
return ar;
|
|
31
|
+
};
|
|
32
|
+
return ownKeys(o);
|
|
33
|
+
};
|
|
34
|
+
return function (mod) {
|
|
35
|
+
if (mod && mod.__esModule) return mod;
|
|
36
|
+
var result = {};
|
|
37
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
38
|
+
__setModuleDefault(result, mod);
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
41
|
+
})();
|
|
42
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
+
exports.createGenericModulePage = exports.GenericDrawer = exports.GenericTable = exports.DRAWER_TYPES = void 0;
|
|
44
|
+
var react_1 = __importStar(require("react"));
|
|
45
|
+
var next_intl_1 = require("next-intl");
|
|
46
|
+
var general_1 = require("../general");
|
|
47
|
+
var use_rtl_1 = require("../hooks/use-rtl");
|
|
48
|
+
var enhanced_table_1 = require("@appcorp/shadcn/components/enhanced-table");
|
|
49
|
+
var sonner_1 = require("@appcorp/shadcn/components/ui/sonner");
|
|
50
|
+
var drawer_generic_1 = require("@appcorp/shadcn/components/drawer-generic");
|
|
51
|
+
var enhanced_drawer_header_1 = require("@appcorp/shadcn/components/enhanced-drawer-header");
|
|
52
|
+
var enhanced_drawer_footer_1 = require("@appcorp/shadcn/components/enhanced-drawer-footer");
|
|
53
|
+
// ============================================================================
|
|
54
|
+
// CONSTANTS
|
|
55
|
+
// ============================================================================
|
|
56
|
+
exports.DRAWER_TYPES = {
|
|
57
|
+
FORM_DRAWER: 'FORM_DRAWER',
|
|
58
|
+
FILTER_DRAWER: 'FILTER_DRAWER',
|
|
59
|
+
VIEW_DRAWER: 'VIEW_DRAWER',
|
|
60
|
+
MORE_ACTIONS_DRAWER: 'MORE_ACTIONS_DRAWER',
|
|
61
|
+
};
|
|
62
|
+
var GenericTable = function (_a) {
|
|
63
|
+
var config = _a.config, context = _a.context, tableBodyCols = _a.tableBodyCols, headerActions = _a.headerActions, rowActions = _a.rowActions;
|
|
64
|
+
var t = (0, next_intl_1.useTranslations)(config.moduleName.toLowerCase());
|
|
65
|
+
var isRTL = (0, use_rtl_1.useRTL)();
|
|
66
|
+
var tableHeadItems = (0, react_1.useMemo)(function () {
|
|
67
|
+
return config.tableColumns.map(function (col) { return ({
|
|
68
|
+
label: t(col.label),
|
|
69
|
+
width: col.width,
|
|
70
|
+
}); });
|
|
71
|
+
}, [config.tableColumns, t]);
|
|
72
|
+
var totalPages = (0, general_1.calculatePages)(context.state.count, context.state.pageLimit);
|
|
73
|
+
// Build header actions from context or props
|
|
74
|
+
var allHeaderActions = (0, react_1.useMemo)(function () { return headerActions || context.headerActions || []; }, [headerActions, context.headerActions]);
|
|
75
|
+
return (react_1.default.createElement("div", { className: "space-y-4 ".concat(isRTL ? 'rtl' : 'ltr'), dir: isRTL ? 'rtl' : 'ltr' },
|
|
76
|
+
react_1.default.createElement(enhanced_table_1.EnhancedTable, { currentPage: Number(context.state.currentPage), handleNextOnClick: context.handlePageChange, handleOnSelect: context.handlePageLimitChange, handlePreviousOnClick: function () {
|
|
77
|
+
return context.handlePageChange(context.state.currentPage - 1);
|
|
78
|
+
}, handleSearchInput: context.handleSearch, headerActions: allHeaderActions, isNextDisabled: (0, general_1.isNextButtonDisabled)(context.state.currentPage, totalPages), isPreviousDisabled: (0, general_1.isPreviousButtonDisabled)(context.state.currentPage), listOptions: (0, general_1.getAvailablePageLimits)(context.state.count), loading: context.listLoading, nodeSelectKey: "pageLimit", pageLimit: context.state.pageLimit, rowActions: rowActions || context.rowActions || [], searchDisabled: false, searchEnabled: true, searchId: "".concat(config.moduleName.toLowerCase(), "-search"), searchPlaceholder: t(config.searchPlaceholder), searchValue: context.state.searchQuery, tableBodyCols: tableBodyCols, tableBodyRows: context.state.items, tableDescription: t(config.tableDescription), tableHeadItems: tableHeadItems, tableHeading: t(config.tableTitle), totalPages: Number(totalPages) })));
|
|
79
|
+
};
|
|
80
|
+
exports.GenericTable = GenericTable;
|
|
81
|
+
var GenericDrawer = function (_a) {
|
|
82
|
+
var _b, _c, _d, _e, _f, _g;
|
|
83
|
+
var config = _a.config, context = _a.context, formContent = _a.formContent, viewContent = _a.viewContent, filterContent = _a.filterContent, moreActionsContent = _a.moreActionsContent;
|
|
84
|
+
var t = (0, next_intl_1.useTranslations)(config.moduleName.toLowerCase());
|
|
85
|
+
var isRTL = (0, use_rtl_1.useRTL)();
|
|
86
|
+
var closeDrawer = context.closeDrawer || context.handleCloseDrawer;
|
|
87
|
+
var _h = context.state, disableSaveButton = _h.disableSaveButton, drawer = _h.drawer;
|
|
88
|
+
var isFormDrawer = drawer === exports.DRAWER_TYPES.FORM_DRAWER;
|
|
89
|
+
var isViewDrawer = drawer === exports.DRAWER_TYPES.VIEW_DRAWER;
|
|
90
|
+
var isFilterDrawer = drawer === exports.DRAWER_TYPES.FILTER_DRAWER;
|
|
91
|
+
var isMoreActionsDrawer = drawer === exports.DRAWER_TYPES.MORE_ACTIONS_DRAWER;
|
|
92
|
+
var isOpen = isFormDrawer || isViewDrawer || isFilterDrawer || isMoreActionsDrawer;
|
|
93
|
+
var drawerTitle = t(config.drawerTitle);
|
|
94
|
+
var drawerDescription = config.drawerDescription
|
|
95
|
+
? t(config.drawerDescription)
|
|
96
|
+
: '';
|
|
97
|
+
var errors = (_b = context.state.errors) !== null && _b !== void 0 ? _b : {};
|
|
98
|
+
var formHeader = isFormDrawer ? (react_1.default.createElement(enhanced_drawer_header_1.EnhancedDrawerHeader, { title: drawerTitle, description: drawerDescription })) : null;
|
|
99
|
+
var viewHeader = isViewDrawer ? (react_1.default.createElement(enhanced_drawer_header_1.EnhancedDrawerHeader, { title: drawerTitle, description: drawerDescription })) : null;
|
|
100
|
+
var filterHeader = isFilterDrawer ? (react_1.default.createElement(enhanced_drawer_header_1.EnhancedDrawerHeader, { title: drawerTitle, description: drawerDescription })) : null;
|
|
101
|
+
var moreActionsHeader = isMoreActionsDrawer ? (react_1.default.createElement(enhanced_drawer_header_1.EnhancedDrawerHeader, { title: drawerTitle, description: drawerDescription })) : null;
|
|
102
|
+
var formFooter = isFormDrawer ? (react_1.default.createElement(enhanced_drawer_footer_1.EnhancedDrawerFooter, { applyFilters: function () { }, clearFilters: function () { }, closeDrawer: closeDrawer, disableSaveButton: disableSaveButton, drawerType: enhanced_drawer_footer_1.DRAWER_FOOTER_COMPONENT_TYPE.FORM_DRAWER, errors: errors, handleSubmit: context.handleSubmit, updateLoading: (_c = context.updateLoading) !== null && _c !== void 0 ? _c : false })) : null;
|
|
103
|
+
var viewFooter = isViewDrawer ? (react_1.default.createElement(enhanced_drawer_footer_1.EnhancedDrawerFooter, { applyFilters: function () { }, clearFilters: function () { }, closeDrawer: closeDrawer, disableSaveButton: false, drawerType: enhanced_drawer_footer_1.DRAWER_FOOTER_COMPONENT_TYPE.VIEW_DRAWER, errors: errors, handleSubmit: function () { }, updateLoading: false })) : null;
|
|
104
|
+
var filterFooter = isFilterDrawer ? (react_1.default.createElement(enhanced_drawer_footer_1.EnhancedDrawerFooter, { applyFilters: (_d = context.applyFilters) !== null && _d !== void 0 ? _d : (function () { }), clearFilters: (_e = context.clearFilters) !== null && _e !== void 0 ? _e : (function () { }), closeDrawer: closeDrawer, disableSaveButton: false, drawerType: enhanced_drawer_footer_1.DRAWER_FOOTER_COMPONENT_TYPE.FILTER_DRAWER, errors: errors, handleSubmit: (_f = context.handleSubmit) !== null && _f !== void 0 ? _f : (function () { }), updateLoading: false })) : null;
|
|
105
|
+
var moreActionsFooter = isMoreActionsDrawer ? (react_1.default.createElement(enhanced_drawer_footer_1.EnhancedDrawerFooter, { applyFilters: function () { }, clearFilters: function () { }, closeDrawer: closeDrawer, disableSaveButton: false, drawerType: enhanced_drawer_footer_1.DRAWER_FOOTER_COMPONENT_TYPE.MORE_ACTIONS_DRAWER, errors: errors, handleSubmit: function () { }, updateLoading: false })) : null;
|
|
106
|
+
return (react_1.default.createElement(drawer_generic_1.DrawerGeneric, { direction: isRTL ? 'left' : 'right', filterDrawer: isFilterDrawer ? filterContent : null, filterDrawerFooter: filterFooter, filterDrawerHeader: filterHeader, formDrawer: isFormDrawer ? formContent : null, formDrawerFooter: formFooter, formDrawerHeader: formHeader, moreActionsDrawer: isMoreActionsDrawer ? moreActionsContent : null, moreActionsDrawerFooter: moreActionsFooter, moreActionsDrawerHeader: moreActionsHeader, onOpenChange: function (open) { return !open && closeDrawer(); }, open: isOpen, viewDrawer: isViewDrawer ? viewContent : null, viewDrawerFooter: viewFooter, viewDrawerHeader: viewHeader, width: (_g = config.size) !== null && _g !== void 0 ? _g : 'small' }));
|
|
107
|
+
};
|
|
108
|
+
exports.GenericDrawer = GenericDrawer;
|
|
109
|
+
var createGenericModulePage = function (config) {
|
|
110
|
+
var GenericModulePage = function (_a) {
|
|
111
|
+
var context = _a.context, tableBodyCols = _a.tableBodyCols, headerActions = _a.headerActions, rowActions = _a.rowActions, iconMap = _a.iconMap;
|
|
112
|
+
return (react_1.default.createElement("div", { className: "space-y-6" },
|
|
113
|
+
react_1.default.createElement(exports.GenericTable, { config: config, context: context, tableBodyCols: tableBodyCols, headerActions: headerActions, rowActions: rowActions, iconMap: iconMap }),
|
|
114
|
+
react_1.default.createElement(exports.GenericDrawer, { config: config, context: context, formContent: config.formContent, viewContent: config.viewContent, filterContent: config.filterContent, moreActionsContent: config.moreActionsContent }),
|
|
115
|
+
react_1.default.createElement(sonner_1.Toaster, null)));
|
|
116
|
+
};
|
|
117
|
+
return GenericModulePage;
|
|
118
|
+
};
|
|
119
|
+
exports.createGenericModulePage = createGenericModulePage;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic Module Factory - Minimal Version
|
|
3
|
+
*
|
|
4
|
+
* Provides reusable reducer and context structure for CRUD modules.
|
|
5
|
+
* API integration is handled by individual modules for maximum flexibility.
|
|
6
|
+
*/
|
|
7
|
+
import React from 'react';
|
|
8
|
+
export interface ModuleConfig<T = any> {
|
|
9
|
+
name: string;
|
|
10
|
+
displayName: string;
|
|
11
|
+
initialState: T;
|
|
12
|
+
drawerTypes: Record<string, string>;
|
|
13
|
+
hooks?: {
|
|
14
|
+
onFormValidation?: (data: any) => Promise<boolean>;
|
|
15
|
+
onBeforeSubmit?: (data: any) => Promise<any>;
|
|
16
|
+
onAfterSubmit?: (state: any, response: any) => Promise<void>;
|
|
17
|
+
customActions?: Record<string, (state: any, payload?: any) => any>;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export interface GenericModuleContext<T = any> {
|
|
21
|
+
state: T;
|
|
22
|
+
dispatch: React.Dispatch<any>;
|
|
23
|
+
}
|
|
24
|
+
export declare const GENERIC_ACTION_TYPES: {
|
|
25
|
+
readonly RESET_FORM: "RESET_FORM";
|
|
26
|
+
readonly SET_CURRENT_PAGE: "SET_CURRENT_PAGE";
|
|
27
|
+
readonly SET_PAGE_LIMIT: "SET_PAGE_LIMIT";
|
|
28
|
+
readonly SET_SEARCH_QUERY: "SET_SEARCH_QUERY";
|
|
29
|
+
readonly SET_DRAWER: "SET_DRAWER";
|
|
30
|
+
readonly SET_ITEMS: "SET_ITEMS";
|
|
31
|
+
readonly SET_FORM_DATA: "SET_FORM_DATA";
|
|
32
|
+
readonly SET_DISABLE_SAVE_BUTTON: "SET_DISABLE_SAVE_BUTTON";
|
|
33
|
+
readonly SET_INPUT_FIELD: "SET_INPUT_FIELD";
|
|
34
|
+
readonly SET_ERRORS: "SET_ERRORS";
|
|
35
|
+
};
|
|
36
|
+
export declare const createGenericReducer: <T>(config: ModuleConfig<T>) => (state: T, action: any) => T;
|
|
37
|
+
export declare const createGenericModuleHook: <T>(config: ModuleConfig<T>) => () => GenericModuleContext<T>;
|
|
38
|
+
export declare const createGenericModuleProvider: <T>(config: ModuleConfig<T>) => {
|
|
39
|
+
Provider: React.FC<{
|
|
40
|
+
children: React.ReactNode;
|
|
41
|
+
}>;
|
|
42
|
+
useContext: () => GenericModuleContext<T>;
|
|
43
|
+
Context: React.Context<GenericModuleContext<T> | undefined>;
|
|
44
|
+
};
|
|
45
|
+
export declare const createGenericModule: <T>(config: ModuleConfig<T>) => {
|
|
46
|
+
reducer: (state: T, action: any) => T;
|
|
47
|
+
Provider: React.FC<{
|
|
48
|
+
children: React.ReactNode;
|
|
49
|
+
}>;
|
|
50
|
+
useContext: () => GenericModuleContext<T>;
|
|
51
|
+
config: ModuleConfig<T>;
|
|
52
|
+
actionTypes: {
|
|
53
|
+
readonly RESET_FORM: "RESET_FORM";
|
|
54
|
+
readonly SET_CURRENT_PAGE: "SET_CURRENT_PAGE";
|
|
55
|
+
readonly SET_PAGE_LIMIT: "SET_PAGE_LIMIT";
|
|
56
|
+
readonly SET_SEARCH_QUERY: "SET_SEARCH_QUERY";
|
|
57
|
+
readonly SET_DRAWER: "SET_DRAWER";
|
|
58
|
+
readonly SET_ITEMS: "SET_ITEMS";
|
|
59
|
+
readonly SET_FORM_DATA: "SET_FORM_DATA";
|
|
60
|
+
readonly SET_DISABLE_SAVE_BUTTON: "SET_DISABLE_SAVE_BUTTON";
|
|
61
|
+
readonly SET_INPUT_FIELD: "SET_INPUT_FIELD";
|
|
62
|
+
readonly SET_ERRORS: "SET_ERRORS";
|
|
63
|
+
};
|
|
64
|
+
initialState: T;
|
|
65
|
+
};
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic Module Factory - Minimal Version
|
|
3
|
+
*
|
|
4
|
+
* Provides reusable reducer and context structure for CRUD modules.
|
|
5
|
+
* API integration is handled by individual modules for maximum flexibility.
|
|
6
|
+
*/
|
|
7
|
+
'use client';
|
|
8
|
+
"use strict";
|
|
9
|
+
var __assign = (this && this.__assign) || function () {
|
|
10
|
+
__assign = Object.assign || function(t) {
|
|
11
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
12
|
+
s = arguments[i];
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
}
|
|
16
|
+
return t;
|
|
17
|
+
};
|
|
18
|
+
return __assign.apply(this, arguments);
|
|
19
|
+
};
|
|
20
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
23
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
24
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
25
|
+
}
|
|
26
|
+
Object.defineProperty(o, k2, desc);
|
|
27
|
+
}) : (function(o, m, k, k2) {
|
|
28
|
+
if (k2 === undefined) k2 = k;
|
|
29
|
+
o[k2] = m[k];
|
|
30
|
+
}));
|
|
31
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
32
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
33
|
+
}) : function(o, v) {
|
|
34
|
+
o["default"] = v;
|
|
35
|
+
});
|
|
36
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
37
|
+
var ownKeys = function(o) {
|
|
38
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
39
|
+
var ar = [];
|
|
40
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
41
|
+
return ar;
|
|
42
|
+
};
|
|
43
|
+
return ownKeys(o);
|
|
44
|
+
};
|
|
45
|
+
return function (mod) {
|
|
46
|
+
if (mod && mod.__esModule) return mod;
|
|
47
|
+
var result = {};
|
|
48
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
49
|
+
__setModuleDefault(result, mod);
|
|
50
|
+
return result;
|
|
51
|
+
};
|
|
52
|
+
})();
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
exports.createGenericModule = exports.createGenericModuleProvider = exports.createGenericModuleHook = exports.createGenericReducer = exports.GENERIC_ACTION_TYPES = void 0;
|
|
55
|
+
var react_1 = __importStar(require("react"));
|
|
56
|
+
// ============================================================================
|
|
57
|
+
// ACTION TYPES
|
|
58
|
+
// ============================================================================
|
|
59
|
+
exports.GENERIC_ACTION_TYPES = {
|
|
60
|
+
RESET_FORM: 'RESET_FORM',
|
|
61
|
+
SET_CURRENT_PAGE: 'SET_CURRENT_PAGE',
|
|
62
|
+
SET_PAGE_LIMIT: 'SET_PAGE_LIMIT',
|
|
63
|
+
SET_SEARCH_QUERY: 'SET_SEARCH_QUERY',
|
|
64
|
+
SET_DRAWER: 'SET_DRAWER',
|
|
65
|
+
SET_ITEMS: 'SET_ITEMS',
|
|
66
|
+
SET_FORM_DATA: 'SET_FORM_DATA',
|
|
67
|
+
SET_DISABLE_SAVE_BUTTON: 'SET_DISABLE_SAVE_BUTTON',
|
|
68
|
+
SET_INPUT_FIELD: 'SET_INPUT_FIELD',
|
|
69
|
+
SET_ERRORS: 'SET_ERRORS',
|
|
70
|
+
};
|
|
71
|
+
// ============================================================================
|
|
72
|
+
// GENERIC REDUCER FACTORY
|
|
73
|
+
// ============================================================================
|
|
74
|
+
var createGenericReducer = function (config) {
|
|
75
|
+
return function (state, action) {
|
|
76
|
+
var _a;
|
|
77
|
+
switch (action.type) {
|
|
78
|
+
case exports.GENERIC_ACTION_TYPES.RESET_FORM: {
|
|
79
|
+
var current = state;
|
|
80
|
+
return __assign(__assign(__assign({}, state), config.initialState), { count: current.count, currentPage: current.currentPage, items: current.items, pageLimit: current.pageLimit, searchQuery: current.searchQuery });
|
|
81
|
+
}
|
|
82
|
+
case exports.GENERIC_ACTION_TYPES.SET_CURRENT_PAGE:
|
|
83
|
+
return __assign(__assign({}, state), { currentPage: action.payload.currentPage });
|
|
84
|
+
case exports.GENERIC_ACTION_TYPES.SET_PAGE_LIMIT:
|
|
85
|
+
return __assign(__assign({}, state), { pageLimit: action.payload.pageLimit });
|
|
86
|
+
case exports.GENERIC_ACTION_TYPES.SET_SEARCH_QUERY:
|
|
87
|
+
return __assign(__assign({}, state), { searchQuery: action.payload.searchQuery });
|
|
88
|
+
case exports.GENERIC_ACTION_TYPES.SET_DRAWER:
|
|
89
|
+
return __assign(__assign({}, state), { drawer: action.payload.drawer });
|
|
90
|
+
case exports.GENERIC_ACTION_TYPES.SET_ITEMS:
|
|
91
|
+
return __assign(__assign({}, state), { items: action.payload.items, count: action.payload.count });
|
|
92
|
+
case exports.GENERIC_ACTION_TYPES.SET_FORM_DATA:
|
|
93
|
+
return __assign(__assign({}, state), action.payload.form);
|
|
94
|
+
case exports.GENERIC_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON:
|
|
95
|
+
return __assign(__assign({}, state), { disableSaveButton: action.payload.disabled });
|
|
96
|
+
case exports.GENERIC_ACTION_TYPES.SET_INPUT_FIELD:
|
|
97
|
+
return __assign(__assign({}, state), (_a = {}, _a[action.payload.key] = action.payload.value, _a));
|
|
98
|
+
case exports.GENERIC_ACTION_TYPES.SET_ERRORS:
|
|
99
|
+
return __assign(__assign({}, state), { errors: action.payload.errors });
|
|
100
|
+
default:
|
|
101
|
+
return state;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
exports.createGenericReducer = createGenericReducer;
|
|
106
|
+
// ============================================================================
|
|
107
|
+
// GENERIC MODULE HOOK FACTORY
|
|
108
|
+
// ============================================================================
|
|
109
|
+
var createGenericModuleHook = function (config) {
|
|
110
|
+
return function () {
|
|
111
|
+
var _a = (0, react_1.useReducer)((0, exports.createGenericReducer)(config), config.initialState), state = _a[0], dispatch = _a[1];
|
|
112
|
+
return {
|
|
113
|
+
state: state,
|
|
114
|
+
dispatch: dispatch,
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
exports.createGenericModuleHook = createGenericModuleHook;
|
|
119
|
+
// ============================================================================
|
|
120
|
+
// GENERIC PROVIDER FACTORY
|
|
121
|
+
// ============================================================================
|
|
122
|
+
var createGenericModuleProvider = function (config) {
|
|
123
|
+
var GenericContext = react_1.default.createContext(undefined);
|
|
124
|
+
var GenericProvider = function (_a) {
|
|
125
|
+
var children = _a.children;
|
|
126
|
+
var useGenericModule = (0, exports.createGenericModuleHook)(config);
|
|
127
|
+
var contextValue = useGenericModule();
|
|
128
|
+
return (react_1.default.createElement(GenericContext.Provider, { value: contextValue }, children));
|
|
129
|
+
};
|
|
130
|
+
var useGenericModuleContext = function () {
|
|
131
|
+
var context = react_1.default.useContext(GenericContext);
|
|
132
|
+
if (context === undefined) {
|
|
133
|
+
throw new Error("useGenericModuleContext must be used within GenericProvider for ".concat(config.name));
|
|
134
|
+
}
|
|
135
|
+
return context;
|
|
136
|
+
};
|
|
137
|
+
return {
|
|
138
|
+
Provider: GenericProvider,
|
|
139
|
+
useContext: useGenericModuleContext,
|
|
140
|
+
Context: GenericContext,
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
exports.createGenericModuleProvider = createGenericModuleProvider;
|
|
144
|
+
// ============================================================================
|
|
145
|
+
// MAIN MODULE FACTORY
|
|
146
|
+
// ============================================================================
|
|
147
|
+
var createGenericModule = function (config) {
|
|
148
|
+
var reducer = (0, exports.createGenericReducer)(config);
|
|
149
|
+
var _a = (0, exports.createGenericModuleProvider)(config), Provider = _a.Provider, useContext = _a.useContext;
|
|
150
|
+
return {
|
|
151
|
+
reducer: reducer,
|
|
152
|
+
Provider: Provider,
|
|
153
|
+
useContext: useContext,
|
|
154
|
+
config: config,
|
|
155
|
+
actionTypes: exports.GENERIC_ACTION_TYPES,
|
|
156
|
+
initialState: config.initialState,
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
exports.createGenericModule = createGenericModule;
|
package/factory/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./generic-component-factory"), exports);
|
|
18
|
+
__exportStar(require("./generic-module-factory"), exports);
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook to detect RTL (Right-to-Left) layout based on current locale
|
|
3
|
+
* @returns {boolean} true if current locale requires RTL layout (Urdu), false otherwise
|
|
4
|
+
*/
|
|
5
|
+
export declare const useRTL: () => boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Hook to get RTL-aware CSS classes
|
|
8
|
+
*
|
|
9
|
+
* @returns Object containing common RTL-aware class combinations
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* const rtlClasses = useRTLClasses();
|
|
14
|
+
*
|
|
15
|
+
* // For icon buttons (ensures proper centering in RTL)
|
|
16
|
+
* <Button size="icon" className={`h-8 w-8 ${rtlClasses.iconButton}`}>
|
|
17
|
+
* <Icon />
|
|
18
|
+
* </Button>
|
|
19
|
+
*
|
|
20
|
+
* // For buttons with icon and text
|
|
21
|
+
* <Button className={rtlClasses.iconWithText("left")}>
|
|
22
|
+
* <Icon />
|
|
23
|
+
* <span>Button Text</span>
|
|
24
|
+
* </Button>
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare const useRTLClasses: () => {
|
|
28
|
+
isRTL: boolean;
|
|
29
|
+
container: string;
|
|
30
|
+
direction: string;
|
|
31
|
+
flexRow: string;
|
|
32
|
+
flexRowReverse: string;
|
|
33
|
+
textAlign: string;
|
|
34
|
+
textAlignReverse: string;
|
|
35
|
+
marginLeft: string;
|
|
36
|
+
marginRight: string;
|
|
37
|
+
paddingLeft: (size: string) => string;
|
|
38
|
+
paddingRight: (size: string) => string;
|
|
39
|
+
gap: (size: string) => string;
|
|
40
|
+
roundedLeft: string;
|
|
41
|
+
roundedRight: string;
|
|
42
|
+
iconButton: string;
|
|
43
|
+
iconWithText: (iconPosition?: "left" | "right") => "flex items-center flex-row-reverse gap-2" | "flex items-center gap-2";
|
|
44
|
+
};
|
package/hooks/use-rtl.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useRTLClasses = exports.useRTL = void 0;
|
|
4
|
+
var next_intl_1 = require("next-intl");
|
|
5
|
+
/**
|
|
6
|
+
* Hook to detect RTL (Right-to-Left) layout based on current locale
|
|
7
|
+
* @returns {boolean} true if current locale requires RTL layout (Urdu), false otherwise
|
|
8
|
+
*/
|
|
9
|
+
var useRTL = function () {
|
|
10
|
+
var locale = (0, next_intl_1.useLocale)();
|
|
11
|
+
return locale === 'ur';
|
|
12
|
+
};
|
|
13
|
+
exports.useRTL = useRTL;
|
|
14
|
+
/**
|
|
15
|
+
* Hook to get RTL-aware CSS classes
|
|
16
|
+
*
|
|
17
|
+
* @returns Object containing common RTL-aware class combinations
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```tsx
|
|
21
|
+
* const rtlClasses = useRTLClasses();
|
|
22
|
+
*
|
|
23
|
+
* // For icon buttons (ensures proper centering in RTL)
|
|
24
|
+
* <Button size="icon" className={`h-8 w-8 ${rtlClasses.iconButton}`}>
|
|
25
|
+
* <Icon />
|
|
26
|
+
* </Button>
|
|
27
|
+
*
|
|
28
|
+
* // For buttons with icon and text
|
|
29
|
+
* <Button className={rtlClasses.iconWithText("left")}>
|
|
30
|
+
* <Icon />
|
|
31
|
+
* <span>Button Text</span>
|
|
32
|
+
* </Button>
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
var useRTLClasses = function () {
|
|
36
|
+
var isRTL = (0, exports.useRTL)();
|
|
37
|
+
return {
|
|
38
|
+
isRTL: isRTL,
|
|
39
|
+
// Container classes
|
|
40
|
+
container: isRTL ? 'rtl' : 'ltr',
|
|
41
|
+
direction: isRTL ? 'rtl' : 'ltr',
|
|
42
|
+
// Flex classes
|
|
43
|
+
flexRow: isRTL ? 'flex-row-reverse' : 'flex-row',
|
|
44
|
+
flexRowReverse: isRTL ? 'flex-row' : 'flex-row-reverse',
|
|
45
|
+
// Text alignment
|
|
46
|
+
textAlign: isRTL ? 'text-right' : 'text-left',
|
|
47
|
+
textAlignReverse: isRTL ? 'text-left' : 'text-right',
|
|
48
|
+
// Margin classes
|
|
49
|
+
marginLeft: isRTL ? 'mr-auto' : 'ml-auto',
|
|
50
|
+
marginRight: isRTL ? 'ml-auto' : 'mr-auto',
|
|
51
|
+
// Padding classes
|
|
52
|
+
paddingLeft: function (size) { return (isRTL ? "pr-".concat(size) : "pl-".concat(size)); },
|
|
53
|
+
paddingRight: function (size) { return (isRTL ? "pl-".concat(size) : "pr-".concat(size)); },
|
|
54
|
+
// Gap and spacing
|
|
55
|
+
gap: function (size) { return "gap-".concat(size); },
|
|
56
|
+
// Border radius (for buttons, cards, etc.)
|
|
57
|
+
roundedLeft: isRTL ? 'rounded-r' : 'rounded-l',
|
|
58
|
+
roundedRight: isRTL ? 'rounded-l' : 'rounded-r',
|
|
59
|
+
// Icon button classes for proper centering in RTL
|
|
60
|
+
iconButton: 'flex items-center justify-center border',
|
|
61
|
+
// Icon with text combinations
|
|
62
|
+
iconWithText: function (iconPosition) {
|
|
63
|
+
if (iconPosition === void 0) { iconPosition = 'left'; }
|
|
64
|
+
if (iconPosition === 'left') {
|
|
65
|
+
return isRTL
|
|
66
|
+
? 'flex items-center flex-row-reverse gap-2'
|
|
67
|
+
: 'flex items-center gap-2';
|
|
68
|
+
}
|
|
69
|
+
return isRTL
|
|
70
|
+
? 'flex items-center gap-2'
|
|
71
|
+
: 'flex items-center flex-row-reverse gap-2';
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
exports.useRTLClasses = useRTLClasses;
|
package/index.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export * from './api/stellar-solutions/quote-invoice';
|
|
|
23
23
|
export * from './api/stellar-solutions/tax';
|
|
24
24
|
export * from './api/stellar-solutions/type';
|
|
25
25
|
export * from './constants';
|
|
26
|
+
export * from './factory';
|
|
26
27
|
export * from './general';
|
|
27
28
|
export * from './hooks';
|
|
28
29
|
export * from './local-storage';
|
package/index.js
CHANGED
|
@@ -39,6 +39,7 @@ __exportStar(require("./api/stellar-solutions/quote-invoice"), exports);
|
|
|
39
39
|
__exportStar(require("./api/stellar-solutions/tax"), exports);
|
|
40
40
|
__exportStar(require("./api/stellar-solutions/type"), exports);
|
|
41
41
|
__exportStar(require("./constants"), exports);
|
|
42
|
+
__exportStar(require("./factory"), exports);
|
|
42
43
|
__exportStar(require("./general"), exports);
|
|
43
44
|
__exportStar(require("./hooks"), exports);
|
|
44
45
|
__exportStar(require("./local-storage"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-pakistan/util-functions",
|
|
3
|
-
"version": "1.25.
|
|
3
|
+
"version": "1.25.33",
|
|
4
4
|
"description": "A library of all util functions",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"homepage": "https://github.com/react-pakistan/util-functions#readme",
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@appcorp/app-corp-vista": "^0.1.20",
|
|
50
|
+
"@appcorp/shadcn": "^1.1.43",
|
|
50
51
|
"@babel/core": "^7.24.5",
|
|
51
52
|
"@babel/preset-typescript": "^7.24.1",
|
|
52
53
|
"@eslint/js": "^9.17.0",
|
|
@@ -74,6 +75,7 @@
|
|
|
74
75
|
"lodash.curry": "^4.1.1",
|
|
75
76
|
"lodash.isequal": "^4.5.0",
|
|
76
77
|
"next": "^15",
|
|
78
|
+
"next-intl": "^4.8.3",
|
|
77
79
|
"prettier": "^3.4.2",
|
|
78
80
|
"react": "^19.2.0",
|
|
79
81
|
"react-dom": "^19.2.0",
|