igniteui-grid-lite 0.4.0-beta.1 → 0.4.0-beta.3
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/components/column.js +1 -1
- package/components/column.js.map +1 -1
- package/components/grid.js +10 -4
- package/components/grid.js.map +1 -1
- package/components/header.js +1 -2
- package/components/header.js.map +1 -1
- package/custom-elements.json +1779 -1922
- package/internal/types.d.ts +10 -1
- package/internal/types.js.map +1 -1
- package/package.json +2 -2
- package/styles/themes/grid-header-themes.d.ts +1 -1
- package/styles/themes/grid-header-themes.js +4 -4
- package/styles/themes/grid-header-themes.js.map +1 -1
- package/styles/themes/grid-themes.d.ts +1 -1
- package/styles/themes/grid-themes.js +10 -10
- package/styles/themes/grid-themes.js.map +1 -1
- package/internal/theming.d.ts +0 -34
- package/internal/theming.js +0 -121
- package/internal/theming.js.map +0 -1
package/internal/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Theme } from 'igniteui-webcomponents';
|
|
2
|
+
import type { CSSResult, ReactiveControllerHost, TemplateResult } from 'lit';
|
|
2
3
|
import type IgcGridLiteCell from '../components/cell.js';
|
|
3
4
|
import type { IgcGridLite } from '../components/grid.js';
|
|
4
5
|
import type IgcGridLiteHeader from '../components/header.js';
|
|
@@ -6,6 +7,14 @@ import type IgcGridLiteRow from '../components/row.js';
|
|
|
6
7
|
import type { SortComparer } from '../operations/sort/types.js';
|
|
7
8
|
export type NavigationState = 'previous' | 'current';
|
|
8
9
|
export type GridHost<T extends object> = ReactiveControllerHost & IgcGridLite<T>;
|
|
10
|
+
export type Themes = {
|
|
11
|
+
light: {
|
|
12
|
+
[K in Theme | 'shared']?: CSSResult;
|
|
13
|
+
};
|
|
14
|
+
dark: {
|
|
15
|
+
[K in Theme | 'shared']?: CSSResult;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
9
18
|
type FlatKeys<T> = keyof T;
|
|
10
19
|
type DotPaths<T> = {
|
|
11
20
|
[K in keyof T & string]: T[K] extends object ? K | `${K}.${DotPaths<T[K]>}` : K;
|
package/internal/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/internal/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ReactiveControllerHost, TemplateResult } from 'lit';\nimport type IgcGridLiteCell from '../components/cell.js';\nimport type { IgcGridLite } from '../components/grid.js';\nimport type IgcGridLiteHeader from '../components/header.js';\nimport type IgcGridLiteRow from '../components/row.js';\nimport type { SortComparer } from '../operations/sort/types.js';\n\nexport type NavigationState = 'previous' | 'current';\nexport type GridHost<T extends object> = ReactiveControllerHost & IgcGridLite<T>;\n\ntype FlatKeys<T> = keyof T;\ntype DotPaths<T> = {\n [K in keyof T & string]: T[K] extends object\n ? K | `${K}.${DotPaths<T[K]>}` // Note: resolving `never` will collapse the entire interpolated string to never, leaving only valid paths\n : K;\n}[keyof T & string];\ntype NestedKeys<T> = Exclude<DotPaths<T>, FlatKeys<T>>;\n\n/**\n * Helper type for resolving keys of type T.\n */\nexport type Keys<T> = FlatKeys<T> | NestedKeys<T>;\n\n/** Recursive T[K] property type resolve with nested dot paths support */\ntype PathValue<T, P extends string> = P extends `${infer K}.${infer Rest}`\n ? K extends keyof T\n ? PathValue<T[K], Rest>\n : never\n : P extends keyof T\n ? T[P]\n : never;\n\n/**\n * Helper type for resolving types of type T.\n */\nexport type PropertyType<T, K extends Keys<T> = Keys<T>> = K extends NestedKeys<T>\n ? PathValue<T, K> // nested path\n : K extends keyof T\n ? T[K] // flat key\n : never;\n\n/** The data for the current column. */\nexport type DataType = 'number' | 'string' | 'boolean';\n\n/**\n * Configures the sort behavior for the grid.\n */\nexport interface GridLiteSortingOptions {\n /**\n * The sorting mode - either 'single' or 'multiple' column sorting.\n */\n mode: 'single' | 'multiple';\n}\n\n/**\n * Extended sort configuration for a column.\n */\nexport interface BaseColumnSortConfiguration<T, K extends Keys<T> = Keys<T>> {\n /**\n * Custom comparer function for sort operations for this column.\n */\n comparer?: SortComparer<T, K>;\n}\n\n/**\n * See {@link BaseColumnSortConfiguration} for the full documentation.\n */\nexport type ColumnSortConfiguration<T, K extends Keys<T> = Keys<T>> = K extends Keys<T>\n ? BaseColumnSortConfiguration<T, K>\n : never;\n\n/** Configuration object for grid columns. */\nexport interface BaseColumnConfiguration<T extends object, K extends Keys<T> = Keys<T>> {\n /**\n * The field from the data for this column.\n */\n field: K;\n /**\n * The type of data this column will reference.\n *\n * Affects the default filter operands if the column is with filtering enabled.\n *\n * @remarks\n * If not passed, `string` is assumed to be the default type.\n *\n */\n dataType?: DataType;\n /**\n * Optional text to display in the column header. By default, the column field is used\n * to render the header text.\n */\n header?: string;\n /**\n * Width for the current column.\n *\n * Accepts most CSS units for controlling width.\n *\n * @remarks\n * If not passed, the column will try to size itself based on the number of other\n * columns and the total width of the grid.\n *\n */\n width?: string;\n /**\n * Whether the column is hidden or not.\n */\n hidden?: boolean;\n /**\n * Whether the the column can be resized or not.\n */\n resizable?: boolean;\n /**\n * Whether the column can be sorted.\n */\n sortable?: boolean;\n /**\n * Whether the sort operations will be case sensitive.\n */\n sortingCaseSensitive?: boolean;\n /**\n * Sort configuration options for the column (e.g., custom comparer).\n */\n sortConfiguration?: ColumnSortConfiguration<T, K>;\n /**\n * Whether the column can be filtered.\n */\n filterable?: boolean;\n /**\n * Whether the filter operations will be case sensitive.\n */\n filteringCaseSensitive?: boolean;\n /**\n * Header template callback.\n */\n headerTemplate?: (params: IgcHeaderContext<T>) => TemplateResult | unknown;\n /**\n * Cell template callback.\n */\n cellTemplate?: (params: IgcCellContext<T, K>) => TemplateResult | unknown;\n}\n\n/**\n * See {@link BaseColumnConfiguration} for the full documentation.\n */\nexport type ColumnConfiguration<T extends object, K extends Keys<T> = Keys<T>> = K extends Keys<T>\n ? BaseColumnConfiguration<T, K>\n : never;\n\nexport interface ActiveNode<T> {\n column: Keys<T>;\n row: number;\n}\n\n/**\n * Context object for the column header template callback.\n */\nexport interface IgcHeaderContext<T extends object> {\n /**\n * The header element parent of the template.\n */\n parent: IgcGridLiteHeader<T>;\n /**\n * The current configuration for the column.\n */\n column: ColumnConfiguration<T>;\n}\n\n/**\n * Context object for the row cell template callback.\n */\nexport interface BaseIgcCellContext<T extends object, K extends Keys<T> = Keys<T>> {\n /**\n * The cell element parent of the template.\n */\n parent: IgcGridLiteCell<T>;\n /**\n * The row element containing the cell.\n */\n row: IgcGridLiteRow<T>;\n /**\n * The current configuration for the column.\n */\n column: ColumnConfiguration<T, K>;\n /**\n * The value from the data source for this cell.\n */\n value: PropertyType<T, K>;\n}\n\n/**\n * See {@link BaseIgcCellContext} for the full documentation.\n */\nexport type IgcCellContext<T extends object, K extends Keys<T> = Keys<T>> = K extends Keys<T>\n ? BaseIgcCellContext<T, K>\n : never;\n\n/**\n * The parameters passed to a {@link DataPipelineHook} callback.\n */\nexport type DataPipelineParams<T extends object> = {\n /**\n * The current data state of the grid.\n */\n data: T[];\n /**\n * The grid component itself.\n */\n grid: IgcGridLite<T>;\n /**\n * The type of data operation being performed.\n */\n type: 'sort' | 'filter';\n};\n\n/**\n * Callback function for customizing data operations in the grid.\n */\nexport type DataPipelineHook<T extends object> = (\n state: DataPipelineParams<T>\n) => T[] | Promise<T[]>;\n\n/**\n * Configuration for customizing the various data operations of the grid.\n */\nexport interface DataPipelineConfiguration<T extends object> {\n /**\n * Hook for customizing sort operations.\n */\n sort?: DataPipelineHook<T>;\n /**\n * Hook for customizing filter operations.\n */\n filter?: DataPipelineHook<T>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/internal/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Theme } from 'igniteui-webcomponents';\nimport type { CSSResult, ReactiveControllerHost, TemplateResult } from 'lit';\nimport type IgcGridLiteCell from '../components/cell.js';\nimport type { IgcGridLite } from '../components/grid.js';\nimport type IgcGridLiteHeader from '../components/header.js';\nimport type IgcGridLiteRow from '../components/row.js';\nimport type { SortComparer } from '../operations/sort/types.js';\n\nexport type NavigationState = 'previous' | 'current';\nexport type GridHost<T extends object> = ReactiveControllerHost & IgcGridLite<T>;\n\nexport type Themes = {\n light: {\n [K in Theme | 'shared']?: CSSResult;\n };\n dark: {\n [K in Theme | 'shared']?: CSSResult;\n };\n};\n\ntype FlatKeys<T> = keyof T;\ntype DotPaths<T> = {\n [K in keyof T & string]: T[K] extends object\n ? K | `${K}.${DotPaths<T[K]>}` // Note: resolving `never` will collapse the entire interpolated string to never, leaving only valid paths\n : K;\n}[keyof T & string];\ntype NestedKeys<T> = Exclude<DotPaths<T>, FlatKeys<T>>;\n\n/**\n * Helper type for resolving keys of type T.\n */\nexport type Keys<T> = FlatKeys<T> | NestedKeys<T>;\n\n/** Recursive T[K] property type resolve with nested dot paths support */\ntype PathValue<T, P extends string> = P extends `${infer K}.${infer Rest}`\n ? K extends keyof T\n ? PathValue<T[K], Rest>\n : never\n : P extends keyof T\n ? T[P]\n : never;\n\n/**\n * Helper type for resolving types of type T.\n */\nexport type PropertyType<T, K extends Keys<T> = Keys<T>> = K extends NestedKeys<T>\n ? PathValue<T, K> // nested path\n : K extends keyof T\n ? T[K] // flat key\n : never;\n\n/** The data for the current column. */\nexport type DataType = 'number' | 'string' | 'boolean';\n\n/**\n * Configures the sort behavior for the grid.\n */\nexport interface GridLiteSortingOptions {\n /**\n * The sorting mode - either 'single' or 'multiple' column sorting.\n */\n mode: 'single' | 'multiple';\n}\n\n/**\n * Extended sort configuration for a column.\n */\nexport interface BaseColumnSortConfiguration<T, K extends Keys<T> = Keys<T>> {\n /**\n * Custom comparer function for sort operations for this column.\n */\n comparer?: SortComparer<T, K>;\n}\n\n/**\n * See {@link BaseColumnSortConfiguration} for the full documentation.\n */\nexport type ColumnSortConfiguration<T, K extends Keys<T> = Keys<T>> = K extends Keys<T>\n ? BaseColumnSortConfiguration<T, K>\n : never;\n\n/** Configuration object for grid columns. */\nexport interface BaseColumnConfiguration<T extends object, K extends Keys<T> = Keys<T>> {\n /**\n * The field from the data for this column.\n */\n field: K;\n /**\n * The type of data this column will reference.\n *\n * Affects the default filter operands if the column is with filtering enabled.\n *\n * @remarks\n * If not passed, `string` is assumed to be the default type.\n *\n */\n dataType?: DataType;\n /**\n * Optional text to display in the column header. By default, the column field is used\n * to render the header text.\n */\n header?: string;\n /**\n * Width for the current column.\n *\n * Accepts most CSS units for controlling width.\n *\n * @remarks\n * If not passed, the column will try to size itself based on the number of other\n * columns and the total width of the grid.\n *\n */\n width?: string;\n /**\n * Whether the column is hidden or not.\n */\n hidden?: boolean;\n /**\n * Whether the the column can be resized or not.\n */\n resizable?: boolean;\n /**\n * Whether the column can be sorted.\n */\n sortable?: boolean;\n /**\n * Whether the sort operations will be case sensitive.\n */\n sortingCaseSensitive?: boolean;\n /**\n * Sort configuration options for the column (e.g., custom comparer).\n */\n sortConfiguration?: ColumnSortConfiguration<T, K>;\n /**\n * Whether the column can be filtered.\n */\n filterable?: boolean;\n /**\n * Whether the filter operations will be case sensitive.\n */\n filteringCaseSensitive?: boolean;\n /**\n * Header template callback.\n */\n headerTemplate?: (params: IgcHeaderContext<T>) => TemplateResult | unknown;\n /**\n * Cell template callback.\n */\n cellTemplate?: (params: IgcCellContext<T, K>) => TemplateResult | unknown;\n}\n\n/**\n * See {@link BaseColumnConfiguration} for the full documentation.\n */\nexport type ColumnConfiguration<T extends object, K extends Keys<T> = Keys<T>> = K extends Keys<T>\n ? BaseColumnConfiguration<T, K>\n : never;\n\nexport interface ActiveNode<T> {\n column: Keys<T>;\n row: number;\n}\n\n/**\n * Context object for the column header template callback.\n */\nexport interface IgcHeaderContext<T extends object> {\n /**\n * The header element parent of the template.\n */\n parent: IgcGridLiteHeader<T>;\n /**\n * The current configuration for the column.\n */\n column: ColumnConfiguration<T>;\n}\n\n/**\n * Context object for the row cell template callback.\n */\nexport interface BaseIgcCellContext<T extends object, K extends Keys<T> = Keys<T>> {\n /**\n * The cell element parent of the template.\n */\n parent: IgcGridLiteCell<T>;\n /**\n * The row element containing the cell.\n */\n row: IgcGridLiteRow<T>;\n /**\n * The current configuration for the column.\n */\n column: ColumnConfiguration<T, K>;\n /**\n * The value from the data source for this cell.\n */\n value: PropertyType<T, K>;\n}\n\n/**\n * See {@link BaseIgcCellContext} for the full documentation.\n */\nexport type IgcCellContext<T extends object, K extends Keys<T> = Keys<T>> = K extends Keys<T>\n ? BaseIgcCellContext<T, K>\n : never;\n\n/**\n * The parameters passed to a {@link DataPipelineHook} callback.\n */\nexport type DataPipelineParams<T extends object> = {\n /**\n * The current data state of the grid.\n */\n data: T[];\n /**\n * The grid component itself.\n */\n grid: IgcGridLite<T>;\n /**\n * The type of data operation being performed.\n */\n type: 'sort' | 'filter';\n};\n\n/**\n * Callback function for customizing data operations in the grid.\n */\nexport type DataPipelineHook<T extends object> = (\n state: DataPipelineParams<T>\n) => T[] | Promise<T[]>;\n\n/**\n * Configuration for customizing the various data operations of the grid.\n */\nexport interface DataPipelineConfiguration<T extends object> {\n /**\n * Hook for customizing sort operations.\n */\n sort?: DataPipelineHook<T>;\n /**\n * Hook for customizing filter operations.\n */\n filter?: DataPipelineHook<T>;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "igniteui-grid-lite",
|
|
3
|
-
"version": "0.4.0-beta.
|
|
3
|
+
"version": "0.4.0-beta.3",
|
|
4
4
|
"description": "Web component data grid following open-wc recommendations",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lit",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@lit-labs/virtualizer": "~2.1.0",
|
|
37
37
|
"@lit/context": "~1.1.5",
|
|
38
|
-
"igniteui-webcomponents": "~6.
|
|
38
|
+
"igniteui-webcomponents": "~6.5.0",
|
|
39
39
|
"lit": "^3.3.0"
|
|
40
40
|
}
|
|
41
41
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Themes } from '../../internal/
|
|
1
|
+
import type { Themes } from '../../internal/types.js';
|
|
2
2
|
export declare const all: Themes;
|
|
@@ -3,18 +3,18 @@ import { styles as bootstrap } from './shared/header.bootstrap.css.js';
|
|
|
3
3
|
import { styles as fluent } from './shared/header.fluent.css.js';
|
|
4
4
|
const light = {
|
|
5
5
|
bootstrap: css `
|
|
6
|
-
|
|
6
|
+
${bootstrap}
|
|
7
7
|
`,
|
|
8
8
|
fluent: css `
|
|
9
|
-
|
|
9
|
+
${fluent}
|
|
10
10
|
`,
|
|
11
11
|
};
|
|
12
12
|
const dark = {
|
|
13
13
|
bootstrap: css `
|
|
14
|
-
|
|
14
|
+
${bootstrap}
|
|
15
15
|
`,
|
|
16
16
|
fluent: css `
|
|
17
|
-
|
|
17
|
+
${fluent}
|
|
18
18
|
`,
|
|
19
19
|
};
|
|
20
20
|
export const all = { light, dark };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grid-header-themes.js","sourceRoot":"","sources":["../../../src/styles/themes/grid-header-themes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"grid-header-themes.js","sourceRoot":"","sources":["../../../src/styles/themes/grid-header-themes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAI1B,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,EAAE,MAAM,IAAI,MAAM,EAAE,MAAM,+BAA+B,CAAC;AAEjE,MAAM,KAAK,GAAG;IACZ,SAAS,EAAE,GAAG,CAAA;MACV,SAAS;GACZ;IACD,MAAM,EAAE,GAAG,CAAA;MACP,MAAM;GACT;CACF,CAAC;AAEF,MAAM,IAAI,GAAG;IACX,SAAS,EAAE,GAAG,CAAA;MACV,SAAS;GACZ;IACD,MAAM,EAAE,GAAG,CAAA;MACP,MAAM;GACT;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,GAAG,GAAW,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC","sourcesContent":["import { css } from 'lit';\n\nimport type { Themes } from '../../internal/types.js';\n// Shared\nimport { styles as bootstrap } from './shared/header.bootstrap.css.js';\nimport { styles as fluent } from './shared/header.fluent.css.js';\n\nconst light = {\n bootstrap: css`\n ${bootstrap}\n `,\n fluent: css`\n ${fluent}\n `,\n};\n\nconst dark = {\n bootstrap: css`\n ${bootstrap}\n `,\n fluent: css`\n ${fluent}\n `,\n};\n\nexport const all: Themes = { light, dark };\n"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Themes } from '../../internal/
|
|
1
|
+
import type { Themes } from '../../internal/types.js';
|
|
2
2
|
export declare const all: Themes;
|
|
@@ -11,36 +11,36 @@ import { styles as shared } from './light/grid.shared.css.js';
|
|
|
11
11
|
import { styles as bootstrap } from './shared/grid.common.css.js';
|
|
12
12
|
const light = {
|
|
13
13
|
shared: css `
|
|
14
|
-
|
|
14
|
+
${shared}
|
|
15
15
|
`,
|
|
16
16
|
bootstrap: css `
|
|
17
|
-
|
|
17
|
+
${bootstrap} ${bootstrapLight}
|
|
18
18
|
`,
|
|
19
19
|
material: css `
|
|
20
|
-
|
|
20
|
+
${materialLight}
|
|
21
21
|
`,
|
|
22
22
|
fluent: css `
|
|
23
|
-
|
|
23
|
+
${fluentLight}
|
|
24
24
|
`,
|
|
25
25
|
indigo: css `
|
|
26
|
-
|
|
26
|
+
${indigoLight}
|
|
27
27
|
`,
|
|
28
28
|
};
|
|
29
29
|
const dark = {
|
|
30
30
|
shared: css `
|
|
31
|
-
|
|
31
|
+
${shared}
|
|
32
32
|
`,
|
|
33
33
|
bootstrap: css `
|
|
34
|
-
|
|
34
|
+
${bootstrapDark}
|
|
35
35
|
`,
|
|
36
36
|
material: css `
|
|
37
|
-
|
|
37
|
+
${materialDark}
|
|
38
38
|
`,
|
|
39
39
|
fluent: css `
|
|
40
|
-
|
|
40
|
+
${fluentDark}
|
|
41
41
|
`,
|
|
42
42
|
indigo: css `
|
|
43
|
-
|
|
43
|
+
${indigoDark}
|
|
44
44
|
`,
|
|
45
45
|
};
|
|
46
46
|
export const all = { light, dark };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grid-themes.js","sourceRoot":"","sources":["../../../src/styles/themes/grid-themes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"grid-themes.js","sourceRoot":"","sources":["../../../src/styles/themes/grid-themes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAG1B,OAAO,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAErE,OAAO,EAAE,MAAM,IAAI,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,MAAM,IAAI,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,MAAM,IAAI,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,MAAM,IAAI,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAE9D,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAElE,MAAM,KAAK,GAAG;IACZ,MAAM,EAAE,GAAG,CAAA;MACP,MAAM;GACT;IACD,SAAS,EAAE,GAAG,CAAA;MACV,SAAS,IAAI,cAAc;GAC9B;IACD,QAAQ,EAAE,GAAG,CAAA;MACT,aAAa;GAChB;IACD,MAAM,EAAE,GAAG,CAAA;MACP,WAAW;GACd;IACD,MAAM,EAAE,GAAG,CAAA;MACP,WAAW;GACd;CACF,CAAC;AAEF,MAAM,IAAI,GAAG;IACX,MAAM,EAAE,GAAG,CAAA;MACP,MAAM;GACT;IACD,SAAS,EAAE,GAAG,CAAA;MACV,aAAa;GAChB;IACD,QAAQ,EAAE,GAAG,CAAA;MACT,YAAY;GACf;IACD,MAAM,EAAE,GAAG,CAAA;MACP,UAAU;GACb;IACD,MAAM,EAAE,GAAG,CAAA;MACP,UAAU;GACb;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,GAAG,GAAW,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC","sourcesContent":["import { css } from 'lit';\nimport type { Themes } from '../../internal/types.js';\n// Dark Overrides\nimport { styles as bootstrapDark } from './dark/grid.bootstrap.css.js';\nimport { styles as fluentDark } from './dark/grid.fluent.css.js';\nimport { styles as indigoDark } from './dark/grid.indigo.css.js';\nimport { styles as materialDark } from './dark/grid.material.css.js';\n// Light Overrides\nimport { styles as bootstrapLight } from './light/grid.bootstrap.css.js';\nimport { styles as fluentLight } from './light/grid.fluent.css.js';\nimport { styles as indigoLight } from './light/grid.indigo.css.js';\nimport { styles as materialLight } from './light/grid.material.css.js';\nimport { styles as shared } from './light/grid.shared.css.js';\n// Shared\nimport { styles as bootstrap } from './shared/grid.common.css.js';\n\nconst light = {\n shared: css`\n ${shared}\n `,\n bootstrap: css`\n ${bootstrap} ${bootstrapLight}\n `,\n material: css`\n ${materialLight}\n `,\n fluent: css`\n ${fluentLight}\n `,\n indigo: css`\n ${indigoLight}\n `,\n};\n\nconst dark = {\n shared: css`\n ${shared}\n `,\n bootstrap: css`\n ${bootstrapDark}\n `,\n material: css`\n ${materialDark}\n `,\n fluent: css`\n ${fluentDark}\n `,\n indigo: css`\n ${indigoDark}\n `,\n};\n\nexport const all: Themes = { light, dark };\n"]}
|
package/internal/theming.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { CSSResult, ReactiveController, ReactiveControllerHost, ReactiveElement } from 'lit';
|
|
2
|
-
type Theme = 'material' | 'bootstrap' | 'indigo' | 'fluent';
|
|
3
|
-
export type Themes = {
|
|
4
|
-
light: {
|
|
5
|
-
[K in Theme | 'shared']?: CSSResult;
|
|
6
|
-
};
|
|
7
|
-
dark: {
|
|
8
|
-
[K in Theme | 'shared']?: CSSResult;
|
|
9
|
-
};
|
|
10
|
-
};
|
|
11
|
-
type ThemeChangedCallback = (theme: Theme) => unknown;
|
|
12
|
-
type ThemingControllerConfig = {
|
|
13
|
-
themeChange?: ThemeChangedCallback;
|
|
14
|
-
};
|
|
15
|
-
declare class ThemingController implements ReactiveController {
|
|
16
|
-
private readonly _host;
|
|
17
|
-
private readonly _themes;
|
|
18
|
-
private readonly _options?;
|
|
19
|
-
private _theme;
|
|
20
|
-
private _variant;
|
|
21
|
-
get theme(): Theme;
|
|
22
|
-
constructor(host: ReactiveControllerHost & ReactiveElement, themes: Themes, config?: ThemingControllerConfig);
|
|
23
|
-
/** @internal */
|
|
24
|
-
hostConnected(): void;
|
|
25
|
-
/** @internal */
|
|
26
|
-
hostDisconnected(): void;
|
|
27
|
-
/** @internal */
|
|
28
|
-
handleEvent(): void;
|
|
29
|
-
private _getStyles;
|
|
30
|
-
protected _adoptStyles(): void;
|
|
31
|
-
private _handleThemeChanged;
|
|
32
|
-
}
|
|
33
|
-
export declare function addThemingController(host: ReactiveControllerHost & ReactiveElement, themes: Themes, config?: ThemingControllerConfig): ThemingController;
|
|
34
|
-
export type { ThemingController };
|
package/internal/theming.js
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { adoptStyles, css, isServer } from 'lit';
|
|
2
|
-
const CHANGE_THEME_EVENT = 'igc-change-theme';
|
|
3
|
-
let theme;
|
|
4
|
-
let themeVariant;
|
|
5
|
-
function isStyleRule(rule) {
|
|
6
|
-
return rule != null && 'style' in rule;
|
|
7
|
-
}
|
|
8
|
-
function cssKeyToJsKey(key) {
|
|
9
|
-
return key.replace(/^--|-./g, (match) => {
|
|
10
|
-
return match.startsWith('--') ? '' : match.charAt(1).toUpperCase();
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
function getAllCssVariableNames() {
|
|
14
|
-
const cssVars = new Set();
|
|
15
|
-
const styleSheets = Array.from(document.styleSheets);
|
|
16
|
-
for (const sheet of styleSheets) {
|
|
17
|
-
let rules;
|
|
18
|
-
try {
|
|
19
|
-
rules = sheet.cssRules;
|
|
20
|
-
}
|
|
21
|
-
catch {
|
|
22
|
-
continue;
|
|
23
|
-
}
|
|
24
|
-
if (!rules) {
|
|
25
|
-
continue;
|
|
26
|
-
}
|
|
27
|
-
for (const rule of Array.from(rules)) {
|
|
28
|
-
if (isStyleRule(rule)) {
|
|
29
|
-
const length = rule.style.length;
|
|
30
|
-
for (let i = 0; i < length; i++) {
|
|
31
|
-
const style = rule.style[i];
|
|
32
|
-
if (style.startsWith('--')) {
|
|
33
|
-
cssVars.add(style);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return cssVars;
|
|
40
|
-
}
|
|
41
|
-
function getElementCssVariables(allCssVars, element, pseudo) {
|
|
42
|
-
const cssVars = {};
|
|
43
|
-
const styles = getComputedStyle(element, pseudo);
|
|
44
|
-
for (const key of allCssVars) {
|
|
45
|
-
const value = styles.getPropertyValue(key);
|
|
46
|
-
if (value) {
|
|
47
|
-
cssVars[cssKeyToJsKey(key)] = value.trim();
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return cssVars;
|
|
51
|
-
}
|
|
52
|
-
function getAllCssVariables() {
|
|
53
|
-
return isServer ? {} : getElementCssVariables(getAllCssVariableNames(), document.documentElement);
|
|
54
|
-
}
|
|
55
|
-
function isOfTypeTheme(theme) {
|
|
56
|
-
return ['bootstrap', 'material', 'indigo', 'fluent'].includes(theme);
|
|
57
|
-
}
|
|
58
|
-
function isOfTypeThemeVariant(variant) {
|
|
59
|
-
return ['light', 'dark'].includes(variant);
|
|
60
|
-
}
|
|
61
|
-
function getTheme() {
|
|
62
|
-
const cssVars = getAllCssVariables();
|
|
63
|
-
const foundTheme = cssVars.igTheme;
|
|
64
|
-
const foundVariant = cssVars.igThemeVariant;
|
|
65
|
-
theme = isOfTypeTheme(foundTheme) ? foundTheme : 'bootstrap';
|
|
66
|
-
themeVariant = isOfTypeThemeVariant(foundVariant) ? foundVariant : 'light';
|
|
67
|
-
return { theme, themeVariant };
|
|
68
|
-
}
|
|
69
|
-
class ThemingController {
|
|
70
|
-
get theme() {
|
|
71
|
-
return this._theme;
|
|
72
|
-
}
|
|
73
|
-
constructor(host, themes, config) {
|
|
74
|
-
this._theme = 'bootstrap';
|
|
75
|
-
this._variant = 'light';
|
|
76
|
-
this._host = host;
|
|
77
|
-
this._themes = themes;
|
|
78
|
-
this._options = config;
|
|
79
|
-
this._host.addController(this);
|
|
80
|
-
}
|
|
81
|
-
hostConnected() {
|
|
82
|
-
this._handleThemeChanged();
|
|
83
|
-
globalThis.addEventListener(CHANGE_THEME_EVENT, this);
|
|
84
|
-
}
|
|
85
|
-
hostDisconnected() {
|
|
86
|
-
globalThis.removeEventListener(CHANGE_THEME_EVENT, this);
|
|
87
|
-
}
|
|
88
|
-
handleEvent() {
|
|
89
|
-
this._handleThemeChanged();
|
|
90
|
-
}
|
|
91
|
-
_getStyles() {
|
|
92
|
-
const props = this._themes[this._variant];
|
|
93
|
-
const styles = { shared: css ``, theme: css `` };
|
|
94
|
-
for (const [name, sheet] of Object.entries(props)) {
|
|
95
|
-
if (name === 'shared') {
|
|
96
|
-
styles.shared = sheet;
|
|
97
|
-
}
|
|
98
|
-
if (name === this.theme) {
|
|
99
|
-
styles.theme = sheet;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return styles;
|
|
103
|
-
}
|
|
104
|
-
_adoptStyles() {
|
|
105
|
-
const { theme: currentTheme, themeVariant } = getTheme();
|
|
106
|
-
this._theme = currentTheme;
|
|
107
|
-
this._variant = themeVariant;
|
|
108
|
-
const ctor = this._host.constructor;
|
|
109
|
-
const { shared, theme } = this._getStyles();
|
|
110
|
-
adoptStyles(this._host.shadowRoot, [...ctor.elementStyles, shared, theme]);
|
|
111
|
-
}
|
|
112
|
-
_handleThemeChanged() {
|
|
113
|
-
this._adoptStyles();
|
|
114
|
-
this._options?.themeChange?.call(this._host, this._theme);
|
|
115
|
-
this._host.requestUpdate();
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
export function addThemingController(host, themes, config) {
|
|
119
|
-
return new ThemingController(host, themes, config);
|
|
120
|
-
}
|
|
121
|
-
//# sourceMappingURL=theming.js.map
|
package/internal/theming.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"theming.js","sourceRoot":"","sources":["../../src/internal/theming.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AAmBjD,MAAM,kBAAkB,GAAG,kBAAkB,CAAC;AAC9C,IAAI,KAAY,CAAC;AACjB,IAAI,YAA0B,CAAC;AAE/B,SAAS,WAAW,CAAC,IAAa;IAChC,OAAO,IAAI,IAAI,IAAI,IAAI,OAAO,IAAI,IAAI,CAAC;AACzC,CAAC;AAED,SAAS,aAAa,CAAC,GAAW;IAChC,OAAO,GAAG,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE;QACtC,OAAO,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;IACrE,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,sBAAsB;IAC7B,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAClC,MAAM,WAAW,GA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UAAU,EAAE,CAAC;QAE5C,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,UAAW,EAAE,CAAC,GAAG,IAAI,CAAC,aAAa,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;IAC9E,CAAC;IAEO,mBAAmB;QACzB,IAAI,CAAC,YAAY,EAAE,CAAC;QACpB,IAAI,CAAC,QAAQ,EAAE,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QAC1D,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC;IAC7B,CAAC;CACF;AAED,MAAM,UAAU,oBAAoB,CAClC,IAA8C,EAC9C,MAAc,EACd,MAAgC;IAEhC,OAAO,IAAI,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AACrD,CAAC","sourcesContent":["import type {\n CSSResult,\n LitElement,\n ReactiveController,\n ReactiveControllerHost,\n ReactiveElement,\n} from 'lit';\nimport { adoptStyles, css, isServer } from 'lit';\n\ntype Theme = 'material' | 'bootstrap' | 'indigo' | 'fluent';\ntype ThemeVariant = 'light' | 'dark';\n\nexport type Themes = {\n light: {\n [K in Theme | 'shared']?: CSSResult;\n };\n dark: {\n [K in Theme | 'shared']?: CSSResult;\n };\n};\n\ntype ThemeChangedCallback = (theme: Theme) => unknown;\ntype ThemingControllerConfig = {\n themeChange?: ThemeChangedCallback;\n};\n\nconst CHANGE_THEME_EVENT = 'igc-change-theme';\nlet theme: Theme;\nlet themeVariant: ThemeVariant;\n\nfunction isStyleRule(rule: CSSRule): rule is CSSStyleRule {\n return rule != null && 'style' in rule;\n}\n\nfunction cssKeyToJsKey(key: string): string {\n return key.replace(/^--|-./g, (match) => {\n return match.startsWith('--') ? '' : match.charAt(1).toUpperCase();\n });\n}\n\nfunction getAllCssVariableNames(): Set<string> {\n const cssVars = new Set<string>();\n const styleSheets = Array.from(document.styleSheets);\n\n for (const sheet of styleSheets) {\n let rules: CSSRuleList | undefined;\n\n // Potential CORS or access errors\n try {\n rules = sheet.cssRules;\n } catch {\n continue;\n }\n\n if (!rules) {\n continue;\n }\n\n for (const rule of Array.from(rules)) {\n if (isStyleRule(rule)) {\n const length = rule.style.length;\n\n for (let i = 0; i < length; i++) {\n const style = rule.style[i];\n\n if (style.startsWith('--')) {\n cssVars.add(style);\n }\n }\n }\n }\n }\n\n return cssVars;\n}\n\nfunction getElementCssVariables(\n allCssVars: Set<string>,\n element: HTMLElement,\n pseudo?: string\n): Record<string, string> {\n const cssVars: Record<string, string> = {};\n const styles = getComputedStyle(element, pseudo);\n\n for (const key of allCssVars) {\n const value = styles.getPropertyValue(key);\n\n if (value) {\n cssVars[cssKeyToJsKey(key)] = value.trim();\n }\n }\n\n return cssVars;\n}\n\nfunction getAllCssVariables(): Record<string, string> {\n /* c8 ignore next 2 */\n return isServer ? {} : getElementCssVariables(getAllCssVariableNames(), document.documentElement);\n}\n\nfunction isOfTypeTheme(theme: string): theme is Theme {\n return ['bootstrap', 'material', 'indigo', 'fluent'].includes(theme);\n}\n\nfunction isOfTypeThemeVariant(variant: string): variant is ThemeVariant {\n return ['light', 'dark'].includes(variant);\n}\n\nfunction getTheme() {\n const cssVars = getAllCssVariables();\n const foundTheme = cssVars.igTheme;\n const foundVariant = cssVars.igThemeVariant;\n\n theme = isOfTypeTheme(foundTheme) ? foundTheme : 'bootstrap';\n themeVariant = isOfTypeThemeVariant(foundVariant) ? foundVariant : 'light';\n\n return { theme, themeVariant };\n}\n\nclass ThemingController implements ReactiveController {\n private readonly _host: ReactiveControllerHost & ReactiveElement;\n private readonly _themes: Themes;\n private readonly _options?: ThemingControllerConfig;\n\n private _theme: Theme = 'bootstrap';\n private _variant: ThemeVariant = 'light';\n\n public get theme(): Theme {\n return this._theme;\n }\n\n constructor(\n host: ReactiveControllerHost & ReactiveElement,\n themes: Themes,\n config?: ThemingControllerConfig\n ) {\n this._host = host;\n this._themes = themes;\n this._options = config;\n this._host.addController(this);\n }\n\n /** @internal */\n public hostConnected(): void {\n this._handleThemeChanged();\n globalThis.addEventListener(CHANGE_THEME_EVENT, this);\n }\n\n /** @internal */\n public hostDisconnected(): void {\n globalThis.removeEventListener(CHANGE_THEME_EVENT, this);\n }\n\n /** @internal */\n public handleEvent(): void {\n this._handleThemeChanged();\n }\n\n private _getStyles() {\n const props = this._themes[this._variant];\n const styles = { shared: css``, theme: css`` };\n\n for (const [name, sheet] of Object.entries(props)) {\n if (name === 'shared') {\n styles.shared = sheet;\n }\n if (name === this.theme) {\n styles.theme = sheet;\n }\n }\n\n return styles;\n }\n\n protected _adoptStyles(): void {\n const { theme: currentTheme, themeVariant } = getTheme();\n this._theme = currentTheme;\n this._variant = themeVariant;\n\n const ctor = this._host.constructor as typeof LitElement;\n const { shared, theme } = this._getStyles();\n\n adoptStyles(this._host.shadowRoot!, [...ctor.elementStyles, shared, theme]);\n }\n\n private _handleThemeChanged(): void {\n this._adoptStyles();\n this._options?.themeChange?.call(this._host, this._theme);\n this._host.requestUpdate();\n }\n}\n\nexport function addThemingController(\n host: ReactiveControllerHost & ReactiveElement,\n themes: Themes,\n config?: ThemingControllerConfig\n): ThemingController {\n return new ThemingController(host, themes, config);\n}\n\nexport type { ThemingController };\n"]}
|