@nice2dev/ui-core 1.0.21 → 1.0.22
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/core/tutorials.d.ts +106 -0
- package/dist/core/tutorials.d.ts.map +1 -0
- package/dist/index.cjs +46 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +1457 -1348
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tutorial launcher — universal, decoupled "?" tutorial button + global toggle.
|
|
3
|
+
* @nice2dev/ui-core
|
|
4
|
+
*
|
|
5
|
+
* The rich overlay (`NiceTutorial`) lives in `@nice2dev/ui`. To let ANY package
|
|
6
|
+
* (even react-only ones) add a tutorial "?" button without importing the overlay,
|
|
7
|
+
* the launcher is split:
|
|
8
|
+
* - this module (ui-core, lowest level): the `?` button, a context, the global
|
|
9
|
+
* on/off flag, types and resolvers — no dependency on the overlay;
|
|
10
|
+
* - `NiceTutorialHost` (in `@nice2dev/ui`): bridges this context to the real
|
|
11
|
+
* `NiceTutorial`. The app mounts the host once; `enabled` comes from prefs
|
|
12
|
+
* (e.g. an OmniVerk "hide all tutorials" preference).
|
|
13
|
+
*
|
|
14
|
+
* Editors expose an optional `tutorial?: NiceComponentTutorial` prop and render
|
|
15
|
+
* `<NiceTutorialButton steps={resolveTutorial(tutorial, BUILTIN_TOUR)} />`.
|
|
16
|
+
*/
|
|
17
|
+
import React from 'react';
|
|
18
|
+
/** A tutorial step authored on a component (i18n-key aware). */
|
|
19
|
+
export interface NiceTutorialStepDef {
|
|
20
|
+
/** CSS selector for the highlighted element (use stable `data-tour="…"`). */
|
|
21
|
+
target: string;
|
|
22
|
+
/** Inline English default (authoritative fallback). */
|
|
23
|
+
title?: string;
|
|
24
|
+
content?: string;
|
|
25
|
+
/** i18n keys resolved via `t(key, default)` at launch (locale-aware). */
|
|
26
|
+
titleKey?: string;
|
|
27
|
+
contentKey?: string;
|
|
28
|
+
placement?: 'top' | 'bottom' | 'left' | 'right' | 'auto';
|
|
29
|
+
highlightPadding?: number;
|
|
30
|
+
showArrow?: boolean;
|
|
31
|
+
scrollIntoView?: boolean;
|
|
32
|
+
disableInteraction?: boolean;
|
|
33
|
+
}
|
|
34
|
+
/** A fully-resolved step (structurally compatible with `NiceTutorialStep`). */
|
|
35
|
+
export interface NiceResolvedTutorialStep {
|
|
36
|
+
target: string;
|
|
37
|
+
title: string;
|
|
38
|
+
content: string;
|
|
39
|
+
placement?: 'top' | 'bottom' | 'left' | 'right' | 'auto';
|
|
40
|
+
highlightPadding?: number;
|
|
41
|
+
showArrow?: boolean;
|
|
42
|
+
scrollIntoView?: boolean;
|
|
43
|
+
disableInteraction?: boolean;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The optional `tutorial?` prop shape used across editors:
|
|
47
|
+
* - `true` → use the component's built-in tour;
|
|
48
|
+
* - `NiceTutorialStepDef[]` → custom steps;
|
|
49
|
+
* - `{ steps?, autoStart?, label? }` → custom steps (fallback to built-in) + options;
|
|
50
|
+
* - `false`/omitted → no "?" button.
|
|
51
|
+
*/
|
|
52
|
+
export type NiceComponentTutorial = boolean | NiceTutorialStepDef[] | {
|
|
53
|
+
steps?: NiceTutorialStepDef[];
|
|
54
|
+
autoStart?: boolean;
|
|
55
|
+
label?: string;
|
|
56
|
+
};
|
|
57
|
+
export interface NiceTutorialsContextValue {
|
|
58
|
+
/** Global on/off — when false, all `NiceTutorialButton`s render nothing. */
|
|
59
|
+
enabled: boolean;
|
|
60
|
+
/** Whether a tutorial is currently running (host-driven). */
|
|
61
|
+
active: boolean;
|
|
62
|
+
/** Launch resolved steps (wired by `NiceTutorialHost`; no-op without a host). */
|
|
63
|
+
run: (steps: NiceResolvedTutorialStep[], opts?: {
|
|
64
|
+
autoStart?: boolean;
|
|
65
|
+
}) => void;
|
|
66
|
+
}
|
|
67
|
+
export interface NiceTutorialsProviderProps {
|
|
68
|
+
/** Global enable flag (default `true`). Set `false` to hide every "?" button. */
|
|
69
|
+
enabled?: boolean;
|
|
70
|
+
/** Whether a tutorial is active (host-driven). */
|
|
71
|
+
active?: boolean;
|
|
72
|
+
/** Launcher implementation (provided by `NiceTutorialHost`). */
|
|
73
|
+
onRun?: (steps: NiceResolvedTutorialStep[], opts?: {
|
|
74
|
+
autoStart?: boolean;
|
|
75
|
+
}) => void;
|
|
76
|
+
children: React.ReactNode;
|
|
77
|
+
}
|
|
78
|
+
export declare const NiceTutorialsProvider: React.FC<NiceTutorialsProviderProps>;
|
|
79
|
+
/** Access the tutorials context (`enabled`, `active`, `run`). */
|
|
80
|
+
export declare function useNiceTutorials(): NiceTutorialsContextValue;
|
|
81
|
+
/** Convenience: whether tutorial "?" buttons should be shown globally. */
|
|
82
|
+
export declare function useNiceTutorialsEnabled(): boolean;
|
|
83
|
+
/** Normalise a `tutorial?` prop value (+ component built-in) to steps or null. */
|
|
84
|
+
export declare function resolveTutorial(tutorial: NiceComponentTutorial | undefined, builtin?: NiceTutorialStepDef[]): NiceTutorialStepDef[] | null;
|
|
85
|
+
/** Resolve i18n-key titles/content to strings using a `t(key, default)` fn. */
|
|
86
|
+
export declare function resolveStepsI18n(steps: NiceTutorialStepDef[], t: (key: string, defaultValue: string) => string): NiceResolvedTutorialStep[];
|
|
87
|
+
export interface NiceTutorialButtonProps {
|
|
88
|
+
/** Steps to run (already normalised via {@link resolveTutorial}). */
|
|
89
|
+
steps?: NiceTutorialStepDef[] | null;
|
|
90
|
+
/** Auto-start option forwarded to `run`. */
|
|
91
|
+
autoStart?: boolean;
|
|
92
|
+
/** Accessible label / tooltip. Defaults to the i18n `tutorial.startAria`. */
|
|
93
|
+
label?: string;
|
|
94
|
+
/** Size. Default `'md'`. */
|
|
95
|
+
size?: 'sm' | 'md';
|
|
96
|
+
className?: string;
|
|
97
|
+
style?: React.CSSProperties;
|
|
98
|
+
'data-testid'?: string;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Small "?" button that launches a tutorial. Renders nothing when tutorials are
|
|
102
|
+
* globally disabled or no steps are provided — so it's safe to render
|
|
103
|
+
* unconditionally as `<NiceTutorialButton steps={resolveTutorial(...)} />`.
|
|
104
|
+
*/
|
|
105
|
+
export declare const NiceTutorialButton: React.FC<NiceTutorialButtonProps>;
|
|
106
|
+
//# sourceMappingURL=tutorials.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tutorials.d.ts","sourceRoot":"","sources":["../../src/core/tutorials.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAA6C,MAAM,OAAO,CAAC;AAMlE,gEAAgE;AAChE,MAAM,WAAW,mBAAmB;IAClC,6EAA6E;IAC7E,MAAM,EAAE,MAAM,CAAC;IACf,uDAAuD;IACvD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,yEAAyE;IACzE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;IACzD,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,+EAA+E;AAC/E,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;IACzD,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,SA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