@limetech/lime-elements 38.38.1-dev.2 → 38.39.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/CHANGELOG.md +5 -5
- package/dist/cjs/config-e7e1a299.js.map +1 -1
- package/dist/cjs/image-resize-99e16554.js +310 -0
- package/dist/cjs/image-resize-99e16554.js.map +1 -0
- package/dist/cjs/index.cjs.js +13 -0
- package/dist/cjs/index.cjs.js.map +1 -1
- package/dist/cjs/layout-8550b993.js +20 -0
- package/dist/cjs/layout-8550b993.js.map +1 -0
- package/dist/cjs/lime-elements.cjs.js +1 -1
- package/dist/cjs/limel-breadcrumbs_7.cjs.entry.js +2 -1
- package/dist/cjs/limel-breadcrumbs_7.cjs.entry.js.map +1 -1
- package/dist/cjs/limel-profile-picture.cjs.entry.js +2 -306
- package/dist/cjs/limel-profile-picture.cjs.entry.js.map +1 -1
- package/dist/cjs/limel-prosemirror-adapter.cjs.entry.js +44 -89
- package/dist/cjs/limel-prosemirror-adapter.cjs.entry.js.map +1 -1
- package/dist/cjs/limel-table.cjs.entry.js +2 -16
- package/dist/cjs/limel-table.cjs.entry.js.map +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/types-cc3c7cea.js +54 -0
- package/dist/cjs/types-cc3c7cea.js.map +1 -0
- package/dist/collection/components/chart/chart.css +87 -0
- package/dist/collection/components/dock/dock.css +93 -0
- package/dist/collection/components/file-viewer/file-viewer.css +93 -0
- package/dist/collection/components/input-field/input-field.css +93 -0
- package/dist/collection/components/list/list.css +12 -0
- package/dist/collection/components/menu/menu.js +19 -1
- package/dist/collection/components/menu/menu.js.map +1 -1
- package/dist/collection/components/menu-list/menu-list.css +12 -0
- package/dist/collection/components/progress-flow/progress-flow-item/progress-flow-item.css +6 -0
- package/dist/collection/components/select/select.css +6 -0
- package/dist/collection/components/slider/slider.css +6 -0
- package/dist/collection/components/table/layout.js +1 -1
- package/dist/collection/components/table/layout.js.map +1 -1
- package/dist/collection/components/table/table.js +2 -2
- package/dist/collection/components/table/table.js.map +1 -1
- package/dist/collection/components/text-editor/prosemirror-adapter/menu/types.js.map +1 -1
- package/dist/collection/components/text-editor/types.js.map +1 -1
- package/dist/collection/global/config.js.map +1 -1
- package/dist/collection/index.js.map +1 -1
- package/dist/collection/interface.js +11 -0
- package/dist/collection/interface.js.map +1 -1
- package/dist/esm/config-656a588f.js.map +1 -1
- package/dist/esm/image-resize-1ea8337d.js +308 -0
- package/dist/esm/image-resize-1ea8337d.js.map +1 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/layout-5da21bb6.js +18 -0
- package/dist/esm/layout-5da21bb6.js.map +1 -0
- package/dist/esm/lime-elements.js +1 -1
- package/dist/esm/limel-breadcrumbs_7.entry.js +2 -1
- package/dist/esm/limel-breadcrumbs_7.entry.js.map +1 -1
- package/dist/esm/limel-profile-picture.entry.js +1 -305
- package/dist/esm/limel-profile-picture.entry.js.map +1 -1
- package/dist/esm/limel-prosemirror-adapter.entry.js +1 -46
- package/dist/esm/limel-prosemirror-adapter.entry.js.map +1 -1
- package/dist/esm/limel-table.entry.js +2 -16
- package/dist/esm/limel-table.entry.js.map +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/esm/types-7dea7a78.js +49 -0
- package/dist/esm/types-7dea7a78.js.map +1 -0
- package/dist/lime-elements/index.esm.js +1 -1
- package/dist/lime-elements/index.esm.js.map +1 -1
- package/dist/lime-elements/lime-elements.esm.js +1 -1
- package/dist/lime-elements/lime-elements.esm.js.map +1 -1
- package/dist/lime-elements/{p-56c9bb65.entry.js → p-19a9b96b.entry.js} +2 -2
- package/dist/lime-elements/p-19a9b96b.entry.js.map +1 -0
- package/dist/lime-elements/p-2bd3f381.entry.js +2 -0
- package/dist/lime-elements/p-2bd3f381.entry.js.map +1 -0
- package/dist/lime-elements/p-2c35fb9d.js.map +1 -1
- package/dist/lime-elements/p-9f223e57.js +2 -0
- package/dist/lime-elements/p-9f223e57.js.map +1 -0
- package/dist/lime-elements/p-b11e7718.entry.js +2 -0
- package/dist/lime-elements/p-b11e7718.entry.js.map +1 -0
- package/dist/lime-elements/p-d4bc7848.js +2 -0
- package/dist/lime-elements/p-d4bc7848.js.map +1 -0
- package/dist/lime-elements/p-e3c87b69.entry.js +2 -0
- package/dist/lime-elements/p-e3c87b69.entry.js.map +1 -0
- package/dist/lime-elements/p-ed67677d.js +2 -0
- package/dist/lime-elements/p-ed67677d.js.map +1 -0
- package/dist/types/components/form/help/help.d.ts +1 -1
- package/dist/types/components/menu/menu.d.ts +4 -0
- package/dist/types/components/table/layout.d.ts +1 -1
- package/dist/types/components/text-editor/types.d.ts +0 -8
- package/dist/types/components.d.ts +8 -0
- package/dist/types/global/config.d.ts +1 -8
- package/dist/types/index.d.ts +3 -0
- package/dist/types/interface.d.ts +13 -2
- package/package.json +2 -5
- package/dist/lime-elements/p-354c2d16.entry.js +0 -2
- package/dist/lime-elements/p-354c2d16.entry.js.map +0 -1
- package/dist/lime-elements/p-56c9bb65.entry.js.map +0 -1
- package/dist/lime-elements/p-9e225545.entry.js +0 -2
- package/dist/lime-elements/p-9e225545.entry.js.map +0 -1
- package/dist/lime-elements/p-f6d8811f.entry.js +0 -2
- package/dist/lime-elements/p-f6d8811f.entry.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
## [38.
|
|
1
|
+
## [38.39.0](https://github.com/Lundalogik/lime-elements/compare/v38.38.1...v38.39.0) (2026-01-22)
|
|
2
2
|
|
|
3
|
-
###
|
|
3
|
+
### Features
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
*
|
|
6
|
+
* **menu:** add `searchPlaceholder` prop ([a61dd4e](https://github.com/Lundalogik/lime-elements/commit/a61dd4e768a313f9d3d6a97e11e3353d826de6c8))
|
|
7
7
|
|
|
8
|
-
## [38.38.1
|
|
8
|
+
## [38.38.1](https://github.com/Lundalogik/lime-elements/compare/v38.38.0...v38.38.1) (2026-01-16)
|
|
9
9
|
|
|
10
10
|
### Bug Fixes
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
*
|
|
13
|
+
* **package.json:** remove unnecessary `engines.node: >=22` restriction ([143f4e9](https://github.com/Lundalogik/lime-elements/commit/143f4e9e6526b16d6fae2e2b181412ced969d701))
|
|
14
14
|
|
|
15
15
|
## [38.38.0](https://github.com/Lundalogik/lime-elements/compare/v38.37.1...v38.38.0) (2026-01-15)
|
|
16
16
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"file":"config-e7e1a299.js","mappings":";;AAgCA,MAAM,WAAW;EAAjB;IACW,aAAQ,GAAG,EAAE,CAAC;IACd,kBAAa,GAAG,SAAS,CAAC,QAAQ,CAAC;IAEnC,oBAAe,GAAQ,kBAAkB,CAAC,YAAY,CAAC,CAAC;GAClE;CAAA;AAED,SAAS,kBAAkB,CAAC,OAAgB;EACxC,MAAM,QAAQ,GAAG,EAAE,CAAC;EACpB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;IACrC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAC3B,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAEnC,IAAI,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;MACpC,SAAS;KACZ;IAED,QAAQ,CAAC,GAAG,CAAC,GAAG,KAAK,KAAK,MAAM,CAAC;GACpC;EAED,OAAO,QAAQ,CAAC;AACpB,CAAC;AAED,MAAM,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;MACpB,YAAY,
|
|
1
|
+
{"file":"config-e7e1a299.js","mappings":";;AAgCA,MAAM,WAAW;EAAjB;IACW,aAAQ,GAAG,EAAE,CAAC;IACd,kBAAa,GAAG,SAAS,CAAC,QAAQ,CAAC;IAEnC,oBAAe,GAAQ,kBAAkB,CAAC,YAAY,CAAC,CAAC;GAClE;CAAA;AAED,SAAS,kBAAkB,CAAC,OAAgB;EACxC,MAAM,QAAQ,GAAG,EAAE,CAAC;EACpB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;IACrC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAC3B,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAEnC,IAAI,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;MACpC,SAAS;KACZ;IAED,QAAQ,CAAC,GAAG,CAAC,GAAG,KAAK,KAAK,MAAM,CAAC;GACpC;EAED,OAAO,QAAQ,CAAC;AACpB,CAAC;AAED,MAAM,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;MACpB,YAAY,GAAW,CAAC;EACjC,OAAO,MAAM,CAAC;AAClB,CAAC;;;;","names":[],"sources":["./src/global/config.ts"],"sourcesContent":["import { CustomElementDefinition } from './shared-types/custom-element.types';\n\n/**\n * Configuration options for limel-config.\n *\n * @public\n */\nexport type Config = {\n /**\n * The path to where the icon library used by limel-icon is located.\n */\n iconPath?: string;\n\n /**\n * The default locale to use for components that support localization.\n */\n defaultLocale?: string;\n\n /**\n * Whitelisted html elements for `limel-markdown`.\n *\n * Any custom element added here will not be sanitized and thus rendered.\n * @alpha\n */\n markdownWhitelist?: CustomElementDefinition[];\n\n /**\n * @internal\n */\n featureSwitches?: Record<string, boolean>;\n};\n\nclass ConfigClass implements Config {\n public iconPath = '';\n public defaultLocale = navigator.language;\n public markdownWhitelist?: CustomElementDefinition[];\n public featureSwitches: any = getFeatureSwitches(localStorage);\n}\n\nfunction getFeatureSwitches(storage: Storage) {\n const features = {};\n for (let i = 0; i < storage.length; i++) {\n const key = storage.key(i);\n const value = storage.getItem(key);\n\n if (!['true', 'false'].includes(value)) {\n continue;\n }\n\n features[key] = value === 'true';\n }\n\n return features;\n}\n\nconst config = new ConfigClass();\nexport const globalConfig: Config = (() => {\n return config;\n})();\n"],"version":3}
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Image resize utilities
|
|
5
|
+
*
|
|
6
|
+
* Overview
|
|
7
|
+
* --------
|
|
8
|
+
* This module provides a small, dependency-free utility to resize images on the client
|
|
9
|
+
* (in the browser) before uploading. It works by decoding an input `File` to an
|
|
10
|
+
* `ImageBitmap` (or falling back to an `HTMLImageElement`), drawing it onto a
|
|
11
|
+
* `Canvas`/`OffscreenCanvas` with the requested strategy (cover/contain), and
|
|
12
|
+
* then exporting the result to a new `File` with your preferred MIME type and
|
|
13
|
+
* quality.
|
|
14
|
+
*
|
|
15
|
+
* Why resize client-side?
|
|
16
|
+
* - Faster perceived uploads and lower bandwidth usage
|
|
17
|
+
* - Consistent avatar sizes and formats (e.g., JPEG 400x400)
|
|
18
|
+
* - No server-side transformation required for common cases
|
|
19
|
+
*
|
|
20
|
+
* Fit strategies
|
|
21
|
+
* - `cover` (default): The image is scaled to cover the target rectangle, and
|
|
22
|
+
* the excess parts are center-cropped. Good for avatars.
|
|
23
|
+
* - `contain`: The image is scaled to fit entirely within the target rectangle
|
|
24
|
+
* without cropping, letterboxing if needed. Good when you must preserve the
|
|
25
|
+
* entire image.
|
|
26
|
+
*
|
|
27
|
+
* Decoding & EXIF orientation
|
|
28
|
+
* EXIF orientation is a piece of metadata stored inside image files
|
|
29
|
+
* (usually JPEGs) that tells image renderer software how the image should be displayed
|
|
30
|
+
* i.e., whether it should be rotated or flipped. This meta data is normally added
|
|
31
|
+
* to photos by digital cameras and phones.
|
|
32
|
+
* - When available, `createImageBitmap(file, { imageOrientation: 'from-image' })`
|
|
33
|
+
* is used to automatically respect EXIF orientation.
|
|
34
|
+
* - If not available or it fails (e.g., unsupported format), we fall back to
|
|
35
|
+
* decoding via an `HTMLImageElement`.
|
|
36
|
+
*
|
|
37
|
+
* OffscreenCanvas
|
|
38
|
+
* - If the environment supports `OffscreenCanvas`, it will be used for the draw
|
|
39
|
+
* and encode operations for better performance in some cases. Otherwise, a
|
|
40
|
+
* regular `HTMLCanvasElement` is used.
|
|
41
|
+
*
|
|
42
|
+
* HEIC/HEIF notes
|
|
43
|
+
* - All major browsers except Safari lack native HEIC/HEIF decoding.
|
|
44
|
+
* In such cases the `resizeImage` function will throw when decoding fails.
|
|
45
|
+
* The caller should catch and fall back
|
|
46
|
+
* to using the original file or handle conversion on the server.
|
|
47
|
+
* - If we need guaranteed client-side HEIC->JPEG conversion, we must add a small
|
|
48
|
+
* library or WASM module; this utility intentionally avoids extra dependencies.
|
|
49
|
+
*
|
|
50
|
+
* Output type & quality
|
|
51
|
+
* - Default output is `image/jpeg` with `quality=0.85`, which is typically
|
|
52
|
+
* appropriate for avatars. You can switch to `image/png` to preserve
|
|
53
|
+
* transparency.
|
|
54
|
+
* - The output filename extension is adjusted to match the chosen MIME type by
|
|
55
|
+
* default (e.g., `.jpg` or `.png`). You can override naming via the `rename`
|
|
56
|
+
* option.
|
|
57
|
+
*
|
|
58
|
+
* Error handling
|
|
59
|
+
* - Throws if canvas/context cannot be created or if canvas->blob conversion fails.
|
|
60
|
+
* - Decoding failures (unsupported type) will throw; caller can try/catch and
|
|
61
|
+
* fall back to the original file.
|
|
62
|
+
*
|
|
63
|
+
* Performance tips
|
|
64
|
+
* - Keep target sizes reasonable (e.g., 256–1024 px) to avoid long processing
|
|
65
|
+
* times on modest devices.
|
|
66
|
+
* - JPEG with quality 0.8–0.9 often strikes a good balance between size and
|
|
67
|
+
* perceived quality for photos/avatars.
|
|
68
|
+
*
|
|
69
|
+
* Usage examples
|
|
70
|
+
* --------------
|
|
71
|
+
* Basic usage:
|
|
72
|
+
* ```ts
|
|
73
|
+
* import { resizeImage } from '@limetech/lime-elements/util/image-resize';
|
|
74
|
+
*
|
|
75
|
+
* const processed = await resizeImage(file, {
|
|
76
|
+
* width: 400,
|
|
77
|
+
* height: 400,
|
|
78
|
+
* fit: 'cover', // default; center-crops
|
|
79
|
+
* type: 'image/jpeg', // default
|
|
80
|
+
* quality: 0.85, // default
|
|
81
|
+
* });
|
|
82
|
+
* // Upload `processed` instead of the original file
|
|
83
|
+
* ```
|
|
84
|
+
*
|
|
85
|
+
* With custom naming:
|
|
86
|
+
* ```ts
|
|
87
|
+
* const processed = await resizeImage(file, {
|
|
88
|
+
* width: 800,
|
|
89
|
+
* height: 800,
|
|
90
|
+
* fit: 'contain',
|
|
91
|
+
* type: 'image/png',
|
|
92
|
+
* rename: (name) => name.replace(/\.[^.]+$/, '') + '_resized.png',
|
|
93
|
+
* });
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* In a Stencil component (simplified):
|
|
97
|
+
* ```tsx
|
|
98
|
+
* private async handleFilesSelected(file: File) {
|
|
99
|
+
* try {
|
|
100
|
+
* const resized = await resizeImage(file, { width: 400, height: 400 });
|
|
101
|
+
* // build your FileInfo and emit
|
|
102
|
+
* } catch {
|
|
103
|
+
* // fall back to original
|
|
104
|
+
* }
|
|
105
|
+
* }
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
// (Removed exported ResizeFit to avoid forcing a public symbol.)
|
|
109
|
+
/**
|
|
110
|
+
* Resize an image file on the client using Canvas/OffscreenCanvas.
|
|
111
|
+
* Returns a new File with the requested format and dimensions.
|
|
112
|
+
*
|
|
113
|
+
* Contract
|
|
114
|
+
* - Input: image `File`
|
|
115
|
+
* - Output: resized image as a new `File` with updated `type`, name, and size
|
|
116
|
+
* - Errors: may throw on decode failure or canvas export failure
|
|
117
|
+
*
|
|
118
|
+
* @beta
|
|
119
|
+
* @param file - The image file to resize.
|
|
120
|
+
* @param options - Configuration for the resize operation.
|
|
121
|
+
*/
|
|
122
|
+
async function resizeImage(file, options) {
|
|
123
|
+
const { width, height, fit = 'cover', type = 'image/jpeg', quality = 0.85, rename = (name) => renameWithType(name, type), } = options;
|
|
124
|
+
const source = await loadSource(file);
|
|
125
|
+
const { sx, sy, sw, sh, dx, dy, dw, dh } = computeRects(source.width, source.height, width, height, fit);
|
|
126
|
+
const canvas = createCanvas(width, height);
|
|
127
|
+
const ctx = get2dContext(canvas);
|
|
128
|
+
ctx.clearRect(0, 0, width, height);
|
|
129
|
+
ctx.drawImage(source, sx, sy, sw, sh, dx, dy, dw, dh);
|
|
130
|
+
const blob = await canvasToBlob(canvas, type, quality);
|
|
131
|
+
const name = rename(file.name);
|
|
132
|
+
return new File([blob], name, { type });
|
|
133
|
+
}
|
|
134
|
+
/** Whether OffscreenCanvas is available in the current environment. */
|
|
135
|
+
function supportsOffscreen() {
|
|
136
|
+
try {
|
|
137
|
+
return typeof globalThis.OffscreenCanvas === 'function';
|
|
138
|
+
}
|
|
139
|
+
catch (_a) {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Create either an OffscreenCanvas or a regular canvas for drawing.
|
|
145
|
+
* @param width - Target width
|
|
146
|
+
* @param height - Target height
|
|
147
|
+
*/
|
|
148
|
+
function createCanvas(width, height) {
|
|
149
|
+
if (supportsOffscreen()) {
|
|
150
|
+
return new globalThis.OffscreenCanvas(width, height);
|
|
151
|
+
}
|
|
152
|
+
const canvas = document.createElement('canvas');
|
|
153
|
+
canvas.width = width;
|
|
154
|
+
canvas.height = height;
|
|
155
|
+
return canvas;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Get the 2D rendering context, throwing a descriptive error if unavailable.
|
|
159
|
+
* @param canvas - The canvas to get context from
|
|
160
|
+
*/
|
|
161
|
+
function get2dContext(canvas) {
|
|
162
|
+
const ctx = canvas.getContext('2d', { alpha: true });
|
|
163
|
+
if (!ctx) {
|
|
164
|
+
throw new Error('2D canvas context not available');
|
|
165
|
+
}
|
|
166
|
+
return ctx;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Convert the canvas content to a Blob, supporting both canvas types.
|
|
170
|
+
* @param canvas - The source canvas
|
|
171
|
+
* @param type - Output MIME type
|
|
172
|
+
* @param quality - JPEG quality (0..1)
|
|
173
|
+
*/
|
|
174
|
+
function canvasToBlob(canvas, type, quality) {
|
|
175
|
+
if ('convertToBlob' in canvas) {
|
|
176
|
+
return canvas.convertToBlob({ type, quality });
|
|
177
|
+
}
|
|
178
|
+
return new Promise((resolve, reject) => {
|
|
179
|
+
canvas.toBlob((blob) => {
|
|
180
|
+
if (!blob) {
|
|
181
|
+
reject(new Error('Failed to create blob from canvas'));
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
resolve(blob);
|
|
185
|
+
}, type, quality);
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Load the image into a decodable source (ImageBitmap preferred).
|
|
190
|
+
* @param file - The input file to decode
|
|
191
|
+
*/
|
|
192
|
+
async function loadSource(file) {
|
|
193
|
+
var _a, _b;
|
|
194
|
+
if (typeof globalThis.createImageBitmap === 'function') {
|
|
195
|
+
try {
|
|
196
|
+
return await globalThis.createImageBitmap(file, {
|
|
197
|
+
imageOrientation: 'from-image',
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
// Log for debugging in development, but continue with fallback
|
|
202
|
+
const isDev = ((_b = (_a = globalThis.process) === null || _a === void 0 ? void 0 : _a.env) === null || _b === void 0 ? void 0 : _b.NODE_ENV) !== 'production';
|
|
203
|
+
if (isDev &&
|
|
204
|
+
typeof console !== 'undefined' &&
|
|
205
|
+
typeof console.debug === 'function') {
|
|
206
|
+
console.debug('createImageBitmap failed, falling back to HTMLImageElement:', error);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return await loadImageElement(file);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Decode an image file via HTMLImageElement when ImageBitmap is unavailable.
|
|
214
|
+
* @param file - The input file to decode
|
|
215
|
+
*/
|
|
216
|
+
async function loadImageElement(file) {
|
|
217
|
+
var _a;
|
|
218
|
+
const url = URL.createObjectURL(file);
|
|
219
|
+
try {
|
|
220
|
+
const img = new Image();
|
|
221
|
+
img.decoding = 'sync';
|
|
222
|
+
img.src = url;
|
|
223
|
+
await ((_a = img.decode) === null || _a === void 0 ? void 0 : _a.call(img).catch(() => undefined));
|
|
224
|
+
if (!img.complete) {
|
|
225
|
+
await new Promise((resolve, reject) => {
|
|
226
|
+
const cleanup = () => {
|
|
227
|
+
img.removeEventListener('load', onLoad);
|
|
228
|
+
img.removeEventListener('error', onError);
|
|
229
|
+
};
|
|
230
|
+
const onLoad = () => {
|
|
231
|
+
cleanup();
|
|
232
|
+
resolve();
|
|
233
|
+
};
|
|
234
|
+
const onError = (e) => {
|
|
235
|
+
cleanup();
|
|
236
|
+
reject(e);
|
|
237
|
+
};
|
|
238
|
+
img.addEventListener('load', onLoad);
|
|
239
|
+
img.addEventListener('error', onError);
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
return img;
|
|
243
|
+
}
|
|
244
|
+
finally {
|
|
245
|
+
URL.revokeObjectURL(url);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Compute source and destination rectangles for drawImage based on the fit mode.
|
|
250
|
+
*
|
|
251
|
+
* Returns sx, sy, sw, sh for the source crop/area and dx, dy, dw, dh for the
|
|
252
|
+
* destination rectangle on the target canvas.
|
|
253
|
+
*
|
|
254
|
+
* @param sw - Source width
|
|
255
|
+
* @param sh - Source height
|
|
256
|
+
* @param tw - Target width
|
|
257
|
+
* @param th - Target height
|
|
258
|
+
* @param fit - Fit mode (cover/contain)
|
|
259
|
+
*/
|
|
260
|
+
function computeRects(sw, sh, tw, th, fit) {
|
|
261
|
+
const sRatio = sw / sh;
|
|
262
|
+
const tRatio = tw / th;
|
|
263
|
+
if (fit === 'cover') {
|
|
264
|
+
// scale source to cover target, then center-crop
|
|
265
|
+
let cropW;
|
|
266
|
+
let cropH;
|
|
267
|
+
if (sRatio > tRatio) {
|
|
268
|
+
// source is wider than target: crop width
|
|
269
|
+
cropH = sh;
|
|
270
|
+
cropW = sh * tRatio;
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
// source is taller than target: crop height
|
|
274
|
+
cropW = sw;
|
|
275
|
+
cropH = sw / tRatio;
|
|
276
|
+
}
|
|
277
|
+
const sx = (sw - cropW) / 2;
|
|
278
|
+
const sy = (sh - cropH) / 2;
|
|
279
|
+
return { sx, sy, sw: cropW, sh: cropH, dx: 0, dy: 0, dw: tw, dh: th };
|
|
280
|
+
}
|
|
281
|
+
// contain: fit inside, letterbox if needed
|
|
282
|
+
let drawW;
|
|
283
|
+
let drawH;
|
|
284
|
+
if (sRatio > tRatio) {
|
|
285
|
+
drawW = tw;
|
|
286
|
+
drawH = tw / sRatio;
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
drawH = th;
|
|
290
|
+
drawW = th * sRatio;
|
|
291
|
+
}
|
|
292
|
+
const dx = (tw - drawW) / 2;
|
|
293
|
+
const dy = (th - drawH) / 2;
|
|
294
|
+
return { sx: 0, sy: 0, sw, sh, dx, dy, dw: drawW, dh: drawH };
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Update filename extension to match the desired MIME type.
|
|
298
|
+
* @param name - Original filename
|
|
299
|
+
* @param type - Output MIME type
|
|
300
|
+
*/
|
|
301
|
+
function renameWithType(name, type) {
|
|
302
|
+
const ext = type === 'image/png' ? 'png' : 'jpg';
|
|
303
|
+
const idx = name.lastIndexOf('.');
|
|
304
|
+
const base = idx > 0 ? name.slice(0, idx) : name;
|
|
305
|
+
return `${base}.${ext}`;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
exports.resizeImage = resizeImage;
|
|
309
|
+
|
|
310
|
+
//# sourceMappingURL=image-resize-99e16554.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"file":"image-resize-99e16554.js","mappings":"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","names":[],"sources":["./src/util/image-resize.ts"],"sourcesContent":["/**\n * Image resize utilities\n *\n * Overview\n * --------\n * This module provides a small, dependency-free utility to resize images on the client\n * (in the browser) before uploading. It works by decoding an input `File` to an\n * `ImageBitmap` (or falling back to an `HTMLImageElement`), drawing it onto a\n * `Canvas`/`OffscreenCanvas` with the requested strategy (cover/contain), and\n * then exporting the result to a new `File` with your preferred MIME type and\n * quality.\n *\n * Why resize client-side?\n * - Faster perceived uploads and lower bandwidth usage\n * - Consistent avatar sizes and formats (e.g., JPEG 400x400)\n * - No server-side transformation required for common cases\n *\n * Fit strategies\n * - `cover` (default): The image is scaled to cover the target rectangle, and\n * the excess parts are center-cropped. Good for avatars.\n * - `contain`: The image is scaled to fit entirely within the target rectangle\n * without cropping, letterboxing if needed. Good when you must preserve the\n * entire image.\n *\n * Decoding & EXIF orientation\n * EXIF orientation is a piece of metadata stored inside image files\n * (usually JPEGs) that tells image renderer software how the image should be displayed\n * i.e., whether it should be rotated or flipped. This meta data is normally added\n * to photos by digital cameras and phones.\n * - When available, `createImageBitmap(file, { imageOrientation: 'from-image' })`\n * is used to automatically respect EXIF orientation.\n * - If not available or it fails (e.g., unsupported format), we fall back to\n * decoding via an `HTMLImageElement`.\n *\n * OffscreenCanvas\n * - If the environment supports `OffscreenCanvas`, it will be used for the draw\n * and encode operations for better performance in some cases. Otherwise, a\n * regular `HTMLCanvasElement` is used.\n *\n * HEIC/HEIF notes\n * - All major browsers except Safari lack native HEIC/HEIF decoding.\n * In such cases the `resizeImage` function will throw when decoding fails.\n * The caller should catch and fall back\n * to using the original file or handle conversion on the server.\n * - If we need guaranteed client-side HEIC->JPEG conversion, we must add a small\n * library or WASM module; this utility intentionally avoids extra dependencies.\n *\n * Output type & quality\n * - Default output is `image/jpeg` with `quality=0.85`, which is typically\n * appropriate for avatars. You can switch to `image/png` to preserve\n * transparency.\n * - The output filename extension is adjusted to match the chosen MIME type by\n * default (e.g., `.jpg` or `.png`). You can override naming via the `rename`\n * option.\n *\n * Error handling\n * - Throws if canvas/context cannot be created or if canvas->blob conversion fails.\n * - Decoding failures (unsupported type) will throw; caller can try/catch and\n * fall back to the original file.\n *\n * Performance tips\n * - Keep target sizes reasonable (e.g., 256–1024 px) to avoid long processing\n * times on modest devices.\n * - JPEG with quality 0.8–0.9 often strikes a good balance between size and\n * perceived quality for photos/avatars.\n *\n * Usage examples\n * --------------\n * Basic usage:\n * ```ts\n * import { resizeImage } from '@limetech/lime-elements/util/image-resize';\n *\n * const processed = await resizeImage(file, {\n * width: 400,\n * height: 400,\n * fit: 'cover', // default; center-crops\n * type: 'image/jpeg', // default\n * quality: 0.85, // default\n * });\n * // Upload `processed` instead of the original file\n * ```\n *\n * With custom naming:\n * ```ts\n * const processed = await resizeImage(file, {\n * width: 800,\n * height: 800,\n * fit: 'contain',\n * type: 'image/png',\n * rename: (name) => name.replace(/\\.[^.]+$/, '') + '_resized.png',\n * });\n * ```\n *\n * In a Stencil component (simplified):\n * ```tsx\n * private async handleFilesSelected(file: File) {\n * try {\n * const resized = await resizeImage(file, { width: 400, height: 400 });\n * // build your FileInfo and emit\n * } catch {\n * // fall back to original\n * }\n * }\n * ```\n */\n// (Removed exported ResizeFit to avoid forcing a public symbol.)\n\n/**\n * Options for client-side image resizing.\n * @beta\n */\nexport type ResizeOptions = {\n /** Target width in CSS pixels. */\n width: number;\n /** Target height in CSS pixels. */\n height: number;\n /** Fit strategy; defaults to 'cover'. */\n fit?: 'cover' | 'contain';\n /** Output MIME type; 'image/jpeg' by default. */\n type?: 'image/jpeg' | 'image/png';\n /** JPEG quality (0..1); used only for 'image/jpeg'. Defaults to 0.85. */\n quality?: number;\n /** Optional renaming function. Defaults to changing extension to match MIME. */\n rename?: (originalName: string) => string;\n};\n\ntype SourceLike = ImageBitmap | HTMLImageElement;\n\n/**\n * Resize an image file on the client using Canvas/OffscreenCanvas.\n * Returns a new File with the requested format and dimensions.\n *\n * Contract\n * - Input: image `File`\n * - Output: resized image as a new `File` with updated `type`, name, and size\n * - Errors: may throw on decode failure or canvas export failure\n *\n * @beta\n * @param file - The image file to resize.\n * @param options - Configuration for the resize operation.\n */\nexport async function resizeImage(\n file: File,\n options: ResizeOptions\n): Promise<File> {\n const {\n width,\n height,\n fit = 'cover',\n type = 'image/jpeg',\n quality = 0.85,\n rename = (name: string) => renameWithType(name, type),\n } = options;\n\n const source = await loadSource(file);\n const { sx, sy, sw, sh, dx, dy, dw, dh } = computeRects(\n source.width as number,\n source.height as number,\n width,\n height,\n fit\n );\n\n const canvas = createCanvas(width, height);\n const ctx = get2dContext(canvas);\n ctx.clearRect(0, 0, width, height);\n ctx.drawImage(source, sx, sy, sw, sh, dx, dy, dw, dh);\n\n const blob = await canvasToBlob(canvas, type, quality);\n const name = rename(file.name);\n return new File([blob], name, { type });\n}\n\n/** Whether OffscreenCanvas is available in the current environment. */\nfunction supportsOffscreen(): boolean {\n try {\n return typeof (globalThis as any).OffscreenCanvas === 'function';\n } catch {\n return false;\n }\n}\n\n/**\n * Create either an OffscreenCanvas or a regular canvas for drawing.\n * @param width - Target width\n * @param height - Target height\n */\nfunction createCanvas(\n width: number,\n height: number\n): HTMLCanvasElement | OffscreenCanvas {\n if (supportsOffscreen()) {\n return new (globalThis as any).OffscreenCanvas(width, height);\n }\n\n const canvas = document.createElement('canvas');\n canvas.width = width;\n canvas.height = height;\n return canvas;\n}\n\n/**\n * Get the 2D rendering context, throwing a descriptive error if unavailable.\n * @param canvas - The canvas to get context from\n */\nfunction get2dContext(canvas: HTMLCanvasElement | OffscreenCanvas) {\n const ctx = (canvas as any).getContext('2d', { alpha: true });\n if (!ctx) {\n throw new Error('2D canvas context not available');\n }\n\n return ctx as CanvasRenderingContext2D;\n}\n\n/**\n * Convert the canvas content to a Blob, supporting both canvas types.\n * @param canvas - The source canvas\n * @param type - Output MIME type\n * @param quality - JPEG quality (0..1)\n */\nfunction canvasToBlob(\n canvas: HTMLCanvasElement | OffscreenCanvas,\n type: string,\n quality: number\n): Promise<Blob> {\n if ('convertToBlob' in canvas) {\n return (canvas as OffscreenCanvas).convertToBlob({ type, quality });\n }\n\n return new Promise((resolve, reject) => {\n (canvas as HTMLCanvasElement).toBlob(\n (blob) => {\n if (!blob) {\n reject(new Error('Failed to create blob from canvas'));\n return;\n }\n resolve(blob);\n },\n type,\n quality\n );\n });\n}\n\n/**\n * Load the image into a decodable source (ImageBitmap preferred).\n * @param file - The input file to decode\n */\n\nasync function loadSource(file: File): Promise<SourceLike> {\n if (typeof (globalThis as any).createImageBitmap === 'function') {\n try {\n return await (globalThis as any).createImageBitmap(file, {\n imageOrientation: 'from-image',\n } as any);\n } catch (error) {\n // Log for debugging in development, but continue with fallback\n const isDev =\n (globalThis as any).process?.env?.NODE_ENV !== 'production';\n\n if (\n isDev &&\n typeof console !== 'undefined' &&\n typeof console.debug === 'function'\n ) {\n console.debug(\n 'createImageBitmap failed, falling back to HTMLImageElement:',\n error\n );\n }\n }\n }\n\n return await loadImageElement(file);\n}\n\n/**\n * Decode an image file via HTMLImageElement when ImageBitmap is unavailable.\n * @param file - The input file to decode\n */\nasync function loadImageElement(file: File): Promise<HTMLImageElement> {\n const url = URL.createObjectURL(file);\n try {\n const img = new Image();\n img.decoding = 'sync';\n img.src = url;\n await img.decode?.().catch(() => undefined);\n if (!img.complete) {\n await new Promise<void>((resolve, reject) => {\n const cleanup = () => {\n img.removeEventListener('load', onLoad);\n img.removeEventListener('error', onError);\n };\n\n const onLoad = () => {\n cleanup();\n resolve();\n };\n const onError = (e: Event) => {\n cleanup();\n reject(e);\n };\n\n img.addEventListener('load', onLoad);\n img.addEventListener('error', onError);\n });\n }\n return img;\n } finally {\n URL.revokeObjectURL(url);\n }\n}\n\n/**\n * Compute source and destination rectangles for drawImage based on the fit mode.\n *\n * Returns sx, sy, sw, sh for the source crop/area and dx, dy, dw, dh for the\n * destination rectangle on the target canvas.\n *\n * @param sw - Source width\n * @param sh - Source height\n * @param tw - Target width\n * @param th - Target height\n * @param fit - Fit mode (cover/contain)\n */\nfunction computeRects(\n sw: number,\n sh: number,\n tw: number,\n th: number,\n fit: 'cover' | 'contain'\n) {\n const sRatio = sw / sh;\n const tRatio = tw / th;\n\n if (fit === 'cover') {\n // scale source to cover target, then center-crop\n let cropW: number;\n let cropH: number;\n if (sRatio > tRatio) {\n // source is wider than target: crop width\n cropH = sh;\n cropW = sh * tRatio;\n } else {\n // source is taller than target: crop height\n cropW = sw;\n cropH = sw / tRatio;\n }\n const sx = (sw - cropW) / 2;\n const sy = (sh - cropH) / 2;\n return { sx, sy, sw: cropW, sh: cropH, dx: 0, dy: 0, dw: tw, dh: th };\n }\n\n // contain: fit inside, letterbox if needed\n let drawW: number;\n let drawH: number;\n if (sRatio > tRatio) {\n drawW = tw;\n drawH = tw / sRatio;\n } else {\n drawH = th;\n drawW = th * sRatio;\n }\n const dx = (tw - drawW) / 2;\n const dy = (th - drawH) / 2;\n\n return { sx: 0, sy: 0, sw, sh, dx, dy, dw: drawW, dh: drawH };\n}\n\n/**\n * Update filename extension to match the desired MIME type.\n * @param name - Original filename\n * @param type - Output MIME type\n */\nfunction renameWithType(name: string, type: string): string {\n const ext = type === 'image/png' ? 'png' : 'jpg';\n const idx = name.lastIndexOf('.');\n const base = idx > 0 ? name.slice(0, idx) : name;\n return `${base}.${ext}`;\n}\n"],"version":3}
|
package/dist/cjs/index.cjs.js
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
const config = require('./config-e7e1a299.js');
|
|
6
|
+
const layout = require('./layout-8550b993.js');
|
|
7
|
+
const types = require('./types-cc3c7cea.js');
|
|
8
|
+
const imageResize = require('./image-resize-99e16554.js');
|
|
9
|
+
|
|
5
10
|
/**
|
|
6
11
|
* Represents the layout types for a form.
|
|
7
12
|
* @public
|
|
@@ -54,4 +59,12 @@ exports.ColumnAggregatorType = void 0;
|
|
|
54
59
|
ColumnAggregatorType["Count"] = "count";
|
|
55
60
|
})(exports.ColumnAggregatorType || (exports.ColumnAggregatorType = {}));
|
|
56
61
|
|
|
62
|
+
exports.globalConfig = config.globalConfig;
|
|
63
|
+
exports._mapLayout = layout._mapLayout;
|
|
64
|
+
exports.EditorMenuTypes = types.EditorMenuTypes;
|
|
65
|
+
exports.LevelMapping = types.LevelMapping;
|
|
66
|
+
exports.MouseButtons = types.MouseButtons;
|
|
67
|
+
exports.editorMenuTypesArray = types.editorMenuTypesArray;
|
|
68
|
+
exports.resizeImage = imageResize.resizeImage;
|
|
69
|
+
|
|
57
70
|
//# sourceMappingURL=index.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"file":"index.cjs.js","mappings":";;;;AAuTA;;;;AAIYA;AAAZ,WAAY,cAAc;;;;EAItB,qCAAmB,CAAA;;;;EAKnB,+BAAa,CAAA;;;;;;;;EASb,6BAAW,CAAA;AACf,CAAC,EAnBWA,sBAAc,KAAdA,sBAAc;;ACtK1B;;;;AAIYC;AAAZ,WAAY,oBAAoB;;;;EAI5B,uCAAe,CAAA;;;;EAKf,uCAAe,CAAA;;;;EAKf,uCAAe,CAAA;;;;EAKf,mCAAW,CAAA;;;;EAKX,uCAAe,CAAA;AACnB,CAAC,EAzBWA,4BAAoB,KAApBA,4BAAoB;;","names":["FormLayoutType","ColumnAggregatorType"],"sources":["./src/components/form/form.types.ts","./src/components/table/table.types.ts"],"sourcesContent":["import { JSONSchema7 } from 'json-schema';\nimport { Help } from '../help/help.types';\nimport { EventEmitter } from '@stencil/core';\n\n/**\n * EventEmitter from `@stencil/core`.\n *\n * @public\n */\nexport { EventEmitter } from '@stencil/core';\n\ndeclare module 'json-schema' {\n interface JSONSchema7 {\n /**\n * Unique identifier for the schema\n * @internal\n */\n id?: string;\n\n /**\n * Lime elements specific options that can be specified in a schema\n */\n lime?: Omit<LimeSchemaOptions, 'layout'> & {\n layout?: Partial<LimeLayoutOptions>;\n };\n }\n}\n\n/**\n * @public\n */\nexport interface ValidationStatus {\n /**\n * True if the form is valid, false otherwise\n *\n * If the form is invalid, any errors can be found on the `errors` property\n */\n valid: boolean;\n\n /**\n * List of validation errors\n */\n errors?: FormError[];\n}\n\n/**\n * @public\n */\nexport interface FormError {\n /**\n * Name of the error\n */\n name: string;\n\n /**\n * Params of the error\n */\n params?: unknown;\n\n /**\n * Name of the invalid property\n */\n property: string;\n\n /**\n * Path to the property within the schema\n */\n schemaPath: string;\n\n /**\n * String describing the error\n */\n message: string;\n}\n\n/**\n * @public\n */\nexport type ValidationError = {\n /**\n * Name of the field the error belongs to\n */\n [key: string]: string[] | ValidationError;\n};\n\n/**\n * @public\n */\nexport interface FormComponent<T = any> {\n /**\n * The value of the current property\n */\n value: T;\n\n /**\n * Whether or not the current property is required\n */\n required?: boolean;\n\n /**\n * Whether or not the current property is readonly\n */\n readonly?: boolean;\n\n /**\n * Whether or not the current property is disabled\n */\n disabled?: boolean;\n\n /**\n * The label of the current property\n */\n label?: string;\n\n /**\n * The helper text for the current property\n */\n helperText?: string;\n\n /**\n * Additional contextual information about the form\n */\n formInfo?: FormInfo;\n\n /**\n * The event to emit when the value of the current property has changed\n */\n change: EventEmitter<T>;\n}\n\n/**\n * @public\n */\nexport interface FormInfo {\n /**\n * The schema of the current property\n */\n schema?: FormSchema;\n\n /**\n * The schema of the whole form\n */\n rootSchema?: FormSchema;\n\n /**\n * A tree of errors for this property and its children\n */\n errorSchema?: object;\n\n /**\n * The value of the whole form\n */\n rootValue?: any;\n\n /**\n * The name of the current property\n */\n name?: string;\n\n /**\n * Path to the property within the schema\n */\n schemaPath?: string[];\n}\n\n/**\n * Lime elements specific options that can be specified under the `lime` key in\n * a schema, e.g.\n *\n * ```ts\n * const schema = {\n * type: 'object',\n * lime: {\n * collapsible: true,\n * },\n * };\n * ```\n *\n * @public\n */\nexport interface LimeSchemaOptions {\n /**\n * When specified on an object it will render all sub components inside a\n * collapsible section\n */\n collapsible?: boolean;\n\n /**\n * When `collapsible` is `true`, set this to `false` to make the\n * collapsible section load in the open state.\n * Defaults to `true`.\n */\n collapsed?: boolean;\n\n /**\n * Will render the field using the specified component. The component\n * should implement the `FormComponent` interface\n */\n component?: FormComponentOptions;\n\n /**\n * When specified on an object it will render the sub components with the\n * specified layout\n */\n layout?: LimeLayoutOptions;\n\n /**\n * Mark the field as disabled\n */\n disabled?: boolean;\n\n /**\n * Hide the field from the UI while preserving its value in the form data.\n */\n hidden?: boolean;\n\n help?: string | Partial<Help>;\n\n /**\n * Controls whether items in an array can be reordered by the end user.\n */\n allowItemReorder?: boolean;\n\n /**\n * Controls whether items in an array can be removed by the end user.\n */\n allowItemRemoval?: boolean;\n}\n\n/**\n * Options for a layout to be used in a form\n * @public\n */\nexport type LimeLayoutOptions = GridLayoutOptions & RowLayoutOptions;\n\n/**\n * Options for a component to be rendered inside a form\n *\n * @public\n */\nexport interface FormComponentOptions {\n /**\n * Name of the component\n */\n name?: string;\n\n /**\n * Extra properties to give the component in addition to the properties\n * specified on the `FormComponent` interface\n */\n props?: Record<string, any>;\n}\n\n/**\n * @public\n */\nexport interface FormLayoutOptions<\n T extends FormLayoutType | `${FormLayoutType}` = FormLayoutType.Default,\n> {\n /**\n * The type of layout to use\n */\n type: T;\n}\n\n/**\n * Layout options for a grid layout\n * @public\n */\nexport interface GridLayoutOptions\n extends FormLayoutOptions<FormLayoutType | `${FormLayoutType}`> {\n /**\n * When specified on a component within the grid, the component will take\n * up the the specified number of columns in the form\n */\n\n colSpan?: 1 | 2 | 3 | 4 | 5 | 'all';\n\n /**\n * When specified on a component within the grid, the component will take\n * up the the specified number of rows in the form\n */\n rowSpan?: number;\n\n /**\n * Number of columns to use in the layout\n */\n\n columns?: 1 | 2 | 3 | 4 | 5;\n\n /**\n * Attempts to fill in holes earlier in the grid, if smaller items come up\n * later. This may cause items to appear out-of-order, when doing so would\n * fill holes left by larger items. Defaults to `true`.\n */\n dense?: boolean;\n}\n\n/**\n * Layout options for a row layout\n * @public\n */\nexport interface RowLayoutOptions\n extends FormLayoutOptions<FormLayoutType | `${FormLayoutType}`> {\n /**\n * When specified on a field, the chosen icon will be displayed\n * on the left side of the row, beside the title.\n */\n icon?: string;\n}\n\n/**\n * Represents the layout types for a form.\n * @public\n */\nexport enum FormLayoutType {\n /**\n * The default layout\n */\n Default = 'default',\n\n /**\n * Render the form fields using a responsive grid layout\n */\n Grid = 'grid',\n\n /**\n * Render the form fields in full-width rows.\n * Each row can have a leading `icon`, and a field.\n * `title` and `description` provided by the schema will be placed\n * on the row itself, and not on the field.\n * This layout is good for creating UIs for user settings pages.\n */\n Row = 'row',\n}\n\n/**\n * Represents the JSON schema with Lime specific options\n * @public\n */\nexport interface FormSchema<T extends Record<string, any> = any>\n extends JSONSchema7 {\n /**\n * The value of \"items\" MUST be either a valid JSON Schema or an array\n * of valid JSON Schemas.\n *\n * This keyword determines how child instances validate for arrays, and\n * does not directly validate the immediate instance itself.\n *\n * If \"items\" is a schema, validation succeeds if all elements in the\n * array successfully validate against that schema.\n *\n * If \"items\" is an array of schemas, validation succeeds if each\n * element of the instance validates against the schema at the same\n * position, if any.\n *\n * Omitting this keyword has the same behavior as an empty schema.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.4.1\n */\n items?: FormSchemaArrayItem<T> | Array<FormSchemaArrayItem<T>>;\n\n /**\n * The value of \"items\" MUST be either a valid JSON Schema or an array\n * of valid JSON Schemas.\n *\n * This keyword determines how child instances validate for arrays, and\n * does not directly validate the immediate instance itself.\n *\n * If \"items\" is a schema, validation succeeds if all elements in the\n * array successfully validate against that schema.\n *\n * If \"items\" is an array of schemas, validation succeeds if each\n * element of the instance validates against the schema at the same\n * position, if any.\n *\n * Omitting this keyword has the same behavior as an empty schema.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.4.2\n */\n additionalItems?: FormSchemaArrayItem<T>;\n\n /**\n * The value of this keyword MUST be a valid JSON Schema.\n *\n * An array instance is valid against \"contains\" if at least one of its\n * elements is valid against the given schema.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.4.6\n */\n contains?: FormSchemaArrayItem<T>;\n\n /**\n * The value of this keyword MUST be an array. Elements of this array,\n * if any, MUST be strings, and MUST be unique.\n *\n * An object instance is valid against this keyword if every item in the\n * array is the name of a property in the instance.\n *\n * Omitting this keyword has the same behavior as an empty array.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.5.3\n */\n required?: Array<ReplaceObjectType<T, Extract<keyof T, string>, string>>;\n\n /**\n * The value of \"properties\" MUST be an object. Each value of this\n * object MUST be a valid JSON Schema.\n *\n * This keyword determines how child instances validate for objects, and\n * does not directly validate the immediate instance itself.\n *\n * Validation succeeds if, for each name that appears in both the\n * instance and as a name within this keyword's value, the child\n * instance for that name successfully validates against the\n * corresponding schema.\n *\n * Omitting this keyword has the same behavior as an empty object.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.5.4\n */\n properties?: ReplaceObjectType<\n T,\n FormSubKeySchema<T>,\n Record<string, FormSchema>\n >;\n\n /**\n * This keyword's value MUST be a non-empty array. Each item of the\n * array MUST be a valid JSON Schema.\n *\n * An instance validates successfully against this keyword if it\n * validates successfully against all schemas defined by this keyword's\n * value.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.7.1\n */\n allOf?: Array<FormSchemaArrayItem<T>>;\n\n /**\n * This keyword's value MUST be a non-empty array. Each item of the\n * array MUST be a valid JSON Schema.\n *\n * An instance validates successfully against this keyword if it\n * validates successfully against at least one schema defined by this\n * keyword's value.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.7.2\n */\n anyOf?: Array<FormSchemaArrayItem<T>>;\n\n /**\n * This keyword's value MUST be a non-empty array. Each item of the\n * array MUST be a valid JSON Schema.\n *\n * An instance validates successfully against this keyword if it\n * validates successfully against exactly one schema defined by this\n * keyword's value.\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.7.3\n */\n oneOf?: Array<FormSchemaArrayItem<T>>;\n\n /**\n * The value of \"patternProperties\" MUST be an object. Each property\n * name of this object SHOULD be a valid regular expression, according\n * to the ECMA 262 regular expression dialect. Each property value of\n * this object MUST be a valid JSON Schema.\n *\n * This keyword determines how child instances validate for objects, and\n * does not directly validate the immediate instance itself. Validation\n * of the primitive instance type against this keyword always succeeds.\n *\n * Validation succeeds if, for each instance name that matches any\n * regular expressions that appear as a property name in this keyword's\n * value, the child instance for that name successfully validates\n * against each schema that corresponds to a matching regular\n * expression.\n *\n * Omitting this keyword has the same behavior as an empty object.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.5.5\n */\n patternProperties?: Record<string, FormSchema>;\n\n /**\n * The value of \"additionalProperties\" MUST be a valid JSON Schema.\n *\n * This keyword determines how child instances validate for objects, and\n * does not directly validate the immediate instance itself.\n *\n * Validation with \"additionalProperties\" applies only to the child\n * values of instance names that do not match any names in \"properties\",\n * and do not match any regular expression in \"patternProperties\".\n *\n * For all such properties, validation succeeds if the child instance\n * validates against the \"additionalProperties\" schema.\n *\n * Omitting this keyword has the same behavior as an empty schema.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.5.6\n */\n additionalProperties?: FormSchema | boolean;\n\n /**\n * This keyword specifies rules that are evaluated if the instance is an\n * object and contains a certain property.\n *\n * This keyword's value MUST be an object. Each property specifies a\n * dependency. Each dependency value MUST be an array or a valid JSON\n * Schema.\n *\n * If the dependency value is a subschema, and the dependency key is a\n * property in the instance, the entire instance must validate against\n * the dependency value.\n *\n * If the dependency value is an array, each element in the array, if\n * any, MUST be a string, and MUST be unique. If the dependency key is\n * a property in the instance, each of the items in the dependency value\n * must be a property that exists in the instance.\n *\n * Omitting this keyword has the same behavior as an empty object.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.5.7\n */\n dependencies?: Record<string, FormSchema | string[]>;\n\n /**\n * The value of \"propertyNames\" MUST be a valid JSON Schema.\n *\n * If the instance is an object, this keyword validates if every\n * property name in the instance validates against the provided schema.\n * Note the property name that the schema is testing will always be a\n * string.\n *\n * Omitting this keyword has the same behavior as an empty schema.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.5.8\n */\n propertyNames?: FormSchema;\n\n /**\n * This keyword's value MUST be a valid JSON Schema.\n *\n * This validation outcome of this keyword's subschema has no direct\n * effect on the overall validation result. Rather, it controls which\n * of the \"then\" or \"else\" keywords are evaluated.\n *\n * Instances that successfully validate against this keyword's subschema\n * MUST also be valid against the subschema value of the \"then\" keyword,\n * if present.\n *\n * Instances that fail to validate against this keyword's subschema MUST\n * also be valid against the subschema value of the \"else\" keyword, if\n * present.\n *\n * If annotations (Section 3.3) are being collected, they are collected\n * from this keyword's subschema in the usual way, including when the\n * keyword is present without either \"then\" or \"else\".\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.6.1\n */\n if?: FormSchema;\n\n /**\n * This keyword's value MUST be a valid JSON Schema.\n *\n * This validation outcome of this keyword's subschema has no direct\n * effect on the overall validation result. Rather, it controls which\n * of the \"then\" or \"else\" keywords are evaluated.\n *\n * Instances that successfully validate against this keyword's subschema\n * MUST also be valid against the subschema value of the \"then\" keyword,\n * if present.\n *\n * Instances that fail to validate against this keyword's subschema MUST\n * also be valid against the subschema value of the \"else\" keyword, if\n * present.\n *\n * If annotations (Section 3.3) are being collected, they are collected\n * from this keyword's subschema in the usual way, including when the\n * keyword is present without either \"then\" or \"else\".\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.6.2\n */\n then?: FormSchema;\n\n /**\n * This keyword's value MUST be a valid JSON Schema.\n *\n * When \"if\" is present, and the instance fails to validate against its\n * subschema, then valiation succeeds against this keyword if the\n * instance successfully validates against this keyword's subschema.\n *\n * This keyword has no effect when \"if\" is absent, or when the instance\n * successfully validates against its subschema. Implementations MUST\n * NOT evaluate the instance against this keyword, for either validation\n * or annotation collection purposes, in such cases.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.6.3\n */\n else?: FormSchema;\n\n /**\n * This keyword's value MUST be a valid JSON Schema.\n *\n * An instance is valid against this keyword if it fails to validate\n * successfully against the schema defined by this keyword.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.7.4\n */\n not?: FormSchema;\n\n /**\n * The \"$defs\" keywords provides a standardized location for\n * schema authors to inline re-usable JSON Schemas into a more general\n * schema. The keyword does not directly affect the validation result.\n *\n * This keyword's value MUST be an object. Each member value of this\n * object MUST be a valid JSON Schema.\n *\n * As an example, here is a schema describing an array of positive\n * integers, where the positive integer constraint is a subschema in\n * \"definitions\":\n * ```\n * {\n * \"type\": \"array\",\n * \"items\": { \"$ref\": \"#/definitions/positiveInteger\" },\n * \"definitions\": {\n * \"positiveInteger\": {\n * \"type\": \"integer\",\n * \"exclusiveMinimum\": 0\n * }\n * }\n * }\n * ```\n *\n * $defs is the newer keyword introduced in the JSON Schema Draft 2019-09, while definitions is from the older drafts.\n *\n * The main difference is that definitions is no longer an official keyword in the latest JSON Schema specification (Draft 2019-09 and later),\n * but it is still widely supported for backward compatibility.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-9\n */\n $defs?: Record<string, FormSchema>;\n\n /**\n * The \"definitions\" keywords provides a standardized location for\n * schema authors to inline re-usable JSON Schemas into a more general\n * schema. The keyword does not directly affect the validation result.\n *\n * This keyword's value MUST be an object. Each member value of this\n * object MUST be a valid JSON Schema.\n *\n * As an example, here is a schema describing an array of positive\n * integers, where the positive integer constraint is a subschema in\n * \"definitions\":\n * ```\n * {\n * \"type\": \"array\",\n * \"items\": { \"$ref\": \"#/definitions/positiveInteger\" },\n * \"definitions\": {\n * \"positiveInteger\": {\n * \"type\": \"integer\",\n * \"exclusiveMinimum\": 0\n * }\n * }\n * }\n * ```\n *\n * $defs is the newer keyword introduced in the JSON Schema Draft 2019-09, while definitions is from the older drafts.\n *\n * The main difference is that definitions is no longer an official keyword in the latest JSON Schema specification (Draft 2019-09 and later),\n * but it is still widely supported for backward compatibility.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-9\n */\n definitions?: Record<string, FormSchema>;\n}\n\n/**\n * Utility type for replacing object types with a specified type\n * @public\n */\nexport type ReplaceObjectType<T, AllowedType, ElseType> = T extends any[]\n ? ElseType\n : T extends Record<string, any>\n ? AllowedType\n : ElseType;\n\n/**\n * Utility type for supporting nested sub items in arrays\n * @public\n */\nexport type FormSchemaArrayItem<T> = T extends any[]\n ? FormSchema<T[Extract<keyof T, number>]>\n : FormSchema;\n\n/**\n * Utility type for recursive properties in a schema\n * @public\n */\nexport type FormSubKeySchema<TObj> = Partial<{\n [Key in Extract<keyof TObj, any>]: FormSchema<TObj[Key]>;\n}>;\n","/**\n * Defines the data for a table\n * @public\n */\nexport interface Column<T extends object = any> {\n /**\n * Column title to be displayed\n */\n title: string;\n\n /**\n * Name of the field in the data\n */\n field: keyof T;\n\n /**\n * Function to format the value before rendering\n */\n formatter?: TableFormatter;\n\n /**\n * Component used to render the field value\n */\n component?: TableComponentDefinition;\n\n /**\n * Type of aggregator to use for the column\n */\n aggregator?: ColumnAggregatorType | ColumnAggregatorFunction<T>;\n\n /**\n * A component used to render inside the column header\n */\n headerComponent?: TableComponentDefinition;\n\n /**\n * Sets the horizontal text alignment for the column\n */\n horizontalAlign?: 'left' | 'center' | 'right';\n\n /**\n * Defines whether end-user can sort a column\n */\n headerSort?: boolean;\n}\n\n/**\n * Definition for a formatter function\n * @param value - The value to be formatted\n * @param data - The data for the current row\n * @returns The formatted value\n * @public\n */\nexport type TableFormatter = (value: any, data?: object) => string;\n\n/**\n * The `component` key in the schema uses this interface to define a\n * component to be rendered inside a cell in the table.\n *\n * @note The table will display the component as `inline-block` in order\n * to give the column the correct size. If the component should have the\n * full width of the column, this might have to be overridden by setting\n * the display mode to `block`, e.g.\n *\n * ```css\n * :host(*) {\n * display: block !important;\n * }\n * ```\n * @public\n */\nexport interface TableComponentDefinition {\n /**\n * Name of the component\n */\n name: string;\n\n /**\n * Properties to send to the component\n */\n props?: Record<string, any>;\n\n /**\n * Factory for creating properties dynamically for a custom component.\n *\n * The properties returned from this function will be merged with the\n * `props` properties when the component is created.\n *\n * When the propsFactory is used for header components there will be no data available.\n *\n * @param data - The data for the current row\n * @returns Properties for the component\n */\n propsFactory?: (data: object) => Record<string, any>;\n}\n\n/**\n * Interface for custom components rendered inside a `limel-table`.\n * @public\n */\nexport interface TableComponent<T extends object = any> {\n /**\n * Name of the field being rendered\n */\n field?: string;\n\n /**\n * Value being rendered\n */\n value?: any;\n\n /**\n * Data for the current row of the table\n */\n data?: T;\n}\n\n/**\n * Indicates whether the specified column is sorted ascending or descending.\n * @public\n */\nexport interface ColumnSorter {\n /**\n * The column being sorted\n */\n column: Column;\n\n /**\n * The direction to sort on\n */\n direction: 'ASC' | 'DESC';\n}\n\n/**\n * Specifies the current page, and which columns the table is currently sorted on.\n * @public\n */\nexport interface TableParams {\n /**\n * The current page being set\n */\n page: number;\n\n /**\n * Sorters applied to the current page\n */\n sorters?: ColumnSorter[];\n}\n\n/**\n * The built-in aggregators available for columns\n * @public\n */\nexport enum ColumnAggregatorType {\n /**\n * Calculates the average value of all numerical cells in the column\n */\n Average = 'avg',\n\n /**\n * Displays the maximum value from all numerical cells in the column\n */\n Maximum = 'max',\n\n /**\n * Displays the minimum value from all numerical cells in the column\n */\n Minimum = 'min',\n\n /**\n * Displays the sum of all numerical cells in the column\n */\n Sum = 'sum',\n\n /**\n * Counts the number of non empty cells in the column\n */\n Count = 'count',\n}\n\n/**\n * Instead of using one of the built-in aggregators, it is possible to\n * define a custom aggregator function.\n *\n * @param column - the configuration for the column\n * @param values - list of all values to be aggregated\n * @param data - list of all objects to be aggregated\n * @returns the aggregated data\n *\n * @public\n */\nexport type ColumnAggregatorFunction<T = object> = (\n column?: Column,\n values?: any[],\n data?: T[]\n) => any;\n\n/**\n * Defines aggregate values for columns\n * @public\n */\nexport interface ColumnAggregate {\n /**\n * The name of the `Column` field\n */\n field: string;\n /**\n * The aggregate value\n */\n value: any;\n}\n\n/**\n * Data for identifying a row of the table\n * @public\n */\nexport type RowData = {\n id?: string | number;\n};\n"],"version":3}
|
|
1
|
+
{"file":"index.cjs.js","mappings":";;;;;;;;;AAuTA;;;;AAIYA;AAAZ,WAAY,cAAc;;;;EAItB,qCAAmB,CAAA;;;;EAKnB,+BAAa,CAAA;;;;;;;;EASb,6BAAW,CAAA;AACf,CAAC,EAnBWA,sBAAc,KAAdA,sBAAc;;ACtK1B;;;;AAIYC;AAAZ,WAAY,oBAAoB;;;;EAI5B,uCAAe,CAAA;;;;EAKf,uCAAe,CAAA;;;;EAKf,uCAAe,CAAA;;;;EAKf,mCAAW,CAAA;;;;EAKX,uCAAe,CAAA;AACnB,CAAC,EAzBWA,4BAAoB,KAApBA,4BAAoB;;;;;;;;;;","names":["FormLayoutType","ColumnAggregatorType"],"sources":["./src/components/form/form.types.ts","./src/components/table/table.types.ts"],"sourcesContent":["import { JSONSchema7 } from 'json-schema';\nimport { Help } from '../help/help.types';\nimport { EventEmitter } from '@stencil/core';\n\n/**\n * EventEmitter from `@stencil/core`.\n *\n * @public\n */\nexport { EventEmitter } from '@stencil/core';\n\ndeclare module 'json-schema' {\n interface JSONSchema7 {\n /**\n * Unique identifier for the schema\n * @internal\n */\n id?: string;\n\n /**\n * Lime elements specific options that can be specified in a schema\n */\n lime?: Omit<LimeSchemaOptions, 'layout'> & {\n layout?: Partial<LimeLayoutOptions>;\n };\n }\n}\n\n/**\n * @public\n */\nexport interface ValidationStatus {\n /**\n * True if the form is valid, false otherwise\n *\n * If the form is invalid, any errors can be found on the `errors` property\n */\n valid: boolean;\n\n /**\n * List of validation errors\n */\n errors?: FormError[];\n}\n\n/**\n * @public\n */\nexport interface FormError {\n /**\n * Name of the error\n */\n name: string;\n\n /**\n * Params of the error\n */\n params?: unknown;\n\n /**\n * Name of the invalid property\n */\n property: string;\n\n /**\n * Path to the property within the schema\n */\n schemaPath: string;\n\n /**\n * String describing the error\n */\n message: string;\n}\n\n/**\n * @public\n */\nexport type ValidationError = {\n /**\n * Name of the field the error belongs to\n */\n [key: string]: string[] | ValidationError;\n};\n\n/**\n * @public\n */\nexport interface FormComponent<T = any> {\n /**\n * The value of the current property\n */\n value: T;\n\n /**\n * Whether or not the current property is required\n */\n required?: boolean;\n\n /**\n * Whether or not the current property is readonly\n */\n readonly?: boolean;\n\n /**\n * Whether or not the current property is disabled\n */\n disabled?: boolean;\n\n /**\n * The label of the current property\n */\n label?: string;\n\n /**\n * The helper text for the current property\n */\n helperText?: string;\n\n /**\n * Additional contextual information about the form\n */\n formInfo?: FormInfo;\n\n /**\n * The event to emit when the value of the current property has changed\n */\n change: EventEmitter<T>;\n}\n\n/**\n * @public\n */\nexport interface FormInfo {\n /**\n * The schema of the current property\n */\n schema?: FormSchema;\n\n /**\n * The schema of the whole form\n */\n rootSchema?: FormSchema;\n\n /**\n * A tree of errors for this property and its children\n */\n errorSchema?: object;\n\n /**\n * The value of the whole form\n */\n rootValue?: any;\n\n /**\n * The name of the current property\n */\n name?: string;\n\n /**\n * Path to the property within the schema\n */\n schemaPath?: string[];\n}\n\n/**\n * Lime elements specific options that can be specified under the `lime` key in\n * a schema, e.g.\n *\n * ```ts\n * const schema = {\n * type: 'object',\n * lime: {\n * collapsible: true,\n * },\n * };\n * ```\n *\n * @public\n */\nexport interface LimeSchemaOptions {\n /**\n * When specified on an object it will render all sub components inside a\n * collapsible section\n */\n collapsible?: boolean;\n\n /**\n * When `collapsible` is `true`, set this to `false` to make the\n * collapsible section load in the open state.\n * Defaults to `true`.\n */\n collapsed?: boolean;\n\n /**\n * Will render the field using the specified component. The component\n * should implement the `FormComponent` interface\n */\n component?: FormComponentOptions;\n\n /**\n * When specified on an object it will render the sub components with the\n * specified layout\n */\n layout?: LimeLayoutOptions;\n\n /**\n * Mark the field as disabled\n */\n disabled?: boolean;\n\n /**\n * Hide the field from the UI while preserving its value in the form data.\n */\n hidden?: boolean;\n\n help?: string | Partial<Help>;\n\n /**\n * Controls whether items in an array can be reordered by the end user.\n */\n allowItemReorder?: boolean;\n\n /**\n * Controls whether items in an array can be removed by the end user.\n */\n allowItemRemoval?: boolean;\n}\n\n/**\n * Options for a layout to be used in a form\n * @public\n */\nexport type LimeLayoutOptions = GridLayoutOptions & RowLayoutOptions;\n\n/**\n * Options for a component to be rendered inside a form\n *\n * @public\n */\nexport interface FormComponentOptions {\n /**\n * Name of the component\n */\n name?: string;\n\n /**\n * Extra properties to give the component in addition to the properties\n * specified on the `FormComponent` interface\n */\n props?: Record<string, any>;\n}\n\n/**\n * @public\n */\nexport interface FormLayoutOptions<\n T extends FormLayoutType | `${FormLayoutType}` = FormLayoutType.Default,\n> {\n /**\n * The type of layout to use\n */\n type: T;\n}\n\n/**\n * Layout options for a grid layout\n * @public\n */\nexport interface GridLayoutOptions\n extends FormLayoutOptions<FormLayoutType | `${FormLayoutType}`> {\n /**\n * When specified on a component within the grid, the component will take\n * up the the specified number of columns in the form\n */\n\n colSpan?: 1 | 2 | 3 | 4 | 5 | 'all';\n\n /**\n * When specified on a component within the grid, the component will take\n * up the the specified number of rows in the form\n */\n rowSpan?: number;\n\n /**\n * Number of columns to use in the layout\n */\n\n columns?: 1 | 2 | 3 | 4 | 5;\n\n /**\n * Attempts to fill in holes earlier in the grid, if smaller items come up\n * later. This may cause items to appear out-of-order, when doing so would\n * fill holes left by larger items. Defaults to `true`.\n */\n dense?: boolean;\n}\n\n/**\n * Layout options for a row layout\n * @public\n */\nexport interface RowLayoutOptions\n extends FormLayoutOptions<FormLayoutType | `${FormLayoutType}`> {\n /**\n * When specified on a field, the chosen icon will be displayed\n * on the left side of the row, beside the title.\n */\n icon?: string;\n}\n\n/**\n * Represents the layout types for a form.\n * @public\n */\nexport enum FormLayoutType {\n /**\n * The default layout\n */\n Default = 'default',\n\n /**\n * Render the form fields using a responsive grid layout\n */\n Grid = 'grid',\n\n /**\n * Render the form fields in full-width rows.\n * Each row can have a leading `icon`, and a field.\n * `title` and `description` provided by the schema will be placed\n * on the row itself, and not on the field.\n * This layout is good for creating UIs for user settings pages.\n */\n Row = 'row',\n}\n\n/**\n * Represents the JSON schema with Lime specific options\n * @public\n */\nexport interface FormSchema<T extends Record<string, any> = any>\n extends JSONSchema7 {\n /**\n * The value of \"items\" MUST be either a valid JSON Schema or an array\n * of valid JSON Schemas.\n *\n * This keyword determines how child instances validate for arrays, and\n * does not directly validate the immediate instance itself.\n *\n * If \"items\" is a schema, validation succeeds if all elements in the\n * array successfully validate against that schema.\n *\n * If \"items\" is an array of schemas, validation succeeds if each\n * element of the instance validates against the schema at the same\n * position, if any.\n *\n * Omitting this keyword has the same behavior as an empty schema.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.4.1\n */\n items?: FormSchemaArrayItem<T> | Array<FormSchemaArrayItem<T>>;\n\n /**\n * The value of \"items\" MUST be either a valid JSON Schema or an array\n * of valid JSON Schemas.\n *\n * This keyword determines how child instances validate for arrays, and\n * does not directly validate the immediate instance itself.\n *\n * If \"items\" is a schema, validation succeeds if all elements in the\n * array successfully validate against that schema.\n *\n * If \"items\" is an array of schemas, validation succeeds if each\n * element of the instance validates against the schema at the same\n * position, if any.\n *\n * Omitting this keyword has the same behavior as an empty schema.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.4.2\n */\n additionalItems?: FormSchemaArrayItem<T>;\n\n /**\n * The value of this keyword MUST be a valid JSON Schema.\n *\n * An array instance is valid against \"contains\" if at least one of its\n * elements is valid against the given schema.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.4.6\n */\n contains?: FormSchemaArrayItem<T>;\n\n /**\n * The value of this keyword MUST be an array. Elements of this array,\n * if any, MUST be strings, and MUST be unique.\n *\n * An object instance is valid against this keyword if every item in the\n * array is the name of a property in the instance.\n *\n * Omitting this keyword has the same behavior as an empty array.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.5.3\n */\n required?: Array<ReplaceObjectType<T, Extract<keyof T, string>, string>>;\n\n /**\n * The value of \"properties\" MUST be an object. Each value of this\n * object MUST be a valid JSON Schema.\n *\n * This keyword determines how child instances validate for objects, and\n * does not directly validate the immediate instance itself.\n *\n * Validation succeeds if, for each name that appears in both the\n * instance and as a name within this keyword's value, the child\n * instance for that name successfully validates against the\n * corresponding schema.\n *\n * Omitting this keyword has the same behavior as an empty object.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.5.4\n */\n properties?: ReplaceObjectType<\n T,\n FormSubKeySchema<T>,\n Record<string, FormSchema>\n >;\n\n /**\n * This keyword's value MUST be a non-empty array. Each item of the\n * array MUST be a valid JSON Schema.\n *\n * An instance validates successfully against this keyword if it\n * validates successfully against all schemas defined by this keyword's\n * value.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.7.1\n */\n allOf?: Array<FormSchemaArrayItem<T>>;\n\n /**\n * This keyword's value MUST be a non-empty array. Each item of the\n * array MUST be a valid JSON Schema.\n *\n * An instance validates successfully against this keyword if it\n * validates successfully against at least one schema defined by this\n * keyword's value.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.7.2\n */\n anyOf?: Array<FormSchemaArrayItem<T>>;\n\n /**\n * This keyword's value MUST be a non-empty array. Each item of the\n * array MUST be a valid JSON Schema.\n *\n * An instance validates successfully against this keyword if it\n * validates successfully against exactly one schema defined by this\n * keyword's value.\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.7.3\n */\n oneOf?: Array<FormSchemaArrayItem<T>>;\n\n /**\n * The value of \"patternProperties\" MUST be an object. Each property\n * name of this object SHOULD be a valid regular expression, according\n * to the ECMA 262 regular expression dialect. Each property value of\n * this object MUST be a valid JSON Schema.\n *\n * This keyword determines how child instances validate for objects, and\n * does not directly validate the immediate instance itself. Validation\n * of the primitive instance type against this keyword always succeeds.\n *\n * Validation succeeds if, for each instance name that matches any\n * regular expressions that appear as a property name in this keyword's\n * value, the child instance for that name successfully validates\n * against each schema that corresponds to a matching regular\n * expression.\n *\n * Omitting this keyword has the same behavior as an empty object.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.5.5\n */\n patternProperties?: Record<string, FormSchema>;\n\n /**\n * The value of \"additionalProperties\" MUST be a valid JSON Schema.\n *\n * This keyword determines how child instances validate for objects, and\n * does not directly validate the immediate instance itself.\n *\n * Validation with \"additionalProperties\" applies only to the child\n * values of instance names that do not match any names in \"properties\",\n * and do not match any regular expression in \"patternProperties\".\n *\n * For all such properties, validation succeeds if the child instance\n * validates against the \"additionalProperties\" schema.\n *\n * Omitting this keyword has the same behavior as an empty schema.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.5.6\n */\n additionalProperties?: FormSchema | boolean;\n\n /**\n * This keyword specifies rules that are evaluated if the instance is an\n * object and contains a certain property.\n *\n * This keyword's value MUST be an object. Each property specifies a\n * dependency. Each dependency value MUST be an array or a valid JSON\n * Schema.\n *\n * If the dependency value is a subschema, and the dependency key is a\n * property in the instance, the entire instance must validate against\n * the dependency value.\n *\n * If the dependency value is an array, each element in the array, if\n * any, MUST be a string, and MUST be unique. If the dependency key is\n * a property in the instance, each of the items in the dependency value\n * must be a property that exists in the instance.\n *\n * Omitting this keyword has the same behavior as an empty object.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.5.7\n */\n dependencies?: Record<string, FormSchema | string[]>;\n\n /**\n * The value of \"propertyNames\" MUST be a valid JSON Schema.\n *\n * If the instance is an object, this keyword validates if every\n * property name in the instance validates against the provided schema.\n * Note the property name that the schema is testing will always be a\n * string.\n *\n * Omitting this keyword has the same behavior as an empty schema.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.5.8\n */\n propertyNames?: FormSchema;\n\n /**\n * This keyword's value MUST be a valid JSON Schema.\n *\n * This validation outcome of this keyword's subschema has no direct\n * effect on the overall validation result. Rather, it controls which\n * of the \"then\" or \"else\" keywords are evaluated.\n *\n * Instances that successfully validate against this keyword's subschema\n * MUST also be valid against the subschema value of the \"then\" keyword,\n * if present.\n *\n * Instances that fail to validate against this keyword's subschema MUST\n * also be valid against the subschema value of the \"else\" keyword, if\n * present.\n *\n * If annotations (Section 3.3) are being collected, they are collected\n * from this keyword's subschema in the usual way, including when the\n * keyword is present without either \"then\" or \"else\".\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.6.1\n */\n if?: FormSchema;\n\n /**\n * This keyword's value MUST be a valid JSON Schema.\n *\n * This validation outcome of this keyword's subschema has no direct\n * effect on the overall validation result. Rather, it controls which\n * of the \"then\" or \"else\" keywords are evaluated.\n *\n * Instances that successfully validate against this keyword's subschema\n * MUST also be valid against the subschema value of the \"then\" keyword,\n * if present.\n *\n * Instances that fail to validate against this keyword's subschema MUST\n * also be valid against the subschema value of the \"else\" keyword, if\n * present.\n *\n * If annotations (Section 3.3) are being collected, they are collected\n * from this keyword's subschema in the usual way, including when the\n * keyword is present without either \"then\" or \"else\".\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.6.2\n */\n then?: FormSchema;\n\n /**\n * This keyword's value MUST be a valid JSON Schema.\n *\n * When \"if\" is present, and the instance fails to validate against its\n * subschema, then valiation succeeds against this keyword if the\n * instance successfully validates against this keyword's subschema.\n *\n * This keyword has no effect when \"if\" is absent, or when the instance\n * successfully validates against its subschema. Implementations MUST\n * NOT evaluate the instance against this keyword, for either validation\n * or annotation collection purposes, in such cases.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.6.3\n */\n else?: FormSchema;\n\n /**\n * This keyword's value MUST be a valid JSON Schema.\n *\n * An instance is valid against this keyword if it fails to validate\n * successfully against the schema defined by this keyword.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.7.4\n */\n not?: FormSchema;\n\n /**\n * The \"$defs\" keywords provides a standardized location for\n * schema authors to inline re-usable JSON Schemas into a more general\n * schema. The keyword does not directly affect the validation result.\n *\n * This keyword's value MUST be an object. Each member value of this\n * object MUST be a valid JSON Schema.\n *\n * As an example, here is a schema describing an array of positive\n * integers, where the positive integer constraint is a subschema in\n * \"definitions\":\n * ```\n * {\n * \"type\": \"array\",\n * \"items\": { \"$ref\": \"#/definitions/positiveInteger\" },\n * \"definitions\": {\n * \"positiveInteger\": {\n * \"type\": \"integer\",\n * \"exclusiveMinimum\": 0\n * }\n * }\n * }\n * ```\n *\n * $defs is the newer keyword introduced in the JSON Schema Draft 2019-09, while definitions is from the older drafts.\n *\n * The main difference is that definitions is no longer an official keyword in the latest JSON Schema specification (Draft 2019-09 and later),\n * but it is still widely supported for backward compatibility.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-9\n */\n $defs?: Record<string, FormSchema>;\n\n /**\n * The \"definitions\" keywords provides a standardized location for\n * schema authors to inline re-usable JSON Schemas into a more general\n * schema. The keyword does not directly affect the validation result.\n *\n * This keyword's value MUST be an object. Each member value of this\n * object MUST be a valid JSON Schema.\n *\n * As an example, here is a schema describing an array of positive\n * integers, where the positive integer constraint is a subschema in\n * \"definitions\":\n * ```\n * {\n * \"type\": \"array\",\n * \"items\": { \"$ref\": \"#/definitions/positiveInteger\" },\n * \"definitions\": {\n * \"positiveInteger\": {\n * \"type\": \"integer\",\n * \"exclusiveMinimum\": 0\n * }\n * }\n * }\n * ```\n *\n * $defs is the newer keyword introduced in the JSON Schema Draft 2019-09, while definitions is from the older drafts.\n *\n * The main difference is that definitions is no longer an official keyword in the latest JSON Schema specification (Draft 2019-09 and later),\n * but it is still widely supported for backward compatibility.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-9\n */\n definitions?: Record<string, FormSchema>;\n}\n\n/**\n * Utility type for replacing object types with a specified type\n * @public\n */\nexport type ReplaceObjectType<T, AllowedType, ElseType> = T extends any[]\n ? ElseType\n : T extends Record<string, any>\n ? AllowedType\n : ElseType;\n\n/**\n * Utility type for supporting nested sub items in arrays\n * @public\n */\nexport type FormSchemaArrayItem<T> = T extends any[]\n ? FormSchema<T[Extract<keyof T, number>]>\n : FormSchema;\n\n/**\n * Utility type for recursive properties in a schema\n * @public\n */\nexport type FormSubKeySchema<TObj> = Partial<{\n [Key in Extract<keyof TObj, any>]: FormSchema<TObj[Key]>;\n}>;\n","/**\n * Defines the data for a table\n * @public\n */\nexport interface Column<T extends object = any> {\n /**\n * Column title to be displayed\n */\n title: string;\n\n /**\n * Name of the field in the data\n */\n field: keyof T;\n\n /**\n * Function to format the value before rendering\n */\n formatter?: TableFormatter;\n\n /**\n * Component used to render the field value\n */\n component?: TableComponentDefinition;\n\n /**\n * Type of aggregator to use for the column\n */\n aggregator?: ColumnAggregatorType | ColumnAggregatorFunction<T>;\n\n /**\n * A component used to render inside the column header\n */\n headerComponent?: TableComponentDefinition;\n\n /**\n * Sets the horizontal text alignment for the column\n */\n horizontalAlign?: 'left' | 'center' | 'right';\n\n /**\n * Defines whether end-user can sort a column\n */\n headerSort?: boolean;\n}\n\n/**\n * Definition for a formatter function\n * @param value - The value to be formatted\n * @param data - The data for the current row\n * @returns The formatted value\n * @public\n */\nexport type TableFormatter = (value: any, data?: object) => string;\n\n/**\n * The `component` key in the schema uses this interface to define a\n * component to be rendered inside a cell in the table.\n *\n * @note The table will display the component as `inline-block` in order\n * to give the column the correct size. If the component should have the\n * full width of the column, this might have to be overridden by setting\n * the display mode to `block`, e.g.\n *\n * ```css\n * :host(*) {\n * display: block !important;\n * }\n * ```\n * @public\n */\nexport interface TableComponentDefinition {\n /**\n * Name of the component\n */\n name: string;\n\n /**\n * Properties to send to the component\n */\n props?: Record<string, any>;\n\n /**\n * Factory for creating properties dynamically for a custom component.\n *\n * The properties returned from this function will be merged with the\n * `props` properties when the component is created.\n *\n * When the propsFactory is used for header components there will be no data available.\n *\n * @param data - The data for the current row\n * @returns Properties for the component\n */\n propsFactory?: (data: object) => Record<string, any>;\n}\n\n/**\n * Interface for custom components rendered inside a `limel-table`.\n * @public\n */\nexport interface TableComponent<T extends object = any> {\n /**\n * Name of the field being rendered\n */\n field?: string;\n\n /**\n * Value being rendered\n */\n value?: any;\n\n /**\n * Data for the current row of the table\n */\n data?: T;\n}\n\n/**\n * Indicates whether the specified column is sorted ascending or descending.\n * @public\n */\nexport interface ColumnSorter {\n /**\n * The column being sorted\n */\n column: Column;\n\n /**\n * The direction to sort on\n */\n direction: 'ASC' | 'DESC';\n}\n\n/**\n * Specifies the current page, and which columns the table is currently sorted on.\n * @public\n */\nexport interface TableParams {\n /**\n * The current page being set\n */\n page: number;\n\n /**\n * Sorters applied to the current page\n */\n sorters?: ColumnSorter[];\n}\n\n/**\n * The built-in aggregators available for columns\n * @public\n */\nexport enum ColumnAggregatorType {\n /**\n * Calculates the average value of all numerical cells in the column\n */\n Average = 'avg',\n\n /**\n * Displays the maximum value from all numerical cells in the column\n */\n Maximum = 'max',\n\n /**\n * Displays the minimum value from all numerical cells in the column\n */\n Minimum = 'min',\n\n /**\n * Displays the sum of all numerical cells in the column\n */\n Sum = 'sum',\n\n /**\n * Counts the number of non empty cells in the column\n */\n Count = 'count',\n}\n\n/**\n * Instead of using one of the built-in aggregators, it is possible to\n * define a custom aggregator function.\n *\n * @param column - the configuration for the column\n * @param values - list of all values to be aggregated\n * @param data - list of all objects to be aggregated\n * @returns the aggregated data\n *\n * @public\n */\nexport type ColumnAggregatorFunction<T = object> = (\n column?: Column,\n values?: any[],\n data?: T[]\n) => any;\n\n/**\n * Defines aggregate values for columns\n * @public\n */\nexport interface ColumnAggregate {\n /**\n * The name of the `Column` field\n */\n field: string;\n /**\n * The aggregate value\n */\n value: any;\n}\n\n/**\n * Data for identifying a row of the table\n * @public\n */\nexport type RowData = {\n id?: string | number;\n};\n"],"version":3}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Maps a layout to a Tabulator layout
|
|
5
|
+
* @param layout - the layout to map
|
|
6
|
+
* @returns the Tabulator layout
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
function _mapLayout(layout) {
|
|
10
|
+
const layouts = {
|
|
11
|
+
stretchLastColumn: 'fitDataStretch',
|
|
12
|
+
stretchColumns: 'fitColumns',
|
|
13
|
+
lowDensity: 'fitData',
|
|
14
|
+
};
|
|
15
|
+
return layouts[layout] || 'fitDataFill';
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
exports._mapLayout = _mapLayout;
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=layout-8550b993.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"file":"layout-8550b993.js","mappings":";;AAcA;;;;;;SAMgB,UAAU,CAAC,MAAc;EACrC,MAAM,OAAO,GAAG;IACZ,iBAAiB,EAAE,gBAAgB;IACnC,cAAc,EAAE,YAAY;IAC5B,UAAU,EAAE,SAAS;GACxB,CAAC;EAEF,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,aAAa,CAAC;AAC5C;;;;","names":[],"sources":["./src/components/table/layout.ts"],"sourcesContent":["/**\n * Layouts:\n * - default: resizes the table's columns, in a way that each column becomes as wide as the data it holds\n * - stretchLastColumn: works like default, but the last column is stretched to fill any remaining space\n * - stretchColumns: when there is extra space, the columns are stretched to fill it, otherwise, this works just like default\n * - lowDensity: converts the table into an airy list of items\n * @public\n */\nexport type Layout =\n | 'default'\n | 'stretchLastColumn'\n | 'stretchColumns'\n | 'lowDensity';\n\n/**\n * Maps a layout to a Tabulator layout\n * @param layout - the layout to map\n * @returns the Tabulator layout\n * @internal\n */\nexport function _mapLayout(layout: Layout) {\n const layouts = {\n stretchLastColumn: 'fitDataStretch',\n stretchColumns: 'fitColumns',\n lowDensity: 'fitData',\n };\n\n return layouts[layout] || 'fitDataFill';\n}\n"],"version":3}
|