@cratis/showrunner.notes.react 2.12.0 → 2.13.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/Feedback/SliceChooser.tsx +3 -3
- package/Feedback/sliceChoice.ts +21 -0
- package/Provider/NotesProvider.tsx +16 -3
- package/Provider/notesVisibility.ts +4 -3
- package/dist/cjs/Feedback/SliceChooser.js +2 -2
- package/dist/cjs/Feedback/SliceChooser.js.map +1 -1
- package/dist/cjs/Feedback/sliceChoice.d.ts +1 -0
- package/dist/cjs/Feedback/sliceChoice.d.ts.map +1 -1
- package/dist/cjs/Feedback/sliceChoice.js +30 -0
- package/dist/cjs/Feedback/sliceChoice.js.map +1 -1
- package/dist/cjs/Provider/NotesProvider.d.ts.map +1 -1
- package/dist/cjs/Provider/NotesProvider.js +15 -2
- package/dist/cjs/Provider/NotesProvider.js.map +1 -1
- package/dist/cjs/Provider/notesVisibility.d.ts.map +1 -1
- package/dist/cjs/Provider/notesVisibility.js +4 -3
- package/dist/cjs/Provider/notesVisibility.js.map +1 -1
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/Feedback/SliceChooser.js +3 -3
- package/dist/esm/Feedback/SliceChooser.js.map +1 -1
- package/dist/esm/Feedback/sliceChoice.d.ts +1 -0
- package/dist/esm/Feedback/sliceChoice.d.ts.map +1 -1
- package/dist/esm/Feedback/sliceChoice.js +30 -1
- package/dist/esm/Feedback/sliceChoice.js.map +1 -1
- package/dist/esm/Provider/NotesProvider.d.ts.map +1 -1
- package/dist/esm/Provider/NotesProvider.js +16 -3
- package/dist/esm/Provider/NotesProvider.js.map +1 -1
- package/dist/esm/Provider/notesVisibility.d.ts.map +1 -1
- package/dist/esm/Provider/notesVisibility.js +4 -3
- package/dist/esm/Provider/notesVisibility.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/package.json +2 -2
|
@@ -7,7 +7,7 @@ import { formatLocation, LocationParts } from '../Context/formatLocation.js';
|
|
|
7
7
|
import { CloseIcon } from '../Icons.js';
|
|
8
8
|
import { format } from '../Labels/index.js';
|
|
9
9
|
import { useNotesLabels } from '../Provider/NotesContext.js';
|
|
10
|
-
import { distinctSlices, isChosen, searchSlices, sliceKey, toggleSlice } from './sliceChoice.js';
|
|
10
|
+
import { distinctSlices, isChosen, searchSlices, sliceKey, toggleSlice, withParentLevels } from './sliceChoice.js';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Props for {@link SliceChooser}.
|
|
@@ -34,8 +34,8 @@ export const SliceChooser = ({ active, known, chosen, onChange }: SliceChooserPr
|
|
|
34
34
|
const [query, setQuery] = useState('');
|
|
35
35
|
const activeId = useId();
|
|
36
36
|
const resultsId = useId();
|
|
37
|
-
const activeSlices = distinctSlices(active);
|
|
38
|
-
const results = searchSlices(known, query);
|
|
37
|
+
const activeSlices = withParentLevels(distinctSlices(active));
|
|
38
|
+
const results = searchSlices(withParentLevels(known), query);
|
|
39
39
|
const name = (location: LocationParts) => formatLocation(location, labels.common.locationSeparator, labels.common.unknownLocation);
|
|
40
40
|
|
|
41
41
|
const option = (location: LocationParts) => (
|
package/Feedback/sliceChoice.ts
CHANGED
|
@@ -30,6 +30,27 @@ export function distinctSlices<TLocation extends LocationParts>(locations: reado
|
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Adds the broader levels of every location: its module, and its feature within the module. A note can be about a whole
|
|
35
|
+
* module or a whole feature, not only a slice, and such a level is a location whose finer parts are empty, which is how the
|
|
36
|
+
* contracts carry a location Arc could resolve only that far.
|
|
37
|
+
* @param locations The locations, typically slices.
|
|
38
|
+
* @returns The distinct, non-empty locations with the module and feature of each, broader levels before the slices in them.
|
|
39
|
+
*/
|
|
40
|
+
export function withParentLevels(locations: readonly LocationParts[]): LocationParts[] {
|
|
41
|
+
return distinctSlices(locations.flatMap(location => {
|
|
42
|
+
const levels: LocationParts[] = [];
|
|
43
|
+
if (location.module.length > 0) {
|
|
44
|
+
levels.push({ module: location.module, feature: '', slice: '' });
|
|
45
|
+
if (location.feature.length > 0) {
|
|
46
|
+
levels.push({ module: location.module, feature: location.feature, slice: '' });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return [...levels, location];
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
|
|
33
54
|
/**
|
|
34
55
|
* Adds a slice to the chosen ones, or removes it when it is chosen already.
|
|
35
56
|
* @param chosen The chosen slices.
|
|
@@ -9,7 +9,7 @@ import { DialogHeaderContext } from '@cratis/components/Dialogs';
|
|
|
9
9
|
import { toast } from '@cratis/components/Notifications';
|
|
10
10
|
import { Guid } from '@cratis/fundamentals';
|
|
11
11
|
import { Availability } from '@cratis/showrunner.notes';
|
|
12
|
-
import { ReactNode, useCallback, useMemo, useRef } from 'react';
|
|
12
|
+
import { ReactNode, useCallback, useEffect, useMemo, useRef } from 'react';
|
|
13
13
|
import { buildNoteContext, DialogReference, resolveComponentContext } from '../Context/index.js';
|
|
14
14
|
import { LocationParts } from '../Context/formatLocation.js';
|
|
15
15
|
import { ComponentFeedbackDialog } from '../Feedback/ComponentFeedbackDialog.js';
|
|
@@ -44,14 +44,27 @@ const dialogReferenceOf = (dialog?: DialogHeaderContext): DialogReference | unde
|
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
46
|
* Slots Notes into an application: renders the feedback dialogs and the component picker once, asks whether Notes is
|
|
47
|
-
* switched on
|
|
47
|
+
* available to the user - switched on and, when only granted users may give feedback, granted to them - and gives the Notes
|
|
48
|
+
* buttons and `useNotes` what they need. Render it inside `<Arc>`, the `DialogComponents`
|
|
48
49
|
* registration, an `IdentityProvider` and a `CratisComponentsProvider` with a toaster. Turn on `<Arc sliceMarkers>` for
|
|
49
50
|
* Notes to know the slice of a component the user points at.
|
|
50
51
|
*/
|
|
51
52
|
export const NotesProvider = ({ enabled = false, labels, knownSlices = [], children }: NotesProviderProps) => {
|
|
52
53
|
const store = useApplicationContextStore();
|
|
53
54
|
const identity = useIdentity();
|
|
54
|
-
const [availability] = Availability.use();
|
|
55
|
+
const [availability, performAvailability] = Availability.use();
|
|
56
|
+
const wasSignedIn = useRef(identity.isSet);
|
|
57
|
+
|
|
58
|
+
// Whether the user may give feedback depends on who they are, and the first answer can be given before anyone signed in.
|
|
59
|
+
// Asking again once they have keeps the button hidden for a user nobody granted the right and shows it to one who was.
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
if (identity.isSet && !wasSignedIn.current) {
|
|
62
|
+
void performAvailability();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
wasSignedIn.current = identity.isSet;
|
|
66
|
+
}, [identity.isSet, performAvailability]);
|
|
67
|
+
|
|
55
68
|
const isAvailable = isNotesAvailable(identity.isSet, availability.data?.isEnabled);
|
|
56
69
|
const resolvedLabels = useMemo(() => resolveLabels(labels), [labels]);
|
|
57
70
|
const busy = useRef(false);
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Decides whether the Notes components render anything: only for a signed-in user, and only while Notes is
|
|
6
|
-
*
|
|
5
|
+
* Decides whether the Notes components render anything: only for a signed-in user, and only while Notes is available to
|
|
6
|
+
* them. It is not when Notes is switched off, and not when the application lets only granted users give feedback and nobody
|
|
7
|
+
* granted this user.
|
|
7
8
|
* @param isSignedIn Whether the user is signed in.
|
|
8
|
-
* @param isEnabled Whether Notes is
|
|
9
|
+
* @param isEnabled Whether Notes is available to the user, as `NotesAvailability` tells; false until it is known.
|
|
9
10
|
* @returns True when the Notes components render.
|
|
10
11
|
*/
|
|
11
12
|
export function isNotesAvailable(isSignedIn: boolean, isEnabled: boolean | undefined): boolean {
|
|
@@ -16,8 +16,8 @@ var sliceChoice = require('./sliceChoice.js');
|
|
|
16
16
|
const [query, setQuery] = react.useState('');
|
|
17
17
|
const activeId = react.useId();
|
|
18
18
|
const resultsId = react.useId();
|
|
19
|
-
const activeSlices = sliceChoice.distinctSlices(active);
|
|
20
|
-
const results = sliceChoice.searchSlices(known, query);
|
|
19
|
+
const activeSlices = sliceChoice.withParentLevels(sliceChoice.distinctSlices(active));
|
|
20
|
+
const results = sliceChoice.searchSlices(sliceChoice.withParentLevels(known), query);
|
|
21
21
|
const name = (location)=>formatLocation.formatLocation(location, labels.common.locationSeparator, labels.common.unknownLocation);
|
|
22
22
|
const option = (location)=>/*#__PURE__*/ jsxRuntime.jsx("li", {
|
|
23
23
|
children: /*#__PURE__*/ jsxRuntime.jsx(Common.Checkbox, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SliceChooser.js","sources":["../../../Feedback/SliceChooser.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Checkbox, IconButton, TextInput } from '@cratis/components/Common';\nimport { useId, useState } from 'react';\nimport { formatLocation, LocationParts } from '../Context/formatLocation.js';\nimport { CloseIcon } from '../Icons.js';\nimport { format } from '../Labels/index.js';\nimport { useNotesLabels } from '../Provider/NotesContext.js';\nimport { distinctSlices, isChosen, searchSlices, sliceKey, toggleSlice } from './sliceChoice.js';\n\n/**\n * Props for {@link SliceChooser}.\n */\nexport interface SliceChooserProps {\n /** The slices active on the screen. */\n active: readonly LocationParts[];\n\n /** Every slice the host knows about, to search over. */\n known: readonly LocationParts[];\n\n /** The chosen slices. */\n chosen: readonly LocationParts[];\n\n /** Called with the chosen slices after a change. */\n onChange: (chosen: LocationParts[]) => void;\n}\n\n/**\n * Chooses the slices a note is about: the ones active on the screen, and a search over all the slices the host knows.\n */\nexport const SliceChooser = ({ active, known, chosen, onChange }: SliceChooserProps) => {\n const labels = useNotesLabels();\n const [query, setQuery] = useState('');\n const activeId = useId();\n const resultsId = useId();\n const activeSlices = distinctSlices(active);\n const results = searchSlices(known, query);\n const name = (location: LocationParts) => formatLocation(location, labels.common.locationSeparator, labels.common.unknownLocation);\n\n const option = (location: LocationParts) => (\n <li key={sliceKey(location)}>\n <Checkbox label={name(location)} checked={isChosen(chosen, location)} onChange={() => onChange(toggleSlice(chosen, location))} />\n </li>\n );\n\n return (\n <div className='notes-slice-chooser'>\n <section aria-labelledby={activeId}>\n <h3 id={activeId} className='notes-slice-chooser__heading'>{labels.slices.active}</h3>\n {activeSlices.length === 0\n ? <p className='notes-slice-chooser__empty'>{labels.slices.noneActive}</p>\n : <ul className='notes-slice-chooser__list'>{activeSlices.map(option)}</ul>}\n </section>\n <section>\n <label className='notes-slice-chooser__heading' htmlFor={`${resultsId}-search`}>{labels.slices.search}</label>\n <TextInput\n id={`${resultsId}-search`}\n type='search'\n value={query}\n placeholder={labels.slices.searchPlaceholder}\n aria-controls={resultsId}\n onChange={value => setQuery(value)} />\n <div id={resultsId} aria-live='polite'>\n {query.trim().length > 0 && (results.length === 0\n ? <p className='notes-slice-chooser__empty'>{labels.slices.noMatches}</p>\n : <ul className='notes-slice-chooser__list' aria-label={labels.slices.results}>{results.map(option)}</ul>)}\n </div>\n </section>\n {chosen.length > 0 && (\n <section>\n <p className='notes-slice-chooser__heading'>{format(labels.slices.chosen, { count: chosen.length })}</p>\n <ul className='notes-slice-chooser__chosen'>\n {chosen.map(location => (\n <li key={sliceKey(location)} className='notes-slice-chooser__chip'>\n <span>{name(location)}</span>\n <IconButton\n variant='ghost'\n size='small'\n icon={<CloseIcon />}\n aria-label={format(labels.slices.remove, { slice: name(location) })}\n onClick={() => onChange(toggleSlice(chosen, location))} />\n </li>\n ))}\n </ul>\n </section>\n )}\n </div>\n );\n};\n"],"names":["SliceChooser","active","known","chosen","onChange","labels","useNotesLabels","query","setQuery","useState","activeId","useId","resultsId","activeSlices","distinctSlices","results","searchSlices","name","location","formatLocation","common","locationSeparator","unknownLocation","option","_jsx","li","Checkbox","label","checked","isChosen","toggleSlice","sliceKey","_jsxs","div","className","section","aria-labelledby","h3","id","slices","length","p","noneActive","ul","map","htmlFor","search","TextInput","type","value","placeholder","searchPlaceholder","aria-controls","aria-live","trim","noMatches","aria-label","format","count","span","IconButton","variant","size","icon","CloseIcon","remove","slice","onClick"],"mappings":";;;;;;;;;;;AA4BA;;AAEC,IACM,MAAMA,YAAAA,GAAe,CAAC,EAAEC,MAAM,EAAEC,KAAK,EAAEC,MAAM,EAAEC,QAAQ,EAAqB,GAAA;AAC/E,IAAA,MAAMC,MAAAA,GAASC,2BAAAA,EAAAA;AACf,IAAA,MAAM,CAACC,KAAAA,EAAOC,QAAAA,CAAS,GAAGC,cAAAA,CAAS,EAAA,CAAA;AACnC,IAAA,MAAMC,QAAAA,GAAWC,WAAAA,EAAAA;AACjB,IAAA,MAAMC,SAAAA,GAAYD,WAAAA,EAAAA;
|
|
1
|
+
{"version":3,"file":"SliceChooser.js","sources":["../../../Feedback/SliceChooser.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Checkbox, IconButton, TextInput } from '@cratis/components/Common';\nimport { useId, useState } from 'react';\nimport { formatLocation, LocationParts } from '../Context/formatLocation.js';\nimport { CloseIcon } from '../Icons.js';\nimport { format } from '../Labels/index.js';\nimport { useNotesLabels } from '../Provider/NotesContext.js';\nimport { distinctSlices, isChosen, searchSlices, sliceKey, toggleSlice, withParentLevels } from './sliceChoice.js';\n\n/**\n * Props for {@link SliceChooser}.\n */\nexport interface SliceChooserProps {\n /** The slices active on the screen. */\n active: readonly LocationParts[];\n\n /** Every slice the host knows about, to search over. */\n known: readonly LocationParts[];\n\n /** The chosen slices. */\n chosen: readonly LocationParts[];\n\n /** Called with the chosen slices after a change. */\n onChange: (chosen: LocationParts[]) => void;\n}\n\n/**\n * Chooses the slices a note is about: the ones active on the screen, and a search over all the slices the host knows.\n */\nexport const SliceChooser = ({ active, known, chosen, onChange }: SliceChooserProps) => {\n const labels = useNotesLabels();\n const [query, setQuery] = useState('');\n const activeId = useId();\n const resultsId = useId();\n const activeSlices = withParentLevels(distinctSlices(active));\n const results = searchSlices(withParentLevels(known), query);\n const name = (location: LocationParts) => formatLocation(location, labels.common.locationSeparator, labels.common.unknownLocation);\n\n const option = (location: LocationParts) => (\n <li key={sliceKey(location)}>\n <Checkbox label={name(location)} checked={isChosen(chosen, location)} onChange={() => onChange(toggleSlice(chosen, location))} />\n </li>\n );\n\n return (\n <div className='notes-slice-chooser'>\n <section aria-labelledby={activeId}>\n <h3 id={activeId} className='notes-slice-chooser__heading'>{labels.slices.active}</h3>\n {activeSlices.length === 0\n ? <p className='notes-slice-chooser__empty'>{labels.slices.noneActive}</p>\n : <ul className='notes-slice-chooser__list'>{activeSlices.map(option)}</ul>}\n </section>\n <section>\n <label className='notes-slice-chooser__heading' htmlFor={`${resultsId}-search`}>{labels.slices.search}</label>\n <TextInput\n id={`${resultsId}-search`}\n type='search'\n value={query}\n placeholder={labels.slices.searchPlaceholder}\n aria-controls={resultsId}\n onChange={value => setQuery(value)} />\n <div id={resultsId} aria-live='polite'>\n {query.trim().length > 0 && (results.length === 0\n ? <p className='notes-slice-chooser__empty'>{labels.slices.noMatches}</p>\n : <ul className='notes-slice-chooser__list' aria-label={labels.slices.results}>{results.map(option)}</ul>)}\n </div>\n </section>\n {chosen.length > 0 && (\n <section>\n <p className='notes-slice-chooser__heading'>{format(labels.slices.chosen, { count: chosen.length })}</p>\n <ul className='notes-slice-chooser__chosen'>\n {chosen.map(location => (\n <li key={sliceKey(location)} className='notes-slice-chooser__chip'>\n <span>{name(location)}</span>\n <IconButton\n variant='ghost'\n size='small'\n icon={<CloseIcon />}\n aria-label={format(labels.slices.remove, { slice: name(location) })}\n onClick={() => onChange(toggleSlice(chosen, location))} />\n </li>\n ))}\n </ul>\n </section>\n )}\n </div>\n );\n};\n"],"names":["SliceChooser","active","known","chosen","onChange","labels","useNotesLabels","query","setQuery","useState","activeId","useId","resultsId","activeSlices","withParentLevels","distinctSlices","results","searchSlices","name","location","formatLocation","common","locationSeparator","unknownLocation","option","_jsx","li","Checkbox","label","checked","isChosen","toggleSlice","sliceKey","_jsxs","div","className","section","aria-labelledby","h3","id","slices","length","p","noneActive","ul","map","htmlFor","search","TextInput","type","value","placeholder","searchPlaceholder","aria-controls","aria-live","trim","noMatches","aria-label","format","count","span","IconButton","variant","size","icon","CloseIcon","remove","slice","onClick"],"mappings":";;;;;;;;;;;AA4BA;;AAEC,IACM,MAAMA,YAAAA,GAAe,CAAC,EAAEC,MAAM,EAAEC,KAAK,EAAEC,MAAM,EAAEC,QAAQ,EAAqB,GAAA;AAC/E,IAAA,MAAMC,MAAAA,GAASC,2BAAAA,EAAAA;AACf,IAAA,MAAM,CAACC,KAAAA,EAAOC,QAAAA,CAAS,GAAGC,cAAAA,CAAS,EAAA,CAAA;AACnC,IAAA,MAAMC,QAAAA,GAAWC,WAAAA,EAAAA;AACjB,IAAA,MAAMC,SAAAA,GAAYD,WAAAA,EAAAA;IAClB,MAAME,YAAAA,GAAeC,6BAAiBC,0BAAAA,CAAed,MAAAA,CAAAA,CAAAA;IACrD,MAAMe,OAAAA,GAAUC,wBAAAA,CAAaH,4BAAAA,CAAiBZ,KAAAA,CAAAA,EAAQK,KAAAA,CAAAA;AACtD,IAAA,MAAMW,IAAAA,GAAO,CAACC,QAAAA,GAA4BC,6BAAAA,CAAeD,QAAAA,EAAUd,MAAAA,CAAOgB,MAAM,CAACC,iBAAiB,EAAEjB,MAAAA,CAAOgB,MAAM,CAACE,eAAe,CAAA;IAEjI,MAAMC,MAAAA,GAAS,CAACL,QAAAA,iBACZM,cAAA,CAACC,IAAAA,EAAAA;AACG,YAAA,QAAA,gBAAAD,cAAA,CAACE,eAAAA,EAAAA;AAASC,gBAAAA,KAAAA,EAAOV,IAAAA,CAAKC,QAAAA,CAAAA;AAAWU,gBAAAA,OAAAA,EAASC,qBAAS3B,MAAAA,EAAQgB,QAAAA,CAAAA;gBAAWf,QAAAA,EAAU,IAAMA,QAAAA,CAAS2B,uBAAAA,CAAY5B,MAAAA,EAAQ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,MAAM,EAAE;AAAEC,4CAAAA,KAAAA,EAAOjD,IAAAA,CAAKC,QAAAA;AAAU,yCAAA,CAAA;wCACjEiD,OAAAA,EAAS,IAAMhE,QAAAA,CAAS2B,uBAAAA,CAAY5B,MAAAA,EAAQgB,QAAAA,CAAAA;;;+BAP3Ca,oBAAAA,CAASb,QAAAA,CAAAA,CAAAA;;;;;;AAe9C;;"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { LocationParts } from '../Context/formatLocation.js';
|
|
2
2
|
export declare function sliceKey(location: LocationParts): string;
|
|
3
3
|
export declare function distinctSlices<TLocation extends LocationParts>(locations: readonly TLocation[]): TLocation[];
|
|
4
|
+
export declare function withParentLevels(locations: readonly LocationParts[]): LocationParts[];
|
|
4
5
|
export declare function toggleSlice<TLocation extends LocationParts>(chosen: readonly TLocation[], location: TLocation): TLocation[];
|
|
5
6
|
export declare function isChosen(chosen: readonly LocationParts[], location: LocationParts): boolean;
|
|
6
7
|
export declare function searchSlices<TLocation extends LocationParts>(known: readonly TLocation[], query: string): TLocation[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sliceChoice.d.ts","sourceRoot":"","sources":["../../../Feedback/sliceChoice.ts"],"names":[],"mappings":"AAGA,OAAO,EAAkB,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAO7E,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,aAAa,GAAG,MAAM,CAExD;AAOD,wBAAgB,cAAc,CAAC,SAAS,SAAS,aAAa,EAAE,SAAS,EAAE,SAAS,SAAS,EAAE,GAAG,SAAS,EAAE,CAW5G;AAQD,wBAAgB,WAAW,CAAC,SAAS,SAAS,aAAa,EAAE,MAAM,EAAE,SAAS,SAAS,EAAE,EAAE,QAAQ,EAAE,SAAS,GAAG,SAAS,EAAE,CAK3H;AAQD,wBAAgB,QAAQ,CAAC,MAAM,EAAE,SAAS,aAAa,EAAE,EAAE,QAAQ,EAAE,aAAa,GAAG,OAAO,CAG3F;AAQD,wBAAgB,YAAY,CAAC,SAAS,SAAS,aAAa,EAAE,KAAK,EAAE,SAAS,SAAS,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,CAUrH"}
|
|
1
|
+
{"version":3,"file":"sliceChoice.d.ts","sourceRoot":"","sources":["../../../Feedback/sliceChoice.ts"],"names":[],"mappings":"AAGA,OAAO,EAAkB,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAO7E,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,aAAa,GAAG,MAAM,CAExD;AAOD,wBAAgB,cAAc,CAAC,SAAS,SAAS,aAAa,EAAE,SAAS,EAAE,SAAS,SAAS,EAAE,GAAG,SAAS,EAAE,CAW5G;AASD,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,SAAS,aAAa,EAAE,GAAG,aAAa,EAAE,CAYrF;AAQD,wBAAgB,WAAW,CAAC,SAAS,SAAS,aAAa,EAAE,MAAM,EAAE,SAAS,SAAS,EAAE,EAAE,QAAQ,EAAE,SAAS,GAAG,SAAS,EAAE,CAK3H;AAQD,wBAAgB,QAAQ,CAAC,MAAM,EAAE,SAAS,aAAa,EAAE,EAAE,QAAQ,EAAE,aAAa,GAAG,OAAO,CAG3F;AAQD,wBAAgB,YAAY,CAAC,SAAS,SAAS,aAAa,EAAE,KAAK,EAAE,SAAS,SAAS,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,CAUrH"}
|
|
@@ -26,6 +26,35 @@ var formatLocation = require('../Context/formatLocation.js');
|
|
|
26
26
|
return true;
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Adds the broader levels of every location: its module, and its feature within the module. A note can be about a whole
|
|
31
|
+
* module or a whole feature, not only a slice, and such a level is a location whose finer parts are empty, which is how the
|
|
32
|
+
* contracts carry a location Arc could resolve only that far.
|
|
33
|
+
* @param locations The locations, typically slices.
|
|
34
|
+
* @returns The distinct, non-empty locations with the module and feature of each, broader levels before the slices in them.
|
|
35
|
+
*/ function withParentLevels(locations) {
|
|
36
|
+
return distinctSlices(locations.flatMap((location)=>{
|
|
37
|
+
const levels = [];
|
|
38
|
+
if (location.module.length > 0) {
|
|
39
|
+
levels.push({
|
|
40
|
+
module: location.module,
|
|
41
|
+
feature: '',
|
|
42
|
+
slice: ''
|
|
43
|
+
});
|
|
44
|
+
if (location.feature.length > 0) {
|
|
45
|
+
levels.push({
|
|
46
|
+
module: location.module,
|
|
47
|
+
feature: location.feature,
|
|
48
|
+
slice: ''
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return [
|
|
53
|
+
...levels,
|
|
54
|
+
location
|
|
55
|
+
];
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
29
58
|
/**
|
|
30
59
|
* Adds a slice to the chosen ones, or removes it when it is chosen already.
|
|
31
60
|
* @param chosen The chosen slices.
|
|
@@ -68,4 +97,5 @@ exports.isChosen = isChosen;
|
|
|
68
97
|
exports.searchSlices = searchSlices;
|
|
69
98
|
exports.sliceKey = sliceKey;
|
|
70
99
|
exports.toggleSlice = toggleSlice;
|
|
100
|
+
exports.withParentLevels = withParentLevels;
|
|
71
101
|
//# sourceMappingURL=sliceChoice.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sliceChoice.js","sources":["../../../Feedback/sliceChoice.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { formatLocation, LocationParts } from '../Context/formatLocation.js';\n\n/**\n * Gets what identifies a slice location.\n * @param location The location.\n * @returns A key that is the same for the same location.\n */\nexport function sliceKey(location: LocationParts): string {\n return `${location.module}/${location.feature}/${location.slice}`;\n}\n\n/**\n * Removes the slices that repeat an earlier one, and the ones that are empty.\n * @param locations The locations.\n * @returns The distinct, non-empty locations in their order.\n */\nexport function distinctSlices<TLocation extends LocationParts>(locations: readonly TLocation[]): TLocation[] {\n const seen = new Set<string>();\n return locations.filter(location => {\n const key = sliceKey(location);\n if (key === '//' || seen.has(key)) {\n return false;\n }\n\n seen.add(key);\n return true;\n });\n}\n\n/**\n * Adds a slice to the chosen ones, or removes it when it is chosen already.\n * @param chosen The chosen slices.\n * @param location The slice to toggle.\n * @returns The chosen slices after the toggle.\n */\nexport function toggleSlice<TLocation extends LocationParts>(chosen: readonly TLocation[], location: TLocation): TLocation[] {\n const key = sliceKey(location);\n return chosen.some(slice => sliceKey(slice) === key)\n ? chosen.filter(slice => sliceKey(slice) !== key)\n : [...chosen, location];\n}\n\n/**\n * Whether a slice is among the chosen ones.\n * @param chosen The chosen slices.\n * @param location The slice.\n * @returns True when it is chosen.\n */\nexport function isChosen(chosen: readonly LocationParts[], location: LocationParts): boolean {\n const key = sliceKey(location);\n return chosen.some(slice => sliceKey(slice) === key);\n}\n\n/**\n * Searches the slices the host knows about.\n * @param known Every slice the host knows about.\n * @param query What the user typed; every word has to be part of the module, feature or slice.\n * @returns The distinct slices that match; none for an empty query.\n */\nexport function searchSlices<TLocation extends LocationParts>(known: readonly TLocation[], query: string): TLocation[] {\n const words = query.toLowerCase().split(/\\s+/).filter(word => word.length > 0);\n if (words.length === 0) {\n return [];\n }\n\n return distinctSlices(known).filter(location => {\n const text = formatLocation(location, ' ', '').toLowerCase();\n return words.every(word => text.includes(word));\n });\n}\n"],"names":["sliceKey","location","module","feature","slice","distinctSlices","locations","seen","Set","filter","key","has","add","toggleSlice","chosen","some","isChosen","searchSlices","known","query","words","toLowerCase","split","word","
|
|
1
|
+
{"version":3,"file":"sliceChoice.js","sources":["../../../Feedback/sliceChoice.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { formatLocation, LocationParts } from '../Context/formatLocation.js';\n\n/**\n * Gets what identifies a slice location.\n * @param location The location.\n * @returns A key that is the same for the same location.\n */\nexport function sliceKey(location: LocationParts): string {\n return `${location.module}/${location.feature}/${location.slice}`;\n}\n\n/**\n * Removes the slices that repeat an earlier one, and the ones that are empty.\n * @param locations The locations.\n * @returns The distinct, non-empty locations in their order.\n */\nexport function distinctSlices<TLocation extends LocationParts>(locations: readonly TLocation[]): TLocation[] {\n const seen = new Set<string>();\n return locations.filter(location => {\n const key = sliceKey(location);\n if (key === '//' || seen.has(key)) {\n return false;\n }\n\n seen.add(key);\n return true;\n });\n}\n\n/**\n * Adds the broader levels of every location: its module, and its feature within the module. A note can be about a whole\n * module or a whole feature, not only a slice, and such a level is a location whose finer parts are empty, which is how the\n * contracts carry a location Arc could resolve only that far.\n * @param locations The locations, typically slices.\n * @returns The distinct, non-empty locations with the module and feature of each, broader levels before the slices in them.\n */\nexport function withParentLevels(locations: readonly LocationParts[]): LocationParts[] {\n return distinctSlices(locations.flatMap(location => {\n const levels: LocationParts[] = [];\n if (location.module.length > 0) {\n levels.push({ module: location.module, feature: '', slice: '' });\n if (location.feature.length > 0) {\n levels.push({ module: location.module, feature: location.feature, slice: '' });\n }\n }\n\n return [...levels, location];\n }));\n}\n\n/**\n * Adds a slice to the chosen ones, or removes it when it is chosen already.\n * @param chosen The chosen slices.\n * @param location The slice to toggle.\n * @returns The chosen slices after the toggle.\n */\nexport function toggleSlice<TLocation extends LocationParts>(chosen: readonly TLocation[], location: TLocation): TLocation[] {\n const key = sliceKey(location);\n return chosen.some(slice => sliceKey(slice) === key)\n ? chosen.filter(slice => sliceKey(slice) !== key)\n : [...chosen, location];\n}\n\n/**\n * Whether a slice is among the chosen ones.\n * @param chosen The chosen slices.\n * @param location The slice.\n * @returns True when it is chosen.\n */\nexport function isChosen(chosen: readonly LocationParts[], location: LocationParts): boolean {\n const key = sliceKey(location);\n return chosen.some(slice => sliceKey(slice) === key);\n}\n\n/**\n * Searches the slices the host knows about.\n * @param known Every slice the host knows about.\n * @param query What the user typed; every word has to be part of the module, feature or slice.\n * @returns The distinct slices that match; none for an empty query.\n */\nexport function searchSlices<TLocation extends LocationParts>(known: readonly TLocation[], query: string): TLocation[] {\n const words = query.toLowerCase().split(/\\s+/).filter(word => word.length > 0);\n if (words.length === 0) {\n return [];\n }\n\n return distinctSlices(known).filter(location => {\n const text = formatLocation(location, ' ', '').toLowerCase();\n return words.every(word => text.includes(word));\n });\n}\n"],"names":["sliceKey","location","module","feature","slice","distinctSlices","locations","seen","Set","filter","key","has","add","withParentLevels","flatMap","levels","length","push","toggleSlice","chosen","some","isChosen","searchSlices","known","query","words","toLowerCase","split","word","text","formatLocation","every","includes"],"mappings":";;;;AAAA;AACA;AAIA;;;;IAKO,SAASA,QAAAA,CAASC,QAAuB,EAAA;AAC5C,IAAA,OAAO,CAAA,EAAGA,QAAAA,CAASC,MAAM,CAAC,CAAC,EAAED,QAAAA,CAASE,OAAO,CAAC,CAAC,EAAEF,QAAAA,CAASG,KAAK,CAAA,CAAE;AACrE;AAEA;;;;IAKO,SAASC,cAAAA,CAAgDC,SAA+B,EAAA;AAC3F,IAAA,MAAMC,OAAO,IAAIC,GAAAA,EAAAA;IACjB,OAAOF,SAAAA,CAAUG,MAAM,CAACR,CAAAA,QAAAA,GAAAA;AACpB,QAAA,MAAMS,MAAMV,QAAAA,CAASC,QAAAA,CAAAA;AACrB,QAAA,IAAIS,GAAAA,KAAQ,IAAA,IAAQH,IAAAA,CAAKI,GAAG,CAACD,GAAAA,CAAAA,EAAM;YAC/B,OAAO,KAAA;AACX,QAAA;AAEAH,QAAAA,IAAAA,CAAKK,GAAG,CAACF,GAAAA,CAAAA;QACT,OAAO,IAAA;AACX,IAAA,CAAA,CAAA;AACJ;AAEA;;;;;;IAOO,SAASG,gBAAAA,CAAiBP,SAAmC,EAAA;AAChE,IAAA,OAAOD,cAAAA,CAAeC,SAAAA,CAAUQ,OAAO,CAACb,CAAAA,QAAAA,GAAAA;AACpC,QAAA,MAAMc,SAA0B,EAAE;AAClC,QAAA,IAAId,QAAAA,CAASC,MAAM,CAACc,MAAM,GAAG,CAAA,EAAG;AAC5BD,YAAAA,MAAAA,CAAOE,IAAI,CAAC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AW,EAAA,CAAGC,KAAK,CAAC,KAAA,CAAA,CAAOlB,MAAM,CAACmB,CAAAA,IAAAA,GAAQA,IAAAA,CAAKZ,MAAM,GAAG,CAAA,CAAA;IAC5E,IAAIS,KAAAA,CAAMT,MAAM,KAAK,CAAA,EAAG;AACpB,QAAA,OAAO,EAAE;AACb,IAAA;AAEA,IAAA,OAAOX,cAAAA,CAAekB,KAAAA,CAAAA,CAAOd,MAAM,CAACR,CAAAA,QAAAA,GAAAA;AAChC,QAAA,MAAM4B,IAAAA,GAAOC,6BAAAA,CAAe7B,QAAAA,EAAU,GAAA,EAAK,IAAIyB,WAAW,EAAA;AAC1D,QAAA,OAAOD,MAAMM,KAAK,CAACH,CAAAA,IAAAA,GAAQC,IAAAA,CAAKG,QAAQ,CAACJ,IAAAA,CAAAA,CAAAA;AAC7C,IAAA,CAAA,CAAA;AACJ;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NotesProvider.d.ts","sourceRoot":"","sources":["../../../Provider/NotesProvider.tsx"],"names":[],"mappings":"AAWA,OAAO,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"NotesProvider.d.ts","sourceRoot":"","sources":["../../../Provider/NotesProvider.tsx"],"names":[],"mappings":"AAWA,OAAO,EAAE,SAAS,EAA2C,MAAM,OAAO,CAAC;AAE3E,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAI7D,OAAO,EAAE,mBAAmB,EAAiB,MAAM,oBAAoB,CAAC;AAQxE,MAAM,WAAW,kBAAkB;IAE/B,OAAO,CAAC,EAAE,OAAO,CAAC;IAGlB,MAAM,CAAC,EAAE,mBAAmB,CAAC;IAG7B,WAAW,CAAC,EAAE,SAAS,aAAa,EAAE,CAAC;IAGvC,QAAQ,CAAC,EAAE,SAAS,CAAC;CACxB;AAcD,eAAO,MAAM,aAAa,GAAI,4CAAyD,kBAAkB,gCAmFxG,CAAC"}
|
|
@@ -26,13 +26,26 @@ const dialogReferenceOf = (dialog)=>dialog?.sliceLocation ? {
|
|
|
26
26
|
} : undefined;
|
|
27
27
|
/**
|
|
28
28
|
* Slots Notes into an application: renders the feedback dialogs and the component picker once, asks whether Notes is
|
|
29
|
-
* switched on
|
|
29
|
+
* available to the user - switched on and, when only granted users may give feedback, granted to them - and gives the Notes
|
|
30
|
+
* buttons and `useNotes` what they need. Render it inside `<Arc>`, the `DialogComponents`
|
|
30
31
|
* registration, an `IdentityProvider` and a `CratisComponentsProvider` with a toaster. Turn on `<Arc sliceMarkers>` for
|
|
31
32
|
* Notes to know the slice of a component the user points at.
|
|
32
33
|
*/ const NotesProvider = ({ enabled = false, labels, knownSlices = [], children })=>{
|
|
33
34
|
const store = arc_react.useApplicationContextStore();
|
|
34
35
|
const identity$1 = identity.useIdentity();
|
|
35
|
-
const [availability] = showrunner_notes.Availability.use();
|
|
36
|
+
const [availability, performAvailability] = showrunner_notes.Availability.use();
|
|
37
|
+
const wasSignedIn = react.useRef(identity$1.isSet);
|
|
38
|
+
// Whether the user may give feedback depends on who they are, and the first answer can be given before anyone signed in.
|
|
39
|
+
// Asking again once they have keeps the button hidden for a user nobody granted the right and shows it to one who was.
|
|
40
|
+
react.useEffect(()=>{
|
|
41
|
+
if (identity$1.isSet && !wasSignedIn.current) {
|
|
42
|
+
void performAvailability();
|
|
43
|
+
}
|
|
44
|
+
wasSignedIn.current = identity$1.isSet;
|
|
45
|
+
}, [
|
|
46
|
+
identity$1.isSet,
|
|
47
|
+
performAvailability
|
|
48
|
+
]);
|
|
36
49
|
const isAvailable = notesVisibility.isNotesAvailable(identity$1.isSet, availability.data?.isEnabled);
|
|
37
50
|
const resolvedLabels = react.useMemo(()=>resolveLabels.resolveLabels(labels), [
|
|
38
51
|
labels
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NotesProvider.js","sources":["../../../Provider/NotesProvider.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { ApplicationContext, useApplicationContextStore } from '@cratis/arc.react';\nimport { DialogResult, useDialog } from '@cratis/arc.react/dialogs';\nimport { useIdentity } from '@cratis/arc.react/identity';\nimport { useComponentPicker } from '@cratis/components/ComponentPicker';\nimport { DialogHeaderContext } from '@cratis/components/Dialogs';\nimport { toast } from '@cratis/components/Notifications';\nimport { Guid } from '@cratis/fundamentals';\nimport { Availability } from '@cratis/showrunner.notes';\nimport { ReactNode, useCallback, useMemo, useRef } from 'react';\nimport { buildNoteContext, DialogReference, resolveComponentContext } from '../Context/index.js';\nimport { LocationParts } from '../Context/formatLocation.js';\nimport { ComponentFeedbackDialog } from '../Feedback/ComponentFeedbackDialog.js';\nimport { FeedbackDialog, FeedbackGiven } from '../Feedback/FeedbackDialog.js';\nimport { SlicesFeedbackDialog } from '../Feedback/SlicesFeedbackDialog.js';\nimport { NotesLabelOverrides, resolveLabels } from '../Labels/index.js';\nimport { MyFeedbackDialog } from '../MyFeedback/MyFeedbackDialog.js';\nimport { NotesContext, NotesContextValue } from './NotesContext.js';\nimport { isNotesAvailable } from './notesVisibility.js';\n\n/**\n * Props for {@link NotesProvider}.\n */\nexport interface NotesProviderProps {\n /** Whether the feedback button registers itself in the header of dialogs that have a slice. Defaults to false. It takes effect through `notesDialogHeaderActions` on `CratisComponentsProvider`. */\n enabled?: boolean;\n\n /** The labels that replace the English defaults, for instance to localize them. */\n labels?: NotesLabelOverrides;\n\n /** Every slice the host knows about, for the search of the give feedback on slices dialog. */\n knownSlices?: readonly LocationParts[];\n\n /** The application. */\n children?: ReactNode;\n}\n\nconst emptySnapshot = new ApplicationContext().getSnapshot();\n\nconst dialogReferenceOf = (dialog?: DialogHeaderContext): DialogReference | undefined =>\n dialog?.sliceLocation ? { title: dialog.title, location: dialog.sliceLocation } : undefined;\n\n/**\n * Slots Notes into an application: renders the feedback dialogs and the component picker once, asks whether Notes is\n * switched on, and gives the Notes buttons and `useNotes` what they need. Render it inside `<Arc>`, the `DialogComponents`\n * registration, an `IdentityProvider` and a `CratisComponentsProvider` with a toaster. Turn on `<Arc sliceMarkers>` for\n * Notes to know the slice of a component the user points at.\n */\nexport const NotesProvider = ({ enabled = false, labels, knownSlices = [], children }: NotesProviderProps) => {\n const store = useApplicationContextStore();\n const identity = useIdentity();\n const [availability] = Availability.use();\n const isAvailable = isNotesAvailable(identity.isSet, availability.data?.isEnabled);\n const resolvedLabels = useMemo(() => resolveLabels(labels), [labels]);\n const busy = useRef(false);\n\n const [FeedbackDialogWrapper, showFeedbackDialog] = useDialog<FeedbackGiven, Parameters<typeof FeedbackDialog>[0]>(FeedbackDialog);\n const [SlicesDialogWrapper, showSlicesDialog] = useDialog<FeedbackGiven, Parameters<typeof SlicesFeedbackDialog>[0]>(SlicesFeedbackDialog);\n const [ComponentDialogWrapper, showComponentDialog] = useDialog<FeedbackGiven, Parameters<typeof ComponentFeedbackDialog>[0]>(ComponentFeedbackDialog);\n const [MyFeedbackDialogWrapper, showMyFeedbackDialog] = useDialog<object, object>(MyFeedbackDialog);\n const picker = useComponentPicker({ resolve: resolveComponentContext });\n\n const capture = useCallback((dialog?: DialogHeaderContext) => buildNoteContext({\n snapshot: store?.getSnapshot() ?? emptySnapshot,\n route: window.location.pathname,\n correlationId: Guid.create(),\n dialog: dialogReferenceOf(dialog)\n }), [store]);\n\n const whileOpen = useCallback(async <TResult,>(open: () => Promise<[DialogResult, TResult?]>, announceSent = true) => {\n if (busy.current) {\n return;\n }\n\n busy.current = true;\n try {\n const [result] = await open();\n if (announceSent && result === DialogResult.Ok) {\n toast.success({ title: resolvedLabels.feedback.sent });\n }\n } finally {\n busy.current = false;\n }\n }, [resolvedLabels]);\n\n const value = useMemo<NotesContextValue>(() => ({\n isProvided: true,\n labels: resolvedLabels,\n isAvailable,\n showsInDialogHeaders: enabled,\n isPicking: picker.isPicking,\n giveFeedback: dialog => void whileOpen(() => showFeedbackDialog({ context: capture(dialog) })),\n giveFeedbackOnScreen: dialog => void whileOpen(() => showFeedbackDialog({ context: capture(dialog), about: 'screen' })),\n giveFeedbackOnSlices: dialog => void whileOpen(() => showSlicesDialog({ context: capture(dialog), knownSlices })),\n pointAtSomething: dialog => {\n if (busy.current || picker.isPicking) {\n return;\n }\n\n const context = capture(dialog);\n void picker.start().then(picked => {\n if (picked) {\n void whileOpen(() => showComponentDialog({ context, picked }));\n }\n });\n },\n showMyFeedback: () => void whileOpen(() => showMyFeedbackDialog({}), false)\n }), [resolvedLabels, isAvailable, enabled, picker, knownSlices, capture, whileOpen, showFeedbackDialog, showSlicesDialog, showComponentDialog, showMyFeedbackDialog]);\n\n return (\n <NotesContext.Provider value={value}>\n {children}\n <FeedbackDialogWrapper />\n <SlicesDialogWrapper />\n <ComponentDialogWrapper />\n <MyFeedbackDialogWrapper />\n {picker.picker}\n </NotesContext.Provider>\n );\n};\n"],"names":["emptySnapshot","ApplicationContext","getSnapshot","dialogReferenceOf","dialog","sliceLocation","title","location","undefined","NotesProvider","enabled","labels","knownSlices","children","store","useApplicationContextStore","identity","useIdentity","availability","Availability","use","isAvailable","isNotesAvailable","isSet","data","isEnabled","resolvedLabels","useMemo","resolveLabels","busy","useRef","FeedbackDialogWrapper","showFeedbackDialog","useDialog","FeedbackDialog","SlicesDialogWrapper","showSlicesDialog","SlicesFeedbackDialog","ComponentDialogWrapper","showComponentDialog","ComponentFeedbackDialog","MyFeedbackDialogWrapper","showMyFeedbackDialog","MyFeedbackDialog","picker","useComponentPicker","resolve","resolveComponentContext","capture","useCallback","buildNoteContext","snapshot","route","window","pathname","correlationId","Guid","create","whileOpen","open","announceSent","current","result","DialogResult","Ok","toast","success","feedback","sent","value","isProvided","showsInDialogHeaders","isPicking","giveFeedback","context","giveFeedbackOnScreen","about","giveFeedbackOnSlices","pointAtSomething","start","then","picked","showMyFeedback","_jsxs","NotesContext","Provider","_jsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAuCA,MAAMA,aAAAA,GAAgB,IAAIC,4BAAAA,EAAAA,CAAqBC,WAAW,EAAA;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,QAAAA,cAAAA;AAAgBL,QAAAA,WAAAA;AAAaX,QAAAA,OAAAA;AAASkC,QAAAA,MAAAA;AAAQhC,QAAAA,WAAAA;AAAaoC,QAAAA,OAAAA;AAASU,QAAAA,SAAAA;AAAW1B,QAAAA,kBAAAA;AAAoBI,QAAAA,gBAAAA;AAAkBG,QAAAA,mBAAAA;AAAqBG,QAAAA;AAAqB,KAAA,CAAA;IAEpK,qBACIyC,eAAA,CAACC,0BAAaC,QAAQ,EAAA;QAAChB,KAAAA,EAAOA,KAAAA;;AACzBxD,YAAAA,QAAAA;0BACDyE,cAAA,CAACvD,qBAAAA,EAAAA,EAAAA,CAAAA;0BACDuD,cAAA,CAACnD,mBAAAA,EAAAA,EAAAA,CAAAA;0BACDmD,cAAA,CAAChD,sBAAAA,EAAAA,EAAAA,CAAAA;0BACDgD,cAAA,CAAC7C,uBAAAA,EAAAA,EAAAA,CAAAA;AACAG,YAAAA,MAAAA,CAAOA;;;AAGpB;;"}
|
|
1
|
+
{"version":3,"file":"NotesProvider.js","sources":["../../../Provider/NotesProvider.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { ApplicationContext, useApplicationContextStore } from '@cratis/arc.react';\nimport { DialogResult, useDialog } from '@cratis/arc.react/dialogs';\nimport { useIdentity } from '@cratis/arc.react/identity';\nimport { useComponentPicker } from '@cratis/components/ComponentPicker';\nimport { DialogHeaderContext } from '@cratis/components/Dialogs';\nimport { toast } from '@cratis/components/Notifications';\nimport { Guid } from '@cratis/fundamentals';\nimport { Availability } from '@cratis/showrunner.notes';\nimport { ReactNode, useCallback, useEffect, useMemo, useRef } from 'react';\nimport { buildNoteContext, DialogReference, resolveComponentContext } from '../Context/index.js';\nimport { LocationParts } from '../Context/formatLocation.js';\nimport { ComponentFeedbackDialog } from '../Feedback/ComponentFeedbackDialog.js';\nimport { FeedbackDialog, FeedbackGiven } from '../Feedback/FeedbackDialog.js';\nimport { SlicesFeedbackDialog } from '../Feedback/SlicesFeedbackDialog.js';\nimport { NotesLabelOverrides, resolveLabels } from '../Labels/index.js';\nimport { MyFeedbackDialog } from '../MyFeedback/MyFeedbackDialog.js';\nimport { NotesContext, NotesContextValue } from './NotesContext.js';\nimport { isNotesAvailable } from './notesVisibility.js';\n\n/**\n * Props for {@link NotesProvider}.\n */\nexport interface NotesProviderProps {\n /** Whether the feedback button registers itself in the header of dialogs that have a slice. Defaults to false. It takes effect through `notesDialogHeaderActions` on `CratisComponentsProvider`. */\n enabled?: boolean;\n\n /** The labels that replace the English defaults, for instance to localize them. */\n labels?: NotesLabelOverrides;\n\n /** Every slice the host knows about, for the search of the give feedback on slices dialog. */\n knownSlices?: readonly LocationParts[];\n\n /** The application. */\n children?: ReactNode;\n}\n\nconst emptySnapshot = new ApplicationContext().getSnapshot();\n\nconst dialogReferenceOf = (dialog?: DialogHeaderContext): DialogReference | undefined =>\n dialog?.sliceLocation ? { title: dialog.title, location: dialog.sliceLocation } : undefined;\n\n/**\n * Slots Notes into an application: renders the feedback dialogs and the component picker once, asks whether Notes is\n * available to the user - switched on and, when only granted users may give feedback, granted to them - and gives the Notes\n * buttons and `useNotes` what they need. Render it inside `<Arc>`, the `DialogComponents`\n * registration, an `IdentityProvider` and a `CratisComponentsProvider` with a toaster. Turn on `<Arc sliceMarkers>` for\n * Notes to know the slice of a component the user points at.\n */\nexport const NotesProvider = ({ enabled = false, labels, knownSlices = [], children }: NotesProviderProps) => {\n const store = useApplicationContextStore();\n const identity = useIdentity();\n const [availability, performAvailability] = Availability.use();\n const wasSignedIn = useRef(identity.isSet);\n\n // Whether the user may give feedback depends on who they are, and the first answer can be given before anyone signed in.\n // Asking again once they have keeps the button hidden for a user nobody granted the right and shows it to one who was.\n useEffect(() => {\n if (identity.isSet && !wasSignedIn.current) {\n void performAvailability();\n }\n\n wasSignedIn.current = identity.isSet;\n }, [identity.isSet, performAvailability]);\n\n const isAvailable = isNotesAvailable(identity.isSet, availability.data?.isEnabled);\n const resolvedLabels = useMemo(() => resolveLabels(labels), [labels]);\n const busy = useRef(false);\n\n const [FeedbackDialogWrapper, showFeedbackDialog] = useDialog<FeedbackGiven, Parameters<typeof FeedbackDialog>[0]>(FeedbackDialog);\n const [SlicesDialogWrapper, showSlicesDialog] = useDialog<FeedbackGiven, Parameters<typeof SlicesFeedbackDialog>[0]>(SlicesFeedbackDialog);\n const [ComponentDialogWrapper, showComponentDialog] = useDialog<FeedbackGiven, Parameters<typeof ComponentFeedbackDialog>[0]>(ComponentFeedbackDialog);\n const [MyFeedbackDialogWrapper, showMyFeedbackDialog] = useDialog<object, object>(MyFeedbackDialog);\n const picker = useComponentPicker({ resolve: resolveComponentContext });\n\n const capture = useCallback((dialog?: DialogHeaderContext) => buildNoteContext({\n snapshot: store?.getSnapshot() ?? emptySnapshot,\n route: window.location.pathname,\n correlationId: Guid.create(),\n dialog: dialogReferenceOf(dialog)\n }), [store]);\n\n const whileOpen = useCallback(async <TResult,>(open: () => Promise<[DialogResult, TResult?]>, announceSent = true) => {\n if (busy.current) {\n return;\n }\n\n busy.current = true;\n try {\n const [result] = await open();\n if (announceSent && result === DialogResult.Ok) {\n toast.success({ title: resolvedLabels.feedback.sent });\n }\n } finally {\n busy.current = false;\n }\n }, [resolvedLabels]);\n\n const value = useMemo<NotesContextValue>(() => ({\n isProvided: true,\n labels: resolvedLabels,\n isAvailable,\n showsInDialogHeaders: enabled,\n isPicking: picker.isPicking,\n giveFeedback: dialog => void whileOpen(() => showFeedbackDialog({ context: capture(dialog) })),\n giveFeedbackOnScreen: dialog => void whileOpen(() => showFeedbackDialog({ context: capture(dialog), about: 'screen' })),\n giveFeedbackOnSlices: dialog => void whileOpen(() => showSlicesDialog({ context: capture(dialog), knownSlices })),\n pointAtSomething: dialog => {\n if (busy.current || picker.isPicking) {\n return;\n }\n\n const context = capture(dialog);\n void picker.start().then(picked => {\n if (picked) {\n void whileOpen(() => showComponentDialog({ context, picked }));\n }\n });\n },\n showMyFeedback: () => void whileOpen(() => showMyFeedbackDialog({}), false)\n }), [resolvedLabels, isAvailable, enabled, picker, knownSlices, capture, whileOpen, showFeedbackDialog, showSlicesDialog, showComponentDialog, showMyFeedbackDialog]);\n\n return (\n <NotesContext.Provider value={value}>\n {children}\n <FeedbackDialogWrapper />\n <SlicesDialogWrapper />\n <ComponentDialogWrapper />\n <MyFeedbackDialogWrapper />\n {picker.picker}\n </NotesContext.Provider>\n );\n};\n"],"names":["emptySnapshot","ApplicationContext","getSnapshot","dialogReferenceOf","dialog","sliceLocation","title","location","undefined","NotesProvider","enabled","labels","knownSlices","children","store","useApplicationContextStore","identity","useIdentity","availability","performAvailability","Availability","use","wasSignedIn","useRef","isSet","useEffect","current","isAvailable","isNotesAvailable","data","isEnabled","resolvedLabels","useMemo","resolveLabels","busy","FeedbackDialogWrapper","showFeedbackDialog","useDialog","FeedbackDialog","SlicesDialogWrapper","showSlicesDialog","SlicesFeedbackDialog","ComponentDialogWrapper","showComponentDialog","ComponentFeedbackDialog","MyFeedbackDialogWrapper","showMyFeedbackDialog","MyFeedbackDialog","picker","useComponentPicker","resolve","resolveComponentContext","capture","useCallback","buildNoteContext","snapshot","route","window","pathname","correlationId","Guid","create","whileOpen","open","announceSent","result","DialogResult","Ok","toast","success","feedback","sent","value","isProvided","showsInDialogHeaders","isPicking","giveFeedback","context","giveFeedbackOnScreen","about","giveFeedbackOnSlices","pointAtSomething","start","then","picked","showMyFeedback","_jsxs","NotesContext","Provider","_jsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAuCA,MAAMA,aAAAA,GAAgB,IAAIC,4BAAAA,EAAAA,CAAqBC,WAAW,EAAA;AAE1D,MAAMC,iBAAAA,GAAoB,CAACC,MAAAA,GACvBA,MAAAA,EAAQC,aAAAA,GAAgB;AAAEC,QAAAA,KAAAA,EAAOF,OAAOE,KAAK;AAAEC,QAAAA,QAAAA,EAAUH,OAAOC;KAAc,GAAIG,SAAAA;AAEtF;;;;;;AAMC,IACM,MAA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AA,CAAA;AACAC,YAAAA,cAAAA,EAAgB,IAAM,KAAKvB,SAAAA,CAAU,IAAMhB,oBAAAA,CAAqB,EAAC,CAAA,EAAI,KAAA;AACzE,SAAA,CAAA,EAAI;AAACf,QAAAA,cAAAA;AAAgBJ,QAAAA,WAAAA;AAAajB,QAAAA,OAAAA;AAASsC,QAAAA,MAAAA;AAAQpC,QAAAA,WAAAA;AAAawC,QAAAA,OAAAA;AAASU,QAAAA,SAAAA;AAAW1B,QAAAA,kBAAAA;AAAoBI,QAAAA,gBAAAA;AAAkBG,QAAAA,mBAAAA;AAAqBG,QAAAA;AAAqB,KAAA,CAAA;IAEpK,qBACIwC,eAAA,CAACC,0BAAaC,QAAQ,EAAA;QAAChB,KAAAA,EAAOA,KAAAA;;AACzB3D,YAAAA,QAAAA;0BACD4E,cAAA,CAACtD,qBAAAA,EAAAA,EAAAA,CAAAA;0BACDsD,cAAA,CAAClD,mBAAAA,EAAAA,EAAAA,CAAAA;0BACDkD,cAAA,CAAC/C,sBAAAA,EAAAA,EAAAA,CAAAA;0BACD+C,cAAA,CAAC5C,uBAAAA,EAAAA,EAAAA,CAAAA;AACAG,YAAAA,MAAAA,CAAOA;;;AAGpB;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notesVisibility.d.ts","sourceRoot":"","sources":["../../../Provider/notesVisibility.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"notesVisibility.d.ts","sourceRoot":"","sources":["../../../Provider/notesVisibility.ts"],"names":[],"mappings":"AAWA,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,GAAG,SAAS,GAAG,OAAO,CAE7F"}
|
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
// Copyright (c) Cratis. All rights reserved.
|
|
4
4
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
5
5
|
/**
|
|
6
|
-
* Decides whether the Notes components render anything: only for a signed-in user, and only while Notes is
|
|
7
|
-
*
|
|
6
|
+
* Decides whether the Notes components render anything: only for a signed-in user, and only while Notes is available to
|
|
7
|
+
* them. It is not when Notes is switched off, and not when the application lets only granted users give feedback and nobody
|
|
8
|
+
* granted this user.
|
|
8
9
|
* @param isSignedIn Whether the user is signed in.
|
|
9
|
-
* @param isEnabled Whether Notes is
|
|
10
|
+
* @param isEnabled Whether Notes is available to the user, as `NotesAvailability` tells; false until it is known.
|
|
10
11
|
* @returns True when the Notes components render.
|
|
11
12
|
*/ function isNotesAvailable(isSignedIn, isEnabled) {
|
|
12
13
|
return isSignedIn && isEnabled === true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notesVisibility.js","sources":["../../../Provider/notesVisibility.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\n/**\n * Decides whether the Notes components render anything: only for a signed-in user, and only while Notes is switched\n *
|
|
1
|
+
{"version":3,"file":"notesVisibility.js","sources":["../../../Provider/notesVisibility.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\n/**\n * Decides whether the Notes components render anything: only for a signed-in user, and only while Notes is available to\n * them. It is not when Notes is switched off, and not when the application lets only granted users give feedback and nobody\n * granted this user.\n * @param isSignedIn Whether the user is signed in.\n * @param isEnabled Whether Notes is available to the user, as `NotesAvailability` tells; false until it is known.\n * @returns True when the Notes components render.\n */\nexport function isNotesAvailable(isSignedIn: boolean, isEnabled: boolean | undefined): boolean {\n return isSignedIn && isEnabled === true;\n}\n"],"names":["isNotesAvailable","isSignedIn","isEnabled"],"mappings":";;AAAA;AACA;AAEA;;;;;;;AAOC,IACM,SAASA,gBAAAA,CAAiBC,UAAmB,EAAEC,SAA8B,EAAA;AAChF,IAAA,OAAOD,cAAcC,SAAAA,KAAc,IAAA;AACvC;;"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -61,6 +61,7 @@ exports.isChosen = sliceChoice.isChosen;
|
|
|
61
61
|
exports.searchSlices = sliceChoice.searchSlices;
|
|
62
62
|
exports.sliceKey = sliceChoice.sliceKey;
|
|
63
63
|
exports.toggleSlice = sliceChoice.toggleSlice;
|
|
64
|
+
exports.withParentLevels = sliceChoice.withParentLevels;
|
|
64
65
|
exports.ChevronIcon = Icons.ChevronIcon;
|
|
65
66
|
exports.CloseIcon = Icons.CloseIcon;
|
|
66
67
|
exports.FeedbackIcon = Icons.FeedbackIcon;
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -5,7 +5,7 @@ import { formatLocation } from '../Context/formatLocation.js';
|
|
|
5
5
|
import { CloseIcon } from '../Icons.js';
|
|
6
6
|
import { format } from '../Labels/format.js';
|
|
7
7
|
import { useNotesLabels } from '../Provider/NotesContext.js';
|
|
8
|
-
import { distinctSlices, searchSlices, toggleSlice, sliceKey, isChosen } from './sliceChoice.js';
|
|
8
|
+
import { withParentLevels, distinctSlices, searchSlices, toggleSlice, sliceKey, isChosen } from './sliceChoice.js';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Chooses the slices a note is about: the ones active on the screen, and a search over all the slices the host knows.
|
|
@@ -14,8 +14,8 @@ import { distinctSlices, searchSlices, toggleSlice, sliceKey, isChosen } from '.
|
|
|
14
14
|
const [query, setQuery] = useState('');
|
|
15
15
|
const activeId = useId();
|
|
16
16
|
const resultsId = useId();
|
|
17
|
-
const activeSlices = distinctSlices(active);
|
|
18
|
-
const results = searchSlices(known, query);
|
|
17
|
+
const activeSlices = withParentLevels(distinctSlices(active));
|
|
18
|
+
const results = searchSlices(withParentLevels(known), query);
|
|
19
19
|
const name = (location)=>formatLocation(location, labels.common.locationSeparator, labels.common.unknownLocation);
|
|
20
20
|
const option = (location)=>/*#__PURE__*/ jsx("li", {
|
|
21
21
|
children: /*#__PURE__*/ jsx(Checkbox, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SliceChooser.js","sources":["../../../Feedback/SliceChooser.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Checkbox, IconButton, TextInput } from '@cratis/components/Common';\nimport { useId, useState } from 'react';\nimport { formatLocation, LocationParts } from '../Context/formatLocation.js';\nimport { CloseIcon } from '../Icons.js';\nimport { format } from '../Labels/index.js';\nimport { useNotesLabels } from '../Provider/NotesContext.js';\nimport { distinctSlices, isChosen, searchSlices, sliceKey, toggleSlice } from './sliceChoice.js';\n\n/**\n * Props for {@link SliceChooser}.\n */\nexport interface SliceChooserProps {\n /** The slices active on the screen. */\n active: readonly LocationParts[];\n\n /** Every slice the host knows about, to search over. */\n known: readonly LocationParts[];\n\n /** The chosen slices. */\n chosen: readonly LocationParts[];\n\n /** Called with the chosen slices after a change. */\n onChange: (chosen: LocationParts[]) => void;\n}\n\n/**\n * Chooses the slices a note is about: the ones active on the screen, and a search over all the slices the host knows.\n */\nexport const SliceChooser = ({ active, known, chosen, onChange }: SliceChooserProps) => {\n const labels = useNotesLabels();\n const [query, setQuery] = useState('');\n const activeId = useId();\n const resultsId = useId();\n const activeSlices = distinctSlices(active);\n const results = searchSlices(known, query);\n const name = (location: LocationParts) => formatLocation(location, labels.common.locationSeparator, labels.common.unknownLocation);\n\n const option = (location: LocationParts) => (\n <li key={sliceKey(location)}>\n <Checkbox label={name(location)} checked={isChosen(chosen, location)} onChange={() => onChange(toggleSlice(chosen, location))} />\n </li>\n );\n\n return (\n <div className='notes-slice-chooser'>\n <section aria-labelledby={activeId}>\n <h3 id={activeId} className='notes-slice-chooser__heading'>{labels.slices.active}</h3>\n {activeSlices.length === 0\n ? <p className='notes-slice-chooser__empty'>{labels.slices.noneActive}</p>\n : <ul className='notes-slice-chooser__list'>{activeSlices.map(option)}</ul>}\n </section>\n <section>\n <label className='notes-slice-chooser__heading' htmlFor={`${resultsId}-search`}>{labels.slices.search}</label>\n <TextInput\n id={`${resultsId}-search`}\n type='search'\n value={query}\n placeholder={labels.slices.searchPlaceholder}\n aria-controls={resultsId}\n onChange={value => setQuery(value)} />\n <div id={resultsId} aria-live='polite'>\n {query.trim().length > 0 && (results.length === 0\n ? <p className='notes-slice-chooser__empty'>{labels.slices.noMatches}</p>\n : <ul className='notes-slice-chooser__list' aria-label={labels.slices.results}>{results.map(option)}</ul>)}\n </div>\n </section>\n {chosen.length > 0 && (\n <section>\n <p className='notes-slice-chooser__heading'>{format(labels.slices.chosen, { count: chosen.length })}</p>\n <ul className='notes-slice-chooser__chosen'>\n {chosen.map(location => (\n <li key={sliceKey(location)} className='notes-slice-chooser__chip'>\n <span>{name(location)}</span>\n <IconButton\n variant='ghost'\n size='small'\n icon={<CloseIcon />}\n aria-label={format(labels.slices.remove, { slice: name(location) })}\n onClick={() => onChange(toggleSlice(chosen, location))} />\n </li>\n ))}\n </ul>\n </section>\n )}\n </div>\n );\n};\n"],"names":["SliceChooser","active","known","chosen","onChange","labels","useNotesLabels","query","setQuery","useState","activeId","useId","resultsId","activeSlices","distinctSlices","results","searchSlices","name","location","formatLocation","common","locationSeparator","unknownLocation","option","_jsx","li","Checkbox","label","checked","isChosen","toggleSlice","sliceKey","_jsxs","div","className","section","aria-labelledby","h3","id","slices","length","p","noneActive","ul","map","htmlFor","search","TextInput","type","value","placeholder","searchPlaceholder","aria-controls","aria-live","trim","noMatches","aria-label","format","count","span","IconButton","variant","size","icon","CloseIcon","remove","slice","onClick"],"mappings":";;;;;;;;;AA4BA;;AAEC,IACM,MAAMA,YAAAA,GAAe,CAAC,EAAEC,MAAM,EAAEC,KAAK,EAAEC,MAAM,EAAEC,QAAQ,EAAqB,GAAA;AAC/E,IAAA,MAAMC,MAAAA,GAASC,cAAAA,EAAAA;AACf,IAAA,MAAM,CAACC,KAAAA,EAAOC,QAAAA,CAAS,GAAGC,QAAAA,CAAS,EAAA,CAAA;AACnC,IAAA,MAAMC,QAAAA,GAAWC,KAAAA,EAAAA;AACjB,IAAA,MAAMC,SAAAA,GAAYD,KAAAA,EAAAA;
|
|
1
|
+
{"version":3,"file":"SliceChooser.js","sources":["../../../Feedback/SliceChooser.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Checkbox, IconButton, TextInput } from '@cratis/components/Common';\nimport { useId, useState } from 'react';\nimport { formatLocation, LocationParts } from '../Context/formatLocation.js';\nimport { CloseIcon } from '../Icons.js';\nimport { format } from '../Labels/index.js';\nimport { useNotesLabels } from '../Provider/NotesContext.js';\nimport { distinctSlices, isChosen, searchSlices, sliceKey, toggleSlice, withParentLevels } from './sliceChoice.js';\n\n/**\n * Props for {@link SliceChooser}.\n */\nexport interface SliceChooserProps {\n /** The slices active on the screen. */\n active: readonly LocationParts[];\n\n /** Every slice the host knows about, to search over. */\n known: readonly LocationParts[];\n\n /** The chosen slices. */\n chosen: readonly LocationParts[];\n\n /** Called with the chosen slices after a change. */\n onChange: (chosen: LocationParts[]) => void;\n}\n\n/**\n * Chooses the slices a note is about: the ones active on the screen, and a search over all the slices the host knows.\n */\nexport const SliceChooser = ({ active, known, chosen, onChange }: SliceChooserProps) => {\n const labels = useNotesLabels();\n const [query, setQuery] = useState('');\n const activeId = useId();\n const resultsId = useId();\n const activeSlices = withParentLevels(distinctSlices(active));\n const results = searchSlices(withParentLevels(known), query);\n const name = (location: LocationParts) => formatLocation(location, labels.common.locationSeparator, labels.common.unknownLocation);\n\n const option = (location: LocationParts) => (\n <li key={sliceKey(location)}>\n <Checkbox label={name(location)} checked={isChosen(chosen, location)} onChange={() => onChange(toggleSlice(chosen, location))} />\n </li>\n );\n\n return (\n <div className='notes-slice-chooser'>\n <section aria-labelledby={activeId}>\n <h3 id={activeId} className='notes-slice-chooser__heading'>{labels.slices.active}</h3>\n {activeSlices.length === 0\n ? <p className='notes-slice-chooser__empty'>{labels.slices.noneActive}</p>\n : <ul className='notes-slice-chooser__list'>{activeSlices.map(option)}</ul>}\n </section>\n <section>\n <label className='notes-slice-chooser__heading' htmlFor={`${resultsId}-search`}>{labels.slices.search}</label>\n <TextInput\n id={`${resultsId}-search`}\n type='search'\n value={query}\n placeholder={labels.slices.searchPlaceholder}\n aria-controls={resultsId}\n onChange={value => setQuery(value)} />\n <div id={resultsId} aria-live='polite'>\n {query.trim().length > 0 && (results.length === 0\n ? <p className='notes-slice-chooser__empty'>{labels.slices.noMatches}</p>\n : <ul className='notes-slice-chooser__list' aria-label={labels.slices.results}>{results.map(option)}</ul>)}\n </div>\n </section>\n {chosen.length > 0 && (\n <section>\n <p className='notes-slice-chooser__heading'>{format(labels.slices.chosen, { count: chosen.length })}</p>\n <ul className='notes-slice-chooser__chosen'>\n {chosen.map(location => (\n <li key={sliceKey(location)} className='notes-slice-chooser__chip'>\n <span>{name(location)}</span>\n <IconButton\n variant='ghost'\n size='small'\n icon={<CloseIcon />}\n aria-label={format(labels.slices.remove, { slice: name(location) })}\n onClick={() => onChange(toggleSlice(chosen, location))} />\n </li>\n ))}\n </ul>\n </section>\n )}\n </div>\n );\n};\n"],"names":["SliceChooser","active","known","chosen","onChange","labels","useNotesLabels","query","setQuery","useState","activeId","useId","resultsId","activeSlices","withParentLevels","distinctSlices","results","searchSlices","name","location","formatLocation","common","locationSeparator","unknownLocation","option","_jsx","li","Checkbox","label","checked","isChosen","toggleSlice","sliceKey","_jsxs","div","className","section","aria-labelledby","h3","id","slices","length","p","noneActive","ul","map","htmlFor","search","TextInput","type","value","placeholder","searchPlaceholder","aria-controls","aria-live","trim","noMatches","aria-label","format","count","span","IconButton","variant","size","icon","CloseIcon","remove","slice","onClick"],"mappings":";;;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;;AAe9C;;"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { LocationParts } from '../Context/formatLocation.js';
|
|
2
2
|
export declare function sliceKey(location: LocationParts): string;
|
|
3
3
|
export declare function distinctSlices<TLocation extends LocationParts>(locations: readonly TLocation[]): TLocation[];
|
|
4
|
+
export declare function withParentLevels(locations: readonly LocationParts[]): LocationParts[];
|
|
4
5
|
export declare function toggleSlice<TLocation extends LocationParts>(chosen: readonly TLocation[], location: TLocation): TLocation[];
|
|
5
6
|
export declare function isChosen(chosen: readonly LocationParts[], location: LocationParts): boolean;
|
|
6
7
|
export declare function searchSlices<TLocation extends LocationParts>(known: readonly TLocation[], query: string): TLocation[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sliceChoice.d.ts","sourceRoot":"","sources":["../../../Feedback/sliceChoice.ts"],"names":[],"mappings":"AAGA,OAAO,EAAkB,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAO7E,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,aAAa,GAAG,MAAM,CAExD;AAOD,wBAAgB,cAAc,CAAC,SAAS,SAAS,aAAa,EAAE,SAAS,EAAE,SAAS,SAAS,EAAE,GAAG,SAAS,EAAE,CAW5G;AAQD,wBAAgB,WAAW,CAAC,SAAS,SAAS,aAAa,EAAE,MAAM,EAAE,SAAS,SAAS,EAAE,EAAE,QAAQ,EAAE,SAAS,GAAG,SAAS,EAAE,CAK3H;AAQD,wBAAgB,QAAQ,CAAC,MAAM,EAAE,SAAS,aAAa,EAAE,EAAE,QAAQ,EAAE,aAAa,GAAG,OAAO,CAG3F;AAQD,wBAAgB,YAAY,CAAC,SAAS,SAAS,aAAa,EAAE,KAAK,EAAE,SAAS,SAAS,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,CAUrH"}
|
|
1
|
+
{"version":3,"file":"sliceChoice.d.ts","sourceRoot":"","sources":["../../../Feedback/sliceChoice.ts"],"names":[],"mappings":"AAGA,OAAO,EAAkB,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAO7E,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,aAAa,GAAG,MAAM,CAExD;AAOD,wBAAgB,cAAc,CAAC,SAAS,SAAS,aAAa,EAAE,SAAS,EAAE,SAAS,SAAS,EAAE,GAAG,SAAS,EAAE,CAW5G;AASD,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,SAAS,aAAa,EAAE,GAAG,aAAa,EAAE,CAYrF;AAQD,wBAAgB,WAAW,CAAC,SAAS,SAAS,aAAa,EAAE,MAAM,EAAE,SAAS,SAAS,EAAE,EAAE,QAAQ,EAAE,SAAS,GAAG,SAAS,EAAE,CAK3H;AAQD,wBAAgB,QAAQ,CAAC,MAAM,EAAE,SAAS,aAAa,EAAE,EAAE,QAAQ,EAAE,aAAa,GAAG,OAAO,CAG3F;AAQD,wBAAgB,YAAY,CAAC,SAAS,SAAS,aAAa,EAAE,KAAK,EAAE,SAAS,SAAS,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,CAUrH"}
|
|
@@ -24,6 +24,35 @@ import { formatLocation } from '../Context/formatLocation.js';
|
|
|
24
24
|
return true;
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Adds the broader levels of every location: its module, and its feature within the module. A note can be about a whole
|
|
29
|
+
* module or a whole feature, not only a slice, and such a level is a location whose finer parts are empty, which is how the
|
|
30
|
+
* contracts carry a location Arc could resolve only that far.
|
|
31
|
+
* @param locations The locations, typically slices.
|
|
32
|
+
* @returns The distinct, non-empty locations with the module and feature of each, broader levels before the slices in them.
|
|
33
|
+
*/ function withParentLevels(locations) {
|
|
34
|
+
return distinctSlices(locations.flatMap((location)=>{
|
|
35
|
+
const levels = [];
|
|
36
|
+
if (location.module.length > 0) {
|
|
37
|
+
levels.push({
|
|
38
|
+
module: location.module,
|
|
39
|
+
feature: '',
|
|
40
|
+
slice: ''
|
|
41
|
+
});
|
|
42
|
+
if (location.feature.length > 0) {
|
|
43
|
+
levels.push({
|
|
44
|
+
module: location.module,
|
|
45
|
+
feature: location.feature,
|
|
46
|
+
slice: ''
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return [
|
|
51
|
+
...levels,
|
|
52
|
+
location
|
|
53
|
+
];
|
|
54
|
+
}));
|
|
55
|
+
}
|
|
27
56
|
/**
|
|
28
57
|
* Adds a slice to the chosen ones, or removes it when it is chosen already.
|
|
29
58
|
* @param chosen The chosen slices.
|
|
@@ -61,5 +90,5 @@ import { formatLocation } from '../Context/formatLocation.js';
|
|
|
61
90
|
});
|
|
62
91
|
}
|
|
63
92
|
|
|
64
|
-
export { distinctSlices, isChosen, searchSlices, sliceKey, toggleSlice };
|
|
93
|
+
export { distinctSlices, isChosen, searchSlices, sliceKey, toggleSlice, withParentLevels };
|
|
65
94
|
//# sourceMappingURL=sliceChoice.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sliceChoice.js","sources":["../../../Feedback/sliceChoice.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { formatLocation, LocationParts } from '../Context/formatLocation.js';\n\n/**\n * Gets what identifies a slice location.\n * @param location The location.\n * @returns A key that is the same for the same location.\n */\nexport function sliceKey(location: LocationParts): string {\n return `${location.module}/${location.feature}/${location.slice}`;\n}\n\n/**\n * Removes the slices that repeat an earlier one, and the ones that are empty.\n * @param locations The locations.\n * @returns The distinct, non-empty locations in their order.\n */\nexport function distinctSlices<TLocation extends LocationParts>(locations: readonly TLocation[]): TLocation[] {\n const seen = new Set<string>();\n return locations.filter(location => {\n const key = sliceKey(location);\n if (key === '//' || seen.has(key)) {\n return false;\n }\n\n seen.add(key);\n return true;\n });\n}\n\n/**\n * Adds a slice to the chosen ones, or removes it when it is chosen already.\n * @param chosen The chosen slices.\n * @param location The slice to toggle.\n * @returns The chosen slices after the toggle.\n */\nexport function toggleSlice<TLocation extends LocationParts>(chosen: readonly TLocation[], location: TLocation): TLocation[] {\n const key = sliceKey(location);\n return chosen.some(slice => sliceKey(slice) === key)\n ? chosen.filter(slice => sliceKey(slice) !== key)\n : [...chosen, location];\n}\n\n/**\n * Whether a slice is among the chosen ones.\n * @param chosen The chosen slices.\n * @param location The slice.\n * @returns True when it is chosen.\n */\nexport function isChosen(chosen: readonly LocationParts[], location: LocationParts): boolean {\n const key = sliceKey(location);\n return chosen.some(slice => sliceKey(slice) === key);\n}\n\n/**\n * Searches the slices the host knows about.\n * @param known Every slice the host knows about.\n * @param query What the user typed; every word has to be part of the module, feature or slice.\n * @returns The distinct slices that match; none for an empty query.\n */\nexport function searchSlices<TLocation extends LocationParts>(known: readonly TLocation[], query: string): TLocation[] {\n const words = query.toLowerCase().split(/\\s+/).filter(word => word.length > 0);\n if (words.length === 0) {\n return [];\n }\n\n return distinctSlices(known).filter(location => {\n const text = formatLocation(location, ' ', '').toLowerCase();\n return words.every(word => text.includes(word));\n });\n}\n"],"names":["sliceKey","location","module","feature","slice","distinctSlices","locations","seen","Set","filter","key","has","add","toggleSlice","chosen","some","isChosen","searchSlices","known","query","words","toLowerCase","split","word","
|
|
1
|
+
{"version":3,"file":"sliceChoice.js","sources":["../../../Feedback/sliceChoice.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { formatLocation, LocationParts } from '../Context/formatLocation.js';\n\n/**\n * Gets what identifies a slice location.\n * @param location The location.\n * @returns A key that is the same for the same location.\n */\nexport function sliceKey(location: LocationParts): string {\n return `${location.module}/${location.feature}/${location.slice}`;\n}\n\n/**\n * Removes the slices that repeat an earlier one, and the ones that are empty.\n * @param locations The locations.\n * @returns The distinct, non-empty locations in their order.\n */\nexport function distinctSlices<TLocation extends LocationParts>(locations: readonly TLocation[]): TLocation[] {\n const seen = new Set<string>();\n return locations.filter(location => {\n const key = sliceKey(location);\n if (key === '//' || seen.has(key)) {\n return false;\n }\n\n seen.add(key);\n return true;\n });\n}\n\n/**\n * Adds the broader levels of every location: its module, and its feature within the module. A note can be about a whole\n * module or a whole feature, not only a slice, and such a level is a location whose finer parts are empty, which is how the\n * contracts carry a location Arc could resolve only that far.\n * @param locations The locations, typically slices.\n * @returns The distinct, non-empty locations with the module and feature of each, broader levels before the slices in them.\n */\nexport function withParentLevels(locations: readonly LocationParts[]): LocationParts[] {\n return distinctSlices(locations.flatMap(location => {\n const levels: LocationParts[] = [];\n if (location.module.length > 0) {\n levels.push({ module: location.module, feature: '', slice: '' });\n if (location.feature.length > 0) {\n levels.push({ module: location.module, feature: location.feature, slice: '' });\n }\n }\n\n return [...levels, location];\n }));\n}\n\n/**\n * Adds a slice to the chosen ones, or removes it when it is chosen already.\n * @param chosen The chosen slices.\n * @param location The slice to toggle.\n * @returns The chosen slices after the toggle.\n */\nexport function toggleSlice<TLocation extends LocationParts>(chosen: readonly TLocation[], location: TLocation): TLocation[] {\n const key = sliceKey(location);\n return chosen.some(slice => sliceKey(slice) === key)\n ? chosen.filter(slice => sliceKey(slice) !== key)\n : [...chosen, location];\n}\n\n/**\n * Whether a slice is among the chosen ones.\n * @param chosen The chosen slices.\n * @param location The slice.\n * @returns True when it is chosen.\n */\nexport function isChosen(chosen: readonly LocationParts[], location: LocationParts): boolean {\n const key = sliceKey(location);\n return chosen.some(slice => sliceKey(slice) === key);\n}\n\n/**\n * Searches the slices the host knows about.\n * @param known Every slice the host knows about.\n * @param query What the user typed; every word has to be part of the module, feature or slice.\n * @returns The distinct slices that match; none for an empty query.\n */\nexport function searchSlices<TLocation extends LocationParts>(known: readonly TLocation[], query: string): TLocation[] {\n const words = query.toLowerCase().split(/\\s+/).filter(word => word.length > 0);\n if (words.length === 0) {\n return [];\n }\n\n return distinctSlices(known).filter(location => {\n const text = formatLocation(location, ' ', '').toLowerCase();\n return words.every(word => text.includes(word));\n });\n}\n"],"names":["sliceKey","location","module","feature","slice","distinctSlices","locations","seen","Set","filter","key","has","add","withParentLevels","flatMap","levels","length","push","toggleSlice","chosen","some","isChosen","searchSlices","known","query","words","toLowerCase","split","word","text","formatLocation","every","includes"],"mappings":";;AAAA;AACA;AAIA;;;;IAKO,SAASA,QAAAA,CAASC,QAAuB,EAAA;AAC5C,IAAA,OAAO,CAAA,EAAGA,QAAAA,CAASC,MAAM,CAAC,CAAC,EAAED,QAAAA,CAASE,OAAO,CAAC,CAAC,EAAEF,QAAAA,CAASG,KAAK,CAAA,CAAE;AACrE;AAEA;;;;IAKO,SAASC,cAAAA,CAAgDC,SAA+B,EAAA;AAC3F,IAAA,MAAMC,OAAO,IAAIC,GAAAA,EAAAA;IACjB,OAAOF,SAAAA,CAAUG,MAAM,CAACR,CAAAA,QAAAA,GAAAA;AACpB,QAAA,MAAMS,MAAMV,QAAAA,CAASC,QAAAA,CAAAA;AACrB,QAAA,IAAIS,GAAAA,KAAQ,IAAA,IAAQH,IAAAA,CAAKI,GAAG,CAACD,GAAAA,CAAAA,EAAM;YAC/B,OAAO,KAAA;AACX,QAAA;AAEAH,QAAAA,IAAAA,CAAKK,GAAG,CAACF,GAAAA,CAAAA;QACT,OAAO,IAAA;AACX,IAAA,CAAA,CAAA;AACJ;AAEA;;;;;;IAOO,SAASG,gBAAAA,CAAiBP,SAAmC,EAAA;AAChE,IAAA,OAAOD,cAAAA,CAAeC,SAAAA,CAAUQ,OAAO,CAACb,CAAAA,QAAAA,GAAAA;AACpC,QAAA,MAAMc,SAA0B,EAAE;AAClC,QAAA,IAAId,QAAAA,CAASC,MAAM,CAACc,MAAM,GAAG,CAAA,EAAG;AAC5BD,YAAAA,MAAAA,CAAOE,IAAI,CAAC;AAAEf,gBAAAA,MAAAA,EAAQD,SAASC,MAAM;gBAAEC,OAAAA,EAAS,EAAA;gBAAIC,KAAAA,EAAO;AAAG,aAAA,CAAA;AAC9D,YAAA,IAAIH,QAAAA,CAASE,OAAO,CAACa,MAAM,GAAG,CAAA,EAAG;AAC7BD,gBAAAA,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AE;AACb,IAAA;AAEA,IAAA,OAAOX,cAAAA,CAAekB,KAAAA,CAAAA,CAAOd,MAAM,CAACR,CAAAA,QAAAA,GAAAA;AAChC,QAAA,MAAM4B,IAAAA,GAAOC,cAAAA,CAAe7B,QAAAA,EAAU,GAAA,EAAK,IAAIyB,WAAW,EAAA;AAC1D,QAAA,OAAOD,MAAMM,KAAK,CAACH,CAAAA,IAAAA,GAAQC,IAAAA,CAAKG,QAAQ,CAACJ,IAAAA,CAAAA,CAAAA;AAC7C,IAAA,CAAA,CAAA;AACJ;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NotesProvider.d.ts","sourceRoot":"","sources":["../../../Provider/NotesProvider.tsx"],"names":[],"mappings":"AAWA,OAAO,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"NotesProvider.d.ts","sourceRoot":"","sources":["../../../Provider/NotesProvider.tsx"],"names":[],"mappings":"AAWA,OAAO,EAAE,SAAS,EAA2C,MAAM,OAAO,CAAC;AAE3E,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAI7D,OAAO,EAAE,mBAAmB,EAAiB,MAAM,oBAAoB,CAAC;AAQxE,MAAM,WAAW,kBAAkB;IAE/B,OAAO,CAAC,EAAE,OAAO,CAAC;IAGlB,MAAM,CAAC,EAAE,mBAAmB,CAAC;IAG7B,WAAW,CAAC,EAAE,SAAS,aAAa,EAAE,CAAC;IAGvC,QAAQ,CAAC,EAAE,SAAS,CAAC;CACxB;AAcD,eAAO,MAAM,aAAa,GAAI,4CAAyD,kBAAkB,gCAmFxG,CAAC"}
|
|
@@ -6,7 +6,7 @@ import { useComponentPicker } from '@cratis/components/ComponentPicker';
|
|
|
6
6
|
import { toast } from '@cratis/components/Notifications';
|
|
7
7
|
import { Guid } from '@cratis/fundamentals';
|
|
8
8
|
import { Availability } from '@cratis/showrunner.notes';
|
|
9
|
-
import {
|
|
9
|
+
import { useRef, useEffect, useMemo, useCallback } from 'react';
|
|
10
10
|
import { resolveComponentContext } from '../Context/componentContext.js';
|
|
11
11
|
import { buildNoteContext } from '../Context/noteContext.js';
|
|
12
12
|
import { ComponentFeedbackDialog } from '../Feedback/ComponentFeedbackDialog.js';
|
|
@@ -24,13 +24,26 @@ const dialogReferenceOf = (dialog)=>dialog?.sliceLocation ? {
|
|
|
24
24
|
} : undefined;
|
|
25
25
|
/**
|
|
26
26
|
* Slots Notes into an application: renders the feedback dialogs and the component picker once, asks whether Notes is
|
|
27
|
-
* switched on
|
|
27
|
+
* available to the user - switched on and, when only granted users may give feedback, granted to them - and gives the Notes
|
|
28
|
+
* buttons and `useNotes` what they need. Render it inside `<Arc>`, the `DialogComponents`
|
|
28
29
|
* registration, an `IdentityProvider` and a `CratisComponentsProvider` with a toaster. Turn on `<Arc sliceMarkers>` for
|
|
29
30
|
* Notes to know the slice of a component the user points at.
|
|
30
31
|
*/ const NotesProvider = ({ enabled = false, labels, knownSlices = [], children })=>{
|
|
31
32
|
const store = useApplicationContextStore();
|
|
32
33
|
const identity = useIdentity();
|
|
33
|
-
const [availability] = Availability.use();
|
|
34
|
+
const [availability, performAvailability] = Availability.use();
|
|
35
|
+
const wasSignedIn = useRef(identity.isSet);
|
|
36
|
+
// Whether the user may give feedback depends on who they are, and the first answer can be given before anyone signed in.
|
|
37
|
+
// Asking again once they have keeps the button hidden for a user nobody granted the right and shows it to one who was.
|
|
38
|
+
useEffect(()=>{
|
|
39
|
+
if (identity.isSet && !wasSignedIn.current) {
|
|
40
|
+
void performAvailability();
|
|
41
|
+
}
|
|
42
|
+
wasSignedIn.current = identity.isSet;
|
|
43
|
+
}, [
|
|
44
|
+
identity.isSet,
|
|
45
|
+
performAvailability
|
|
46
|
+
]);
|
|
34
47
|
const isAvailable = isNotesAvailable(identity.isSet, availability.data?.isEnabled);
|
|
35
48
|
const resolvedLabels = useMemo(()=>resolveLabels(labels), [
|
|
36
49
|
labels
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NotesProvider.js","sources":["../../../Provider/NotesProvider.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { ApplicationContext, useApplicationContextStore } from '@cratis/arc.react';\nimport { DialogResult, useDialog } from '@cratis/arc.react/dialogs';\nimport { useIdentity } from '@cratis/arc.react/identity';\nimport { useComponentPicker } from '@cratis/components/ComponentPicker';\nimport { DialogHeaderContext } from '@cratis/components/Dialogs';\nimport { toast } from '@cratis/components/Notifications';\nimport { Guid } from '@cratis/fundamentals';\nimport { Availability } from '@cratis/showrunner.notes';\nimport { ReactNode, useCallback, useMemo, useRef } from 'react';\nimport { buildNoteContext, DialogReference, resolveComponentContext } from '../Context/index.js';\nimport { LocationParts } from '../Context/formatLocation.js';\nimport { ComponentFeedbackDialog } from '../Feedback/ComponentFeedbackDialog.js';\nimport { FeedbackDialog, FeedbackGiven } from '../Feedback/FeedbackDialog.js';\nimport { SlicesFeedbackDialog } from '../Feedback/SlicesFeedbackDialog.js';\nimport { NotesLabelOverrides, resolveLabels } from '../Labels/index.js';\nimport { MyFeedbackDialog } from '../MyFeedback/MyFeedbackDialog.js';\nimport { NotesContext, NotesContextValue } from './NotesContext.js';\nimport { isNotesAvailable } from './notesVisibility.js';\n\n/**\n * Props for {@link NotesProvider}.\n */\nexport interface NotesProviderProps {\n /** Whether the feedback button registers itself in the header of dialogs that have a slice. Defaults to false. It takes effect through `notesDialogHeaderActions` on `CratisComponentsProvider`. */\n enabled?: boolean;\n\n /** The labels that replace the English defaults, for instance to localize them. */\n labels?: NotesLabelOverrides;\n\n /** Every slice the host knows about, for the search of the give feedback on slices dialog. */\n knownSlices?: readonly LocationParts[];\n\n /** The application. */\n children?: ReactNode;\n}\n\nconst emptySnapshot = new ApplicationContext().getSnapshot();\n\nconst dialogReferenceOf = (dialog?: DialogHeaderContext): DialogReference | undefined =>\n dialog?.sliceLocation ? { title: dialog.title, location: dialog.sliceLocation } : undefined;\n\n/**\n * Slots Notes into an application: renders the feedback dialogs and the component picker once, asks whether Notes is\n * switched on, and gives the Notes buttons and `useNotes` what they need. Render it inside `<Arc>`, the `DialogComponents`\n * registration, an `IdentityProvider` and a `CratisComponentsProvider` with a toaster. Turn on `<Arc sliceMarkers>` for\n * Notes to know the slice of a component the user points at.\n */\nexport const NotesProvider = ({ enabled = false, labels, knownSlices = [], children }: NotesProviderProps) => {\n const store = useApplicationContextStore();\n const identity = useIdentity();\n const [availability] = Availability.use();\n const isAvailable = isNotesAvailable(identity.isSet, availability.data?.isEnabled);\n const resolvedLabels = useMemo(() => resolveLabels(labels), [labels]);\n const busy = useRef(false);\n\n const [FeedbackDialogWrapper, showFeedbackDialog] = useDialog<FeedbackGiven, Parameters<typeof FeedbackDialog>[0]>(FeedbackDialog);\n const [SlicesDialogWrapper, showSlicesDialog] = useDialog<FeedbackGiven, Parameters<typeof SlicesFeedbackDialog>[0]>(SlicesFeedbackDialog);\n const [ComponentDialogWrapper, showComponentDialog] = useDialog<FeedbackGiven, Parameters<typeof ComponentFeedbackDialog>[0]>(ComponentFeedbackDialog);\n const [MyFeedbackDialogWrapper, showMyFeedbackDialog] = useDialog<object, object>(MyFeedbackDialog);\n const picker = useComponentPicker({ resolve: resolveComponentContext });\n\n const capture = useCallback((dialog?: DialogHeaderContext) => buildNoteContext({\n snapshot: store?.getSnapshot() ?? emptySnapshot,\n route: window.location.pathname,\n correlationId: Guid.create(),\n dialog: dialogReferenceOf(dialog)\n }), [store]);\n\n const whileOpen = useCallback(async <TResult,>(open: () => Promise<[DialogResult, TResult?]>, announceSent = true) => {\n if (busy.current) {\n return;\n }\n\n busy.current = true;\n try {\n const [result] = await open();\n if (announceSent && result === DialogResult.Ok) {\n toast.success({ title: resolvedLabels.feedback.sent });\n }\n } finally {\n busy.current = false;\n }\n }, [resolvedLabels]);\n\n const value = useMemo<NotesContextValue>(() => ({\n isProvided: true,\n labels: resolvedLabels,\n isAvailable,\n showsInDialogHeaders: enabled,\n isPicking: picker.isPicking,\n giveFeedback: dialog => void whileOpen(() => showFeedbackDialog({ context: capture(dialog) })),\n giveFeedbackOnScreen: dialog => void whileOpen(() => showFeedbackDialog({ context: capture(dialog), about: 'screen' })),\n giveFeedbackOnSlices: dialog => void whileOpen(() => showSlicesDialog({ context: capture(dialog), knownSlices })),\n pointAtSomething: dialog => {\n if (busy.current || picker.isPicking) {\n return;\n }\n\n const context = capture(dialog);\n void picker.start().then(picked => {\n if (picked) {\n void whileOpen(() => showComponentDialog({ context, picked }));\n }\n });\n },\n showMyFeedback: () => void whileOpen(() => showMyFeedbackDialog({}), false)\n }), [resolvedLabels, isAvailable, enabled, picker, knownSlices, capture, whileOpen, showFeedbackDialog, showSlicesDialog, showComponentDialog, showMyFeedbackDialog]);\n\n return (\n <NotesContext.Provider value={value}>\n {children}\n <FeedbackDialogWrapper />\n <SlicesDialogWrapper />\n <ComponentDialogWrapper />\n <MyFeedbackDialogWrapper />\n {picker.picker}\n </NotesContext.Provider>\n );\n};\n"],"names":["emptySnapshot","ApplicationContext","getSnapshot","dialogReferenceOf","dialog","sliceLocation","title","location","undefined","NotesProvider","enabled","labels","knownSlices","children","store","useApplicationContextStore","identity","useIdentity","availability","Availability","use","isAvailable","isNotesAvailable","isSet","data","isEnabled","resolvedLabels","useMemo","resolveLabels","busy","useRef","FeedbackDialogWrapper","showFeedbackDialog","useDialog","FeedbackDialog","SlicesDialogWrapper","showSlicesDialog","SlicesFeedbackDialog","ComponentDialogWrapper","showComponentDialog","ComponentFeedbackDialog","MyFeedbackDialogWrapper","showMyFeedbackDialog","MyFeedbackDialog","picker","useComponentPicker","resolve","resolveComponentContext","capture","useCallback","buildNoteContext","snapshot","route","window","pathname","correlationId","Guid","create","whileOpen","open","announceSent","current","result","DialogResult","Ok","toast","success","feedback","sent","value","isProvided","showsInDialogHeaders","isPicking","giveFeedback","context","giveFeedbackOnScreen","about","giveFeedbackOnSlices","pointAtSomething","start","then","picked","showMyFeedback","_jsxs","NotesContext","Provider","_jsx"],"mapp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AU,IAAMhB,oBAAAA,CAAqB,EAAC,CAAA,EAAI,KAAA;AACzE,SAAA,CAAA,EAAI;AAAChB,QAAAA,cAAAA;AAAgBL,QAAAA,WAAAA;AAAaX,QAAAA,OAAAA;AAASkC,QAAAA,MAAAA;AAAQhC,QAAAA,WAAAA;AAAaoC,QAAAA,OAAAA;AAASU,QAAAA,SAAAA;AAAW1B,QAAAA,kBAAAA;AAAoBI,QAAAA,gBAAAA;AAAkBG,QAAAA,mBAAAA;AAAqBG,QAAAA;AAAqB,KAAA,CAAA;IAEpK,qBACIyC,IAAA,CAACC,aAAaC,QAAQ,EAAA;QAAChB,KAAAA,EAAOA,KAAAA;;AACzBxD,YAAAA,QAAAA;0BACDyE,GAAA,CAACvD,qBAAAA,EAAAA,EAAAA,CAAAA;0BACDuD,GAAA,CAACnD,mBAAAA,EAAAA,EAAAA,CAAAA;0BACDmD,GAAA,CAAChD,sBAAAA,EAAAA,EAAAA,CAAAA;0BACDgD,GAAA,CAAC7C,uBAAAA,EAAAA,EAAAA,CAAAA;AACAG,YAAAA,MAAAA,CAAOA;;;AAGpB;;"}
|
|
1
|
+
{"version":3,"file":"NotesProvider.js","sources":["../../../Provider/NotesProvider.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { ApplicationContext, useApplicationContextStore } from '@cratis/arc.react';\nimport { DialogResult, useDialog } from '@cratis/arc.react/dialogs';\nimport { useIdentity } from '@cratis/arc.react/identity';\nimport { useComponentPicker } from '@cratis/components/ComponentPicker';\nimport { DialogHeaderContext } from '@cratis/components/Dialogs';\nimport { toast } from '@cratis/components/Notifications';\nimport { Guid } from '@cratis/fundamentals';\nimport { Availability } from '@cratis/showrunner.notes';\nimport { ReactNode, useCallback, useEffect, useMemo, useRef } from 'react';\nimport { buildNoteContext, DialogReference, resolveComponentContext } from '../Context/index.js';\nimport { LocationParts } from '../Context/formatLocation.js';\nimport { ComponentFeedbackDialog } from '../Feedback/ComponentFeedbackDialog.js';\nimport { FeedbackDialog, FeedbackGiven } from '../Feedback/FeedbackDialog.js';\nimport { SlicesFeedbackDialog } from '../Feedback/SlicesFeedbackDialog.js';\nimport { NotesLabelOverrides, resolveLabels } from '../Labels/index.js';\nimport { MyFeedbackDialog } from '../MyFeedback/MyFeedbackDialog.js';\nimport { NotesContext, NotesContextValue } from './NotesContext.js';\nimport { isNotesAvailable } from './notesVisibility.js';\n\n/**\n * Props for {@link NotesProvider}.\n */\nexport interface NotesProviderProps {\n /** Whether the feedback button registers itself in the header of dialogs that have a slice. Defaults to false. It takes effect through `notesDialogHeaderActions` on `CratisComponentsProvider`. */\n enabled?: boolean;\n\n /** The labels that replace the English defaults, for instance to localize them. */\n labels?: NotesLabelOverrides;\n\n /** Every slice the host knows about, for the search of the give feedback on slices dialog. */\n knownSlices?: readonly LocationParts[];\n\n /** The application. */\n children?: ReactNode;\n}\n\nconst emptySnapshot = new ApplicationContext().getSnapshot();\n\nconst dialogReferenceOf = (dialog?: DialogHeaderContext): DialogReference | undefined =>\n dialog?.sliceLocation ? { title: dialog.title, location: dialog.sliceLocation } : undefined;\n\n/**\n * Slots Notes into an application: renders the feedback dialogs and the component picker once, asks whether Notes is\n * available to the user - switched on and, when only granted users may give feedback, granted to them - and gives the Notes\n * buttons and `useNotes` what they need. Render it inside `<Arc>`, the `DialogComponents`\n * registration, an `IdentityProvider` and a `CratisComponentsProvider` with a toaster. Turn on `<Arc sliceMarkers>` for\n * Notes to know the slice of a component the user points at.\n */\nexport const NotesProvider = ({ enabled = false, labels, knownSlices = [], children }: NotesProviderProps) => {\n const store = useApplicationContextStore();\n const identity = useIdentity();\n const [availability, performAvailability] = Availability.use();\n const wasSignedIn = useRef(identity.isSet);\n\n // Whether the user may give feedback depends on who they are, and the first answer can be given before anyone signed in.\n // Asking again once they have keeps the button hidden for a user nobody granted the right and shows it to one who was.\n useEffect(() => {\n if (identity.isSet && !wasSignedIn.current) {\n void performAvailability();\n }\n\n wasSignedIn.current = identity.isSet;\n }, [identity.isSet, performAvailability]);\n\n const isAvailable = isNotesAvailable(identity.isSet, availability.data?.isEnabled);\n const resolvedLabels = useMemo(() => resolveLabels(labels), [labels]);\n const busy = useRef(false);\n\n const [FeedbackDialogWrapper, showFeedbackDialog] = useDialog<FeedbackGiven, Parameters<typeof FeedbackDialog>[0]>(FeedbackDialog);\n const [SlicesDialogWrapper, showSlicesDialog] = useDialog<FeedbackGiven, Parameters<typeof SlicesFeedbackDialog>[0]>(SlicesFeedbackDialog);\n const [ComponentDialogWrapper, showComponentDialog] = useDialog<FeedbackGiven, Parameters<typeof ComponentFeedbackDialog>[0]>(ComponentFeedbackDialog);\n const [MyFeedbackDialogWrapper, showMyFeedbackDialog] = useDialog<object, object>(MyFeedbackDialog);\n const picker = useComponentPicker({ resolve: resolveComponentContext });\n\n const capture = useCallback((dialog?: DialogHeaderContext) => buildNoteContext({\n snapshot: store?.getSnapshot() ?? emptySnapshot,\n route: window.location.pathname,\n correlationId: Guid.create(),\n dialog: dialogReferenceOf(dialog)\n }), [store]);\n\n const whileOpen = useCallback(async <TResult,>(open: () => Promise<[DialogResult, TResult?]>, announceSent = true) => {\n if (busy.current) {\n return;\n }\n\n busy.current = true;\n try {\n const [result] = await open();\n if (announceSent && result === DialogResult.Ok) {\n toast.success({ title: resolvedLabels.feedback.sent });\n }\n } finally {\n busy.current = false;\n }\n }, [resolvedLabels]);\n\n const value = useMemo<NotesContextValue>(() => ({\n isProvided: true,\n labels: resolvedLabels,\n isAvailable,\n showsInDialogHeaders: enabled,\n isPicking: picker.isPicking,\n giveFeedback: dialog => void whileOpen(() => showFeedbackDialog({ context: capture(dialog) })),\n giveFeedbackOnScreen: dialog => void whileOpen(() => showFeedbackDialog({ context: capture(dialog), about: 'screen' })),\n giveFeedbackOnSlices: dialog => void whileOpen(() => showSlicesDialog({ context: capture(dialog), knownSlices })),\n pointAtSomething: dialog => {\n if (busy.current || picker.isPicking) {\n return;\n }\n\n const context = capture(dialog);\n void picker.start().then(picked => {\n if (picked) {\n void whileOpen(() => showComponentDialog({ context, picked }));\n }\n });\n },\n showMyFeedback: () => void whileOpen(() => showMyFeedbackDialog({}), false)\n }), [resolvedLabels, isAvailable, enabled, picker, knownSlices, capture, whileOpen, showFeedbackDialog, showSlicesDialog, showComponentDialog, showMyFeedbackDialog]);\n\n return (\n <NotesContext.Provider value={value}>\n {children}\n <FeedbackDialogWrapper />\n <SlicesDialogWrapper />\n <ComponentDialogWrapper />\n <MyFeedbackDialogWrapper />\n {picker.picker}\n </NotesContext.Provider>\n );\n};\n"],"names":["emptySnapshot","ApplicationContext","getSnapshot","dialogReferenceOf","dialog","sliceLocation","title","location","undefined","NotesProvider","enabled","labels","knownSlices","children","store","useApplicationContextStore","identity","useIdentity","availability","performAvailability","Availability","use","wasSignedIn","useRef","isSet","useEffect","current","isAvailable","isNotesAvailable","data","isEnabled","resolvedLabels","useMemo","resolveLabels","busy","FeedbackDialogWrapper","showFeedbackDialog","useDialog","FeedbackDialog","SlicesDialogWrapper","showSlicesDialog","SlicesFeedbackDialog","ComponentDialogWrapper","showComponentDialog","ComponentFeedbackDialog","MyFeedbackDialogWrapper","showMyFeedbackDialog","MyFeedbackDialog","picker","useComponentPicker","resolve","resolveComponentContext","capture","useCallback","buildNoteContext","snapshot","route","window","pathname","correlationId","Guid","create","whileOpen","open","announceSent","result","DialogResult","Ok","toast","success","feedback","sent","value","isProvided","showsInDialogHeaders","isPicking","giveFeedback","context","giveFeedbackOnScreen","about","giveFeedbackOnSlices","pointAtSomething","start","then","picked","showMyFeedback","_jsxs","NotesContext","Provider","_jsx"],"mappings":";;;;;;;;;;;;;;;;;;;AAuCA,MAAMA,aAAAA,GAAgB,IAAIC,kBAAAA,EAAAA,CAAqBC,WAAW,EAAA;AAE1D,MAAMC,iBAAAA,GAAoB,CAACC,MAAAA,GACvBA,MAAAA,EAAQC,aAAAA,GAAgB;AAAEC,QAAAA,KAAAA,EAAOF,OAAOE,KAAK;AAAEC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A,CAAA,CAAA;AAC/D,oBAAA;AACJ,gBAAA,CAAA,CAAA;AACJ,YAAA,CAAA;AACAC,YAAAA,cAAAA,EAAgB,IAAM,KAAKvB,SAAAA,CAAU,IAAMhB,oBAAAA,CAAqB,EAAC,CAAA,EAAI,KAAA;AACzE,SAAA,CAAA,EAAI;AAACf,QAAAA,cAAAA;AAAgBJ,QAAAA,WAAAA;AAAajB,QAAAA,OAAAA;AAASsC,QAAAA,MAAAA;AAAQpC,QAAAA,WAAAA;AAAawC,QAAAA,OAAAA;AAASU,QAAAA,SAAAA;AAAW1B,QAAAA,kBAAAA;AAAoBI,QAAAA,gBAAAA;AAAkBG,QAAAA,mBAAAA;AAAqBG,QAAAA;AAAqB,KAAA,CAAA;IAEpK,qBACIwC,IAAA,CAACC,aAAaC,QAAQ,EAAA;QAAChB,KAAAA,EAAOA,KAAAA;;AACzB3D,YAAAA,QAAAA;0BACD4E,GAAA,CAACtD,qBAAAA,EAAAA,EAAAA,CAAAA;0BACDsD,GAAA,CAAClD,mBAAAA,EAAAA,EAAAA,CAAAA;0BACDkD,GAAA,CAAC/C,sBAAAA,EAAAA,EAAAA,CAAAA;0BACD+C,GAAA,CAAC5C,uBAAAA,EAAAA,EAAAA,CAAAA;AACAG,YAAAA,MAAAA,CAAOA;;;AAGpB;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notesVisibility.d.ts","sourceRoot":"","sources":["../../../Provider/notesVisibility.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"notesVisibility.d.ts","sourceRoot":"","sources":["../../../Provider/notesVisibility.ts"],"names":[],"mappings":"AAWA,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,GAAG,SAAS,GAAG,OAAO,CAE7F"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// Copyright (c) Cratis. All rights reserved.
|
|
2
2
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
3
|
/**
|
|
4
|
-
* Decides whether the Notes components render anything: only for a signed-in user, and only while Notes is
|
|
5
|
-
*
|
|
4
|
+
* Decides whether the Notes components render anything: only for a signed-in user, and only while Notes is available to
|
|
5
|
+
* them. It is not when Notes is switched off, and not when the application lets only granted users give feedback and nobody
|
|
6
|
+
* granted this user.
|
|
6
7
|
* @param isSignedIn Whether the user is signed in.
|
|
7
|
-
* @param isEnabled Whether Notes is
|
|
8
|
+
* @param isEnabled Whether Notes is available to the user, as `NotesAvailability` tells; false until it is known.
|
|
8
9
|
* @returns True when the Notes components render.
|
|
9
10
|
*/ function isNotesAvailable(isSignedIn, isEnabled) {
|
|
10
11
|
return isSignedIn && isEnabled === true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notesVisibility.js","sources":["../../../Provider/notesVisibility.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\n/**\n * Decides whether the Notes components render anything: only for a signed-in user, and only while Notes is switched\n *
|
|
1
|
+
{"version":3,"file":"notesVisibility.js","sources":["../../../Provider/notesVisibility.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\n/**\n * Decides whether the Notes components render anything: only for a signed-in user, and only while Notes is available to\n * them. It is not when Notes is switched off, and not when the application lets only granted users give feedback and nobody\n * granted this user.\n * @param isSignedIn Whether the user is signed in.\n * @param isEnabled Whether Notes is available to the user, as `NotesAvailability` tells; false until it is known.\n * @returns True when the Notes components render.\n */\nexport function isNotesAvailable(isSignedIn: boolean, isEnabled: boolean | undefined): boolean {\n return isSignedIn && isEnabled === true;\n}\n"],"names":["isNotesAvailable","isSignedIn","isEnabled"],"mappings":"AAAA;AACA;AAEA;;;;;;;AAOC,IACM,SAASA,gBAAAA,CAAiBC,UAAmB,EAAEC,SAA8B,EAAA;AAChF,IAAA,OAAOD,cAAcC,SAAAA,KAAc,IAAA;AACvC;;"}
|
package/dist/esm/index.js
CHANGED
|
@@ -13,7 +13,7 @@ export { KindAndText } from './Feedback/KindAndText.js';
|
|
|
13
13
|
export { propertySuggestions, propertyValueText } from './Feedback/propertySuggestions.js';
|
|
14
14
|
export { SliceChooser } from './Feedback/SliceChooser.js';
|
|
15
15
|
export { SlicesFeedbackDialog } from './Feedback/SlicesFeedbackDialog.js';
|
|
16
|
-
export { distinctSlices, isChosen, searchSlices, sliceKey, toggleSlice } from './Feedback/sliceChoice.js';
|
|
16
|
+
export { distinctSlices, isChosen, searchSlices, sliceKey, toggleSlice, withParentLevels } from './Feedback/sliceChoice.js';
|
|
17
17
|
export { ChevronIcon, CloseIcon, FeedbackIcon } from './Icons.js';
|
|
18
18
|
export { defaultNotesLabels } from './Labels/defaultNotesLabels.js';
|
|
19
19
|
export { format } from './Labels/format.js';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@cratis/showrunner.notes.react",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.13.0",
|
|
5
5
|
"description": "React components for Notes — the Showrunner product feedback part: a feedback button with a context drop-down, slice-aware feedback dialogs, a component picker and the user's own feedback, built on Cratis Arc and Cratis Components.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"cratis",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"up": "yarn g:up"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@cratis/showrunner.notes": "2.
|
|
64
|
+
"@cratis/showrunner.notes": "2.13.0"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"@cratis/arc": "22.185.1",
|