@things-factory/help 10.1.283 → 10.1.290
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-client/bootstrap.js +9 -0
- package/dist-client/guide/deep-find.d.ts +4 -0
- package/dist-client/guide/deep-find.js +29 -0
- package/dist-client/guide/guide-anchors.d.ts +33 -0
- package/dist-client/guide/guide-anchors.js +29 -0
- package/dist-client/guide/guide-api.d.ts +24 -0
- package/dist-client/guide/guide-api.js +23 -0
- package/dist-client/guide/guide-progress.d.ts +37 -0
- package/dist-client/guide/guide-progress.js +51 -0
- package/dist-client/guide/guide-recorder.d.ts +9 -0
- package/dist-client/guide/guide-recorder.js +94 -0
- package/dist-client/guide/guide-runner.d.ts +18 -0
- package/dist-client/guide/guide-runner.js +191 -0
- package/dist-client/guide/guide-words.d.ts +8 -0
- package/dist-client/guide/guide-words.js +21 -0
- package/dist-client/guide/ox-guide-overlay.d.ts +30 -0
- package/dist-client/guide/ox-guide-overlay.js +273 -0
- package/dist-client/guide/ox-guide-recorder-bar.d.ts +10 -0
- package/dist-client/guide/ox-guide-recorder-bar.js +92 -0
- package/dist-client/index.d.ts +4 -0
- package/dist-client/index.js +4 -0
- package/dist-client/pages/guide-editor.d.ts +36 -0
- package/dist-client/pages/guide-editor.js +339 -0
- package/dist-client/pages/guide-list.d.ts +45 -0
- package/dist-client/pages/guide-list.js +74 -0
- package/dist-client/route.js +6 -0
- package/dist-server/index.d.ts +2 -0
- package/dist-server/index.js +8 -1
- package/dist-server/role-tasks.d.ts +2 -0
- package/dist-server/role-tasks.js +11 -0
- package/dist-server/service/guide/guide-conditions.d.ts +21 -0
- package/dist-server/service/guide/guide-conditions.js +27 -0
- package/dist-server/service/guide/guide-resolver.d.ts +12 -0
- package/dist-server/service/guide/guide-resolver.js +142 -0
- package/dist-server/service/guide/guide-rules.d.ts +12 -0
- package/dist-server/service/guide/guide-rules.js +30 -0
- package/dist-server/service/guide/guide-types.d.ts +14 -0
- package/dist-server/service/guide/guide-types.js +43 -0
- package/dist-server/service/guide/guide.d.ts +24 -0
- package/dist-server/service/guide/guide.js +90 -0
- package/dist-server/service/guide/index.d.ts +4 -0
- package/dist-server/service/guide/index.js +8 -0
- package/dist-server/service/index.d.ts +7 -0
- package/dist-server/service/index.js +15 -0
- package/package.json +15 -3
- package/things-factory.config.js +3 -1
- package/translations/en.json +74 -2
- package/translations/es.json +73 -1
- package/translations/ja.json +74 -2
- package/translations/ko.json +74 -2
- package/translations/ms.json +73 -1
- package/translations/zh.json +73 -1
package/dist-client/bootstrap.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import '@operato/help/ox-help-panel.js';
|
|
2
2
|
import { html } from 'lit';
|
|
3
3
|
import { appendViewpart, VIEWPART_POSITION } from '@operato/layout';
|
|
4
|
+
import { auth } from '@things-factory/auth-base/dist-client/auth.js';
|
|
5
|
+
import { resumeRecording } from './guide/guide-recorder.js';
|
|
6
|
+
import { resumeGuide, stopGuide } from './guide/guide-runner.js';
|
|
4
7
|
export default function bootstrap() {
|
|
5
8
|
appendViewpart({
|
|
6
9
|
name: 'help',
|
|
@@ -12,5 +15,11 @@ export default function bootstrap() {
|
|
|
12
15
|
},
|
|
13
16
|
position: VIEWPART_POSITION.ASIDEBAR
|
|
14
17
|
});
|
|
18
|
+
/* A guide or a recording in progress goes on after a reload (ADR-0212 decision 5). */
|
|
19
|
+
auth.on('profile', () => {
|
|
20
|
+
resumeGuide();
|
|
21
|
+
resumeRecording();
|
|
22
|
+
});
|
|
23
|
+
auth.on('presignout', () => stopGuide());
|
|
15
24
|
}
|
|
16
25
|
//# sourceMappingURL=bootstrap.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Whether the element takes room on the screen now. */
|
|
2
|
+
export declare function shown(element: Element): boolean;
|
|
3
|
+
/** The first element the selector finds that is on the screen, searched through every shadow root. */
|
|
4
|
+
export declare function findShown(selector: string): Element | undefined;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Finding a point of the screen through the shadow roots the screens are drawn in (ADR-0212 decision 5).
|
|
3
|
+
*/
|
|
4
|
+
function* elementsOf(root) {
|
|
5
|
+
const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT);
|
|
6
|
+
let node = walker.nextNode();
|
|
7
|
+
while (node) {
|
|
8
|
+
yield node;
|
|
9
|
+
if (node.shadowRoot)
|
|
10
|
+
yield* elementsOf(node.shadowRoot);
|
|
11
|
+
node = walker.nextNode();
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/** Whether the element takes room on the screen now. */
|
|
15
|
+
export function shown(element) {
|
|
16
|
+
const rect = element.getBoundingClientRect();
|
|
17
|
+
if (rect.width <= 0 || rect.height <= 0)
|
|
18
|
+
return false;
|
|
19
|
+
const style = getComputedStyle(element);
|
|
20
|
+
return style.visibility !== 'hidden' && style.display !== 'none';
|
|
21
|
+
}
|
|
22
|
+
/** The first element the selector finds that is on the screen, searched through every shadow root. */
|
|
23
|
+
export function findShown(selector) {
|
|
24
|
+
for (const element of elementsOf(document))
|
|
25
|
+
if (element.matches(selector) && shown(element))
|
|
26
|
+
return element;
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=deep-find.js.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** What the person does at the point - the step moves on when it is done. */
|
|
2
|
+
export type GuideAnchorAction = 'click' | 'input' | 'select';
|
|
3
|
+
/**
|
|
4
|
+
* Where the point is on the screen:
|
|
5
|
+
* - `{ action }` a page action - the bar draws its button with `data-action` (its id);
|
|
6
|
+
* - `{ column, row: 'new' }` a cell of the row just added to an ox-grist - the grist marks it `data-column` and `new-record`;
|
|
7
|
+
* - `{ guide }` any element the screen marks `data-guide`.
|
|
8
|
+
*/
|
|
9
|
+
export type GuideAnchorTarget = {
|
|
10
|
+
action: string;
|
|
11
|
+
} | {
|
|
12
|
+
column: string;
|
|
13
|
+
row: 'new';
|
|
14
|
+
} | {
|
|
15
|
+
guide: string;
|
|
16
|
+
};
|
|
17
|
+
export interface GuideAnchor {
|
|
18
|
+
/** `<module>.<screen>.<point>` - `asset.my-items.save`. */
|
|
19
|
+
id: string;
|
|
20
|
+
/** The page it is on - `my-asset-item-list`. */
|
|
21
|
+
page: string;
|
|
22
|
+
/** A translation key of the declaring module - what the point is, in the reader's words. */
|
|
23
|
+
labelKey: string;
|
|
24
|
+
action: GuideAnchorAction;
|
|
25
|
+
target: GuideAnchorTarget;
|
|
26
|
+
}
|
|
27
|
+
/** What a module calls at load. Declaring the same id again replaces it. */
|
|
28
|
+
export declare function registerGuideAnchors(anchors: readonly GuideAnchor[]): void;
|
|
29
|
+
export declare function guideAnchor(id: string | null | undefined): GuideAnchor | undefined;
|
|
30
|
+
/** Every declared point - of one page when it is named. */
|
|
31
|
+
export declare function guideAnchors(page?: string): GuideAnchor[];
|
|
32
|
+
/** The CSS selector that finds the point's element (searched through every shadow root). */
|
|
33
|
+
export declare function selectorOf(target: GuideAnchorTarget): string;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The points of the screens a guide may lead to, as modules declare them (ADR-0212 decision 2). A point that is not
|
|
3
|
+
* declared cannot be a step, so a screen that loses one breaks a test, not a guide in silence.
|
|
4
|
+
*
|
|
5
|
+
* Kept free of the browser's globals and of i18next so the tests read it.
|
|
6
|
+
*/
|
|
7
|
+
const ANCHORS = new Map();
|
|
8
|
+
/** What a module calls at load. Declaring the same id again replaces it. */
|
|
9
|
+
export function registerGuideAnchors(anchors) {
|
|
10
|
+
for (const anchor of anchors)
|
|
11
|
+
ANCHORS.set(anchor.id, anchor);
|
|
12
|
+
}
|
|
13
|
+
export function guideAnchor(id) {
|
|
14
|
+
return id ? ANCHORS.get(id) : undefined;
|
|
15
|
+
}
|
|
16
|
+
/** Every declared point - of one page when it is named. */
|
|
17
|
+
export function guideAnchors(page) {
|
|
18
|
+
return [...ANCHORS.values()].filter(anchor => !page || anchor.page === page);
|
|
19
|
+
}
|
|
20
|
+
const quoted = (value) => JSON.stringify(value);
|
|
21
|
+
/** The CSS selector that finds the point's element (searched through every shadow root). */
|
|
22
|
+
export function selectorOf(target) {
|
|
23
|
+
if ('action' in target)
|
|
24
|
+
return `[data-action=${quoted(target.action)}]`;
|
|
25
|
+
if ('column' in target)
|
|
26
|
+
return `[data-column=${quoted(target.column)}][new-record]`;
|
|
27
|
+
return `[data-guide=${quoted(target.guide)}]`;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=guide-anchors.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { GuideItem, GuideStep } from './guide-progress.js';
|
|
2
|
+
export type GuideRow = GuideItem & {
|
|
3
|
+
id: string;
|
|
4
|
+
updatedAt?: string;
|
|
5
|
+
updater?: {
|
|
6
|
+
name?: string;
|
|
7
|
+
} | null;
|
|
8
|
+
};
|
|
9
|
+
export declare const guideApi: {
|
|
10
|
+
one: (id: string) => Promise<GuideRow | null>;
|
|
11
|
+
list: () => Promise<GuideRow[]>;
|
|
12
|
+
conditions: () => Promise<{
|
|
13
|
+
id: string;
|
|
14
|
+
label: string;
|
|
15
|
+
}[]>;
|
|
16
|
+
met: (id: string) => Promise<boolean>;
|
|
17
|
+
save: (input: {
|
|
18
|
+
name: string;
|
|
19
|
+
opening: string;
|
|
20
|
+
steps: GuideStep[];
|
|
21
|
+
condition?: string | null;
|
|
22
|
+
}, id?: string) => Promise<GuideRow>;
|
|
23
|
+
remove: (id: string) => Promise<boolean>;
|
|
24
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The guide doors the runner, the recorder and the screens call (ADR-0212). Every call throws the server's words when it
|
|
3
|
+
* is refused.
|
|
4
|
+
*/
|
|
5
|
+
import gql from 'graphql-tag';
|
|
6
|
+
import { client } from '@operato/graphql';
|
|
7
|
+
const FIELDS = 'id name opening steps condition updatedAt updater { name }';
|
|
8
|
+
function answer(response, field) {
|
|
9
|
+
if (response.errors?.length)
|
|
10
|
+
throw new Error(response.errors.map((one) => one.message).join(' · '));
|
|
11
|
+
return response.data?.[field];
|
|
12
|
+
}
|
|
13
|
+
const ask = async (query, variables, field) => answer(await client.query({ query: gql(query), variables, fetchPolicy: 'network-only' }), field);
|
|
14
|
+
const change = async (mutation, variables, field) => answer(await client.mutate({ mutation: gql(mutation), variables }), field);
|
|
15
|
+
export const guideApi = {
|
|
16
|
+
one: (id) => ask(`query ($id: String!) { guide(id: $id) { ${FIELDS} } }`, { id }, 'guide'),
|
|
17
|
+
list: () => ask(`query { guides { ${FIELDS} } }`, {}, 'guides'),
|
|
18
|
+
conditions: () => ask(`query { guideConditions { id label } }`, {}, 'guideConditions'),
|
|
19
|
+
met: (id) => ask(`query ($id: String!) { guideMet(id: $id) }`, { id }, 'guideMet'),
|
|
20
|
+
save: (input, id) => change(`mutation ($input: GuideInput!, $id: String) { saveGuide(input: $input, id: $id) { ${FIELDS} } }`, { input, id: id ?? null }, 'saveGuide'),
|
|
21
|
+
remove: (id) => change(`mutation ($id: String!) { deleteGuide(id: $id) }`, { id }, 'deleteGuide')
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=guide-api.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { GuideAnchor } from './guide-anchors.js';
|
|
2
|
+
export interface GuideStep {
|
|
3
|
+
page: string;
|
|
4
|
+
anchor?: string | null;
|
|
5
|
+
text: string;
|
|
6
|
+
}
|
|
7
|
+
export interface GuideItem {
|
|
8
|
+
id?: string;
|
|
9
|
+
name: string;
|
|
10
|
+
opening: string;
|
|
11
|
+
steps: GuideStep[];
|
|
12
|
+
condition?: string | null;
|
|
13
|
+
}
|
|
14
|
+
/** What the person did at a point: a click, or a value entered or chosen. */
|
|
15
|
+
export type Observed = {
|
|
16
|
+
kind: 'click' | 'change';
|
|
17
|
+
anchor: string;
|
|
18
|
+
};
|
|
19
|
+
/** Whether what was done finishes the step. A step with no point only explains - its 「다음」 moves it on. */
|
|
20
|
+
export declare function stepFinishedBy(step: GuideStep, anchor: GuideAnchor | undefined, observed: Observed): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Whether a move planned at one step may still be made. One entry at a point can reach the document as more than one
|
|
23
|
+
* event (a grid cell sends `field-change` and its input `change`); each plans a move, and only the first, made while
|
|
24
|
+
* the guide is still at the step it was planned at, moves it on.
|
|
25
|
+
*/
|
|
26
|
+
export declare function moveStillDue(plannedAt: number, now: number): boolean;
|
|
27
|
+
/** The step a recording adds for what was done at a point - none when it repeats the last step (a click into a field, then its value). */
|
|
28
|
+
export declare function recordedStep(page: string, anchor: string, last: GuideStep | undefined): GuideStep | undefined;
|
|
29
|
+
/** The steps that cannot be used: their point is no longer declared, or not on the step's page. */
|
|
30
|
+
export declare function brokenSteps(steps: readonly GuideStep[], anchorOf: (id: string) => GuideAnchor | undefined): number[];
|
|
31
|
+
/** The point an event happened at: the first element on its path that one of the page's points finds. */
|
|
32
|
+
export declare function anchorOnPath(path: readonly unknown[], anchors: readonly {
|
|
33
|
+
id: string;
|
|
34
|
+
selector: string;
|
|
35
|
+
}[]): string | undefined;
|
|
36
|
+
/** Moves a step up or down - the list as it was when it cannot move. */
|
|
37
|
+
export declare function moveStep<T>(steps: readonly T[], index: number, by: -1 | 1): T[];
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** Whether what was done finishes the step. A step with no point only explains - its 「다음」 moves it on. */
|
|
2
|
+
export function stepFinishedBy(step, anchor, observed) {
|
|
3
|
+
if (!step.anchor || !anchor || observed.anchor !== step.anchor)
|
|
4
|
+
return false;
|
|
5
|
+
return anchor.action === 'click' ? observed.kind === 'click' : observed.kind === 'change';
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Whether a move planned at one step may still be made. One entry at a point can reach the document as more than one
|
|
9
|
+
* event (a grid cell sends `field-change` and its input `change`); each plans a move, and only the first, made while
|
|
10
|
+
* the guide is still at the step it was planned at, moves it on.
|
|
11
|
+
*/
|
|
12
|
+
export function moveStillDue(plannedAt, now) {
|
|
13
|
+
return plannedAt === now;
|
|
14
|
+
}
|
|
15
|
+
/** The step a recording adds for what was done at a point - none when it repeats the last step (a click into a field, then its value). */
|
|
16
|
+
export function recordedStep(page, anchor, last) {
|
|
17
|
+
if (last && last.anchor === anchor && last.page === page)
|
|
18
|
+
return undefined;
|
|
19
|
+
return { page, anchor, text: '' };
|
|
20
|
+
}
|
|
21
|
+
/** The steps that cannot be used: their point is no longer declared, or not on the step's page. */
|
|
22
|
+
export function brokenSteps(steps, anchorOf) {
|
|
23
|
+
return steps.flatMap((step, index) => {
|
|
24
|
+
if (!step.anchor)
|
|
25
|
+
return [];
|
|
26
|
+
const anchor = anchorOf(step.anchor);
|
|
27
|
+
return !anchor || anchor.page !== step.page ? [index] : [];
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/** The point an event happened at: the first element on its path that one of the page's points finds. */
|
|
31
|
+
export function anchorOnPath(path, anchors) {
|
|
32
|
+
for (const node of path) {
|
|
33
|
+
const element = node;
|
|
34
|
+
if (typeof element?.matches !== 'function')
|
|
35
|
+
continue;
|
|
36
|
+
for (const anchor of anchors)
|
|
37
|
+
if (element.matches(anchor.selector))
|
|
38
|
+
return anchor.id;
|
|
39
|
+
}
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
/** Moves a step up or down - the list as it was when it cannot move. */
|
|
43
|
+
export function moveStep(steps, index, by) {
|
|
44
|
+
const to = index + by;
|
|
45
|
+
if (index < 0 || index >= steps.length || to < 0 || to >= steps.length)
|
|
46
|
+
return [...steps];
|
|
47
|
+
const next = [...steps];
|
|
48
|
+
[next[index], next[to]] = [next[to], next[index]];
|
|
49
|
+
return next;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=guide-progress.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import './ox-guide-recorder-bar.js';
|
|
2
|
+
/** Where the editor finds the steps of a recording that ended. */
|
|
3
|
+
export declare const RECORDED_KEY = "guide.recorded";
|
|
4
|
+
/** Starts a recording; ending it returns to `returnTo` (the editor). */
|
|
5
|
+
export declare function startRecording(returnTo: string): void;
|
|
6
|
+
/** Goes on with the recording the session was in. */
|
|
7
|
+
export declare function resumeRecording(): void;
|
|
8
|
+
/** Ends the recording: kept → its steps go to the editor; not kept → dropped. */
|
|
9
|
+
export declare function endRecording(kept: boolean): void;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Recording a guide (ADR-0212 decision 7): the writer does the work once, and each declared point they work at becomes a
|
|
3
|
+
* step. Values entered are not kept - only that a value was entered. The recording is kept in the browser session so it
|
|
4
|
+
* goes on across screens; ending it returns to the editor with the steps.
|
|
5
|
+
*/
|
|
6
|
+
import './ox-guide-recorder-bar.js';
|
|
7
|
+
import { navigate, store } from '@operato/shell';
|
|
8
|
+
import { guideAnchors, selectorOf } from './guide-anchors.js';
|
|
9
|
+
import { anchorOnPath, recordedStep } from './guide-progress.js';
|
|
10
|
+
const KEY = 'guide.recording';
|
|
11
|
+
/** Where the editor finds the steps of a recording that ended. */
|
|
12
|
+
export const RECORDED_KEY = 'guide.recorded';
|
|
13
|
+
let recording;
|
|
14
|
+
let bar;
|
|
15
|
+
const currentPage = () => String(store.getState()?.route?.page ?? '');
|
|
16
|
+
function keep() {
|
|
17
|
+
try {
|
|
18
|
+
if (recording)
|
|
19
|
+
sessionStorage.setItem(KEY, JSON.stringify(recording));
|
|
20
|
+
else
|
|
21
|
+
sessionStorage.removeItem(KEY);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
/* kept in memory only */
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** Starts a recording; ending it returns to `returnTo` (the editor). */
|
|
28
|
+
export function startRecording(returnTo) {
|
|
29
|
+
recording = { steps: [], returnTo };
|
|
30
|
+
keep();
|
|
31
|
+
show();
|
|
32
|
+
}
|
|
33
|
+
/** Goes on with the recording the session was in. */
|
|
34
|
+
export function resumeRecording() {
|
|
35
|
+
if (recording)
|
|
36
|
+
return;
|
|
37
|
+
try {
|
|
38
|
+
const kept = JSON.parse(sessionStorage.getItem(KEY) || 'null');
|
|
39
|
+
if (kept?.returnTo) {
|
|
40
|
+
recording = kept;
|
|
41
|
+
show();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
/* nothing kept */
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/** Ends the recording: kept → its steps go to the editor; not kept → dropped. */
|
|
49
|
+
export function endRecording(kept) {
|
|
50
|
+
if (!recording)
|
|
51
|
+
return;
|
|
52
|
+
const { steps, returnTo } = recording;
|
|
53
|
+
recording = undefined;
|
|
54
|
+
keep();
|
|
55
|
+
try {
|
|
56
|
+
if (kept)
|
|
57
|
+
sessionStorage.setItem(RECORDED_KEY, JSON.stringify(steps));
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
/* the editor gets nothing */
|
|
61
|
+
}
|
|
62
|
+
document.removeEventListener('click', onEvent, true);
|
|
63
|
+
document.removeEventListener('change', onEvent, true);
|
|
64
|
+
document.removeEventListener('field-change', onEvent, true);
|
|
65
|
+
bar?.remove();
|
|
66
|
+
bar = undefined;
|
|
67
|
+
navigate(returnTo);
|
|
68
|
+
}
|
|
69
|
+
function show() {
|
|
70
|
+
if (!bar) {
|
|
71
|
+
bar = document.createElement('ox-guide-recorder-bar');
|
|
72
|
+
bar.addEventListener('recording-end', (e) => endRecording(e.detail === true));
|
|
73
|
+
document.body.appendChild(bar);
|
|
74
|
+
document.addEventListener('click', onEvent, true);
|
|
75
|
+
document.addEventListener('change', onEvent, true);
|
|
76
|
+
document.addEventListener('field-change', onEvent, true);
|
|
77
|
+
}
|
|
78
|
+
bar.steps = [...recording.steps];
|
|
79
|
+
}
|
|
80
|
+
function onEvent(event) {
|
|
81
|
+
if (!recording || event.composedPath().includes(bar))
|
|
82
|
+
return;
|
|
83
|
+
const page = currentPage();
|
|
84
|
+
const id = anchorOnPath(event.composedPath(), guideAnchors(page).map(one => ({ id: one.id, selector: selectorOf(one.target) })));
|
|
85
|
+
if (!id)
|
|
86
|
+
return;
|
|
87
|
+
const step = recordedStep(page, id, recording.steps[recording.steps.length - 1]);
|
|
88
|
+
if (!step)
|
|
89
|
+
return;
|
|
90
|
+
recording.steps.push(step);
|
|
91
|
+
keep();
|
|
92
|
+
show();
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=guide-recorder.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import './ox-guide-overlay.js';
|
|
2
|
+
import { type GuideItem } from './guide-progress.js';
|
|
3
|
+
/** Where the guide came from - the announcement that carried it records its completion; none for a writer's preview. */
|
|
4
|
+
export type GuideOrigin = {
|
|
5
|
+
kind: string;
|
|
6
|
+
id: string;
|
|
7
|
+
};
|
|
8
|
+
/** Answers whether the person's work is done, and records it - registered by the module that carries guides to people. */
|
|
9
|
+
export type GuideFinisher = (originId: string, guide: GuideItem) => Promise<boolean>;
|
|
10
|
+
/** What a module that carries guides to people calls at load - `announcement`. */
|
|
11
|
+
export declare function registerGuideFinisher(kind: string, finisher: GuideFinisher): void;
|
|
12
|
+
/** Starts a guide - by its id, or as the writer has it in the editor (a preview). */
|
|
13
|
+
export declare function startGuide(guide: GuideItem | string, origin?: GuideOrigin): Promise<void>;
|
|
14
|
+
/** Goes on with the guide the session was in - at sign-in or after a reload. */
|
|
15
|
+
export declare function resumeGuide(): void;
|
|
16
|
+
export declare function guideRunning(): boolean;
|
|
17
|
+
/** Ends the guide - the person closed it, or it is done. It is offered again while its work is not done. */
|
|
18
|
+
export declare function stopGuide(): void;
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The guide runner (ADR-0212 decisions 4, 5): an overlay over the screens - a frame around the point of the step and a
|
|
3
|
+
* card beside it. The screens do not know it: it opens the step's page, finds the point through the shadow roots, and
|
|
4
|
+
* watches the clicks and values the person enters at the document. Nothing is covered; the person works as usual.
|
|
5
|
+
*
|
|
6
|
+
* The guide in progress is kept in the browser session, so moving to another screen or reloading goes on with it.
|
|
7
|
+
*/
|
|
8
|
+
import './ox-guide-overlay.js';
|
|
9
|
+
import { navigate, store } from '@operato/shell';
|
|
10
|
+
import { findShown } from './deep-find.js';
|
|
11
|
+
import { guideAnchor, guideAnchors, selectorOf } from './guide-anchors.js';
|
|
12
|
+
import { guideApi } from './guide-api.js';
|
|
13
|
+
import { anchorOnPath, moveStillDue, stepFinishedBy } from './guide-progress.js';
|
|
14
|
+
const KEY = 'guide.running';
|
|
15
|
+
const FINISHERS = new Map();
|
|
16
|
+
const CHECK_AGAIN_AFTER = [1000, 2000];
|
|
17
|
+
let running;
|
|
18
|
+
let overlay;
|
|
19
|
+
let ticker;
|
|
20
|
+
let openedFor = -1;
|
|
21
|
+
let state = 'working';
|
|
22
|
+
/** What a module that carries guides to people calls at load - `announcement`. */
|
|
23
|
+
export function registerGuideFinisher(kind, finisher) {
|
|
24
|
+
FINISHERS.set(kind, finisher);
|
|
25
|
+
}
|
|
26
|
+
function keep() {
|
|
27
|
+
try {
|
|
28
|
+
if (running)
|
|
29
|
+
sessionStorage.setItem(KEY, JSON.stringify(running));
|
|
30
|
+
else
|
|
31
|
+
sessionStorage.removeItem(KEY);
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
/* a browser that keeps nothing loses the guide on reload - no harm */
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const currentPage = () => String(store.getState()?.route?.page ?? '');
|
|
38
|
+
/** Starts a guide - by its id, or as the writer has it in the editor (a preview). */
|
|
39
|
+
export async function startGuide(guide, origin) {
|
|
40
|
+
const one = typeof guide === 'string' ? await guideApi.one(guide) : guide;
|
|
41
|
+
if (!one?.steps?.length)
|
|
42
|
+
return;
|
|
43
|
+
running = { guide: one, index: 0, origin };
|
|
44
|
+
state = 'working';
|
|
45
|
+
openedFor = -1;
|
|
46
|
+
keep();
|
|
47
|
+
show();
|
|
48
|
+
}
|
|
49
|
+
/** Goes on with the guide the session was in - at sign-in or after a reload. */
|
|
50
|
+
export function resumeGuide() {
|
|
51
|
+
if (running)
|
|
52
|
+
return;
|
|
53
|
+
try {
|
|
54
|
+
const kept = JSON.parse(sessionStorage.getItem(KEY) || 'null');
|
|
55
|
+
if (kept?.guide?.steps?.length) {
|
|
56
|
+
running = kept;
|
|
57
|
+
state = 'working';
|
|
58
|
+
openedFor = -1;
|
|
59
|
+
show();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
/* nothing kept */
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export function guideRunning() {
|
|
67
|
+
return !!running;
|
|
68
|
+
}
|
|
69
|
+
/** Ends the guide - the person closed it, or it is done. It is offered again while its work is not done. */
|
|
70
|
+
export function stopGuide() {
|
|
71
|
+
running = undefined;
|
|
72
|
+
keep();
|
|
73
|
+
if (ticker)
|
|
74
|
+
clearInterval(ticker);
|
|
75
|
+
ticker = undefined;
|
|
76
|
+
document.removeEventListener('click', onClick, true);
|
|
77
|
+
document.removeEventListener('change', onChange, true);
|
|
78
|
+
document.removeEventListener('field-change', onChange, true);
|
|
79
|
+
overlay?.remove();
|
|
80
|
+
overlay = undefined;
|
|
81
|
+
}
|
|
82
|
+
function show() {
|
|
83
|
+
if (!overlay) {
|
|
84
|
+
overlay = document.createElement('ox-guide-overlay');
|
|
85
|
+
overlay.addEventListener('guide-next', () => next());
|
|
86
|
+
overlay.addEventListener('guide-stop', () => stopGuide());
|
|
87
|
+
overlay.addEventListener('guide-check', () => finish());
|
|
88
|
+
document.body.appendChild(overlay);
|
|
89
|
+
document.addEventListener('click', onClick, true);
|
|
90
|
+
document.addEventListener('change', onChange, true);
|
|
91
|
+
document.addEventListener('field-change', onChange, true);
|
|
92
|
+
}
|
|
93
|
+
if (!ticker)
|
|
94
|
+
ticker = setInterval(tick, 300);
|
|
95
|
+
tick();
|
|
96
|
+
}
|
|
97
|
+
/* Each beat: open the step's page once, find its point, and draw the frame and the card where it is now. */
|
|
98
|
+
function tick() {
|
|
99
|
+
if (!running || !overlay)
|
|
100
|
+
return;
|
|
101
|
+
const { guide, index } = running;
|
|
102
|
+
const step = guide.steps[index];
|
|
103
|
+
/* Only once the application has routed its first page - moving before that loses the domain from the address. */
|
|
104
|
+
const page = currentPage();
|
|
105
|
+
if (state === 'working' && step.page && page && page !== step.page && openedFor !== index) {
|
|
106
|
+
openedFor = index;
|
|
107
|
+
navigate(step.page);
|
|
108
|
+
}
|
|
109
|
+
const anchor = guideAnchor(step.anchor);
|
|
110
|
+
const target = anchor && currentPage() === step.page ? findShown(selectorOf(anchor.target)) : undefined;
|
|
111
|
+
overlay.view = {
|
|
112
|
+
text: step.text,
|
|
113
|
+
index,
|
|
114
|
+
total: guide.steps.length,
|
|
115
|
+
rect: target?.getBoundingClientRect() ?? null,
|
|
116
|
+
explains: !step.anchor,
|
|
117
|
+
action: anchor?.action,
|
|
118
|
+
checked: !!guide.condition,
|
|
119
|
+
state
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function observe(event, kind) {
|
|
123
|
+
if (!running || state !== 'working')
|
|
124
|
+
return;
|
|
125
|
+
const step = running.guide.steps[running.index];
|
|
126
|
+
const anchor = guideAnchor(step.anchor);
|
|
127
|
+
if (!anchor)
|
|
128
|
+
return;
|
|
129
|
+
const id = anchorOnPath(event.composedPath(), guideAnchors(currentPage()).map(one => ({ id: one.id, selector: selectorOf(one.target) })));
|
|
130
|
+
if (!id || !stepFinishedBy(step, anchor, { kind, anchor: id }))
|
|
131
|
+
return;
|
|
132
|
+
/* The screen does its work first (a row added, a value taken) - then the next point is there to find. */
|
|
133
|
+
const plannedAt = running.index;
|
|
134
|
+
setTimeout(() => {
|
|
135
|
+
if (running && state === 'working' && moveStillDue(plannedAt, running.index))
|
|
136
|
+
next();
|
|
137
|
+
}, 200);
|
|
138
|
+
}
|
|
139
|
+
const onClick = (event) => observe(event, 'click');
|
|
140
|
+
const onChange = (event) => observe(event, 'change');
|
|
141
|
+
function next() {
|
|
142
|
+
if (!running)
|
|
143
|
+
return;
|
|
144
|
+
if (running.index >= running.guide.steps.length - 1) {
|
|
145
|
+
void finish();
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
running.index++;
|
|
149
|
+
keep();
|
|
150
|
+
tick();
|
|
151
|
+
}
|
|
152
|
+
/* The last step is done: the work is checked - recorded by the announcement that carried it, only checked in a preview. */
|
|
153
|
+
async function finish() {
|
|
154
|
+
/* One check at a time - a second would record the same completion again. */
|
|
155
|
+
if (!running || state === 'checking')
|
|
156
|
+
return;
|
|
157
|
+
state = 'checking';
|
|
158
|
+
tick();
|
|
159
|
+
const { guide, origin } = running;
|
|
160
|
+
const finisher = origin ? FINISHERS.get(origin.kind) : undefined;
|
|
161
|
+
const check = async () => {
|
|
162
|
+
try {
|
|
163
|
+
return finisher ? await finisher(origin.id, guide) : guide.id ? await guideApi.met(guide.id) : true;
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
/* The last click (저장) may still be on its way to the server - asked again a little later before saying it is not done. */
|
|
170
|
+
let done = await check();
|
|
171
|
+
for (const wait of CHECK_AGAIN_AFTER) {
|
|
172
|
+
if (done || !running)
|
|
173
|
+
break;
|
|
174
|
+
await new Promise(resolve => setTimeout(resolve, wait));
|
|
175
|
+
done = await check();
|
|
176
|
+
}
|
|
177
|
+
if (!running)
|
|
178
|
+
return;
|
|
179
|
+
state = done ? 'done' : 'unfinished';
|
|
180
|
+
if (done) {
|
|
181
|
+
running = { ...running, index: running.guide.steps.length - 1 };
|
|
182
|
+
try {
|
|
183
|
+
sessionStorage.removeItem(KEY);
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
/* nothing kept */
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
tick();
|
|
190
|
+
}
|
|
191
|
+
//# sourceMappingURL=guide-runner.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type GuideAnchor } from './guide-anchors.js';
|
|
2
|
+
export declare const t: (key: string, options?: Record<string, unknown>) => string;
|
|
3
|
+
export declare const anchorLabel: (anchor: GuideAnchor | string | null | undefined) => string;
|
|
4
|
+
/** The page's name as the menu calls it, or its address. */
|
|
5
|
+
export declare const pageLabel: (page: string) => string;
|
|
6
|
+
/** The sentence a recorded step starts with - the writer rewrites it. */
|
|
7
|
+
export declare function defaultStepText(anchorId: string): string;
|
|
8
|
+
export declare const reasonOf: (error: unknown) => string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The words of screen guides - one place for the runner, the recorder and the screens.
|
|
3
|
+
*/
|
|
4
|
+
import { i18next } from '@operato/i18n';
|
|
5
|
+
import { guideAnchor } from './guide-anchors.js';
|
|
6
|
+
export const t = (key, options = {}) => String(i18next.t(key, options));
|
|
7
|
+
export const anchorLabel = (anchor) => {
|
|
8
|
+
const one = typeof anchor === 'string' ? guideAnchor(anchor) : anchor;
|
|
9
|
+
return one ? String(i18next.t(one.labelKey, { defaultValue: one.id })) : typeof anchor === 'string' ? anchor : '';
|
|
10
|
+
};
|
|
11
|
+
/** The page's name as the menu calls it, or its address. */
|
|
12
|
+
export const pageLabel = (page) => String(i18next.t(`title.${page}`, { defaultValue: i18next.t(`menu.${page}`, { defaultValue: page }) }));
|
|
13
|
+
/** The sentence a recorded step starts with - the writer rewrites it. */
|
|
14
|
+
export function defaultStepText(anchorId) {
|
|
15
|
+
const anchor = guideAnchor(anchorId);
|
|
16
|
+
if (!anchor)
|
|
17
|
+
return '';
|
|
18
|
+
return t(`guide.text.default-${anchor.action}`, { label: anchorLabel(anchor) });
|
|
19
|
+
}
|
|
20
|
+
export const reasonOf = (error) => error?.message || t('guide.text.failed');
|
|
21
|
+
//# sourceMappingURL=guide-words.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import '@material/web/button/filled-tonal-button.js';
|
|
2
|
+
import '@material/web/button/text-button.js';
|
|
3
|
+
import '@material/web/icon/icon.js';
|
|
4
|
+
import { LitElement, nothing } from 'lit';
|
|
5
|
+
import type { GuideAnchorAction } from './guide-anchors.js';
|
|
6
|
+
export type GuideView = {
|
|
7
|
+
text: string;
|
|
8
|
+
index: number;
|
|
9
|
+
total: number;
|
|
10
|
+
rect: DOMRect | null;
|
|
11
|
+
explains: boolean;
|
|
12
|
+
/** What the person does at the step's point - its icon. */
|
|
13
|
+
action?: GuideAnchorAction;
|
|
14
|
+
/** Whether the server checks the work - only then is the work said to be confirmed. */
|
|
15
|
+
checked: boolean;
|
|
16
|
+
state: 'working' | 'checking' | 'unfinished' | 'done';
|
|
17
|
+
};
|
|
18
|
+
export declare class OxGuideOverlay extends LitElement {
|
|
19
|
+
static styles: import("lit").CSSResult;
|
|
20
|
+
view?: GuideView;
|
|
21
|
+
render(): typeof nothing | import("lit-html").TemplateResult<1>;
|
|
22
|
+
private iconOf;
|
|
23
|
+
private renderBody;
|
|
24
|
+
/**
|
|
25
|
+
* Below the point when there is room, above it otherwise, starting a little left of the point's middle; the upper
|
|
26
|
+
* right when there is no point - the page's actions are below.
|
|
27
|
+
*/
|
|
28
|
+
private placeOf;
|
|
29
|
+
private say;
|
|
30
|
+
}
|