@dloizides/ui-feedback 1.25.1 → 1.26.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 CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.26.0
4
+
5
+ - `LocalModelGate` + `useLocalModel(model)` (INV-EXTRACT-1 W9): shows its children once a `@dloizides/text-generation` local model is ready, else the offer, download percent, failure retry or blocked reason; labels, test ids and the card/text/button slots come from the app.
6
+
3
7
  ## 1.24.0
4
8
 
5
9
  - `UiThemeOverride({ map, children })` (INV-EXTRACT-1 W4, D-EXTRACT-2): re-provides the surrounding UI context with its theme passed through `map`; translate and navigate are kept. Generic over the host's theme type. Showcase story `src/showcase/UiThemeOverride.showcase.tsx`.
package/dist/index.d.mts CHANGED
@@ -1,5 +1,6 @@
1
- import React, { Component, ReactNode, ErrorInfo } from 'react';
1
+ import React, { Component, ReactNode, ErrorInfo, ComponentType, ReactElement } from 'react';
2
2
  import { StyleProp, ViewStyle } from 'react-native';
3
+ import { LocalModel, LocalModelBlock, LocalModelState } from '@dloizides/text-generation';
3
4
 
4
5
  /**
5
6
  * The minimal theme surface the feedback components read. Each consuming app's
@@ -690,4 +691,51 @@ declare function LiveRunCard(props: LiveRunCardProps): React.ReactElement;
690
691
  /** The theme colour for a step or group state; falls back to primary/text when a semantic scale is absent. */
691
692
  declare function runToneColor(theme: FeedbackTheme, state: RunStepState): string;
692
693
 
693
- export { AppErrorBoundary, type AppErrorBoundaryProps, AsyncSurface, type AsyncSurfaceProps, COPY_FEEDBACK_MS, ConfirmDialog, type ConfirmDialogProps, CopyStatus, type CopyToClipboard, DEFAULT_ERROR_BOUNDARY_LABELS, DISABLED_OPACITY, type DoneSummary, EmptyListState, type EmptyListStateProps, type ErrorBoundaryLabels, type ErrorFallbackState, ErrorNotice, type ErrorNoticeProps, ErrorReferenceRow, type ErrorReferenceRowProps, ErrorState, type ErrorStateAction, type ErrorStateProps, FEEDBACK_TEST_IDS, type FeedbackColorScale, type FeedbackNavigate, type FeedbackTheme, type FeedbackThemeColors, type FeedbackThemePalette, type FeedbackThemeSemantic, type FeedbackThemeSemanticText, type FeedbackTranslate, FeedbackUiProvider, type FeedbackUiProviderProps, type FeedbackUiValue, type FlatRunStep, LIVE_RUN_CARD_COMPACT_MAX_PX, LiveRunCard, type LiveRunCardLabels, type LiveRunCardProps, LoadingFallback, type LoadingFallbackProps, MODAL_OVERLAY_COLOR, PageSkeleton, type PageSkeletonProps, ProgressBar, type ProgressBarProps, type RunGroup, type RunStep, type RunStepState, type StepSplit, type ToastActionSpec, type ToastBus, ToastHost, type ToastHostProps, type ToastInput, type ToastPush, type ToastType, type FeedbackColorScale as UiColorScale, type FeedbackNavigate as UiNavigate, FeedbackUiProvider as UiProvider, type FeedbackUiProviderProps as UiProviderProps, type FeedbackTheme as UiTheme, type FeedbackThemeColors as UiThemeColors, UiThemeOverride, type UiThemeOverrideProps, type FeedbackThemePalette as UiThemePalette, type FeedbackThemeSemantic as UiThemeSemantic, type FeedbackThemeSemanticText as UiThemeSemanticText, type FeedbackTranslate as UiTranslate, type FeedbackUiValue as UiValue, WARMING_QUIET_PERIOD_MS, type WarmingInfo, WarmingOverlay, type WarmingOverlayLabels, type WarmingOverlayProps, type WarmingSnapshot, barFraction, clampPercent, copyText, createToastBus, defaultGroupId, getWarmingSnapshot, mergeRunSteps, notifyWarming, progressPercent, readTraceId, runToneColor, settleWarming, splitShorterSteps, subscribeWarming, summariseDoneGroups, useCopyToClipboard, useFeedbackUi, useFeedbackUi as useUi };
694
+ interface LocalModelGateLabels {
695
+ blocked: (block: LocalModelBlock | null) => string;
696
+ title: string;
697
+ offerBody: string;
698
+ consent: string;
699
+ consentHint: string;
700
+ loading: (percent: string) => string;
701
+ failed: string;
702
+ retry: string;
703
+ }
704
+ interface LocalModelGateTestIds {
705
+ blocked: string;
706
+ offer: string;
707
+ loading: string;
708
+ failed: string;
709
+ consent: string;
710
+ }
711
+ interface LocalModelGateSlots {
712
+ Card: ComponentType<{
713
+ testID: string;
714
+ children: ReactNode;
715
+ }>;
716
+ Text: ComponentType<{
717
+ heading?: boolean;
718
+ children: string;
719
+ }>;
720
+ Button: ComponentType<{
721
+ label: string;
722
+ hint: string;
723
+ testID: string;
724
+ onPress: () => void;
725
+ }>;
726
+ }
727
+ interface LocalModelGateProps {
728
+ model: LocalModel;
729
+ labels: LocalModelGateLabels;
730
+ testIds: LocalModelGateTestIds;
731
+ slots: LocalModelGateSlots;
732
+ children: ReactElement;
733
+ }
734
+
735
+ /** Shows its children only once the local model is ready; before that it offers the download or says why it cannot run. */
736
+ declare const LocalModelGate: ({ model, labels, testIds, slots, children, }: LocalModelGateProps) => React.ReactElement | null;
737
+
738
+ /** Follows a local model and checks the browser on first use. */
739
+ declare function useLocalModel(model: LocalModel): LocalModelState;
740
+
741
+ export { AppErrorBoundary, type AppErrorBoundaryProps, AsyncSurface, type AsyncSurfaceProps, COPY_FEEDBACK_MS, ConfirmDialog, type ConfirmDialogProps, CopyStatus, type CopyToClipboard, DEFAULT_ERROR_BOUNDARY_LABELS, DISABLED_OPACITY, type DoneSummary, EmptyListState, type EmptyListStateProps, type ErrorBoundaryLabels, type ErrorFallbackState, ErrorNotice, type ErrorNoticeProps, ErrorReferenceRow, type ErrorReferenceRowProps, ErrorState, type ErrorStateAction, type ErrorStateProps, FEEDBACK_TEST_IDS, type FeedbackColorScale, type FeedbackNavigate, type FeedbackTheme, type FeedbackThemeColors, type FeedbackThemePalette, type FeedbackThemeSemantic, type FeedbackThemeSemanticText, type FeedbackTranslate, FeedbackUiProvider, type FeedbackUiProviderProps, type FeedbackUiValue, type FlatRunStep, LIVE_RUN_CARD_COMPACT_MAX_PX, LiveRunCard, type LiveRunCardLabels, type LiveRunCardProps, LoadingFallback, type LoadingFallbackProps, LocalModelGate, type LocalModelGateLabels, type LocalModelGateProps, type LocalModelGateSlots, type LocalModelGateTestIds, MODAL_OVERLAY_COLOR, PageSkeleton, type PageSkeletonProps, ProgressBar, type ProgressBarProps, type RunGroup, type RunStep, type RunStepState, type StepSplit, type ToastActionSpec, type ToastBus, ToastHost, type ToastHostProps, type ToastInput, type ToastPush, type ToastType, type FeedbackColorScale as UiColorScale, type FeedbackNavigate as UiNavigate, FeedbackUiProvider as UiProvider, type FeedbackUiProviderProps as UiProviderProps, type FeedbackTheme as UiTheme, type FeedbackThemeColors as UiThemeColors, UiThemeOverride, type UiThemeOverrideProps, type FeedbackThemePalette as UiThemePalette, type FeedbackThemeSemantic as UiThemeSemantic, type FeedbackThemeSemanticText as UiThemeSemanticText, type FeedbackTranslate as UiTranslate, type FeedbackUiValue as UiValue, WARMING_QUIET_PERIOD_MS, type WarmingInfo, WarmingOverlay, type WarmingOverlayLabels, type WarmingOverlayProps, type WarmingSnapshot, barFraction, clampPercent, copyText, createToastBus, defaultGroupId, getWarmingSnapshot, mergeRunSteps, notifyWarming, progressPercent, readTraceId, runToneColor, settleWarming, splitShorterSteps, subscribeWarming, summariseDoneGroups, useCopyToClipboard, useFeedbackUi, useLocalModel, useFeedbackUi as useUi };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import React, { Component, ReactNode, ErrorInfo } from 'react';
1
+ import React, { Component, ReactNode, ErrorInfo, ComponentType, ReactElement } from 'react';
2
2
  import { StyleProp, ViewStyle } from 'react-native';
3
+ import { LocalModel, LocalModelBlock, LocalModelState } from '@dloizides/text-generation';
3
4
 
4
5
  /**
5
6
  * The minimal theme surface the feedback components read. Each consuming app's
@@ -690,4 +691,51 @@ declare function LiveRunCard(props: LiveRunCardProps): React.ReactElement;
690
691
  /** The theme colour for a step or group state; falls back to primary/text when a semantic scale is absent. */
691
692
  declare function runToneColor(theme: FeedbackTheme, state: RunStepState): string;
692
693
 
693
- export { AppErrorBoundary, type AppErrorBoundaryProps, AsyncSurface, type AsyncSurfaceProps, COPY_FEEDBACK_MS, ConfirmDialog, type ConfirmDialogProps, CopyStatus, type CopyToClipboard, DEFAULT_ERROR_BOUNDARY_LABELS, DISABLED_OPACITY, type DoneSummary, EmptyListState, type EmptyListStateProps, type ErrorBoundaryLabels, type ErrorFallbackState, ErrorNotice, type ErrorNoticeProps, ErrorReferenceRow, type ErrorReferenceRowProps, ErrorState, type ErrorStateAction, type ErrorStateProps, FEEDBACK_TEST_IDS, type FeedbackColorScale, type FeedbackNavigate, type FeedbackTheme, type FeedbackThemeColors, type FeedbackThemePalette, type FeedbackThemeSemantic, type FeedbackThemeSemanticText, type FeedbackTranslate, FeedbackUiProvider, type FeedbackUiProviderProps, type FeedbackUiValue, type FlatRunStep, LIVE_RUN_CARD_COMPACT_MAX_PX, LiveRunCard, type LiveRunCardLabels, type LiveRunCardProps, LoadingFallback, type LoadingFallbackProps, MODAL_OVERLAY_COLOR, PageSkeleton, type PageSkeletonProps, ProgressBar, type ProgressBarProps, type RunGroup, type RunStep, type RunStepState, type StepSplit, type ToastActionSpec, type ToastBus, ToastHost, type ToastHostProps, type ToastInput, type ToastPush, type ToastType, type FeedbackColorScale as UiColorScale, type FeedbackNavigate as UiNavigate, FeedbackUiProvider as UiProvider, type FeedbackUiProviderProps as UiProviderProps, type FeedbackTheme as UiTheme, type FeedbackThemeColors as UiThemeColors, UiThemeOverride, type UiThemeOverrideProps, type FeedbackThemePalette as UiThemePalette, type FeedbackThemeSemantic as UiThemeSemantic, type FeedbackThemeSemanticText as UiThemeSemanticText, type FeedbackTranslate as UiTranslate, type FeedbackUiValue as UiValue, WARMING_QUIET_PERIOD_MS, type WarmingInfo, WarmingOverlay, type WarmingOverlayLabels, type WarmingOverlayProps, type WarmingSnapshot, barFraction, clampPercent, copyText, createToastBus, defaultGroupId, getWarmingSnapshot, mergeRunSteps, notifyWarming, progressPercent, readTraceId, runToneColor, settleWarming, splitShorterSteps, subscribeWarming, summariseDoneGroups, useCopyToClipboard, useFeedbackUi, useFeedbackUi as useUi };
694
+ interface LocalModelGateLabels {
695
+ blocked: (block: LocalModelBlock | null) => string;
696
+ title: string;
697
+ offerBody: string;
698
+ consent: string;
699
+ consentHint: string;
700
+ loading: (percent: string) => string;
701
+ failed: string;
702
+ retry: string;
703
+ }
704
+ interface LocalModelGateTestIds {
705
+ blocked: string;
706
+ offer: string;
707
+ loading: string;
708
+ failed: string;
709
+ consent: string;
710
+ }
711
+ interface LocalModelGateSlots {
712
+ Card: ComponentType<{
713
+ testID: string;
714
+ children: ReactNode;
715
+ }>;
716
+ Text: ComponentType<{
717
+ heading?: boolean;
718
+ children: string;
719
+ }>;
720
+ Button: ComponentType<{
721
+ label: string;
722
+ hint: string;
723
+ testID: string;
724
+ onPress: () => void;
725
+ }>;
726
+ }
727
+ interface LocalModelGateProps {
728
+ model: LocalModel;
729
+ labels: LocalModelGateLabels;
730
+ testIds: LocalModelGateTestIds;
731
+ slots: LocalModelGateSlots;
732
+ children: ReactElement;
733
+ }
734
+
735
+ /** Shows its children only once the local model is ready; before that it offers the download or says why it cannot run. */
736
+ declare const LocalModelGate: ({ model, labels, testIds, slots, children, }: LocalModelGateProps) => React.ReactElement | null;
737
+
738
+ /** Follows a local model and checks the browser on first use. */
739
+ declare function useLocalModel(model: LocalModel): LocalModelState;
740
+
741
+ export { AppErrorBoundary, type AppErrorBoundaryProps, AsyncSurface, type AsyncSurfaceProps, COPY_FEEDBACK_MS, ConfirmDialog, type ConfirmDialogProps, CopyStatus, type CopyToClipboard, DEFAULT_ERROR_BOUNDARY_LABELS, DISABLED_OPACITY, type DoneSummary, EmptyListState, type EmptyListStateProps, type ErrorBoundaryLabels, type ErrorFallbackState, ErrorNotice, type ErrorNoticeProps, ErrorReferenceRow, type ErrorReferenceRowProps, ErrorState, type ErrorStateAction, type ErrorStateProps, FEEDBACK_TEST_IDS, type FeedbackColorScale, type FeedbackNavigate, type FeedbackTheme, type FeedbackThemeColors, type FeedbackThemePalette, type FeedbackThemeSemantic, type FeedbackThemeSemanticText, type FeedbackTranslate, FeedbackUiProvider, type FeedbackUiProviderProps, type FeedbackUiValue, type FlatRunStep, LIVE_RUN_CARD_COMPACT_MAX_PX, LiveRunCard, type LiveRunCardLabels, type LiveRunCardProps, LoadingFallback, type LoadingFallbackProps, LocalModelGate, type LocalModelGateLabels, type LocalModelGateProps, type LocalModelGateSlots, type LocalModelGateTestIds, MODAL_OVERLAY_COLOR, PageSkeleton, type PageSkeletonProps, ProgressBar, type ProgressBarProps, type RunGroup, type RunStep, type RunStepState, type StepSplit, type ToastActionSpec, type ToastBus, ToastHost, type ToastHostProps, type ToastInput, type ToastPush, type ToastType, type FeedbackColorScale as UiColorScale, type FeedbackNavigate as UiNavigate, FeedbackUiProvider as UiProvider, type FeedbackUiProviderProps as UiProviderProps, type FeedbackTheme as UiTheme, type FeedbackThemeColors as UiThemeColors, UiThemeOverride, type UiThemeOverrideProps, type FeedbackThemePalette as UiThemePalette, type FeedbackThemeSemantic as UiThemeSemantic, type FeedbackThemeSemanticText as UiThemeSemanticText, type FeedbackTranslate as UiTranslate, type FeedbackUiValue as UiValue, WARMING_QUIET_PERIOD_MS, type WarmingInfo, WarmingOverlay, type WarmingOverlayLabels, type WarmingOverlayProps, type WarmingSnapshot, barFraction, clampPercent, copyText, createToastBus, defaultGroupId, getWarmingSnapshot, mergeRunSteps, notifyWarming, progressPercent, readTraceId, runToneColor, settleWarming, splitShorterSteps, subscribeWarming, summariseDoneGroups, useCopyToClipboard, useFeedbackUi, useLocalModel, useFeedbackUi as useUi };
package/dist/index.js CHANGED
@@ -7,6 +7,7 @@ var a11y = require('@dloizides/a11y');
7
7
  var uiMotion = require('@dloizides/ui-motion');
8
8
  var designTokens = require('@dloizides/design-tokens');
9
9
  var reactDom = require('react-dom');
10
+ var textGeneration = require('@dloizides/text-generation');
10
11
 
11
12
  // src/context/FeedbackUiContext.tsx
12
13
  var DEFAULT_FEEDBACK_VALUE = {
@@ -1765,6 +1766,49 @@ function LiveRunCard(props) {
1765
1766
  showTimings && selected !== void 0 && selected.steps.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx(RunStepBars, { steps: selected.steps, maxBars, labels, compact, testID: `${testID}-steps` }, selected.id) : null
1766
1767
  ] });
1767
1768
  }
1769
+ function useLocalModel(model) {
1770
+ const state = react.useSyncExternalStore(model.subscribe, model.state);
1771
+ react.useEffect(() => {
1772
+ model.check().catch(() => void 0);
1773
+ }, [model]);
1774
+ return state;
1775
+ }
1776
+ var PERCENT2 = 100;
1777
+ var LocalModelGate = ({
1778
+ model,
1779
+ labels,
1780
+ testIds,
1781
+ slots,
1782
+ children
1783
+ }) => {
1784
+ const { phase, block, progress } = useLocalModel(model);
1785
+ const consent = react.useCallback(() => {
1786
+ model.consent().catch(() => void 0);
1787
+ }, [model]);
1788
+ const { Card, Text: Text16, Button } = slots;
1789
+ switch (phase) {
1790
+ case textGeneration.LocalModelPhase.Checking:
1791
+ return null;
1792
+ case textGeneration.LocalModelPhase.Blocked:
1793
+ return /* @__PURE__ */ jsxRuntime.jsx(Card, { testID: testIds.blocked, children: /* @__PURE__ */ jsxRuntime.jsx(Text16, { children: labels.blocked(block) }) });
1794
+ case textGeneration.LocalModelPhase.Offer:
1795
+ return /* @__PURE__ */ jsxRuntime.jsxs(Card, { testID: testIds.offer, children: [
1796
+ /* @__PURE__ */ jsxRuntime.jsx(Text16, { heading: true, children: labels.title }),
1797
+ /* @__PURE__ */ jsxRuntime.jsx(Text16, { children: labels.offerBody }),
1798
+ /* @__PURE__ */ jsxRuntime.jsx(Button, { hint: labels.consentHint, label: labels.consent, testID: testIds.consent, onPress: consent })
1799
+ ] });
1800
+ case textGeneration.LocalModelPhase.Loading:
1801
+ return /* @__PURE__ */ jsxRuntime.jsx(Card, { testID: testIds.loading, children: /* @__PURE__ */ jsxRuntime.jsx(Text16, { children: labels.loading(String(Math.round(progress * PERCENT2))) }) });
1802
+ case textGeneration.LocalModelPhase.Failed:
1803
+ return /* @__PURE__ */ jsxRuntime.jsxs(Card, { testID: testIds.failed, children: [
1804
+ /* @__PURE__ */ jsxRuntime.jsx(Text16, { children: labels.failed }),
1805
+ /* @__PURE__ */ jsxRuntime.jsx(Button, { hint: labels.consentHint, label: labels.retry, testID: testIds.consent, onPress: consent })
1806
+ ] });
1807
+ case textGeneration.LocalModelPhase.Ready:
1808
+ default:
1809
+ return children;
1810
+ }
1811
+ };
1768
1812
 
1769
1813
  exports.AppErrorBoundary = AppErrorBoundary;
1770
1814
  exports.AsyncSurface = AsyncSurface;
@@ -1782,6 +1826,7 @@ exports.FeedbackUiProvider = FeedbackUiProvider;
1782
1826
  exports.LIVE_RUN_CARD_COMPACT_MAX_PX = LIVE_RUN_CARD_COMPACT_MAX_PX;
1783
1827
  exports.LiveRunCard = LiveRunCard;
1784
1828
  exports.LoadingFallback = LoadingFallback;
1829
+ exports.LocalModelGate = LocalModelGate;
1785
1830
  exports.MODAL_OVERLAY_COLOR = MODAL_OVERLAY_COLOR;
1786
1831
  exports.PageSkeleton = PageSkeleton;
1787
1832
  exports.ProgressBar = ProgressBar;
@@ -1807,6 +1852,7 @@ exports.subscribeWarming = subscribeWarming;
1807
1852
  exports.summariseDoneGroups = summariseDoneGroups;
1808
1853
  exports.useCopyToClipboard = useCopyToClipboard;
1809
1854
  exports.useFeedbackUi = useFeedbackUi;
1855
+ exports.useLocalModel = useLocalModel;
1810
1856
  exports.useUi = useFeedbackUi;
1811
1857
  //# sourceMappingURL=index.js.map
1812
1858
  //# sourceMappingURL=index.js.map