@frontmcp/ui 0.5.0
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/LICENSE +201 -0
- package/README.md +438 -0
- package/package.json +147 -0
- package/src/adapters/index.d.ts +10 -0
- package/src/adapters/index.js +18 -0
- package/src/adapters/index.js.map +1 -0
- package/src/adapters/platform-meta.d.ts +165 -0
- package/src/adapters/platform-meta.js +310 -0
- package/src/adapters/platform-meta.js.map +1 -0
- package/src/base-template/bridge.d.ts +89 -0
- package/src/base-template/bridge.js +452 -0
- package/src/base-template/bridge.js.map +1 -0
- package/src/base-template/default-base-template.d.ts +91 -0
- package/src/base-template/default-base-template.js +435 -0
- package/src/base-template/default-base-template.js.map +1 -0
- package/src/base-template/index.d.ts +14 -0
- package/src/base-template/index.js +30 -0
- package/src/base-template/index.js.map +1 -0
- package/src/base-template/polyfills.d.ts +30 -0
- package/src/base-template/polyfills.js +190 -0
- package/src/base-template/polyfills.js.map +1 -0
- package/src/base-template/theme-styles.d.ts +73 -0
- package/src/base-template/theme-styles.js +95 -0
- package/src/base-template/theme-styles.js.map +1 -0
- package/src/bridge/adapters/base-adapter.d.ts +103 -0
- package/src/bridge/adapters/base-adapter.js +314 -0
- package/src/bridge/adapters/base-adapter.js.map +1 -0
- package/src/bridge/adapters/claude.adapter.d.ts +66 -0
- package/src/bridge/adapters/claude.adapter.js +145 -0
- package/src/bridge/adapters/claude.adapter.js.map +1 -0
- package/src/bridge/adapters/ext-apps.adapter.d.ts +142 -0
- package/src/bridge/adapters/ext-apps.adapter.js +416 -0
- package/src/bridge/adapters/ext-apps.adapter.js.map +1 -0
- package/src/bridge/adapters/gemini.adapter.d.ts +63 -0
- package/src/bridge/adapters/gemini.adapter.js +160 -0
- package/src/bridge/adapters/gemini.adapter.js.map +1 -0
- package/src/bridge/adapters/generic.adapter.d.ts +55 -0
- package/src/bridge/adapters/generic.adapter.js +108 -0
- package/src/bridge/adapters/generic.adapter.js.map +1 -0
- package/src/bridge/adapters/index.d.ts +25 -0
- package/src/bridge/adapters/index.js +65 -0
- package/src/bridge/adapters/index.js.map +1 -0
- package/src/bridge/adapters/openai.adapter.d.ts +64 -0
- package/src/bridge/adapters/openai.adapter.js +194 -0
- package/src/bridge/adapters/openai.adapter.js.map +1 -0
- package/src/bridge/core/adapter-registry.d.ts +121 -0
- package/src/bridge/core/adapter-registry.js +271 -0
- package/src/bridge/core/adapter-registry.js.map +1 -0
- package/src/bridge/core/bridge-factory.d.ts +198 -0
- package/src/bridge/core/bridge-factory.js +428 -0
- package/src/bridge/core/bridge-factory.js.map +1 -0
- package/src/bridge/core/index.d.ts +9 -0
- package/src/bridge/core/index.js +22 -0
- package/src/bridge/core/index.js.map +1 -0
- package/src/bridge/index.d.ts +61 -0
- package/src/bridge/index.js +94 -0
- package/src/bridge/index.js.map +1 -0
- package/src/bridge/runtime/iife-generator.d.ts +61 -0
- package/src/bridge/runtime/iife-generator.js +940 -0
- package/src/bridge/runtime/iife-generator.js.map +1 -0
- package/src/bridge/runtime/index.d.ts +8 -0
- package/src/bridge/runtime/index.js +16 -0
- package/src/bridge/runtime/index.js.map +1 -0
- package/src/bridge/types.d.ts +385 -0
- package/src/bridge/types.js +11 -0
- package/src/bridge/types.js.map +1 -0
- package/src/build/cdn-resources.d.ts +140 -0
- package/src/build/cdn-resources.js +314 -0
- package/src/build/cdn-resources.js.map +1 -0
- package/src/build/index.d.ts +294 -0
- package/src/build/index.js +325 -0
- package/src/build/index.js.map +1 -0
- package/src/build/widget-manifest.d.ts +212 -0
- package/src/build/widget-manifest.js +652 -0
- package/src/build/widget-manifest.js.map +1 -0
- package/src/bundler/bundler.d.ts +110 -0
- package/src/bundler/bundler.js +432 -0
- package/src/bundler/bundler.js.map +1 -0
- package/src/bundler/cache.d.ts +172 -0
- package/src/bundler/cache.js +250 -0
- package/src/bundler/cache.js.map +1 -0
- package/src/bundler/index.d.ts +41 -0
- package/src/bundler/index.js +73 -0
- package/src/bundler/index.js.map +1 -0
- package/src/bundler/sandbox/enclave-adapter.d.ts +120 -0
- package/src/bundler/sandbox/enclave-adapter.js +339 -0
- package/src/bundler/sandbox/enclave-adapter.js.map +1 -0
- package/src/bundler/sandbox/executor.d.ts +13 -0
- package/src/bundler/sandbox/executor.js +22 -0
- package/src/bundler/sandbox/executor.js.map +1 -0
- package/src/bundler/sandbox/policy.d.ts +61 -0
- package/src/bundler/sandbox/policy.js +238 -0
- package/src/bundler/sandbox/policy.js.map +1 -0
- package/src/bundler/types.d.ts +347 -0
- package/src/bundler/types.js +132 -0
- package/src/bundler/types.js.map +1 -0
- package/src/components/alert.d.ts +71 -0
- package/src/components/alert.js +189 -0
- package/src/components/alert.js.map +1 -0
- package/src/components/alert.schema.d.ts +114 -0
- package/src/components/alert.schema.js +105 -0
- package/src/components/alert.schema.js.map +1 -0
- package/src/components/avatar.d.ts +76 -0
- package/src/components/avatar.js +176 -0
- package/src/components/avatar.js.map +1 -0
- package/src/components/avatar.schema.d.ts +169 -0
- package/src/components/avatar.schema.js +103 -0
- package/src/components/avatar.schema.js.map +1 -0
- package/src/components/badge.d.ts +70 -0
- package/src/components/badge.js +149 -0
- package/src/components/badge.js.map +1 -0
- package/src/components/badge.schema.d.ts +109 -0
- package/src/components/badge.schema.js +96 -0
- package/src/components/badge.schema.js.map +1 -0
- package/src/components/button.d.ts +111 -0
- package/src/components/button.js +336 -0
- package/src/components/button.js.map +1 -0
- package/src/components/button.schema.d.ts +148 -0
- package/src/components/button.schema.js +121 -0
- package/src/components/button.schema.js.map +1 -0
- package/src/components/card.d.ts +60 -0
- package/src/components/card.js +117 -0
- package/src/components/card.js.map +1 -0
- package/src/components/card.schema.d.ts +113 -0
- package/src/components/card.schema.js +98 -0
- package/src/components/card.schema.js.map +1 -0
- package/src/components/form.d.ts +239 -0
- package/src/components/form.js +420 -0
- package/src/components/form.js.map +1 -0
- package/src/components/form.schema.d.ts +441 -0
- package/src/components/form.schema.js +406 -0
- package/src/components/form.schema.js.map +1 -0
- package/src/components/index.d.ts +29 -0
- package/src/components/index.js +98 -0
- package/src/components/index.js.map +1 -0
- package/src/components/list.d.ts +127 -0
- package/src/components/list.js +279 -0
- package/src/components/list.js.map +1 -0
- package/src/components/list.schema.d.ts +134 -0
- package/src/components/list.schema.js +168 -0
- package/src/components/list.schema.js.map +1 -0
- package/src/components/modal.d.ts +111 -0
- package/src/components/modal.js +260 -0
- package/src/components/modal.js.map +1 -0
- package/src/components/modal.schema.d.ts +186 -0
- package/src/components/modal.schema.js +167 -0
- package/src/components/modal.schema.js.map +1 -0
- package/src/components/table.d.ts +105 -0
- package/src/components/table.js +283 -0
- package/src/components/table.js.map +1 -0
- package/src/components/table.schema.d.ts +159 -0
- package/src/components/table.schema.js +173 -0
- package/src/components/table.schema.js.map +1 -0
- package/src/handlebars/helpers.d.ts +348 -0
- package/src/handlebars/helpers.js +605 -0
- package/src/handlebars/helpers.js.map +1 -0
- package/src/handlebars/index.d.ts +193 -0
- package/src/handlebars/index.js +350 -0
- package/src/handlebars/index.js.map +1 -0
- package/src/index.d.ts +50 -0
- package/src/index.js +192 -0
- package/src/index.js.map +1 -0
- package/src/layouts/base.d.ts +88 -0
- package/src/layouts/base.js +227 -0
- package/src/layouts/base.js.map +1 -0
- package/src/layouts/index.d.ts +7 -0
- package/src/layouts/index.js +25 -0
- package/src/layouts/index.js.map +1 -0
- package/src/layouts/presets.d.ts +133 -0
- package/src/layouts/presets.js +277 -0
- package/src/layouts/presets.js.map +1 -0
- package/src/pages/consent.d.ts +116 -0
- package/src/pages/consent.js +218 -0
- package/src/pages/consent.js.map +1 -0
- package/src/pages/error.d.ts +100 -0
- package/src/pages/error.js +263 -0
- package/src/pages/error.js.map +1 -0
- package/src/pages/index.d.ts +8 -0
- package/src/pages/index.js +27 -0
- package/src/pages/index.js.map +1 -0
- package/src/react/Alert.d.ts +101 -0
- package/src/react/Alert.js +51 -0
- package/src/react/Alert.js.map +1 -0
- package/src/react/Badge.d.ts +100 -0
- package/src/react/Badge.js +55 -0
- package/src/react/Badge.js.map +1 -0
- package/src/react/Button.d.ts +108 -0
- package/src/react/Button.js +52 -0
- package/src/react/Button.js.map +1 -0
- package/src/react/Card.d.ts +103 -0
- package/src/react/Card.js +55 -0
- package/src/react/Card.js.map +1 -0
- package/src/react/hooks/context.d.ts +178 -0
- package/src/react/hooks/context.js +287 -0
- package/src/react/hooks/context.js.map +1 -0
- package/src/react/hooks/index.d.ts +41 -0
- package/src/react/hooks/index.js +61 -0
- package/src/react/hooks/index.js.map +1 -0
- package/src/react/hooks/tools.d.ts +283 -0
- package/src/react/hooks/tools.js +465 -0
- package/src/react/hooks/tools.js.map +1 -0
- package/src/react/index.d.ts +80 -0
- package/src/react/index.js +113 -0
- package/src/react/index.js.map +1 -0
- package/src/react/types.d.ts +105 -0
- package/src/react/types.js +12 -0
- package/src/react/types.js.map +1 -0
- package/src/react/utils.d.ts +42 -0
- package/src/react/utils.js +99 -0
- package/src/react/utils.js.map +1 -0
- package/src/registry/index.d.ts +45 -0
- package/src/registry/index.js +67 -0
- package/src/registry/index.js.map +1 -0
- package/src/registry/render-template.d.ts +86 -0
- package/src/registry/render-template.js +239 -0
- package/src/registry/render-template.js.map +1 -0
- package/src/registry/tool-ui.registry.d.ts +260 -0
- package/src/registry/tool-ui.registry.js +438 -0
- package/src/registry/tool-ui.registry.js.map +1 -0
- package/src/registry/uri-utils.d.ts +55 -0
- package/src/registry/uri-utils.js +97 -0
- package/src/registry/uri-utils.js.map +1 -0
- package/src/render/index.d.ts +7 -0
- package/src/render/index.js +14 -0
- package/src/render/index.js.map +1 -0
- package/src/render/prerender.d.ts +56 -0
- package/src/render/prerender.js +98 -0
- package/src/render/prerender.js.map +1 -0
- package/src/renderers/cache.d.ts +144 -0
- package/src/renderers/cache.js +240 -0
- package/src/renderers/cache.js.map +1 -0
- package/src/renderers/html.renderer.d.ts +122 -0
- package/src/renderers/html.renderer.js +204 -0
- package/src/renderers/html.renderer.js.map +1 -0
- package/src/renderers/index.d.ts +35 -0
- package/src/renderers/index.js +70 -0
- package/src/renderers/index.js.map +1 -0
- package/src/renderers/mdx.renderer.d.ts +119 -0
- package/src/renderers/mdx.renderer.js +305 -0
- package/src/renderers/mdx.renderer.js.map +1 -0
- package/src/renderers/react.renderer.d.ts +95 -0
- package/src/renderers/react.renderer.js +260 -0
- package/src/renderers/react.renderer.js.map +1 -0
- package/src/renderers/registry.d.ts +133 -0
- package/src/renderers/registry.js +232 -0
- package/src/renderers/registry.js.map +1 -0
- package/src/renderers/types.d.ts +341 -0
- package/src/renderers/types.js +9 -0
- package/src/renderers/types.js.map +1 -0
- package/src/renderers/utils/detect.d.ts +106 -0
- package/src/renderers/utils/detect.js +267 -0
- package/src/renderers/utils/detect.js.map +1 -0
- package/src/renderers/utils/hash.d.ts +39 -0
- package/src/renderers/utils/hash.js +75 -0
- package/src/renderers/utils/hash.js.map +1 -0
- package/src/renderers/utils/index.d.ts +8 -0
- package/src/renderers/utils/index.js +28 -0
- package/src/renderers/utils/index.js.map +1 -0
- package/src/renderers/utils/transpiler.d.ts +88 -0
- package/src/renderers/utils/transpiler.js +215 -0
- package/src/renderers/utils/transpiler.js.map +1 -0
- package/src/runtime/adapters/html.adapter.d.ts +58 -0
- package/src/runtime/adapters/html.adapter.js +131 -0
- package/src/runtime/adapters/html.adapter.js.map +1 -0
- package/src/runtime/adapters/index.d.ts +25 -0
- package/src/runtime/adapters/index.js +54 -0
- package/src/runtime/adapters/index.js.map +1 -0
- package/src/runtime/adapters/mdx.adapter.d.ts +72 -0
- package/src/runtime/adapters/mdx.adapter.js +241 -0
- package/src/runtime/adapters/mdx.adapter.js.map +1 -0
- package/src/runtime/adapters/react.adapter.d.ts +69 -0
- package/src/runtime/adapters/react.adapter.js +245 -0
- package/src/runtime/adapters/react.adapter.js.map +1 -0
- package/src/runtime/adapters/types.d.ts +94 -0
- package/src/runtime/adapters/types.js +11 -0
- package/src/runtime/adapters/types.js.map +1 -0
- package/src/runtime/csp.d.ts +37 -0
- package/src/runtime/csp.js +140 -0
- package/src/runtime/csp.js.map +1 -0
- package/src/runtime/index.d.ts +16 -0
- package/src/runtime/index.js +72 -0
- package/src/runtime/index.js.map +1 -0
- package/src/runtime/mcp-bridge.d.ts +100 -0
- package/src/runtime/mcp-bridge.js +581 -0
- package/src/runtime/mcp-bridge.js.map +1 -0
- package/src/runtime/renderer-runtime.d.ts +132 -0
- package/src/runtime/renderer-runtime.js +389 -0
- package/src/runtime/renderer-runtime.js.map +1 -0
- package/src/runtime/sanitizer.d.ts +171 -0
- package/src/runtime/sanitizer.js +318 -0
- package/src/runtime/sanitizer.js.map +1 -0
- package/src/runtime/types.d.ts +414 -0
- package/src/runtime/types.js +12 -0
- package/src/runtime/types.js.map +1 -0
- package/src/runtime/wrapper.d.ts +375 -0
- package/src/runtime/wrapper.js +1793 -0
- package/src/runtime/wrapper.js.map +1 -0
- package/src/styles/index.d.ts +7 -0
- package/src/styles/index.js +11 -0
- package/src/styles/index.js.map +1 -0
- package/src/styles/variants.d.ts +50 -0
- package/src/styles/variants.js +175 -0
- package/src/styles/variants.js.map +1 -0
- package/src/theme/cdn.d.ts +194 -0
- package/src/theme/cdn.js +375 -0
- package/src/theme/cdn.js.map +1 -0
- package/src/theme/index.d.ts +17 -0
- package/src/theme/index.js +57 -0
- package/src/theme/index.js.map +1 -0
- package/src/theme/platforms.d.ts +106 -0
- package/src/theme/platforms.js +161 -0
- package/src/theme/platforms.js.map +1 -0
- package/src/theme/presets/github-openai.d.ts +49 -0
- package/src/theme/presets/github-openai.js +189 -0
- package/src/theme/presets/github-openai.js.map +1 -0
- package/src/theme/presets/index.d.ts +10 -0
- package/src/theme/presets/index.js +17 -0
- package/src/theme/presets/index.js.map +1 -0
- package/src/theme/theme.d.ts +395 -0
- package/src/theme/theme.js +332 -0
- package/src/theme/theme.js.map +1 -0
- package/src/tool-template/builder.d.ts +212 -0
- package/src/tool-template/builder.js +397 -0
- package/src/tool-template/builder.js.map +1 -0
- package/src/tool-template/index.d.ts +15 -0
- package/src/tool-template/index.js +38 -0
- package/src/tool-template/index.js.map +1 -0
- package/src/types/index.d.ts +13 -0
- package/src/types/index.js +26 -0
- package/src/types/index.js.map +1 -0
- package/src/types/ui-config.d.ts +357 -0
- package/src/types/ui-config.js +12 -0
- package/src/types/ui-config.js.map +1 -0
- package/src/types/ui-runtime.d.ts +965 -0
- package/src/types/ui-runtime.js +117 -0
- package/src/types/ui-runtime.js.map +1 -0
- package/src/validation/error-box.d.ts +55 -0
- package/src/validation/error-box.js +75 -0
- package/src/validation/error-box.js.map +1 -0
- package/src/validation/index.d.ts +12 -0
- package/src/validation/index.js +21 -0
- package/src/validation/index.js.map +1 -0
- package/src/validation/wrapper.d.ts +96 -0
- package/src/validation/wrapper.js +117 -0
- package/src/validation/wrapper.js.map +1 -0
- package/src/web-components/core/attribute-parser.d.ts +85 -0
- package/src/web-components/core/attribute-parser.js +189 -0
- package/src/web-components/core/attribute-parser.js.map +1 -0
- package/src/web-components/core/base-element.d.ts +197 -0
- package/src/web-components/core/base-element.js +289 -0
- package/src/web-components/core/base-element.js.map +1 -0
- package/src/web-components/core/index.d.ts +8 -0
- package/src/web-components/core/index.js +18 -0
- package/src/web-components/core/index.js.map +1 -0
- package/src/web-components/elements/fmcp-alert.d.ts +45 -0
- package/src/web-components/elements/fmcp-alert.js +93 -0
- package/src/web-components/elements/fmcp-alert.js.map +1 -0
- package/src/web-components/elements/fmcp-badge.d.ts +46 -0
- package/src/web-components/elements/fmcp-badge.js +99 -0
- package/src/web-components/elements/fmcp-badge.js.map +1 -0
- package/src/web-components/elements/fmcp-button.d.ts +124 -0
- package/src/web-components/elements/fmcp-button.js +233 -0
- package/src/web-components/elements/fmcp-button.js.map +1 -0
- package/src/web-components/elements/fmcp-card.d.ts +52 -0
- package/src/web-components/elements/fmcp-card.js +115 -0
- package/src/web-components/elements/fmcp-card.js.map +1 -0
- package/src/web-components/elements/fmcp-input.d.ts +95 -0
- package/src/web-components/elements/fmcp-input.js +248 -0
- package/src/web-components/elements/fmcp-input.js.map +1 -0
- package/src/web-components/elements/fmcp-select.d.ts +99 -0
- package/src/web-components/elements/fmcp-select.js +243 -0
- package/src/web-components/elements/fmcp-select.js.map +1 -0
- package/src/web-components/elements/index.d.ts +12 -0
- package/src/web-components/elements/index.js +34 -0
- package/src/web-components/elements/index.js.map +1 -0
- package/src/web-components/index.d.ts +49 -0
- package/src/web-components/index.js +75 -0
- package/src/web-components/index.js.map +1 -0
- package/src/web-components/register.d.ts +56 -0
- package/src/web-components/register.js +80 -0
- package/src/web-components/register.js.map +1 -0
- package/src/web-components/types.d.ts +121 -0
- package/src/web-components/types.js +25 -0
- package/src/web-components/types.js.map +1 -0
- package/src/widgets/index.d.ts +7 -0
- package/src/widgets/index.js +24 -0
- package/src/widgets/index.js.map +1 -0
- package/src/widgets/progress.d.ts +132 -0
- package/src/widgets/progress.js +303 -0
- package/src/widgets/progress.js.map +1 -0
- package/src/widgets/resource.d.ts +162 -0
- package/src/widgets/resource.js +340 -0
- package/src/widgets/resource.js.map +1 -0
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Table Component
|
|
4
|
+
*
|
|
5
|
+
* Data tables with sorting, selection, and HTMX support.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.table = table;
|
|
9
|
+
exports.pagination = pagination;
|
|
10
|
+
const base_1 = require("../layouts/base");
|
|
11
|
+
// ============================================
|
|
12
|
+
// Table Builder
|
|
13
|
+
// ============================================
|
|
14
|
+
/**
|
|
15
|
+
* Get alignment classes
|
|
16
|
+
*/
|
|
17
|
+
function getAlignClasses(align = 'left') {
|
|
18
|
+
const alignments = {
|
|
19
|
+
left: 'text-left',
|
|
20
|
+
center: 'text-center',
|
|
21
|
+
right: 'text-right',
|
|
22
|
+
};
|
|
23
|
+
return alignments[align];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Build sort indicator
|
|
27
|
+
*/
|
|
28
|
+
function buildSortIndicator(direction) {
|
|
29
|
+
if (direction === 'asc') {
|
|
30
|
+
return `<svg class="w-4 h-4 ml-1 inline-block" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
31
|
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 15l7-7 7 7"/>
|
|
32
|
+
</svg>`;
|
|
33
|
+
}
|
|
34
|
+
if (direction === 'desc') {
|
|
35
|
+
return `<svg class="w-4 h-4 ml-1 inline-block" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
36
|
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"/>
|
|
37
|
+
</svg>`;
|
|
38
|
+
}
|
|
39
|
+
return `<svg class="w-4 h-4 ml-1 inline-block opacity-30" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
40
|
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 16V4m0 0L3 8m4-4l4 4m6 0v12m0 0l4-4m-4 4l-4-4"/>
|
|
41
|
+
</svg>`;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Build table header
|
|
45
|
+
*/
|
|
46
|
+
function buildTableHeader(columns, options) {
|
|
47
|
+
const { selectable, sortHtmx, compact } = options;
|
|
48
|
+
const paddingClass = compact ? 'px-3 py-2' : 'px-4 py-3';
|
|
49
|
+
const selectAllCell = selectable
|
|
50
|
+
? `<th class="${paddingClass} w-12">
|
|
51
|
+
<input
|
|
52
|
+
type="checkbox"
|
|
53
|
+
class="w-4 h-4 rounded border-border text-primary focus:ring-primary/20"
|
|
54
|
+
aria-label="Select all"
|
|
55
|
+
>
|
|
56
|
+
</th>`
|
|
57
|
+
: '';
|
|
58
|
+
const headerCells = columns
|
|
59
|
+
.map((col) => {
|
|
60
|
+
const alignClass = getAlignClasses(col.align);
|
|
61
|
+
const widthStyle = col.width ? `style="width: ${col.width}"` : '';
|
|
62
|
+
if (col.sortable && sortHtmx) {
|
|
63
|
+
const nextDirection = col.sortDirection === 'asc' ? 'desc' : 'asc';
|
|
64
|
+
const sortUrl = `${sortHtmx.get}${sortHtmx.get.includes('?') ? '&' : '?'}sort=${col.key}&dir=${nextDirection}`;
|
|
65
|
+
return `<th
|
|
66
|
+
class="${paddingClass} ${alignClass} font-semibold text-text-primary cursor-pointer hover:bg-gray-50 ${col.headerClass || ''}"
|
|
67
|
+
${widthStyle}
|
|
68
|
+
hx-get="${(0, base_1.escapeHtml)(sortUrl)}"
|
|
69
|
+
${sortHtmx.target ? `hx-target="${(0, base_1.escapeHtml)(sortHtmx.target)}"` : ''}
|
|
70
|
+
${sortHtmx.swap ? `hx-swap="${(0, base_1.escapeHtml)(sortHtmx.swap)}"` : ''}
|
|
71
|
+
>
|
|
72
|
+
<span class="inline-flex items-center">
|
|
73
|
+
${(0, base_1.escapeHtml)(col.header)}
|
|
74
|
+
${buildSortIndicator(col.sortDirection || null)}
|
|
75
|
+
</span>
|
|
76
|
+
</th>`;
|
|
77
|
+
}
|
|
78
|
+
return `<th
|
|
79
|
+
class="${paddingClass} ${alignClass} font-semibold text-text-primary ${col.headerClass || ''}"
|
|
80
|
+
${widthStyle}
|
|
81
|
+
>
|
|
82
|
+
${(0, base_1.escapeHtml)(col.header)}
|
|
83
|
+
</th>`;
|
|
84
|
+
})
|
|
85
|
+
.join('\n');
|
|
86
|
+
return `<thead class="bg-gray-50 border-b border-border">
|
|
87
|
+
<tr>
|
|
88
|
+
${selectAllCell}
|
|
89
|
+
${headerCells}
|
|
90
|
+
</tr>
|
|
91
|
+
</thead>`;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Build table body
|
|
95
|
+
*/
|
|
96
|
+
function buildTableBody(data, columns, options) {
|
|
97
|
+
const { selectable, hoverable, striped, bordered, compact, selectHtmx, rowKey = 'id', onRowClick, } = options;
|
|
98
|
+
const paddingClass = compact ? 'px-3 py-2' : 'px-4 py-3';
|
|
99
|
+
if (data.length === 0) {
|
|
100
|
+
const colspan = columns.length + (selectable ? 1 : 0);
|
|
101
|
+
const emptyContent = options.emptyContent ||
|
|
102
|
+
`
|
|
103
|
+
<div class="text-center py-8">
|
|
104
|
+
<svg class="w-12 h-12 mx-auto text-gray-300 mb-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
105
|
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20 13V6a2 2 0 00-2-2H6a2 2 0 00-2 2v7m16 0v5a2 2 0 01-2 2H6a2 2 0 01-2-2v-5m16 0h-2.586a1 1 0 00-.707.293l-2.414 2.414a1 1 0 01-.707.293h-3.172a1 1 0 01-.707-.293l-2.414-2.414A1 1 0 006.586 13H4"/>
|
|
106
|
+
</svg>
|
|
107
|
+
<p class="text-text-secondary">${options.emptyMessage || 'No data available'}</p>
|
|
108
|
+
</div>
|
|
109
|
+
`;
|
|
110
|
+
return `<tbody>
|
|
111
|
+
<tr>
|
|
112
|
+
<td colspan="${colspan}">${emptyContent}</td>
|
|
113
|
+
</tr>
|
|
114
|
+
</tbody>`;
|
|
115
|
+
}
|
|
116
|
+
const rows = data
|
|
117
|
+
.map((row, rowIndex) => {
|
|
118
|
+
const rowId = String(row[rowKey] || rowIndex);
|
|
119
|
+
const rowClasses = [
|
|
120
|
+
hoverable ? 'hover:bg-gray-50' : '',
|
|
121
|
+
striped && rowIndex % 2 === 1 ? 'bg-gray-50/50' : '',
|
|
122
|
+
bordered ? 'border-b border-border' : '',
|
|
123
|
+
onRowClick ? 'cursor-pointer' : '',
|
|
124
|
+
]
|
|
125
|
+
.filter(Boolean)
|
|
126
|
+
.join(' ');
|
|
127
|
+
const clickHandler = onRowClick
|
|
128
|
+
? `onclick="window.location.href='${(0, base_1.escapeHtml)(onRowClick.replace('{key}', rowId))}'"`
|
|
129
|
+
: '';
|
|
130
|
+
const selectCell = selectable
|
|
131
|
+
? `<td class="${paddingClass}" onclick="event.stopPropagation()">
|
|
132
|
+
<input
|
|
133
|
+
type="checkbox"
|
|
134
|
+
class="w-4 h-4 rounded border-border text-primary focus:ring-primary/20"
|
|
135
|
+
name="selected[]"
|
|
136
|
+
value="${(0, base_1.escapeHtml)(rowId)}"
|
|
137
|
+
${selectHtmx
|
|
138
|
+
? `
|
|
139
|
+
hx-post="${(0, base_1.escapeHtml)(selectHtmx.post)}"
|
|
140
|
+
${selectHtmx.target ? `hx-target="${(0, base_1.escapeHtml)(selectHtmx.target)}"` : ''}
|
|
141
|
+
hx-trigger="change"
|
|
142
|
+
`
|
|
143
|
+
: ''}
|
|
144
|
+
aria-label="Select row"
|
|
145
|
+
>
|
|
146
|
+
</td>`
|
|
147
|
+
: '';
|
|
148
|
+
const cells = columns
|
|
149
|
+
.map((col) => {
|
|
150
|
+
const value = row[col.key];
|
|
151
|
+
const alignClass = getAlignClasses(col.align);
|
|
152
|
+
const cellContent = col.render ? col.render(value, row, rowIndex) : (0, base_1.escapeHtml)(String(value ?? ''));
|
|
153
|
+
return `<td class="${paddingClass} ${alignClass} ${col.cellClass || ''}">${cellContent}</td>`;
|
|
154
|
+
})
|
|
155
|
+
.join('\n');
|
|
156
|
+
return `<tr class="${rowClasses}" ${clickHandler}>
|
|
157
|
+
${selectCell}
|
|
158
|
+
${cells}
|
|
159
|
+
</tr>`;
|
|
160
|
+
})
|
|
161
|
+
.join('\n');
|
|
162
|
+
return `<tbody class="divide-y divide-border">${rows}</tbody>`;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Build loading overlay
|
|
166
|
+
*/
|
|
167
|
+
function buildLoadingOverlay() {
|
|
168
|
+
return `<div class="absolute inset-0 bg-white/70 flex items-center justify-center">
|
|
169
|
+
<svg class="animate-spin w-8 h-8 text-primary" fill="none" viewBox="0 0 24 24">
|
|
170
|
+
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
|
|
171
|
+
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
|
|
172
|
+
</svg>
|
|
173
|
+
</div>`;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Build a data table
|
|
177
|
+
*/
|
|
178
|
+
function table(data, options) {
|
|
179
|
+
const { id, bordered, stickyHeader, className = '', loading = false } = options;
|
|
180
|
+
const tableClasses = ['w-full', bordered ? 'border border-border' : '', 'text-sm'].filter(Boolean).join(' ');
|
|
181
|
+
const wrapperClasses = ['relative overflow-x-auto', stickyHeader ? 'max-h-96 overflow-y-auto' : '', className]
|
|
182
|
+
.filter(Boolean)
|
|
183
|
+
.join(' ');
|
|
184
|
+
const idAttr = id ? `id="${(0, base_1.escapeHtml)(id)}"` : '';
|
|
185
|
+
const header = buildTableHeader(options.columns, options);
|
|
186
|
+
const body = buildTableBody(data, options.columns, options);
|
|
187
|
+
const loadingOverlay = loading ? buildLoadingOverlay() : '';
|
|
188
|
+
return `<div class="${wrapperClasses}" ${idAttr}>
|
|
189
|
+
<table class="${tableClasses}">
|
|
190
|
+
${header}
|
|
191
|
+
${body}
|
|
192
|
+
</table>
|
|
193
|
+
${loadingOverlay}
|
|
194
|
+
</div>`;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Build pagination component
|
|
198
|
+
*/
|
|
199
|
+
function pagination(options) {
|
|
200
|
+
const { page, totalPages, totalItems, pageSize = 10, showPageSize = false, pageSizeOptions = [10, 25, 50, 100], className = '', htmx, } = options;
|
|
201
|
+
const buildPageLink = (pageNum, label, disabled, active) => {
|
|
202
|
+
const baseClasses = 'px-3 py-2 text-sm rounded-lg transition-colors';
|
|
203
|
+
const stateClasses = disabled
|
|
204
|
+
? 'text-gray-300 cursor-not-allowed'
|
|
205
|
+
: active
|
|
206
|
+
? 'bg-primary text-white'
|
|
207
|
+
: 'text-text-primary hover:bg-gray-100';
|
|
208
|
+
if (disabled) {
|
|
209
|
+
return `<span class="${baseClasses} ${stateClasses}">${label}</span>`;
|
|
210
|
+
}
|
|
211
|
+
const pageUrl = htmx ? `${htmx.get}${htmx.get.includes('?') ? '&' : '?'}page=${pageNum}` : `?page=${pageNum}`;
|
|
212
|
+
const htmxAttrs = htmx
|
|
213
|
+
? `hx-get="${(0, base_1.escapeHtml)(pageUrl)}" ${htmx.target ? `hx-target="${(0, base_1.escapeHtml)(htmx.target)}"` : ''} ${htmx.swap ? `hx-swap="${(0, base_1.escapeHtml)(htmx.swap)}"` : ''}`
|
|
214
|
+
: '';
|
|
215
|
+
return `<a href="${(0, base_1.escapeHtml)(pageUrl)}" class="${baseClasses} ${stateClasses}" ${htmxAttrs}>${label}</a>`;
|
|
216
|
+
};
|
|
217
|
+
// Build page numbers
|
|
218
|
+
const pageNumbers = [];
|
|
219
|
+
const maxVisible = 5;
|
|
220
|
+
if (totalPages <= maxVisible) {
|
|
221
|
+
for (let i = 1; i <= totalPages; i++) {
|
|
222
|
+
pageNumbers.push(i);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
pageNumbers.push(1);
|
|
227
|
+
let start = Math.max(2, page - 1);
|
|
228
|
+
let end = Math.min(totalPages - 1, page + 1);
|
|
229
|
+
if (page <= 2) {
|
|
230
|
+
end = 4;
|
|
231
|
+
}
|
|
232
|
+
else if (page >= totalPages - 1) {
|
|
233
|
+
start = totalPages - 3;
|
|
234
|
+
}
|
|
235
|
+
if (start > 2) {
|
|
236
|
+
pageNumbers.push(-1); // Ellipsis
|
|
237
|
+
}
|
|
238
|
+
for (let i = start; i <= end; i++) {
|
|
239
|
+
pageNumbers.push(i);
|
|
240
|
+
}
|
|
241
|
+
if (end < totalPages - 1) {
|
|
242
|
+
pageNumbers.push(-1); // Ellipsis
|
|
243
|
+
}
|
|
244
|
+
pageNumbers.push(totalPages);
|
|
245
|
+
}
|
|
246
|
+
const pagesHtml = pageNumbers
|
|
247
|
+
.map((num) => {
|
|
248
|
+
if (num === -1) {
|
|
249
|
+
return '<span class="px-2 py-2 text-text-secondary">...</span>';
|
|
250
|
+
}
|
|
251
|
+
return buildPageLink(num, String(num), false, num === page);
|
|
252
|
+
})
|
|
253
|
+
.join('\n');
|
|
254
|
+
const prevLink = buildPageLink(page - 1, '← Previous', page <= 1, false);
|
|
255
|
+
const nextLink = buildPageLink(page + 1, 'Next →', page >= totalPages, false);
|
|
256
|
+
const infoHtml = totalItems !== undefined
|
|
257
|
+
? `<span class="text-sm text-text-secondary">
|
|
258
|
+
Showing ${(page - 1) * pageSize + 1} to ${Math.min(page * pageSize, totalItems)} of ${totalItems} results
|
|
259
|
+
</span>`
|
|
260
|
+
: '';
|
|
261
|
+
const pageSizeHtml = showPageSize
|
|
262
|
+
? `<select
|
|
263
|
+
class="ml-4 px-2 py-1 text-sm border border-border rounded-lg bg-white"
|
|
264
|
+
onchange="window.location.href = '${htmx?.get || ''}?page=1&pageSize=' + this.value"
|
|
265
|
+
>
|
|
266
|
+
${pageSizeOptions
|
|
267
|
+
.map((size) => `<option value="${size}" ${size === pageSize ? 'selected' : ''}>${size} per page</option>`)
|
|
268
|
+
.join('')}
|
|
269
|
+
</select>`
|
|
270
|
+
: '';
|
|
271
|
+
return `<div class="flex items-center justify-between ${className}">
|
|
272
|
+
<div class="flex items-center">
|
|
273
|
+
${infoHtml}
|
|
274
|
+
${pageSizeHtml}
|
|
275
|
+
</div>
|
|
276
|
+
<div class="flex items-center gap-1">
|
|
277
|
+
${prevLink}
|
|
278
|
+
${pagesHtml}
|
|
279
|
+
${nextLink}
|
|
280
|
+
</div>
|
|
281
|
+
</div>`;
|
|
282
|
+
}
|
|
283
|
+
//# sourceMappingURL=table.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table.js","sourceRoot":"","sources":["../../../src/components/table.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;AA4RH,sBAsBC;AAmCD,gCA+GC;AAlcD,0CAA6C;AA2E7C,+CAA+C;AAC/C,gBAAgB;AAChB,+CAA+C;AAE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I,CAAC,CAAC;IAEd,MAAM,QAAQ,GAAG,aAAa,CAAC,IAAI,GAAG,CAAC,EAAE,iBAAiB,EAAE,IAAI,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC;IAC9E,MAAM,QAAQ,GAAG,aAAa,CAAC,IAAI,GAAG,CAAC,EAAE,aAAa,EAAE,IAAI,IAAI,UAAU,EAAE,KAAK,CAAC,CAAC;IAEnF,MAAM,QAAQ,GACZ,UAAU,KAAK,SAAS;QACtB,CAAC,CAAC;kBACU,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,QAAQ,GAAG,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,QAAQ,EAAE,UAAU,CAAC,OAAO,UAAU;cAC1F;QACR,CAAC,CAAC,EAAE,CAAC;IAET,MAAM,YAAY,GAAG,YAAY;QAC/B,CAAC,CAAC;;4CAEsC,IAAI,EAAE,GAAG,IAAI,EAAE;;UAEjD,eAAe;aACd,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,kBAAkB,IAAI,KAAK,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,IAAI,IAAI,oBAAoB,CAAC;aACzG,IAAI,CAAC,EAAE,CAAC;gBACH;QACZ,CAAC,CAAC,EAAE,CAAC;IAEP,OAAO,iDAAiD,SAAS;;QAE3D,QAAQ;QACR,YAAY;;;QAGZ,QAAQ;QACR,SAAS;QACT,QAAQ;;SAEP,CAAC;AACV,CAAC","sourcesContent":["/**\n * Table Component\n *\n * Data tables with sorting, selection, and HTMX support.\n */\n\nimport { escapeHtml } from '../layouts/base';\n\n// ============================================\n// Table Types\n// ============================================\n\n/**\n * Table column definition\n */\nexport interface TableColumn<T = Record<string, unknown>> {\n /** Column key (property name) */\n key: string;\n /** Column header text */\n header: string;\n /** Column width */\n width?: string;\n /** Text alignment */\n align?: 'left' | 'center' | 'right';\n /** Sortable column */\n sortable?: boolean;\n /** Current sort direction */\n sortDirection?: 'asc' | 'desc' | null;\n /** Custom cell renderer */\n render?: (value: unknown, row: T, index: number) => string;\n /** Additional header CSS classes */\n headerClass?: string;\n /** Additional cell CSS classes */\n cellClass?: string;\n}\n\n/**\n * Table options\n */\nexport interface TableOptions<T = Record<string, unknown>> {\n /** Column definitions */\n columns: TableColumn<T>[];\n /** Table ID */\n id?: string;\n /** Show row selection checkboxes */\n selectable?: boolean;\n /** Row hover effect */\n hoverable?: boolean;\n /** Striped rows */\n striped?: boolean;\n /** Bordered cells */\n bordered?: boolean;\n /** Compact size */\n compact?: boolean;\n /** Fixed header (sticky) */\n stickyHeader?: boolean;\n /** Additional CSS classes */\n className?: string;\n /** Empty state message */\n emptyMessage?: string;\n /** Empty state HTML */\n emptyContent?: string;\n /** Loading state */\n loading?: boolean;\n /** HTMX for sorting */\n sortHtmx?: {\n get: string;\n target?: string;\n swap?: string;\n };\n /** HTMX for selection */\n selectHtmx?: {\n post: string;\n target?: string;\n };\n /** Row key property for selection */\n rowKey?: keyof T;\n /** Row click handler (URL template with {key}) */\n onRowClick?: string;\n}\n\n// ============================================\n// Table Builder\n// ============================================\n\n/**\n * Get alignment classes\n */\nfunction getAlignClasses(align: 'left' | 'center' | 'right' = 'left'): string {\n const alignments: Record<string, string> = {\n left: 'text-left',\n center: 'text-center',\n right: 'text-right',\n };\n return alignments[align];\n}\n\n/**\n * Build sort indicator\n */\nfunction buildSortIndicator(direction: 'asc' | 'desc' | null): string {\n if (direction === 'asc') {\n return `<svg class=\"w-4 h-4 ml-1 inline-block\" fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\">\n <path stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M5 15l7-7 7 7\"/>\n </svg>`;\n }\n if (direction === 'desc') {\n return `<svg class=\"w-4 h-4 ml-1 inline-block\" fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\">\n <path stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M19 9l-7 7-7-7\"/>\n </svg>`;\n }\n return `<svg class=\"w-4 h-4 ml-1 inline-block opacity-30\" fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\">\n <path stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M7 16V4m0 0L3 8m4-4l4 4m6 0v12m0 0l4-4m-4 4l-4-4\"/>\n </svg>`;\n}\n\n/**\n * Build table header\n */\nfunction buildTableHeader<T>(columns: TableColumn<T>[], options: TableOptions<T>): string {\n const { selectable, sortHtmx, compact } = options;\n const paddingClass = compact ? 'px-3 py-2' : 'px-4 py-3';\n\n const selectAllCell = selectable\n ? `<th class=\"${paddingClass} w-12\">\n <input\n type=\"checkbox\"\n class=\"w-4 h-4 rounded border-border text-primary focus:ring-primary/20\"\n aria-label=\"Select all\"\n >\n </th>`\n : '';\n\n const headerCells = columns\n .map((col) => {\n const alignClass = getAlignClasses(col.align);\n const widthStyle = col.width ? `style=\"width: ${col.width}\"` : '';\n\n if (col.sortable && sortHtmx) {\n const nextDirection = col.sortDirection === 'asc' ? 'desc' : 'asc';\n const sortUrl = `${sortHtmx.get}${sortHtmx.get.includes('?') ? '&' : '?'}sort=${col.key}&dir=${nextDirection}`;\n\n return `<th\n class=\"${paddingClass} ${alignClass} font-semibold text-text-primary cursor-pointer hover:bg-gray-50 ${\n col.headerClass || ''\n }\"\n ${widthStyle}\n hx-get=\"${escapeHtml(sortUrl)}\"\n ${sortHtmx.target ? `hx-target=\"${escapeHtml(sortHtmx.target)}\"` : ''}\n ${sortHtmx.swap ? `hx-swap=\"${escapeHtml(sortHtmx.swap)}\"` : ''}\n >\n <span class=\"inline-flex items-center\">\n ${escapeHtml(col.header)}\n ${buildSortIndicator(col.sortDirection || null)}\n </span>\n </th>`;\n }\n\n return `<th\n class=\"${paddingClass} ${alignClass} font-semibold text-text-primary ${col.headerClass || ''}\"\n ${widthStyle}\n >\n ${escapeHtml(col.header)}\n </th>`;\n })\n .join('\\n');\n\n return `<thead class=\"bg-gray-50 border-b border-border\">\n <tr>\n ${selectAllCell}\n ${headerCells}\n </tr>\n </thead>`;\n}\n\n/**\n * Build table body\n */\nfunction buildTableBody<T extends Record<string, unknown>>(\n data: T[],\n columns: TableColumn<T>[],\n options: TableOptions<T>,\n): string {\n const {\n selectable,\n hoverable,\n striped,\n bordered,\n compact,\n selectHtmx,\n rowKey = 'id' as keyof T,\n onRowClick,\n } = options;\n\n const paddingClass = compact ? 'px-3 py-2' : 'px-4 py-3';\n\n if (data.length === 0) {\n const colspan = columns.length + (selectable ? 1 : 0);\n const emptyContent =\n options.emptyContent ||\n `\n <div class=\"text-center py-8\">\n <svg class=\"w-12 h-12 mx-auto text-gray-300 mb-4\" fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\">\n <path stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M20 13V6a2 2 0 00-2-2H6a2 2 0 00-2 2v7m16 0v5a2 2 0 01-2 2H6a2 2 0 01-2-2v-5m16 0h-2.586a1 1 0 00-.707.293l-2.414 2.414a1 1 0 01-.707.293h-3.172a1 1 0 01-.707-.293l-2.414-2.414A1 1 0 006.586 13H4\"/>\n </svg>\n <p class=\"text-text-secondary\">${options.emptyMessage || 'No data available'}</p>\n </div>\n `;\n\n return `<tbody>\n <tr>\n <td colspan=\"${colspan}\">${emptyContent}</td>\n </tr>\n </tbody>`;\n }\n\n const rows = data\n .map((row, rowIndex) => {\n const rowId = String(row[rowKey] || rowIndex);\n const rowClasses = [\n hoverable ? 'hover:bg-gray-50' : '',\n striped && rowIndex % 2 === 1 ? 'bg-gray-50/50' : '',\n bordered ? 'border-b border-border' : '',\n onRowClick ? 'cursor-pointer' : '',\n ]\n .filter(Boolean)\n .join(' ');\n\n const clickHandler = onRowClick\n ? `onclick=\"window.location.href='${escapeHtml(onRowClick.replace('{key}', rowId))}'\"`\n : '';\n\n const selectCell = selectable\n ? `<td class=\"${paddingClass}\" onclick=\"event.stopPropagation()\">\n <input\n type=\"checkbox\"\n class=\"w-4 h-4 rounded border-border text-primary focus:ring-primary/20\"\n name=\"selected[]\"\n value=\"${escapeHtml(rowId)}\"\n ${\n selectHtmx\n ? `\n hx-post=\"${escapeHtml(selectHtmx.post)}\"\n ${selectHtmx.target ? `hx-target=\"${escapeHtml(selectHtmx.target)}\"` : ''}\n hx-trigger=\"change\"\n `\n : ''\n }\n aria-label=\"Select row\"\n >\n </td>`\n : '';\n\n const cells = columns\n .map((col) => {\n const value = row[col.key];\n const alignClass = getAlignClasses(col.align);\n const cellContent = col.render ? col.render(value, row, rowIndex) : escapeHtml(String(value ?? ''));\n\n return `<td class=\"${paddingClass} ${alignClass} ${col.cellClass || ''}\">${cellContent}</td>`;\n })\n .join('\\n');\n\n return `<tr class=\"${rowClasses}\" ${clickHandler}>\n ${selectCell}\n ${cells}\n </tr>`;\n })\n .join('\\n');\n\n return `<tbody class=\"divide-y divide-border\">${rows}</tbody>`;\n}\n\n/**\n * Build loading overlay\n */\nfunction buildLoadingOverlay(): string {\n return `<div class=\"absolute inset-0 bg-white/70 flex items-center justify-center\">\n <svg class=\"animate-spin w-8 h-8 text-primary\" fill=\"none\" viewBox=\"0 0 24 24\">\n <circle class=\"opacity-25\" cx=\"12\" cy=\"12\" r=\"10\" stroke=\"currentColor\" stroke-width=\"4\"></circle>\n <path class=\"opacity-75\" fill=\"currentColor\" d=\"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z\"></path>\n </svg>\n </div>`;\n}\n\n/**\n * Build a data table\n */\nexport function table<T extends Record<string, unknown>>(data: T[], options: TableOptions<T>): string {\n const { id, bordered, stickyHeader, className = '', loading = false } = options;\n\n const tableClasses = ['w-full', bordered ? 'border border-border' : '', 'text-sm'].filter(Boolean).join(' ');\n\n const wrapperClasses = ['relative overflow-x-auto', stickyHeader ? 'max-h-96 overflow-y-auto' : '', className]\n .filter(Boolean)\n .join(' ');\n\n const idAttr = id ? `id=\"${escapeHtml(id)}\"` : '';\n\n const header = buildTableHeader(options.columns, options);\n const body = buildTableBody(data, options.columns, options);\n const loadingOverlay = loading ? buildLoadingOverlay() : '';\n\n return `<div class=\"${wrapperClasses}\" ${idAttr}>\n <table class=\"${tableClasses}\">\n ${header}\n ${body}\n </table>\n ${loadingOverlay}\n </div>`;\n}\n\n// ============================================\n// Pagination Component\n// ============================================\n\n/**\n * Pagination options\n */\nexport interface PaginationOptions {\n /** Current page (1-indexed) */\n page: number;\n /** Total pages */\n totalPages: number;\n /** Total items */\n totalItems?: number;\n /** Items per page */\n pageSize?: number;\n /** Show page size selector */\n showPageSize?: boolean;\n /** Page size options */\n pageSizeOptions?: number[];\n /** Additional CSS classes */\n className?: string;\n /** HTMX for page changes */\n htmx?: {\n get: string;\n target?: string;\n swap?: string;\n };\n}\n\n/**\n * Build pagination component\n */\nexport function pagination(options: PaginationOptions): string {\n const {\n page,\n totalPages,\n totalItems,\n pageSize = 10,\n showPageSize = false,\n pageSizeOptions = [10, 25, 50, 100],\n className = '',\n htmx,\n } = options;\n\n const buildPageLink = (pageNum: number, label: string, disabled: boolean, active: boolean) => {\n const baseClasses = 'px-3 py-2 text-sm rounded-lg transition-colors';\n const stateClasses = disabled\n ? 'text-gray-300 cursor-not-allowed'\n : active\n ? 'bg-primary text-white'\n : 'text-text-primary hover:bg-gray-100';\n\n if (disabled) {\n return `<span class=\"${baseClasses} ${stateClasses}\">${label}</span>`;\n }\n\n const pageUrl = htmx ? `${htmx.get}${htmx.get.includes('?') ? '&' : '?'}page=${pageNum}` : `?page=${pageNum}`;\n\n const htmxAttrs = htmx\n ? `hx-get=\"${escapeHtml(pageUrl)}\" ${htmx.target ? `hx-target=\"${escapeHtml(htmx.target)}\"` : ''} ${\n htmx.swap ? `hx-swap=\"${escapeHtml(htmx.swap)}\"` : ''\n }`\n : '';\n\n return `<a href=\"${escapeHtml(pageUrl)}\" class=\"${baseClasses} ${stateClasses}\" ${htmxAttrs}>${label}</a>`;\n };\n\n // Build page numbers\n const pageNumbers: number[] = [];\n const maxVisible = 5;\n\n if (totalPages <= maxVisible) {\n for (let i = 1; i <= totalPages; i++) {\n pageNumbers.push(i);\n }\n } else {\n pageNumbers.push(1);\n\n let start = Math.max(2, page - 1);\n let end = Math.min(totalPages - 1, page + 1);\n\n if (page <= 2) {\n end = 4;\n } else if (page >= totalPages - 1) {\n start = totalPages - 3;\n }\n\n if (start > 2) {\n pageNumbers.push(-1); // Ellipsis\n }\n\n for (let i = start; i <= end; i++) {\n pageNumbers.push(i);\n }\n\n if (end < totalPages - 1) {\n pageNumbers.push(-1); // Ellipsis\n }\n\n pageNumbers.push(totalPages);\n }\n\n const pagesHtml = pageNumbers\n .map((num) => {\n if (num === -1) {\n return '<span class=\"px-2 py-2 text-text-secondary\">...</span>';\n }\n return buildPageLink(num, String(num), false, num === page);\n })\n .join('\\n');\n\n const prevLink = buildPageLink(page - 1, '← Previous', page <= 1, false);\n const nextLink = buildPageLink(page + 1, 'Next →', page >= totalPages, false);\n\n const infoHtml =\n totalItems !== undefined\n ? `<span class=\"text-sm text-text-secondary\">\n Showing ${(page - 1) * pageSize + 1} to ${Math.min(page * pageSize, totalItems)} of ${totalItems} results\n </span>`\n : '';\n\n const pageSizeHtml = showPageSize\n ? `<select\n class=\"ml-4 px-2 py-1 text-sm border border-border rounded-lg bg-white\"\n onchange=\"window.location.href = '${htmx?.get || ''}?page=1&pageSize=' + this.value\"\n >\n ${pageSizeOptions\n .map((size) => `<option value=\"${size}\" ${size === pageSize ? 'selected' : ''}>${size} per page</option>`)\n .join('')}\n </select>`\n : '';\n\n return `<div class=\"flex items-center justify-between ${className}\">\n <div class=\"flex items-center\">\n ${infoHtml}\n ${pageSizeHtml}\n </div>\n <div class=\"flex items-center gap-1\">\n ${prevLink}\n ${pagesHtml}\n ${nextLink}\n </div>\n </div>`;\n}\n"]}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file table.schema.ts
|
|
3
|
+
* @description Zod schemas for Table and Pagination component options validation.
|
|
4
|
+
*
|
|
5
|
+
* Provides strict validation schemas for table options including columns,
|
|
6
|
+
* sorting, selection, and pagination with HTMX support.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { TableColumnSchema, TableOptionsSchema } from '@frontmcp/ui';
|
|
11
|
+
*
|
|
12
|
+
* const columnResult = TableColumnSchema.safeParse({
|
|
13
|
+
* key: 'name',
|
|
14
|
+
* header: 'Name',
|
|
15
|
+
* sortable: true,
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @module @frontmcp/ui/components/table.schema
|
|
20
|
+
*/
|
|
21
|
+
import { z } from 'zod';
|
|
22
|
+
/**
|
|
23
|
+
* Table column alignment schema
|
|
24
|
+
*/
|
|
25
|
+
export declare const TableAlignSchema: z.ZodEnum<{
|
|
26
|
+
center: "center";
|
|
27
|
+
left: "left";
|
|
28
|
+
right: "right";
|
|
29
|
+
}>;
|
|
30
|
+
/**
|
|
31
|
+
* Table column sort direction schema
|
|
32
|
+
*/
|
|
33
|
+
export declare const TableSortDirectionSchema: z.ZodNullable<z.ZodEnum<{
|
|
34
|
+
asc: "asc";
|
|
35
|
+
desc: "desc";
|
|
36
|
+
}>>;
|
|
37
|
+
/**
|
|
38
|
+
* Table column definition schema
|
|
39
|
+
* Note: render function cannot be validated by Zod, so we use z.any() for it
|
|
40
|
+
*/
|
|
41
|
+
export declare const TableColumnSchema: z.ZodObject<{
|
|
42
|
+
key: z.ZodString;
|
|
43
|
+
header: z.ZodString;
|
|
44
|
+
width: z.ZodOptional<z.ZodString>;
|
|
45
|
+
align: z.ZodOptional<z.ZodEnum<{
|
|
46
|
+
center: "center";
|
|
47
|
+
left: "left";
|
|
48
|
+
right: "right";
|
|
49
|
+
}>>;
|
|
50
|
+
sortable: z.ZodOptional<z.ZodBoolean>;
|
|
51
|
+
sortDirection: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
52
|
+
asc: "asc";
|
|
53
|
+
desc: "desc";
|
|
54
|
+
}>>>;
|
|
55
|
+
render: z.ZodOptional<z.ZodAny>;
|
|
56
|
+
headerClass: z.ZodOptional<z.ZodString>;
|
|
57
|
+
cellClass: z.ZodOptional<z.ZodString>;
|
|
58
|
+
}, z.core.$strict>;
|
|
59
|
+
/**
|
|
60
|
+
* Table column type
|
|
61
|
+
*/
|
|
62
|
+
export type TableColumn = z.infer<typeof TableColumnSchema>;
|
|
63
|
+
/**
|
|
64
|
+
* Sort HTMX options schema
|
|
65
|
+
*/
|
|
66
|
+
export declare const TableSortHtmxSchema: z.ZodOptional<z.ZodObject<{
|
|
67
|
+
get: z.ZodString;
|
|
68
|
+
target: z.ZodOptional<z.ZodString>;
|
|
69
|
+
swap: z.ZodOptional<z.ZodString>;
|
|
70
|
+
}, z.core.$strict>>;
|
|
71
|
+
/**
|
|
72
|
+
* Select HTMX options schema
|
|
73
|
+
*/
|
|
74
|
+
export declare const TableSelectHtmxSchema: z.ZodOptional<z.ZodObject<{
|
|
75
|
+
post: z.ZodString;
|
|
76
|
+
target: z.ZodOptional<z.ZodString>;
|
|
77
|
+
}, z.core.$strict>>;
|
|
78
|
+
/**
|
|
79
|
+
* Complete table options schema
|
|
80
|
+
*/
|
|
81
|
+
export declare const TableOptionsSchema: z.ZodObject<{
|
|
82
|
+
columns: z.ZodArray<z.ZodObject<{
|
|
83
|
+
key: z.ZodString;
|
|
84
|
+
header: z.ZodString;
|
|
85
|
+
width: z.ZodOptional<z.ZodString>;
|
|
86
|
+
align: z.ZodOptional<z.ZodEnum<{
|
|
87
|
+
center: "center";
|
|
88
|
+
left: "left";
|
|
89
|
+
right: "right";
|
|
90
|
+
}>>;
|
|
91
|
+
sortable: z.ZodOptional<z.ZodBoolean>;
|
|
92
|
+
sortDirection: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
93
|
+
asc: "asc";
|
|
94
|
+
desc: "desc";
|
|
95
|
+
}>>>;
|
|
96
|
+
render: z.ZodOptional<z.ZodAny>;
|
|
97
|
+
headerClass: z.ZodOptional<z.ZodString>;
|
|
98
|
+
cellClass: z.ZodOptional<z.ZodString>;
|
|
99
|
+
}, z.core.$strict>>;
|
|
100
|
+
id: z.ZodOptional<z.ZodString>;
|
|
101
|
+
selectable: z.ZodOptional<z.ZodBoolean>;
|
|
102
|
+
hoverable: z.ZodOptional<z.ZodBoolean>;
|
|
103
|
+
striped: z.ZodOptional<z.ZodBoolean>;
|
|
104
|
+
bordered: z.ZodOptional<z.ZodBoolean>;
|
|
105
|
+
compact: z.ZodOptional<z.ZodBoolean>;
|
|
106
|
+
stickyHeader: z.ZodOptional<z.ZodBoolean>;
|
|
107
|
+
className: z.ZodOptional<z.ZodString>;
|
|
108
|
+
emptyMessage: z.ZodOptional<z.ZodString>;
|
|
109
|
+
emptyContent: z.ZodOptional<z.ZodString>;
|
|
110
|
+
loading: z.ZodOptional<z.ZodBoolean>;
|
|
111
|
+
sortHtmx: z.ZodOptional<z.ZodObject<{
|
|
112
|
+
get: z.ZodString;
|
|
113
|
+
target: z.ZodOptional<z.ZodString>;
|
|
114
|
+
swap: z.ZodOptional<z.ZodString>;
|
|
115
|
+
}, z.core.$strict>>;
|
|
116
|
+
selectHtmx: z.ZodOptional<z.ZodObject<{
|
|
117
|
+
post: z.ZodString;
|
|
118
|
+
target: z.ZodOptional<z.ZodString>;
|
|
119
|
+
}, z.core.$strict>>;
|
|
120
|
+
rowKey: z.ZodOptional<z.ZodString>;
|
|
121
|
+
onRowClick: z.ZodOptional<z.ZodString>;
|
|
122
|
+
}, z.core.$strict>;
|
|
123
|
+
/**
|
|
124
|
+
* Table options type (derived from schema)
|
|
125
|
+
*/
|
|
126
|
+
export type TableOptions = z.infer<typeof TableOptionsSchema>;
|
|
127
|
+
/**
|
|
128
|
+
* Pagination HTMX options schema
|
|
129
|
+
*/
|
|
130
|
+
export declare const PaginationHtmxSchema: z.ZodOptional<z.ZodObject<{
|
|
131
|
+
get: z.ZodString;
|
|
132
|
+
target: z.ZodOptional<z.ZodString>;
|
|
133
|
+
swap: z.ZodOptional<z.ZodString>;
|
|
134
|
+
}, z.core.$strict>>;
|
|
135
|
+
/**
|
|
136
|
+
* Pagination options schema
|
|
137
|
+
*/
|
|
138
|
+
export declare const PaginationOptionsSchema: z.ZodObject<{
|
|
139
|
+
page: z.ZodNumber;
|
|
140
|
+
totalPages: z.ZodNumber;
|
|
141
|
+
totalItems: z.ZodOptional<z.ZodNumber>;
|
|
142
|
+
pageSize: z.ZodOptional<z.ZodNumber>;
|
|
143
|
+
pageSizeOptions: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
|
|
144
|
+
showFirstLast: z.ZodOptional<z.ZodBoolean>;
|
|
145
|
+
showPageCount: z.ZodOptional<z.ZodBoolean>;
|
|
146
|
+
showItemCount: z.ZodOptional<z.ZodBoolean>;
|
|
147
|
+
showPageSize: z.ZodOptional<z.ZodBoolean>;
|
|
148
|
+
maxVisiblePages: z.ZodOptional<z.ZodNumber>;
|
|
149
|
+
className: z.ZodOptional<z.ZodString>;
|
|
150
|
+
htmx: z.ZodOptional<z.ZodObject<{
|
|
151
|
+
get: z.ZodString;
|
|
152
|
+
target: z.ZodOptional<z.ZodString>;
|
|
153
|
+
swap: z.ZodOptional<z.ZodString>;
|
|
154
|
+
}, z.core.$strict>>;
|
|
155
|
+
}, z.core.$strict>;
|
|
156
|
+
/**
|
|
157
|
+
* Pagination options type
|
|
158
|
+
*/
|
|
159
|
+
export type PaginationOptions = z.infer<typeof PaginationOptionsSchema>;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file table.schema.ts
|
|
4
|
+
* @description Zod schemas for Table and Pagination component options validation.
|
|
5
|
+
*
|
|
6
|
+
* Provides strict validation schemas for table options including columns,
|
|
7
|
+
* sorting, selection, and pagination with HTMX support.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { TableColumnSchema, TableOptionsSchema } from '@frontmcp/ui';
|
|
12
|
+
*
|
|
13
|
+
* const columnResult = TableColumnSchema.safeParse({
|
|
14
|
+
* key: 'name',
|
|
15
|
+
* header: 'Name',
|
|
16
|
+
* sortable: true,
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @module @frontmcp/ui/components/table.schema
|
|
21
|
+
*/
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.PaginationOptionsSchema = exports.PaginationHtmxSchema = exports.TableOptionsSchema = exports.TableSelectHtmxSchema = exports.TableSortHtmxSchema = exports.TableColumnSchema = exports.TableSortDirectionSchema = exports.TableAlignSchema = void 0;
|
|
24
|
+
const zod_1 = require("zod");
|
|
25
|
+
// ============================================
|
|
26
|
+
// Column Schema
|
|
27
|
+
// ============================================
|
|
28
|
+
/**
|
|
29
|
+
* Table column alignment schema
|
|
30
|
+
*/
|
|
31
|
+
exports.TableAlignSchema = zod_1.z.enum(['left', 'center', 'right']);
|
|
32
|
+
/**
|
|
33
|
+
* Table column sort direction schema
|
|
34
|
+
*/
|
|
35
|
+
exports.TableSortDirectionSchema = zod_1.z.enum(['asc', 'desc']).nullable();
|
|
36
|
+
/**
|
|
37
|
+
* Table column definition schema
|
|
38
|
+
* Note: render function cannot be validated by Zod, so we use z.any() for it
|
|
39
|
+
*/
|
|
40
|
+
exports.TableColumnSchema = zod_1.z
|
|
41
|
+
.object({
|
|
42
|
+
/** Column key (property name) */
|
|
43
|
+
key: zod_1.z.string(),
|
|
44
|
+
/** Column header text */
|
|
45
|
+
header: zod_1.z.string(),
|
|
46
|
+
/** Column width (CSS value) */
|
|
47
|
+
width: zod_1.z.string().optional(),
|
|
48
|
+
/** Text alignment */
|
|
49
|
+
align: exports.TableAlignSchema.optional(),
|
|
50
|
+
/** Sortable column */
|
|
51
|
+
sortable: zod_1.z.boolean().optional(),
|
|
52
|
+
/** Current sort direction */
|
|
53
|
+
sortDirection: exports.TableSortDirectionSchema.optional(),
|
|
54
|
+
/** Custom cell renderer (function - cannot validate at runtime) */
|
|
55
|
+
render: zod_1.z.any().optional(),
|
|
56
|
+
/** Additional header CSS classes */
|
|
57
|
+
headerClass: zod_1.z.string().optional(),
|
|
58
|
+
/** Additional cell CSS classes */
|
|
59
|
+
cellClass: zod_1.z.string().optional(),
|
|
60
|
+
})
|
|
61
|
+
.strict();
|
|
62
|
+
// ============================================
|
|
63
|
+
// HTMX Schemas
|
|
64
|
+
// ============================================
|
|
65
|
+
/**
|
|
66
|
+
* Sort HTMX options schema
|
|
67
|
+
*/
|
|
68
|
+
exports.TableSortHtmxSchema = zod_1.z
|
|
69
|
+
.object({
|
|
70
|
+
get: zod_1.z.string(),
|
|
71
|
+
target: zod_1.z.string().optional(),
|
|
72
|
+
swap: zod_1.z.string().optional(),
|
|
73
|
+
})
|
|
74
|
+
.strict()
|
|
75
|
+
.optional();
|
|
76
|
+
/**
|
|
77
|
+
* Select HTMX options schema
|
|
78
|
+
*/
|
|
79
|
+
exports.TableSelectHtmxSchema = zod_1.z
|
|
80
|
+
.object({
|
|
81
|
+
post: zod_1.z.string(),
|
|
82
|
+
target: zod_1.z.string().optional(),
|
|
83
|
+
})
|
|
84
|
+
.strict()
|
|
85
|
+
.optional();
|
|
86
|
+
// ============================================
|
|
87
|
+
// Table Options Schema
|
|
88
|
+
// ============================================
|
|
89
|
+
/**
|
|
90
|
+
* Complete table options schema
|
|
91
|
+
*/
|
|
92
|
+
exports.TableOptionsSchema = zod_1.z
|
|
93
|
+
.object({
|
|
94
|
+
/** Column definitions */
|
|
95
|
+
columns: zod_1.z.array(exports.TableColumnSchema),
|
|
96
|
+
/** Table ID */
|
|
97
|
+
id: zod_1.z.string().optional(),
|
|
98
|
+
/** Show row selection checkboxes */
|
|
99
|
+
selectable: zod_1.z.boolean().optional(),
|
|
100
|
+
/** Row hover effect */
|
|
101
|
+
hoverable: zod_1.z.boolean().optional(),
|
|
102
|
+
/** Striped rows */
|
|
103
|
+
striped: zod_1.z.boolean().optional(),
|
|
104
|
+
/** Bordered cells */
|
|
105
|
+
bordered: zod_1.z.boolean().optional(),
|
|
106
|
+
/** Compact size */
|
|
107
|
+
compact: zod_1.z.boolean().optional(),
|
|
108
|
+
/** Fixed header (sticky) */
|
|
109
|
+
stickyHeader: zod_1.z.boolean().optional(),
|
|
110
|
+
/** Additional CSS classes */
|
|
111
|
+
className: zod_1.z.string().optional(),
|
|
112
|
+
/** Empty state message */
|
|
113
|
+
emptyMessage: zod_1.z.string().optional(),
|
|
114
|
+
/** Empty state HTML */
|
|
115
|
+
emptyContent: zod_1.z.string().optional(),
|
|
116
|
+
/** Loading state */
|
|
117
|
+
loading: zod_1.z.boolean().optional(),
|
|
118
|
+
/** HTMX for sorting */
|
|
119
|
+
sortHtmx: exports.TableSortHtmxSchema,
|
|
120
|
+
/** HTMX for selection */
|
|
121
|
+
selectHtmx: exports.TableSelectHtmxSchema,
|
|
122
|
+
/** Row key property for selection */
|
|
123
|
+
rowKey: zod_1.z.string().optional(),
|
|
124
|
+
/** Row click handler (URL template with {key}) */
|
|
125
|
+
onRowClick: zod_1.z.string().optional(),
|
|
126
|
+
})
|
|
127
|
+
.strict();
|
|
128
|
+
// ============================================
|
|
129
|
+
// Pagination Schema
|
|
130
|
+
// ============================================
|
|
131
|
+
/**
|
|
132
|
+
* Pagination HTMX options schema
|
|
133
|
+
*/
|
|
134
|
+
exports.PaginationHtmxSchema = zod_1.z
|
|
135
|
+
.object({
|
|
136
|
+
get: zod_1.z.string(),
|
|
137
|
+
target: zod_1.z.string().optional(),
|
|
138
|
+
swap: zod_1.z.string().optional(),
|
|
139
|
+
})
|
|
140
|
+
.strict()
|
|
141
|
+
.optional();
|
|
142
|
+
/**
|
|
143
|
+
* Pagination options schema
|
|
144
|
+
*/
|
|
145
|
+
exports.PaginationOptionsSchema = zod_1.z
|
|
146
|
+
.object({
|
|
147
|
+
/** Current page (1-indexed) */
|
|
148
|
+
page: zod_1.z.number().min(1),
|
|
149
|
+
/** Total pages */
|
|
150
|
+
totalPages: zod_1.z.number().min(0),
|
|
151
|
+
/** Total items count */
|
|
152
|
+
totalItems: zod_1.z.number().min(0).optional(),
|
|
153
|
+
/** Items per page */
|
|
154
|
+
pageSize: zod_1.z.number().min(1).optional(),
|
|
155
|
+
/** Page size options */
|
|
156
|
+
pageSizeOptions: zod_1.z.array(zod_1.z.number()).optional(),
|
|
157
|
+
/** Show first/last buttons */
|
|
158
|
+
showFirstLast: zod_1.z.boolean().optional(),
|
|
159
|
+
/** Show page count */
|
|
160
|
+
showPageCount: zod_1.z.boolean().optional(),
|
|
161
|
+
/** Show item count */
|
|
162
|
+
showItemCount: zod_1.z.boolean().optional(),
|
|
163
|
+
/** Show page size selector */
|
|
164
|
+
showPageSize: zod_1.z.boolean().optional(),
|
|
165
|
+
/** Max visible page buttons */
|
|
166
|
+
maxVisiblePages: zod_1.z.number().min(1).optional(),
|
|
167
|
+
/** Additional CSS classes */
|
|
168
|
+
className: zod_1.z.string().optional(),
|
|
169
|
+
/** HTMX for page navigation */
|
|
170
|
+
htmx: exports.PaginationHtmxSchema,
|
|
171
|
+
})
|
|
172
|
+
.strict();
|
|
173
|
+
//# sourceMappingURL=table.schema.js.map
|