@mistriwork/ui 1.0.0-rc.10 → 1.0.0-rc.12
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/Icon.d.ts +3 -0
- package/dist/Icon.js +26 -5
- package/package.json +1 -1
package/dist/Icon.d.ts
CHANGED
|
@@ -14,6 +14,9 @@ export interface IconWeighting {
|
|
|
14
14
|
export declare function registerIcons(sent: Readonly<Record<string, IconGlyph>> | undefined): void;
|
|
15
15
|
/** Where the glyphs not yet registered come from: called once, when an icon first names one. */
|
|
16
16
|
export declare function loadIconsWith(load: () => Promise<Readonly<Record<string, IconGlyph>> | undefined>): void;
|
|
17
|
+
/** What a name that names no glyph, once every glyph is in, is told: once a name, with every name there is; it
|
|
18
|
+
answers the name to draw instead, or undefined to keep the empty box. */
|
|
19
|
+
export declare function onUnknownIcon(answer: ((name: string, names: readonly string[]) => string | undefined) | undefined): void;
|
|
17
20
|
/** The page's icon weight, from now on. */
|
|
18
21
|
export declare function weighIconsWith(weights: IconWeighting): void;
|
|
19
22
|
export interface IconProps<Name extends string = string> {
|
package/dist/Icon.js
CHANGED
|
@@ -17,6 +17,10 @@ const listeners = new Set();
|
|
|
17
17
|
let known = 0;
|
|
18
18
|
let loader;
|
|
19
19
|
let loading;
|
|
20
|
+
/* Every glyph there is has been asked for: a name still missing names none. */
|
|
21
|
+
let everyGlyph = false;
|
|
22
|
+
let unknown;
|
|
23
|
+
const answered = new Map();
|
|
20
24
|
const unweighted = { weight: () => 'regular', drawing: () => undefined, subscribe: () => () => { }, version: () => 0 };
|
|
21
25
|
let weighting = unweighted;
|
|
22
26
|
/** Glyphs to draw, by name. A name already known keeps its glyph. */
|
|
@@ -40,6 +44,13 @@ export function registerIcons(sent) {
|
|
|
40
44
|
export function loadIconsWith(load) {
|
|
41
45
|
loader = load;
|
|
42
46
|
loading = undefined;
|
|
47
|
+
everyGlyph = false;
|
|
48
|
+
}
|
|
49
|
+
/** What a name that names no glyph, once every glyph is in, is told: once a name, with every name there is; it
|
|
50
|
+
answers the name to draw instead, or undefined to keep the empty box. */
|
|
51
|
+
export function onUnknownIcon(answer) {
|
|
52
|
+
unknown = answer;
|
|
53
|
+
answered.clear();
|
|
43
54
|
}
|
|
44
55
|
/** The page's icon weight, from now on. */
|
|
45
56
|
export function weighIconsWith(weights) {
|
|
@@ -49,7 +60,13 @@ function loadEveryGlyph() {
|
|
|
49
60
|
if (!loader)
|
|
50
61
|
return;
|
|
51
62
|
loading ??= loader()
|
|
52
|
-
.then(
|
|
63
|
+
.then((sent) => {
|
|
64
|
+
registerIcons(sent);
|
|
65
|
+
everyGlyph = true;
|
|
66
|
+
known += 1;
|
|
67
|
+
for (const listener of listeners)
|
|
68
|
+
listener();
|
|
69
|
+
})
|
|
53
70
|
// A failed load is tried again by the next icon that asks.
|
|
54
71
|
.catch(() => {
|
|
55
72
|
loading = undefined;
|
|
@@ -66,13 +83,17 @@ export function Icon({ name, label, size = '1em', weight, className }) {
|
|
|
66
83
|
useSyncExternalStore(subscribe, version, version);
|
|
67
84
|
const weights = weighting;
|
|
68
85
|
useSyncExternalStore(weights.subscribe, weights.version, weights.version);
|
|
69
|
-
const
|
|
86
|
+
const own = glyphs.get(name);
|
|
87
|
+
if (!own && everyGlyph && unknown && !answered.has(name))
|
|
88
|
+
answered.set(name, unknown(name, [...glyphs.keys()]));
|
|
89
|
+
const instead = own ? undefined : answered.get(name);
|
|
90
|
+
const glyph = own ?? (instead ? glyphs.get(instead) : undefined);
|
|
70
91
|
const drawn = weight ?? weights.weight();
|
|
71
|
-
const drawing = (weight ? undefined : weights.drawing(name)) ?? glyph?.[drawn === 'bold' ? 1 : 0];
|
|
92
|
+
const drawing = (weight || instead ? undefined : weights.drawing(name)) ?? glyph?.[drawn === 'bold' ? 1 : 0];
|
|
72
93
|
useEffect(() => {
|
|
73
|
-
if (!
|
|
94
|
+
if (!own)
|
|
74
95
|
loadEveryGlyph();
|
|
75
|
-
}, [
|
|
96
|
+
}, [own]);
|
|
76
97
|
const accessibleLabel = label?.trim() || undefined;
|
|
77
98
|
return (_jsx("svg", { xmlns: "http://www.w3.org/2000/svg", width: size, height: size, fill: "currentColor", viewBox: "0 0 256 256", className: `tw-icon${className ? ` ${className}` : ''}`, role: accessibleLabel ? 'img' : undefined, "aria-label": accessibleLabel, "aria-hidden": accessibleLabel ? undefined : true, focusable: "false", children: drawing?.map((d, index) => (_jsx("path", { d: d }, index))) }));
|
|
78
99
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mistriwork/ui",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.12",
|
|
4
4
|
"description": "The standalone React primitives both shells are drawn with: Modal, DropMenu, Dropdown, Typeahead, Button, Field, Icon and DateField over Base UI, Switch, Tabs, Drawer, Popover, Avatar, Pagination, Carousel, Resizable, ScrollArea and Tooltip, the form controls built on them (text, masked, money and sensitive boxes, listboxes, choices, slider, progress and action bar; Preview), the landing hero's blocks (badge, photo tiles, icon rows; Preview), their tokens and stylesheet, and the zoom-aware ruler their popups are placed by.",
|
|
5
5
|
"homepage": "https://mistriwork.dev",
|
|
6
6
|
"bugs": {
|