@adecore/ui 0.54.0 → 0.54.2
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/dist/FileIcon.d.ts +1 -1
- package/dist/FileIcon.js +44 -36
- package/dist/file-icon.d.ts +2 -0
- package/dist/file-icon.js +12 -0
- package/package.json +1 -1
- package/src/FileIcon.tsx +15 -6
- package/src/file-icon.ts +15 -0
package/dist/FileIcon.d.ts
CHANGED
|
@@ -3,6 +3,6 @@ export interface FileIconProps {
|
|
|
3
3
|
path: string;
|
|
4
4
|
size?: number;
|
|
5
5
|
className?: string;
|
|
6
|
-
ref?: Ref<SVGSVGElement>;
|
|
6
|
+
ref?: Ref<SVGSVGElement | HTMLImageElement>;
|
|
7
7
|
}
|
|
8
8
|
export declare function FileIcon({ path, size, className, ref }: FileIconProps): import("react").JSX.Element;
|
package/dist/FileIcon.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { c as _c } from "react/compiler-runtime";
|
|
2
2
|
import clsx from 'clsx';
|
|
3
|
-
import { useInsertionEffect } from 'react';
|
|
4
|
-
import { fileIconFor, fileIconOverrideFor, mountFileIconSprite } from './file-icon.js';
|
|
3
|
+
import { useInsertionEffect, useSyncExternalStore } from 'react';
|
|
4
|
+
import { fileIconFor, fileIconOverrideFor, fileIconOverrideVersion, mountFileIconSprite, subscribeFileIconOverride } from './file-icon.js';
|
|
5
5
|
/*
|
|
6
6
|
* The one place the library steps outside Lucide. The glyphs are Seti's, and so are their colors: a
|
|
7
7
|
* TypeScript blue is the mark of the file type, not a theme choice. Decorative like every other icon here.
|
|
8
8
|
*/
|
|
9
9
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
10
|
export function FileIcon(t0) {
|
|
11
|
-
const $ = _c(
|
|
11
|
+
const $ = _c(22);
|
|
12
12
|
const {
|
|
13
13
|
path,
|
|
14
14
|
size: t1,
|
|
@@ -24,71 +24,75 @@ export function FileIcon(t0) {
|
|
|
24
24
|
t2 = $[0];
|
|
25
25
|
}
|
|
26
26
|
useInsertionEffect(mountFileIconSprite, t2);
|
|
27
|
+
const version = useSyncExternalStore(subscribeFileIconOverride, fileIconOverrideVersion, fileIconOverrideVersion);
|
|
27
28
|
let t3;
|
|
28
|
-
if ($[1] !== path) {
|
|
29
|
-
t3 =
|
|
29
|
+
if ($[1] !== path || $[2] !== version) {
|
|
30
|
+
t3 = overrideFor(path, version);
|
|
30
31
|
$[1] = path;
|
|
31
|
-
$[2] =
|
|
32
|
+
$[2] = version;
|
|
33
|
+
$[3] = t3;
|
|
32
34
|
} else {
|
|
33
|
-
t3 = $[
|
|
35
|
+
t3 = $[3];
|
|
34
36
|
}
|
|
35
37
|
const own = t3;
|
|
36
38
|
if (own !== null) {
|
|
37
39
|
let t4;
|
|
38
|
-
if ($[
|
|
40
|
+
if ($[4] !== className) {
|
|
39
41
|
t4 = clsx("file-icon", className);
|
|
40
|
-
$[
|
|
41
|
-
$[
|
|
42
|
+
$[4] = className;
|
|
43
|
+
$[5] = t4;
|
|
42
44
|
} else {
|
|
43
|
-
t4 = $[
|
|
45
|
+
t4 = $[5];
|
|
44
46
|
}
|
|
45
47
|
let t5;
|
|
46
|
-
if ($[
|
|
48
|
+
if ($[6] !== own || $[7] !== ref || $[8] !== size || $[9] !== t4) {
|
|
47
49
|
t5 = /*#__PURE__*/_jsx("img", {
|
|
50
|
+
ref: ref,
|
|
48
51
|
src: own,
|
|
49
52
|
alt: "",
|
|
50
53
|
width: size,
|
|
51
54
|
height: size,
|
|
52
55
|
className: t4
|
|
53
56
|
});
|
|
54
|
-
$[
|
|
55
|
-
$[
|
|
56
|
-
$[
|
|
57
|
-
$[
|
|
57
|
+
$[6] = own;
|
|
58
|
+
$[7] = ref;
|
|
59
|
+
$[8] = size;
|
|
60
|
+
$[9] = t4;
|
|
61
|
+
$[10] = t5;
|
|
58
62
|
} else {
|
|
59
|
-
t5 = $[
|
|
63
|
+
t5 = $[10];
|
|
60
64
|
}
|
|
61
65
|
return t5;
|
|
62
66
|
}
|
|
63
67
|
let t4;
|
|
64
|
-
if ($[
|
|
68
|
+
if ($[11] !== className) {
|
|
65
69
|
t4 = clsx("file-icon", className);
|
|
66
|
-
$[
|
|
67
|
-
$[
|
|
70
|
+
$[11] = className;
|
|
71
|
+
$[12] = t4;
|
|
68
72
|
} else {
|
|
69
|
-
t4 = $[
|
|
73
|
+
t4 = $[12];
|
|
70
74
|
}
|
|
71
75
|
let t5;
|
|
72
|
-
if ($[
|
|
76
|
+
if ($[13] !== path) {
|
|
73
77
|
t5 = fileIconFor(path);
|
|
74
|
-
$[
|
|
75
|
-
$[
|
|
78
|
+
$[13] = path;
|
|
79
|
+
$[14] = t5;
|
|
76
80
|
} else {
|
|
77
|
-
t5 = $[
|
|
81
|
+
t5 = $[14];
|
|
78
82
|
}
|
|
79
83
|
const t6 = `#${t5}`;
|
|
80
84
|
let t7;
|
|
81
|
-
if ($[
|
|
85
|
+
if ($[15] !== t6) {
|
|
82
86
|
t7 = /*#__PURE__*/_jsx("use", {
|
|
83
87
|
href: t6
|
|
84
88
|
});
|
|
85
|
-
$[
|
|
86
|
-
$[
|
|
89
|
+
$[15] = t6;
|
|
90
|
+
$[16] = t7;
|
|
87
91
|
} else {
|
|
88
|
-
t7 = $[
|
|
92
|
+
t7 = $[16];
|
|
89
93
|
}
|
|
90
94
|
let t8;
|
|
91
|
-
if ($[
|
|
95
|
+
if ($[17] !== ref || $[18] !== size || $[19] !== t4 || $[20] !== t7) {
|
|
92
96
|
t8 = /*#__PURE__*/_jsx("svg", {
|
|
93
97
|
ref: ref,
|
|
94
98
|
className: t4,
|
|
@@ -98,13 +102,17 @@ export function FileIcon(t0) {
|
|
|
98
102
|
"aria-hidden": true,
|
|
99
103
|
children: t7
|
|
100
104
|
});
|
|
101
|
-
$[
|
|
102
|
-
$[
|
|
103
|
-
$[
|
|
104
|
-
$[
|
|
105
|
-
$[
|
|
105
|
+
$[17] = ref;
|
|
106
|
+
$[18] = size;
|
|
107
|
+
$[19] = t4;
|
|
108
|
+
$[20] = t7;
|
|
109
|
+
$[21] = t8;
|
|
106
110
|
} else {
|
|
107
|
-
t8 = $[
|
|
111
|
+
t8 = $[21];
|
|
108
112
|
}
|
|
109
113
|
return t8;
|
|
114
|
+
}
|
|
115
|
+
/* Takes the version so the compiler caches the result on it as well as on the path. */
|
|
116
|
+
function overrideFor(path, _version) {
|
|
117
|
+
return fileIconOverrideFor(path);
|
|
110
118
|
}
|
package/dist/file-icon.d.ts
CHANGED
|
@@ -2,5 +2,7 @@ import { type FileTreeIconConfig } from '@pierre/trees';
|
|
|
2
2
|
export declare const FILE_TREE_ICONS: FileTreeIconConfig;
|
|
3
3
|
export declare const fileIconFor: (path: string) => string;
|
|
4
4
|
export declare function setFileIconOverride(next: ((path: string) => string | null) | null): void;
|
|
5
|
+
export declare function subscribeFileIconOverride(onChange: () => void): () => void;
|
|
6
|
+
export declare const fileIconOverrideVersion: () => number;
|
|
5
7
|
export declare function fileIconOverrideFor(path: string): string | null;
|
|
6
8
|
export declare const mountFileIconSprite: () => void;
|
package/dist/file-icon.js
CHANGED
|
@@ -25,10 +25,22 @@ const resolveIcon = (...args) => {
|
|
|
25
25
|
*/
|
|
26
26
|
export const fileIconFor = path => resolveIcon('file-tree-icon-file', path).name;
|
|
27
27
|
let override = null;
|
|
28
|
+
let overrideVersion = 0;
|
|
29
|
+
const overrideListeners = new Set();
|
|
28
30
|
/* What an app knows better about a file's icon: the address of an svg, or null for the icon this set has. */
|
|
29
31
|
export function setFileIconOverride(next) {
|
|
30
32
|
override = next;
|
|
33
|
+
overrideVersion++;
|
|
34
|
+
overrideListeners.forEach(listener => listener());
|
|
31
35
|
}
|
|
36
|
+
export function subscribeFileIconOverride(onChange) {
|
|
37
|
+
overrideListeners.add(onChange);
|
|
38
|
+
return () => {
|
|
39
|
+
overrideListeners.delete(onChange);
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/* A mounted icon reads this so it draws again once the override changes. */
|
|
43
|
+
export const fileIconOverrideVersion = () => overrideVersion;
|
|
32
44
|
export function fileIconOverrideFor(path) {
|
|
33
45
|
return override?.(path) ?? null;
|
|
34
46
|
}
|
package/package.json
CHANGED
package/src/FileIcon.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import clsx from 'clsx';
|
|
2
|
-
import { useInsertionEffect, type Ref } from 'react';
|
|
3
|
-
import { fileIconFor, fileIconOverrideFor, mountFileIconSprite } from './file-icon.ts';
|
|
2
|
+
import { useInsertionEffect, useSyncExternalStore, type Ref } from 'react';
|
|
3
|
+
import { fileIconFor, fileIconOverrideFor, fileIconOverrideVersion, mountFileIconSprite, subscribeFileIconOverride } from './file-icon.ts';
|
|
4
4
|
|
|
5
5
|
export interface FileIconProps {
|
|
6
6
|
/* Absolute or relative; only the last segment decides which icon this is. */
|
|
@@ -8,7 +8,9 @@ export interface FileIconProps {
|
|
|
8
8
|
|
|
9
9
|
size?: number;
|
|
10
10
|
className?: string;
|
|
11
|
-
|
|
11
|
+
|
|
12
|
+
/* An `<img>` when an override gives the file an icon of the app's own, the `<svg>` otherwise. */
|
|
13
|
+
ref?: Ref<SVGSVGElement | HTMLImageElement>;
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
/*
|
|
@@ -19,15 +21,22 @@ export function FileIcon({ path, size = 16, className, ref }: FileIconProps) {
|
|
|
19
21
|
// Before the browser paints, so a `<use>` never points at a symbol that is not in the document yet.
|
|
20
22
|
useInsertionEffect(mountFileIconSprite, []);
|
|
21
23
|
|
|
22
|
-
const
|
|
24
|
+
const version = useSyncExternalStore(subscribeFileIconOverride, fileIconOverrideVersion, fileIconOverrideVersion);
|
|
25
|
+
const own = overrideFor(path, version);
|
|
23
26
|
|
|
27
|
+
// React types a readonly ref object, so the union passes to neither element without a cast; each holds one of its members.
|
|
24
28
|
if (own !== null) {
|
|
25
|
-
return <img src={own} alt="" width={size} height={size} className={clsx('file-icon', className)} />;
|
|
29
|
+
return <img ref={ref as Ref<HTMLImageElement>} src={own} alt="" width={size} height={size} className={clsx('file-icon', className)} />;
|
|
26
30
|
}
|
|
27
31
|
|
|
28
32
|
return (
|
|
29
|
-
<svg ref={ref} className={clsx('file-icon', className)} width={size} height={size} viewBox="0 0 16 16" aria-hidden>
|
|
33
|
+
<svg ref={ref as Ref<SVGSVGElement>} className={clsx('file-icon', className)} width={size} height={size} viewBox="0 0 16 16" aria-hidden>
|
|
30
34
|
<use href={`#${fileIconFor(path)}`} />
|
|
31
35
|
</svg>
|
|
32
36
|
);
|
|
33
37
|
}
|
|
38
|
+
|
|
39
|
+
/* Takes the version so the compiler caches the result on it as well as on the path. */
|
|
40
|
+
function overrideFor(path: string, _version: number): string | null {
|
|
41
|
+
return fileIconOverrideFor(path);
|
|
42
|
+
}
|
package/src/file-icon.ts
CHANGED
|
@@ -30,12 +30,27 @@ const resolveIcon: ReturnType<typeof createFileTreeIconResolver>['resolveIcon']
|
|
|
30
30
|
export const fileIconFor = (path: string): string => resolveIcon('file-tree-icon-file', path).name;
|
|
31
31
|
|
|
32
32
|
let override: ((path: string) => string | null) | null = null;
|
|
33
|
+
let overrideVersion = 0;
|
|
34
|
+
const overrideListeners = new Set<() => void>();
|
|
33
35
|
|
|
34
36
|
/* What an app knows better about a file's icon: the address of an svg, or null for the icon this set has. */
|
|
35
37
|
export function setFileIconOverride(next: ((path: string) => string | null) | null): void {
|
|
36
38
|
override = next;
|
|
39
|
+
overrideVersion++;
|
|
40
|
+
overrideListeners.forEach((listener) => listener());
|
|
37
41
|
}
|
|
38
42
|
|
|
43
|
+
export function subscribeFileIconOverride(onChange: () => void): () => void {
|
|
44
|
+
overrideListeners.add(onChange);
|
|
45
|
+
|
|
46
|
+
return () => {
|
|
47
|
+
overrideListeners.delete(onChange);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/* A mounted icon reads this so it draws again once the override changes. */
|
|
52
|
+
export const fileIconOverrideVersion = (): number => overrideVersion;
|
|
53
|
+
|
|
39
54
|
export function fileIconOverrideFor(path: string): string | null {
|
|
40
55
|
return override?.(path) ?? null;
|
|
41
56
|
}
|