@asteby/metacore-runtime-react 49.10.0 → 49.12.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 +26 -0
- package/README.md +40 -0
- package/dist/column-filter-field.d.ts +21 -0
- package/dist/column-filter-field.d.ts.map +1 -0
- package/dist/column-filter-field.js +51 -0
- package/dist/dialogs/dynamic-record.d.ts +5 -2
- package/dist/dialogs/dynamic-record.d.ts.map +1 -1
- package/dist/dialogs/dynamic-record.js +96 -14
- package/dist/dynamic-columns.d.ts.map +1 -1
- package/dist/dynamic-columns.js +11 -1
- package/dist/dynamic-form.d.ts.map +1 -1
- package/dist/dynamic-form.js +10 -2
- package/dist/dynamic-icon.d.ts +16 -1
- package/dist/dynamic-icon.d.ts.map +1 -1
- package/dist/dynamic-icon.js +36 -5
- package/dist/dynamic-multi-select-field.d.ts +13 -1
- package/dist/dynamic-multi-select-field.d.ts.map +1 -1
- package/dist/dynamic-multi-select-field.js +19 -4
- package/dist/dynamic-table.d.ts.map +1 -1
- package/dist/dynamic-table.js +2 -1
- package/dist/field-widget-registry.d.ts +35 -0
- package/dist/field-widget-registry.d.ts.map +1 -0
- package/dist/field-widget-registry.js +66 -0
- package/dist/icon-aliases.d.ts +2 -0
- package/dist/icon-aliases.d.ts.map +1 -0
- package/dist/icon-aliases.js +594 -0
- package/dist/icon-resolvers.d.ts +13 -0
- package/dist/icon-resolvers.d.ts.map +1 -0
- package/dist/icon-resolvers.js +36 -0
- package/dist/icon-spec.d.ts +17 -0
- package/dist/icon-spec.d.ts.map +1 -0
- package/dist/icon-spec.js +165 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/column-filter-field.test.ts +105 -0
- package/src/__tests__/dynamic-record-field-types.test.tsx +221 -0
- package/src/__tests__/field-widget-registry.test.tsx +165 -0
- package/src/__tests__/icon-component.test.tsx +145 -0
- package/src/__tests__/icon-spec.test.ts +155 -0
- package/src/column-filter-field.ts +66 -0
- package/src/dialogs/dynamic-record.tsx +145 -13
- package/src/dynamic-columns.tsx +22 -1
- package/src/dynamic-form.tsx +12 -1
- package/src/dynamic-icon.tsx +68 -3
- package/src/dynamic-multi-select-field.tsx +29 -4
- package/src/dynamic-table.tsx +2 -1
- package/src/field-widget-registry.tsx +98 -0
- package/src/icon-aliases.ts +602 -0
- package/src/icon-resolvers.ts +59 -0
- package/src/icon-spec.ts +169 -0
- package/src/index.ts +12 -0
- package/src/types.ts +3 -0
package/dist/dynamic-icon.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
// DynamicIcon resolves a lucide glyph by name without pulling the full icon
|
|
3
3
|
// set into the shared chunk. It draws through the shared glyph registry of
|
|
4
4
|
// @asteby/metacore-ui: a glyph seen before renders in the first frame, and an
|
|
5
5
|
// unseen one holds its box until it loads, so the label next to it stays put.
|
|
6
|
+
import { useState } from 'react';
|
|
6
7
|
import dynamicIconImports from 'lucide-react/dynamicIconImports';
|
|
7
8
|
import { Glyph } from '@asteby/metacore-ui/icons';
|
|
9
|
+
import { resolveIconSpec } from './icon-resolvers';
|
|
8
10
|
function pascalToKebab(pascal) {
|
|
9
11
|
return pascal
|
|
10
12
|
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
|
|
@@ -23,11 +25,40 @@ function loaderFor(pascal) {
|
|
|
23
25
|
return (dynamicIconImports[kebab] ??
|
|
24
26
|
dynamicIconImports[kebab.replace(/([a-z])(\d)/g, '$1-$2')]);
|
|
25
27
|
}
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
if (
|
|
28
|
+
function IconImage({ src, className, label }) {
|
|
29
|
+
const [failed, setFailed] = useState(null);
|
|
30
|
+
if (failed === src)
|
|
29
31
|
return null;
|
|
30
|
-
return _jsx(
|
|
32
|
+
return (_jsx("img", { src: src, alt: label ?? '', loading: "lazy", decoding: "async", className: className, onError: () => setFailed(src) }));
|
|
33
|
+
}
|
|
34
|
+
// Icon — renders any icon value the SDK can interpret (see parseIconSpec and
|
|
35
|
+
// registerIconResolver): Lucide glyph, emoji, image or a host-rendered node.
|
|
36
|
+
// A value nobody understands renders `fallback` (default nothing), never the
|
|
37
|
+
// raw text. Decorative (aria-hidden) unless `label` is given.
|
|
38
|
+
export function Icon({ name, className, label, fallback = null, resolveImageSrc, images = true }) {
|
|
39
|
+
const spec = resolveIconSpec(name);
|
|
40
|
+
const a11y = label ? { role: 'img', 'aria-label': label } : { 'aria-hidden': true };
|
|
41
|
+
switch (spec.kind) {
|
|
42
|
+
case 'lucide':
|
|
43
|
+
return _jsx(Glyph, { name: spec.name, className: className, ...a11y });
|
|
44
|
+
case 'emoji':
|
|
45
|
+
return (_jsx("span", { className: className, ...a11y, children: spec.value }));
|
|
46
|
+
case 'image':
|
|
47
|
+
if (!images)
|
|
48
|
+
return _jsx(_Fragment, { children: fallback });
|
|
49
|
+
return (_jsx(IconImage, { src: resolveImageSrc ? resolveImageSrc(spec.src) : spec.src, className: className, label: label }));
|
|
50
|
+
case 'node':
|
|
51
|
+
return _jsx(_Fragment, { children: spec.node });
|
|
52
|
+
default:
|
|
53
|
+
return _jsx(_Fragment, { children: fallback });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// DynamicIcon keeps its { name, className } contract: Lucide names resolve
|
|
57
|
+
// exactly as before; FontAwesome classes, emoji and host resolvers now work
|
|
58
|
+
// too. Image paths still draw nothing here (icon slots in menus/buttons never
|
|
59
|
+
// showed <img>); use <Icon> or a `type: 'icon'` column for images.
|
|
60
|
+
export function DynamicIcon({ name, className }) {
|
|
61
|
+
return _jsx(Icon, { name: name, className: className, images: false });
|
|
31
62
|
}
|
|
32
63
|
// resolveLucideIconName — canonical PascalCase lucide name for a value that is
|
|
33
64
|
// either already PascalCase ("CreditCard") or the kebab slug lucide documents
|
|
@@ -4,6 +4,18 @@ export interface DynamicMultiSelectFieldProps {
|
|
|
4
4
|
/** Plain array of selected target ids. Absent/non-array value → treated as empty. */
|
|
5
5
|
value: unknown;
|
|
6
6
|
onChange: (value: string[]) => void;
|
|
7
|
+
/**
|
|
8
|
+
* Static options (DefineOptions served inline on the field). When the field
|
|
9
|
+
* has no `ref`/`searchEndpoint` and this list is non-empty, it is used as the
|
|
10
|
+
* option set and no request is made. Absent → remote resolution as before.
|
|
11
|
+
*/
|
|
12
|
+
staticOptions?: {
|
|
13
|
+
value: string;
|
|
14
|
+
label: string;
|
|
15
|
+
color?: string;
|
|
16
|
+
icon?: string;
|
|
17
|
+
image?: string;
|
|
18
|
+
}[];
|
|
7
19
|
}
|
|
8
|
-
export declare function DynamicMultiSelectField({ field, value, onChange }: DynamicMultiSelectFieldProps): import("react").JSX.Element;
|
|
20
|
+
export declare function DynamicMultiSelectField({ field, value, onChange, staticOptions }: DynamicMultiSelectFieldProps): import("react").JSX.Element;
|
|
9
21
|
//# sourceMappingURL=dynamic-multi-select-field.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamic-multi-select-field.d.ts","sourceRoot":"","sources":["../src/dynamic-multi-select-field.tsx"],"names":[],"mappings":"AA+BA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C,MAAM,WAAW,4BAA4B;IACzC,KAAK,EAAE,cAAc,CAAA;IACrB,qFAAqF;IACrF,KAAK,EAAE,OAAO,CAAA;IACd,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,IAAI,CAAA;
|
|
1
|
+
{"version":3,"file":"dynamic-multi-select-field.d.ts","sourceRoot":"","sources":["../src/dynamic-multi-select-field.tsx"],"names":[],"mappings":"AA+BA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C,MAAM,WAAW,4BAA4B;IACzC,KAAK,EAAE,cAAc,CAAA;IACrB,qFAAqF;IACrF,KAAK,EAAE,OAAO,CAAA;IACd,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,IAAI,CAAA;IACnC;;;;OAIG;IACH,aAAa,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;CACpG;AAED,wBAAgB,uBAAuB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,EAAE,4BAA4B,+BA6E9G"}
|
|
@@ -30,23 +30,38 @@ import { useOptionsResolver } from './use-options-resolver';
|
|
|
30
30
|
import { useResolveOptionIds } from './use-option-ids';
|
|
31
31
|
import { DELETED_RECORD_LABEL } from './dynamic-select-field';
|
|
32
32
|
import { getFieldRef } from './dynamic-form-schema';
|
|
33
|
-
export function DynamicMultiSelectField({ field, value, onChange }) {
|
|
33
|
+
export function DynamicMultiSelectField({ field, value, onChange, staticOptions }) {
|
|
34
34
|
const ref = getFieldRef(field);
|
|
35
35
|
const [query, setQuery] = useState('');
|
|
36
|
-
const
|
|
36
|
+
const useStatic = !ref && !field.searchEndpoint && !!staticOptions?.length;
|
|
37
|
+
const remote = useOptionsResolver({
|
|
37
38
|
modelKey: '',
|
|
38
39
|
fieldKey: 'id',
|
|
39
40
|
ref,
|
|
40
41
|
endpoint: !ref && field.searchEndpoint ? field.searchEndpoint : undefined,
|
|
41
42
|
limit: 200,
|
|
42
43
|
optionFilter: getOptionFilter(field),
|
|
44
|
+
enabled: !useStatic,
|
|
43
45
|
});
|
|
46
|
+
const staticResolved = useMemo(() => (staticOptions ?? []).map((o) => ({
|
|
47
|
+
id: o.value,
|
|
48
|
+
value: o.value,
|
|
49
|
+
label: o.label,
|
|
50
|
+
name: o.label,
|
|
51
|
+
color: o.color,
|
|
52
|
+
icon: o.icon,
|
|
53
|
+
image: o.image,
|
|
54
|
+
})), [staticOptions]);
|
|
55
|
+
const options = useStatic ? staticResolved : remote.options;
|
|
56
|
+
const loading = useStatic ? false : remote.loading;
|
|
57
|
+
const meta = useStatic ? { type: 'static', count: staticResolved.length } : remote.meta;
|
|
58
|
+
const error = useStatic ? null : remote.error;
|
|
44
59
|
const selected = useMemo(() => (Array.isArray(value) ? value.map(String) : []), [value]);
|
|
45
60
|
const endpoint = !ref && field.searchEndpoint ? field.searchEndpoint : undefined;
|
|
46
61
|
// Ask for the ids the loaded page does not cover — only once it is in.
|
|
47
62
|
const pageSettled = !loading && (meta !== null || error !== null);
|
|
48
63
|
const unresolved = pageSettled ? selected.filter((id) => !options.some((o) => String(o.id) === id)) : [];
|
|
49
|
-
const { resolved } = useResolveOptionIds({ ref, endpoint, field: 'id', ids: unresolved, enabled: unresolved.length > 0 });
|
|
64
|
+
const { resolved } = useResolveOptionIds({ ref, endpoint, field: 'id', ids: unresolved, enabled: !useStatic && unresolved.length > 0 });
|
|
50
65
|
const selectedItems = selected.map((id) => {
|
|
51
66
|
const loaded = options.find((o) => String(o.id) === id);
|
|
52
67
|
if (loaded)
|
|
@@ -54,7 +69,7 @@ export function DynamicMultiSelectField({ field, value, onChange }) {
|
|
|
54
69
|
const r = pageSettled ? resolved.get(id) : undefined;
|
|
55
70
|
if (r?.status === 'found')
|
|
56
71
|
return r.option;
|
|
57
|
-
const label = !r ? 'Cargando…' : r.status === 'missing' ? DELETED_RECORD_LABEL : id;
|
|
72
|
+
const label = useStatic ? id : !r ? 'Cargando…' : r.status === 'missing' ? DELETED_RECORD_LABEL : id;
|
|
58
73
|
return { id, value: id, label, name: label };
|
|
59
74
|
});
|
|
60
75
|
const shown = useMemo(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamic-table.d.ts","sourceRoot":"","sources":["../src/dynamic-table.tsx"],"names":[],"mappings":"AAYA,OAAO,EAAsE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAM1G,OAAO,EAKH,KAAK,SAAS,EAajB,MAAM,uBAAuB,CAAA;AAmC9B,OAAO,KAAK,EAAsB,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"dynamic-table.d.ts","sourceRoot":"","sources":["../src/dynamic-table.tsx"],"names":[],"mappings":"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"}
|
package/dist/dynamic-table.js
CHANGED
|
@@ -31,6 +31,7 @@ import { useReasonPrompt } from './reason-prompt';
|
|
|
31
31
|
import { defaultGetDynamicColumns, DATE_CELL_TYPES, aggregateOf, formatAggregateTotal } from './dynamic-columns';
|
|
32
32
|
import { useFacetLoaders, isLongTextColumn } from './use-facet-loaders';
|
|
33
33
|
import { translateOptionLabels } from './filter-chips';
|
|
34
|
+
import { applyColumnFilterFields } from './column-filter-field';
|
|
34
35
|
import { dedupeById, useInfiniteScrollSentinel } from './use-infinite-scroll';
|
|
35
36
|
import { DYNAMIC_TABLE_CARD_ESTIMATE_PX, DYNAMIC_TABLE_ROW_ESTIMATE_PX, resolveVirtualizeThreshold, } from './table-virtualization';
|
|
36
37
|
import { OptionsContext } from './options-context';
|
|
@@ -1200,7 +1201,7 @@ export function DynamicTable({ model, endpoint, mutationEndpoint, enableUrlSync
|
|
|
1200
1201
|
: undefined,
|
|
1201
1202
|
});
|
|
1202
1203
|
}
|
|
1203
|
-
return map;
|
|
1204
|
+
return applyColumnFilterFields(metadata.columns, map, dynamicFilters);
|
|
1204
1205
|
}, [metadata, filterOptionsMap, dynamicFilters, handleDynamicFilterChange, facetsBase, getFacetLoader, facetOptions, t, defaultFilters, effectiveHiddenColumns]);
|
|
1205
1206
|
// Prewarm every facet field once the configs settle, so a text column's
|
|
1206
1207
|
// header filter opens instantly with values + counts (same as the kanban).
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { ActionFieldDef } from './types';
|
|
3
|
+
export interface FieldWidgetProps {
|
|
4
|
+
/** The served field definition (key, label, type, widget, options…). */
|
|
5
|
+
field: ActionFieldDef;
|
|
6
|
+
/** Current value of the field. */
|
|
7
|
+
value: any;
|
|
8
|
+
/** Report a new value for the field. */
|
|
9
|
+
onChange: (value: any) => void;
|
|
10
|
+
/** The field is not editable right now (readonly / locked). */
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
/** Validation message for the field, when there is one. */
|
|
13
|
+
error?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Record the widget can read sibling fields from. In `DynamicForm` these are the
|
|
16
|
+
* LIVE form values (they update as the user types, also in create mode); in the
|
|
17
|
+
* record dialog (`EditField`) it is the loaded/edited record.
|
|
18
|
+
*/
|
|
19
|
+
record?: Record<string, any>;
|
|
20
|
+
}
|
|
21
|
+
export type FieldWidgetComponent = React.ComponentType<FieldWidgetProps>;
|
|
22
|
+
/**
|
|
23
|
+
* Registers the component that renders fields declaring `widget: <name>`.
|
|
24
|
+
* Returns a disposer; a later registration for the same name replaces the
|
|
25
|
+
* earlier one, and the earlier disposer then leaves the newer one alone.
|
|
26
|
+
*/
|
|
27
|
+
export declare function registerFieldWidget(name: string, component: FieldWidgetComponent): () => void;
|
|
28
|
+
/** The component registered for `name`, or undefined (never throws). */
|
|
29
|
+
export declare function getFieldWidget(name?: string | null): FieldWidgetComponent | undefined;
|
|
30
|
+
/** Registered widget names, for diagnostics. */
|
|
31
|
+
export declare function listFieldWidgets(): string[];
|
|
32
|
+
export declare function clearFieldWidgets(): void;
|
|
33
|
+
/** Re-renders the caller whenever a widget is (un)registered. */
|
|
34
|
+
export declare function useFieldWidgetRegistryVersion(): number;
|
|
35
|
+
//# sourceMappingURL=field-widget-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"field-widget-registry.d.ts","sourceRoot":"","sources":["../src/field-widget-registry.tsx"],"names":[],"mappings":"AAmBA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C,MAAM,WAAW,gBAAgB;IAC7B,wEAAwE;IACxE,KAAK,EAAE,cAAc,CAAA;IACrB,kCAAkC;IAClC,KAAK,EAAE,GAAG,CAAA;IACV,wCAAwC;IACxC,QAAQ,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAA;IAC9B,+DAA+D;IAC/D,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,2DAA2D;IAC3D,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAC/B;AAED,MAAM,MAAM,oBAAoB,GAAG,KAAK,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAA;AAWxE;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,oBAAoB,GAAG,MAAM,IAAI,CAS7F;AAED,wEAAwE;AACxE,wBAAgB,cAAc,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,oBAAoB,GAAG,SAAS,CAGrF;AAED,gDAAgD;AAChD,wBAAgB,gBAAgB,IAAI,MAAM,EAAE,CAE3C;AAED,wBAAgB,iBAAiB,IAAI,IAAI,CAIxC;AAOD,iEAAiE;AACjE,wBAAgB,6BAA6B,IAAI,MAAM,CAMtD"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// Field widget registry. The kernel serves `FieldDef.Widget` (wire: `widget`)
|
|
2
|
+
// on modal/form fields; the SDK knows a closed set of built-ins (upload, icon,
|
|
3
|
+
// dynamic_select…). A host-specific widget — a map pin for latitude/longitude,
|
|
4
|
+
// a weekly schedule editor — plugs in by name, so `DefineModal` can declare
|
|
5
|
+
// `Widget: "map-pin"` and both `<DynamicRecordDialog>` and `<DynamicForm>`
|
|
6
|
+
// render the host's component:
|
|
7
|
+
//
|
|
8
|
+
// import { registerFieldWidget } from '@asteby/metacore-runtime-react'
|
|
9
|
+
//
|
|
10
|
+
// const dispose = registerFieldWidget('map-pin', MapPinWidget)
|
|
11
|
+
//
|
|
12
|
+
// The widget owns the field's value: it receives `value` and reports edits
|
|
13
|
+
// through `onChange`, with no access to the form internals. A name with no
|
|
14
|
+
// registration is ignored and the renderer falls back to its `type`-based
|
|
15
|
+
// default, exactly as before.
|
|
16
|
+
//
|
|
17
|
+
// Module-level singleton like the model-extension / agent-result registries,
|
|
18
|
+
// and observable so a federated addon that registers after first paint
|
|
19
|
+
// re-renders the fields that were waiting for it.
|
|
20
|
+
import * as React from 'react';
|
|
21
|
+
const widgets = new Map();
|
|
22
|
+
const listeners = new Set();
|
|
23
|
+
let version = 0;
|
|
24
|
+
function emit() {
|
|
25
|
+
version++;
|
|
26
|
+
listeners.forEach((l) => l());
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Registers the component that renders fields declaring `widget: <name>`.
|
|
30
|
+
* Returns a disposer; a later registration for the same name replaces the
|
|
31
|
+
* earlier one, and the earlier disposer then leaves the newer one alone.
|
|
32
|
+
*/
|
|
33
|
+
export function registerFieldWidget(name, component) {
|
|
34
|
+
widgets.set(name, component);
|
|
35
|
+
emit();
|
|
36
|
+
return () => {
|
|
37
|
+
if (widgets.get(name) === component) {
|
|
38
|
+
widgets.delete(name);
|
|
39
|
+
emit();
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/** The component registered for `name`, or undefined (never throws). */
|
|
44
|
+
export function getFieldWidget(name) {
|
|
45
|
+
if (!name)
|
|
46
|
+
return undefined;
|
|
47
|
+
return widgets.get(name);
|
|
48
|
+
}
|
|
49
|
+
/** Registered widget names, for diagnostics. */
|
|
50
|
+
export function listFieldWidgets() {
|
|
51
|
+
return [...widgets.keys()];
|
|
52
|
+
}
|
|
53
|
+
export function clearFieldWidgets() {
|
|
54
|
+
if (widgets.size === 0)
|
|
55
|
+
return;
|
|
56
|
+
widgets.clear();
|
|
57
|
+
emit();
|
|
58
|
+
}
|
|
59
|
+
function subscribe(listener) {
|
|
60
|
+
listeners.add(listener);
|
|
61
|
+
return () => listeners.delete(listener);
|
|
62
|
+
}
|
|
63
|
+
/** Re-renders the caller whenever a widget is (un)registered. */
|
|
64
|
+
export function useFieldWidgetRegistryVersion() {
|
|
65
|
+
return React.useSyncExternalStore(subscribe, () => version, () => version);
|
|
66
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"icon-aliases.d.ts","sourceRoot":"","sources":["../src/icon-aliases.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA6kBjE,CAAA"}
|