@operato/context 10.29.69 → 10.29.71

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.
@@ -1 +1 @@
1
- {"version":3,"file":"ox-page-action-overlay-template.js","sourceRoot":"","sources":["../../../src/tools/ox-page-action-overlay-template.ts"],"names":[],"mappings":";AAAA,OAAO,4BAA4B,CAAA;AACnC,OAAO,oCAAoC,CAAA;AAE3C,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAChD,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACxE,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAEtC,OAAO,EAAE,0BAA0B,EAAE,MAAM,+CAA+C,CAAA;AAGnF,IAAM,yBAAyB,GAA/B,MAAM,yBAA0B,SAAQ,UAAU;IAAlD;;QAsCG,WAAM,GAAG,IAAI,eAAe,CAAC,IAAI,CAAC,CAAA;IA0D5C,CAAC;IA/FC,MAAM,KAAK,MAAM;QACf,OAAO;YACL,eAAe;YACf,qBAAqB;YACrB,0BAA0B;YAC1B,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BF;SACF,CAAA;IACH,CAAC;IAID,MAAM;;QACJ,MAAM,OAAO,GAAG,CAAA,MAAA,MAAA,IAAI,CAAC,MAAM,CAAC,OAAO,0CAAE,OAAO,0CAAE,MAAM,CAAC,CAAC,MAAW,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,KAAI,EAAE,CAAA;QAErF,OAAO,IAAI,CAAA;QACP,OAAO,CAAC,GAAG,CAAC,CAAC,OAAY,EAAE,GAAW,EAAE,EAAE;YAC1C,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EA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BAChB,CAAC;oCAAS,CAAC;gCACT,MAAM,KAAK,CAAC,IAAI,CAAC,CAAA,CAAC,qCAAqC;gCAEvD,wEAAwE;gCACxE,IAAI,WAAW,EAAE,CAAC;oCAChB,WAAW,CAAC,WAAW,GAAG,MAAA,OAAO,CAAC,GAAG,CAAC,0CAAE,IAAI,CAAA;oCAC5C,WAAW,CAAC,eAAe,CAAC,SAAS,CAAC,CAAA;gCACxC,CAAC;gCACD,MAAM,CAAC,QAAQ,GAAG,KAAK,CAAA;4BACzB,CAAC;wBACH,CAAC;;2CAEsB,IAAI,IAAI,UAAU;;iBAE5C,CAAA;QACX,CAAC,CAAC;KACH,CAAA;IACH,CAAC;CACF,CAAA;AAhGY,yBAAyB;IADrC,aAAa,CAAC,iCAAiC,CAAC;GACpC,yBAAyB,CAgGrC","sourcesContent":["import '@material/web/icon/icon.js'\nimport '@material/web/chips/assist-chip.js'\n\nimport { css, html, LitElement } from 'lit'\nimport { customElement } from 'lit/decorators.js'\nimport { RouteController } from '@operato/shell'\nimport { ButtonContainerStyles, ScrollbarStyles } from '@operato/styles'\nimport { sleep } from '@operato/utils'\n\nimport { ContextToolbarOverlayStyle } from '../styles/ox-context-toolbar-overlay-style.js'\n\n@customElement('ox-page-action-overlay-template')\nexport class PageActionOverlayTemplate extends LitElement {\n static get styles() {\n return [\n ScrollbarStyles,\n ButtonContainerStyles,\n ContextToolbarOverlayStyle,\n css`\n :host {\n display: flex;\n flex-wrap: wrap;\n gap: var(--spacing-small);\n align-items: center;\n }\n\n :host *:focus {\n outline: none;\n }\n\n md-icon[working] {\n animation: rotate 1s linear infinite;\n }\n\n md-assist-chip[icon-only] {\n --md-assist-chip-trailing-space: 0;\n }\n\n @keyframes rotate {\n from {\n transform: rotate(0deg);\n }\n to {\n transform: rotate(360deg);\n }\n }\n `\n ]\n }\n\n private _route = new RouteController(this)\n\n render() {\n const actions = this._route.context?.actions?.filter((action: any) => !!action) || []\n\n return html`\n ${actions.map(($action: any, idx: number) => {\n let { type, title, icon, action, select, href, emphasis, disabled, disabledTitle } = $action as any\n let { raised, danger } = emphasis || {}\n\n return type == 'text'\n ? html` <span>${title}</span> `\n : type == 'select' || (select && select.length > 0)\n ? html`\n <select @change=${action}>\n ${select.map((option: any) => html` <option>${option}</option> `)}\n </select>\n `\n : type == 'link'\n ? html` <a href=${href}>${title}</a> `\n : html`\n <md-assist-chip\n ?icon-only=${type == 'icon' || !title}\n ?elevated=${raised}\n ?danger=${danger}\n ?disabled=${disabled}\n title=${disabled && disabledTitle ? disabledTitle : title || ''}\n label=${title}\n @click=${async (e: MouseEvent) => {\n /* all actions should be bloked for a second */\n const button = e.currentTarget as any\n const iconElement = button.querySelector('[slot=\"icon\"]')\n if (iconElement) {\n iconElement.textContent = 'refresh'\n iconElement.setAttribute('working', true)\n }\n button.disabled = true\n\n try {\n await action()\n } finally {\n await sleep(1000) /* waiting for additionla 1 second */\n\n /* because icon can be changed after sleep, don't use closure 'icon'. */\n if (iconElement) {\n iconElement.textContent = actions[idx]?.icon\n iconElement.removeAttribute('working')\n }\n button.disabled = false\n }\n }}\n >\n <md-icon slot=\"icon\">${icon || 'done_all'}</md-icon>\n </md-assist-chip>\n `\n })}\n `\n }\n}\n"]}
1
+ {"version":3,"file":"ox-page-action-overlay-template.js","sourceRoot":"","sources":["../../../src/tools/ox-page-action-overlay-template.ts"],"names":[],"mappings":";AAAA,OAAO,4BAA4B,CAAA;AAEnC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAChD,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAExE,OAAO,EAAE,0BAA0B,EAAE,MAAM,+CAA+C,CAAA;AAC1F,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB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nimport { css, html, LitElement } from 'lit'\nimport { customElement } from 'lit/decorators.js'\nimport { RouteController } from '@operato/shell'\nimport { ButtonContainerStyles, ScrollbarStyles } from '@operato/styles'\n\nimport { ContextToolbarOverlayStyle } from '../styles/ox-context-toolbar-overlay-style.js'\nimport { arrangePageActions, pageActionRunner } from './page-action.js'\nimport { PageActionStyles, renderPageAction } from './page-action-render.js'\n\n/**\n * 「더보기」 - every action of the page, drawn by the same renderer as the bar (page-action-render.ts): the same name,\n * icon, main/danger look, disabled reason and running state. A run started here is the same run the bar shows.\n */\n@customElement('ox-page-action-overlay-template')\nexport class PageActionOverlayTemplate extends LitElement {\n static get styles() {\n return [\n ScrollbarStyles,\n ButtonContainerStyles,\n PageActionStyles,\n ContextToolbarOverlayStyle,\n css`\n :host {\n display: flex;\n flex-wrap: wrap;\n gap: var(--spacing-small);\n align-items: center;\n }\n\n /* The same focus mark as the bar: none for a mouse press, a ring for the keyboard. */\n :host *:focus:not(:focus-visible) {\n outline: none;\n }\n\n :host *:focus-visible {\n outline: 3px solid var(--md-sys-color-primary);\n outline-offset: 2px;\n }\n `\n ]\n }\n\n private _route = new RouteController(this)\n private onRunnerChange = () => this.requestUpdate()\n\n connectedCallback() {\n super.connectedCallback()\n pageActionRunner.addEventListener('change', this.onRunnerChange)\n }\n\n disconnectedCallback() {\n super.disconnectedCallback()\n pageActionRunner.removeEventListener('change', this.onRunnerChange)\n }\n\n render() {\n const actions = this._route.context?.actions?.filter((action: any) => !!action) || []\n return html`${arrangePageActions(actions).map(({ action, role }) => renderPageAction(action, role))}`\n }\n}\n"]}
@@ -0,0 +1,23 @@
1
+ import '@material/web/icon/icon.js';
2
+ import { TemplateResult } from 'lit';
3
+ import { PageAction, PageActionRole } from './page-action.js';
4
+ /**
5
+ * One action drawn the same way wherever it stands - the bar and 「더보기」 both call this.
6
+ *
7
+ * The role decides the look: `primary` is filled (`raised`), `danger` carries `danger` (drawn as a secondary
8
+ * destructive button unless also raised - button-container-styles), `secondary` is plain. A running action shows a
9
+ * turning icon and `aria-busy`; an action held by another run, or disabled by the page, is not pressable.
10
+ *
11
+ * A disabled action that says why (`disabledTitle`) stays focusable and hoverable (`aria-disabled`): the reason is its
12
+ * tooltip, and pressing it says the reason instead of doing nothing. One without a reason is natively disabled.
13
+ */
14
+ export declare function renderPageAction(action: PageAction, role: PageActionRole, options?: {
15
+ onRan?: () => void;
16
+ }): TemplateResult;
17
+ /**
18
+ * The running icon, the not-pressable look of an explained disabled action, and the secondary destructive look - shared
19
+ * by the bar and 「더보기」. A danger action that is not the step's main action is drawn in the error colour on the
20
+ * plain surface; filling it red made 삭제 the loudest button of a screen whose main action is 저장 (FOOTER-BUTTON-REVIEW
21
+ * F02). The confirmation that follows a delete is where it is filled.
22
+ */
23
+ export declare const PageActionStyles: import("lit").CSSResult;
@@ -0,0 +1,109 @@
1
+ import '@material/web/icon/icon.js';
2
+ import { css, html, nothing } from 'lit';
3
+ import { notify } from '@operato/layout';
4
+ import { dangerButtonStyles } from '@operato/styles';
5
+ import { isButtonAction, pageActionRunner } from './page-action.js';
6
+ /**
7
+ * One action drawn the same way wherever it stands - the bar and 「더보기」 both call this.
8
+ *
9
+ * The role decides the look: `primary` is filled (`raised`), `danger` carries `danger` (drawn as a secondary
10
+ * destructive button unless also raised - button-container-styles), `secondary` is plain. A running action shows a
11
+ * turning icon and `aria-busy`; an action held by another run, or disabled by the page, is not pressable.
12
+ *
13
+ * A disabled action that says why (`disabledTitle`) stays focusable and hoverable (`aria-disabled`): the reason is its
14
+ * tooltip, and pressing it says the reason instead of doing nothing. One without a reason is natively disabled.
15
+ */
16
+ export function renderPageAction(action, role, options = {}) {
17
+ var _a, _b, _c, _d;
18
+ const { type, title, icon, select, href, disabled, disabledTitle } = action;
19
+ if (type === 'text') {
20
+ return html `<span role="button" tabindex="0" @click=${(e) => run(action, e, options)} @keydown=${keyRun(action, options)}>${title}</span>`;
21
+ }
22
+ if (!isButtonAction(action)) {
23
+ return type === 'link'
24
+ ? html `<a href=${href !== null && href !== void 0 ? href : ''}>${title}</a>`
25
+ : html `
26
+ <select aria-label=${title !== null && title !== void 0 ? title : ''} @change=${(e) => { var _a; return (_a = action.action) === null || _a === void 0 ? void 0 : _a.call(action, e); }}>
27
+ ${(select !== null && select !== void 0 ? select : []).map(option => html `<option>${option}</option>`)}
28
+ </select>
29
+ `;
30
+ }
31
+ const running = pageActionRunner.isRunning(action);
32
+ const held = pageActionRunner.isHeld(action);
33
+ const iconOnly = type === 'icon' || !title;
34
+ const explained = !!disabled && !!disabledTitle;
35
+ const blocked = running || held || !!disabled;
36
+ return html `
37
+ <button
38
+ data-action=${(_c = (_b = (_a = action.id) !== null && _a !== void 0 ? _a : title) !== null && _b !== void 0 ? _b : icon) !== null && _c !== void 0 ? _c : ''}
39
+ ?icon-only=${iconOnly}
40
+ ?raised=${role === 'primary'}
41
+ ?danger=${role === 'danger'}
42
+ ?disabled=${blocked && !explained}
43
+ aria-disabled=${blocked ? 'true' : 'false'}
44
+ aria-busy=${running ? 'true' : 'false'}
45
+ ?running=${running}
46
+ title=${explained ? disabledTitle : title !== null && title !== void 0 ? title : ''}
47
+ aria-label=${iconOnly ? (_d = title !== null && title !== void 0 ? title : icon) !== null && _d !== void 0 ? _d : '' : nothing}
48
+ @click=${(e) => {
49
+ if (explained && !running && !held) {
50
+ notify({ message: disabledTitle, level: 'info' });
51
+ return;
52
+ }
53
+ run(action, e, options);
54
+ }}
55
+ >
56
+ ${running ? html `<md-icon working aria-hidden="true">progress_activity</md-icon>` : icon ? html `<md-icon aria-hidden="true">${icon}</md-icon>` : nothing}
57
+ ${iconOnly ? nothing : title}
58
+ </button>
59
+ `;
60
+ }
61
+ function run(action, event, { onRan }) {
62
+ const started = pageActionRunner.mayRun(action);
63
+ pageActionRunner.run(action, event).finally(() => started && (onRan === null || onRan === void 0 ? void 0 : onRan()));
64
+ }
65
+ function keyRun(action, options) {
66
+ return (e) => {
67
+ if (e.key !== 'Enter' && e.key !== ' ')
68
+ return;
69
+ e.preventDefault();
70
+ run(action, e, options);
71
+ };
72
+ }
73
+ /**
74
+ * The running icon, the not-pressable look of an explained disabled action, and the secondary destructive look - shared
75
+ * by the bar and 「더보기」. A danger action that is not the step's main action is drawn in the error colour on the
76
+ * plain surface; filling it red made 삭제 the loudest button of a screen whose main action is 저장 (FOOTER-BUTTON-REVIEW
77
+ * F02). The confirmation that follows a delete is where it is filled.
78
+ */
79
+ export const PageActionStyles = css `
80
+ ${dangerButtonStyles('button[danger]:not([raised])', 'text')}
81
+
82
+ button[danger]:not([raised]) {
83
+ border-color: var(--md-sys-color-error);
84
+ }
85
+
86
+ md-icon[working] {
87
+ animation: page-action-rotate 1s linear infinite;
88
+ }
89
+
90
+ button[aria-disabled='true'] {
91
+ opacity: 0.38;
92
+ cursor: default;
93
+ }
94
+
95
+ button[running] {
96
+ opacity: 1;
97
+ cursor: progress;
98
+ }
99
+
100
+ @keyframes page-action-rotate {
101
+ from {
102
+ transform: rotate(0deg);
103
+ }
104
+ to {
105
+ transform: rotate(360deg);
106
+ }
107
+ }
108
+ `;
109
+ //# sourceMappingURL=page-action-render.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page-action-render.js","sourceRoot":"","sources":["../../../src/tools/page-action-render.ts"],"names":[],"mappings":"AAAA,OAAO,4BAA4B,CAAA;AAEnC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAkB,MAAM,KAAK,CAAA;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAEpD,OAAO,EAAE,cAAc,EAAc,gBAAgB,EAAkB,MAAM,kBAAkB,CAAA;AAE/F;;;;;;;;;GASG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAkB,EAAE,IAAoB,EAAE,UAAkC,EAAE;;IAC7G,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ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I,KAAK,aAAL,KAAK,uBAAL,KAAK,EAAI,CAAA,CAAC,CAAA;AACzE,CAAC;AAED,SAAS,MAAM,CAAC,MAAkB,EAAE,OAA+B;IACjE,OAAO,CAAC,CAAgB,EAAE,EAAE;QAC1B,IAAI,CAAC,CAAC,GAAG,KAAK,OAAO,IAAI,CAAC,CAAC,GAAG,KAAK,GAAG;YAAE,OAAM;QAC9C,CAAC,CAAC,cAAc,EAAE,CAAA;QAClB,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,OAAO,CAAC,CAAA;IACzB,CAAC,CAAA;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,CAAA;IAC/B,kBAAkB,CAAC,8BAA8B,EAAE,MAAM,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4B7D,CAAA","sourcesContent":["import '@material/web/icon/icon.js'\n\nimport { css, html, nothing, TemplateResult } from 'lit'\nimport { notify } from '@operato/layout'\nimport { dangerButtonStyles } from '@operato/styles'\n\nimport { isButtonAction, PageAction, pageActionRunner, PageActionRole } from './page-action.js'\n\n/**\n * One action drawn the same way wherever it stands - the bar and 「더보기」 both call this.\n *\n * The role decides the look: `primary` is filled (`raised`), `danger` carries `danger` (drawn as a secondary\n * destructive button unless also raised - button-container-styles), `secondary` is plain. A running action shows a\n * turning icon and `aria-busy`; an action held by another run, or disabled by the page, is not pressable.\n *\n * A disabled action that says why (`disabledTitle`) stays focusable and hoverable (`aria-disabled`): the reason is its\n * tooltip, and pressing it says the reason instead of doing nothing. One without a reason is natively disabled.\n */\nexport function renderPageAction(action: PageAction, role: PageActionRole, options: { onRan?: () => void } = {}): TemplateResult {\n const { type, title, icon, select, href, disabled, disabledTitle } = action\n\n if (type === 'text') {\n return html`<span role=\"button\" tabindex=\"0\" @click=${(e: Event) => run(action, e, options)} @keydown=${keyRun(action, options)}>${title}</span>`\n }\n if (!isButtonAction(action)) {\n return type === 'link'\n ? html`<a href=${href ?? ''}>${title}</a>`\n : html`\n <select aria-label=${title ?? ''} @change=${(e: Event) => action.action?.(e)}>\n ${(select ?? []).map(option => html`<option>${option}</option>`)}\n </select>\n `\n }\n\n const running = pageActionRunner.isRunning(action)\n const held = pageActionRunner.isHeld(action)\n const iconOnly = type === 'icon' || !title\n const explained = !!disabled && !!disabledTitle\n const blocked = running || held || !!disabled\n\n return html`\n <button\n data-action=${action.id ?? title ?? icon ?? ''}\n ?icon-only=${iconOnly}\n ?raised=${role === 'primary'}\n ?danger=${role === 'danger'}\n ?disabled=${blocked && !explained}\n aria-disabled=${blocked ? 'true' : 'false'}\n aria-busy=${running ? 'true' : 'false'}\n ?running=${running}\n title=${explained ? disabledTitle! : title ?? ''}\n aria-label=${iconOnly ? title ?? icon ?? '' : nothing}\n @click=${(e: Event) => {\n if (explained && !running && !held) {\n notify({ message: disabledTitle!, level: 'info' })\n return\n }\n run(action, e, options)\n }}\n >\n ${running ? html`<md-icon working aria-hidden=\"true\">progress_activity</md-icon>` : icon ? html`<md-icon aria-hidden=\"true\">${icon}</md-icon>` : nothing}\n ${iconOnly ? nothing : title}\n </button>\n `\n}\n\nfunction run(action: PageAction, event: Event, { onRan }: { onRan?: () => void }) {\n const started = pageActionRunner.mayRun(action)\n pageActionRunner.run(action, event).finally(() => started && onRan?.())\n}\n\nfunction keyRun(action: PageAction, options: { onRan?: () => void }) {\n return (e: KeyboardEvent) => {\n if (e.key !== 'Enter' && e.key !== ' ') return\n e.preventDefault()\n run(action, e, options)\n }\n}\n\n/**\n * The running icon, the not-pressable look of an explained disabled action, and the secondary destructive look - shared\n * by the bar and 「더보기」. A danger action that is not the step's main action is drawn in the error colour on the\n * plain surface; filling it red made 삭제 the loudest button of a screen whose main action is 저장 (FOOTER-BUTTON-REVIEW\n * F02). The confirmation that follows a delete is where it is filled.\n */\nexport const PageActionStyles = css`\n ${dangerButtonStyles('button[danger]:not([raised])', 'text')}\n\n button[danger]:not([raised]) {\n border-color: var(--md-sys-color-error);\n }\n\n md-icon[working] {\n animation: page-action-rotate 1s linear infinite;\n }\n\n button[aria-disabled='true'] {\n opacity: 0.38;\n cursor: default;\n }\n\n button[running] {\n opacity: 1;\n cursor: progress;\n }\n\n @keyframes page-action-rotate {\n from {\n transform: rotate(0deg);\n }\n to {\n transform: rotate(360deg);\n }\n }\n`\n"]}
@@ -0,0 +1,100 @@
1
+ /**
2
+ * What one action of a page's action bar is, and how it runs.
3
+ *
4
+ * A page declares its actions in `context.actions`. The bar draws the ones that fit and 「더보기」 lists every one; both
5
+ * draw an action through `renderPageAction` and run it through `pageActionRunner`, so an action looks and behaves the
6
+ * same in either place, and a run started in one is seen as running in the other.
7
+ *
8
+ * ── Running ────────────────────────────────────────────────────────────────────────────────────
9
+ * An action runs once at a time: while it runs, the same action (by `id`, else `title`) is shown running and does not
10
+ * start again - from the bar or from 「더보기」. Actions sharing a `group` exclude one another. An app can make every
11
+ * action of a page exclusive (`configurePageActions({ exclusive: true })`): one change of a page at a time.
12
+ *
13
+ * Nothing is enabled by the runner when a run ends. Whether an action may run is the page's to say (`disabled`); the
14
+ * bar draws the context the page holds now, so an action the page disabled while the run was out stays disabled.
15
+ *
16
+ * An action that returns at once (it opens a popup without awaiting it, it navigates) is held for `SETTLE_MS`, so a
17
+ * double click does not run it twice. An action that returns a promise is held until it settles - no extra wait.
18
+ *
19
+ * The runner keeps the page's buttons from starting a change twice; it does not replace the server's own checks.
20
+ */
21
+ export type PageActionEmphasis = {
22
+ raised?: boolean;
23
+ outlined?: boolean;
24
+ dense?: boolean;
25
+ danger?: boolean;
26
+ };
27
+ export interface PageAction {
28
+ /** A stable key: the same action in the bar and in 「더보기」, and across the page's context updates. Defaults to the title. */
29
+ id?: string;
30
+ title?: string;
31
+ icon?: string;
32
+ /** What the action does. A promise keeps the action running until it settles. */
33
+ action?: (event?: Event) => unknown;
34
+ /** `button` (default), `icon` (icon only, the title is its name), `text`, `select`, `link`. */
35
+ type?: string;
36
+ select?: string[];
37
+ href?: string;
38
+ /**
39
+ * `{ raised }` marks the page's main action of this step - one per bar; `{ danger }` an action that destroys data.
40
+ * The two are independent: a danger action is drawn as a secondary action unless it is also `raised`.
41
+ */
42
+ emphasis?: PageActionEmphasis | boolean;
43
+ /** Same as `emphasis.raised` (`'primary'`), stated as what it means. */
44
+ priority?: 'primary' | 'secondary';
45
+ disabled?: boolean;
46
+ /** Why the action is disabled - the button's tooltip and accessible description while it is. */
47
+ disabledTitle?: string;
48
+ /** Actions of one group never run at the same time. */
49
+ group?: string;
50
+ [key: string]: any;
51
+ }
52
+ export type PageActionRole = 'primary' | 'secondary' | 'danger';
53
+ export interface PageActionPolicy {
54
+ /** Every action of a page excludes the others while it runs - one change of the page at a time. */
55
+ exclusive: boolean;
56
+ /**
57
+ * The bar arranges what the page declared: danger actions first, then the others in their order, the main action at
58
+ * the right end; only the last `primary` action stays primary.
59
+ */
60
+ arrange: boolean;
61
+ }
62
+ /** Sets the app's policy for every page's action bar (`@operato/context`). The platform default is neither. */
63
+ export declare function configurePageActions(next: Partial<PageActionPolicy>): void;
64
+ export declare function pageActionPolicy(): Readonly<PageActionPolicy>;
65
+ export declare function emphasisOf(action: PageAction): PageActionEmphasis;
66
+ /** The action's role as declared: `primary` (raised, not danger, or `priority: 'primary'`), `danger`, or `secondary`. */
67
+ export declare function roleOf(action: PageAction): PageActionRole;
68
+ /** Whether the action is drawn as a button (not a text, select or link). */
69
+ export declare function isButtonAction(action: PageAction): boolean;
70
+ export declare function actionKey(action: PageAction): string;
71
+ /**
72
+ * The actions as the bar shows them, each with the role it is drawn in. With `arrange`, danger actions come first, then
73
+ * the secondary ones in the page's order, and the main action last; a second `primary` is drawn as secondary.
74
+ */
75
+ export declare function arrangePageActions(actions: readonly PageAction[]): {
76
+ action: PageAction;
77
+ role: PageActionRole;
78
+ }[];
79
+ /** How long an action that returned at once stays running - one double click. */
80
+ export declare const SETTLE_MS = 400;
81
+ /**
82
+ * Which actions are running now, shared by every bar and 「더보기」 of the page. Keyed by the page's address and the
83
+ * action's key, so a run left behind on another page never blocks this one.
84
+ */
85
+ export declare class PageActionRunner extends EventTarget {
86
+ private running;
87
+ private scoped;
88
+ private get here();
89
+ isRunning(action: PageAction): boolean;
90
+ /** Another action holds the page: one of the same group, or any while the policy is exclusive. */
91
+ isHeld(action: PageAction): boolean;
92
+ /** Whether the action may start now - not running, not held, and not disabled by the page. */
93
+ mayRun(action: PageAction): boolean;
94
+ /**
95
+ * Runs the action unless it may not start now. Resolves when it is no longer running; an error the action throws is
96
+ * the action's to report and is passed on to the caller.
97
+ */
98
+ run(action: PageAction, event?: Event): Promise<void>;
99
+ }
100
+ export declare const pageActionRunner: PageActionRunner;
@@ -0,0 +1,129 @@
1
+ /**
2
+ * What one action of a page's action bar is, and how it runs.
3
+ *
4
+ * A page declares its actions in `context.actions`. The bar draws the ones that fit and 「더보기」 lists every one; both
5
+ * draw an action through `renderPageAction` and run it through `pageActionRunner`, so an action looks and behaves the
6
+ * same in either place, and a run started in one is seen as running in the other.
7
+ *
8
+ * ── Running ────────────────────────────────────────────────────────────────────────────────────
9
+ * An action runs once at a time: while it runs, the same action (by `id`, else `title`) is shown running and does not
10
+ * start again - from the bar or from 「더보기」. Actions sharing a `group` exclude one another. An app can make every
11
+ * action of a page exclusive (`configurePageActions({ exclusive: true })`): one change of a page at a time.
12
+ *
13
+ * Nothing is enabled by the runner when a run ends. Whether an action may run is the page's to say (`disabled`); the
14
+ * bar draws the context the page holds now, so an action the page disabled while the run was out stays disabled.
15
+ *
16
+ * An action that returns at once (it opens a popup without awaiting it, it navigates) is held for `SETTLE_MS`, so a
17
+ * double click does not run it twice. An action that returns a promise is held until it settles - no extra wait.
18
+ *
19
+ * The runner keeps the page's buttons from starting a change twice; it does not replace the server's own checks.
20
+ */
21
+ const policy = { exclusive: false, arrange: false };
22
+ /** Sets the app's policy for every page's action bar (`@operato/context`). The platform default is neither. */
23
+ export function configurePageActions(next) {
24
+ Object.assign(policy, next);
25
+ }
26
+ export function pageActionPolicy() {
27
+ return policy;
28
+ }
29
+ export function emphasisOf(action) {
30
+ return typeof action.emphasis === 'object' && action.emphasis ? action.emphasis : {};
31
+ }
32
+ /** The action's role as declared: `primary` (raised, not danger, or `priority: 'primary'`), `danger`, or `secondary`. */
33
+ export function roleOf(action) {
34
+ const { raised, danger } = emphasisOf(action);
35
+ if (action.priority === 'primary')
36
+ return 'primary';
37
+ if (danger || action.danger)
38
+ return 'danger';
39
+ if (action.priority === 'secondary')
40
+ return 'secondary';
41
+ return raised ? 'primary' : 'secondary';
42
+ }
43
+ /** Whether the action is drawn as a button (not a text, select or link). */
44
+ export function isButtonAction(action) {
45
+ const { type, select } = action;
46
+ return !(type === 'text' || type === 'select' || type === 'link' || (select && select.length > 0));
47
+ }
48
+ export function actionKey(action) {
49
+ var _a, _b, _c;
50
+ return String((_c = (_b = (_a = action.id) !== null && _a !== void 0 ? _a : action.title) !== null && _b !== void 0 ? _b : action.icon) !== null && _c !== void 0 ? _c : '');
51
+ }
52
+ /**
53
+ * The actions as the bar shows them, each with the role it is drawn in. With `arrange`, danger actions come first, then
54
+ * the secondary ones in the page's order, and the main action last; a second `primary` is drawn as secondary.
55
+ */
56
+ export function arrangePageActions(actions) {
57
+ const present = actions.filter(Boolean);
58
+ const roles = present.map(action => ({ action, role: roleOf(action) }));
59
+ if (!policy.arrange)
60
+ return roles;
61
+ const lastPrimary = roles.map(one => one.role).lastIndexOf('primary');
62
+ const settled = roles.map((one, at) => (one.role === 'primary' && at !== lastPrimary ? { ...one, role: 'secondary' } : one));
63
+ const rank = (role) => (role === 'danger' ? 0 : role === 'secondary' ? 1 : 2);
64
+ return settled
65
+ .map((one, at) => ({ one, at }))
66
+ .sort((a, b) => rank(a.one.role) - rank(b.one.role) || a.at - b.at)
67
+ .map(({ one }) => one);
68
+ }
69
+ /** How long an action that returned at once stays running - one double click. */
70
+ export const SETTLE_MS = 400;
71
+ /**
72
+ * Which actions are running now, shared by every bar and 「더보기」 of the page. Keyed by the page's address and the
73
+ * action's key, so a run left behind on another page never blocks this one.
74
+ */
75
+ export class PageActionRunner extends EventTarget {
76
+ constructor() {
77
+ super(...arguments);
78
+ this.running = new Map();
79
+ }
80
+ scoped(key) {
81
+ return `${typeof location === 'undefined' ? '' : location.pathname}\u0000${key}`;
82
+ }
83
+ get here() {
84
+ const prefix = this.scoped('');
85
+ return Array.from(this.running.entries()).filter(([key]) => key.startsWith(prefix));
86
+ }
87
+ isRunning(action) {
88
+ return this.running.has(this.scoped(actionKey(action)));
89
+ }
90
+ /** Another action holds the page: one of the same group, or any while the policy is exclusive. */
91
+ isHeld(action) {
92
+ if (this.isRunning(action))
93
+ return false;
94
+ const others = this.here;
95
+ if (!others.length)
96
+ return false;
97
+ if (policy.exclusive)
98
+ return true;
99
+ return !!action.group && others.some(([, one]) => one.group === action.group);
100
+ }
101
+ /** Whether the action may start now - not running, not held, and not disabled by the page. */
102
+ mayRun(action) {
103
+ return !action.disabled && !this.isRunning(action) && !this.isHeld(action) && typeof action.action === 'function';
104
+ }
105
+ /**
106
+ * Runs the action unless it may not start now. Resolves when it is no longer running; an error the action throws is
107
+ * the action's to report and is passed on to the caller.
108
+ */
109
+ async run(action, event) {
110
+ if (!this.mayRun(action))
111
+ return;
112
+ const key = this.scoped(actionKey(action));
113
+ this.running.set(key, { group: action.group });
114
+ this.dispatchEvent(new Event('change'));
115
+ try {
116
+ const result = action.action(event);
117
+ if (result && typeof result.then === 'function')
118
+ await result;
119
+ else
120
+ await new Promise(resolve => setTimeout(resolve, SETTLE_MS));
121
+ }
122
+ finally {
123
+ this.running.delete(key);
124
+ this.dispatchEvent(new Event('change'));
125
+ }
126
+ }
127
+ }
128
+ export const pageActionRunner = new PageActionRunner();
129
+ //# sourceMappingURL=page-action.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page-action.js","sourceRoot":"","sources":["../../../src/tools/page-action.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AA+CH,MAAM,MAAM,GAAqB,EAAE,SAAS,EA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AAI,CAAC,aAAa,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAA;QACzC,CAAC;IACH,CAAC;CACF;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,gBAAgB,EAAE,CAAA","sourcesContent":["/**\n * What one action of a page's action bar is, and how it runs.\n *\n * A page declares its actions in `context.actions`. The bar draws the ones that fit and 「더보기」 lists every one; both\n * draw an action through `renderPageAction` and run it through `pageActionRunner`, so an action looks and behaves the\n * same in either place, and a run started in one is seen as running in the other.\n *\n * ── Running ────────────────────────────────────────────────────────────────────────────────────\n * An action runs once at a time: while it runs, the same action (by `id`, else `title`) is shown running and does not\n * start again - from the bar or from 「더보기」. Actions sharing a `group` exclude one another. An app can make every\n * action of a page exclusive (`configurePageActions({ exclusive: true })`): one change of a page at a time.\n *\n * Nothing is enabled by the runner when a run ends. Whether an action may run is the page's to say (`disabled`); the\n * bar draws the context the page holds now, so an action the page disabled while the run was out stays disabled.\n *\n * An action that returns at once (it opens a popup without awaiting it, it navigates) is held for `SETTLE_MS`, so a\n * double click does not run it twice. An action that returns a promise is held until it settles - no extra wait.\n *\n * The runner keeps the page's buttons from starting a change twice; it does not replace the server's own checks.\n */\n\nexport type PageActionEmphasis = {\n raised?: boolean\n outlined?: boolean\n dense?: boolean\n danger?: boolean\n}\n\nexport interface PageAction {\n /** A stable key: the same action in the bar and in 「더보기」, and across the page's context updates. Defaults to the title. */\n id?: string\n title?: string\n icon?: string\n /** What the action does. A promise keeps the action running until it settles. */\n action?: (event?: Event) => unknown\n /** `button` (default), `icon` (icon only, the title is its name), `text`, `select`, `link`. */\n type?: string\n select?: string[]\n href?: string\n /**\n * `{ raised }` marks the page's main action of this step - one per bar; `{ danger }` an action that destroys data.\n * The two are independent: a danger action is drawn as a secondary action unless it is also `raised`.\n */\n emphasis?: PageActionEmphasis | boolean\n /** Same as `emphasis.raised` (`'primary'`), stated as what it means. */\n priority?: 'primary' | 'secondary'\n disabled?: boolean\n /** Why the action is disabled - the button's tooltip and accessible description while it is. */\n disabledTitle?: string\n /** Actions of one group never run at the same time. */\n group?: string\n [key: string]: any\n}\n\nexport type PageActionRole = 'primary' | 'secondary' | 'danger'\n\nexport interface PageActionPolicy {\n /** Every action of a page excludes the others while it runs - one change of the page at a time. */\n exclusive: boolean\n /**\n * The bar arranges what the page declared: danger actions first, then the others in their order, the main action at\n * the right end; only the last `primary` action stays primary.\n */\n arrange: boolean\n}\n\nconst policy: PageActionPolicy = { exclusive: false, arrange: false }\n\n/** Sets the app's policy for every page's action bar (`@operato/context`). The platform default is neither. */\nexport function configurePageActions(next: Partial<PageActionPolicy>) {\n Object.assign(policy, next)\n}\n\nexport function pageActionPolicy(): Readonly<PageActionPolicy> {\n return policy\n}\n\nexport function emphasisOf(action: PageAction): PageActionEmphasis {\n return typeof action.emphasis === 'object' && action.emphasis ? action.emphasis : {}\n}\n\n/** The action's role as declared: `primary` (raised, not danger, or `priority: 'primary'`), `danger`, or `secondary`. */\nexport function roleOf(action: PageAction): PageActionRole {\n const { raised, danger } = emphasisOf(action)\n if (action.priority === 'primary') return 'primary'\n if (danger || action.danger) return 'danger'\n if (action.priority === 'secondary') return 'secondary'\n return raised ? 'primary' : 'secondary'\n}\n\n/** Whether the action is drawn as a button (not a text, select or link). */\nexport function isButtonAction(action: PageAction): boolean {\n const { type, select } = action\n return !(type === 'text' || type === 'select' || type === 'link' || (select && select.length > 0))\n}\n\nexport function actionKey(action: PageAction): string {\n return String(action.id ?? action.title ?? action.icon ?? '')\n}\n\n/**\n * The actions as the bar shows them, each with the role it is drawn in. With `arrange`, danger actions come first, then\n * the secondary ones in the page's order, and the main action last; a second `primary` is drawn as secondary.\n */\nexport function arrangePageActions(actions: readonly PageAction[]): { action: PageAction; role: PageActionRole }[] {\n const present = actions.filter(Boolean)\n const roles = present.map(action => ({ action, role: roleOf(action) }))\n if (!policy.arrange) return roles\n\n const lastPrimary = roles.map(one => one.role).lastIndexOf('primary')\n const settled = roles.map((one, at) => (one.role === 'primary' && at !== lastPrimary ? { ...one, role: 'secondary' as const } : one))\n const rank = (role: PageActionRole) => (role === 'danger' ? 0 : role === 'secondary' ? 1 : 2)\n return settled\n .map((one, at) => ({ one, at }))\n .sort((a, b) => rank(a.one.role) - rank(b.one.role) || a.at - b.at)\n .map(({ one }) => one)\n}\n\n/** How long an action that returned at once stays running - one double click. */\nexport const SETTLE_MS = 400\n\ntype Running = { group?: string }\n\n/**\n * Which actions are running now, shared by every bar and 「더보기」 of the page. Keyed by the page's address and the\n * action's key, so a run left behind on another page never blocks this one.\n */\nexport class PageActionRunner extends EventTarget {\n private running = new Map<string, Running>()\n\n private scoped(key: string) {\n return `${typeof location === 'undefined' ? '' : location.pathname}\\u0000${key}`\n }\n\n private get here() {\n const prefix = this.scoped('')\n return Array.from(this.running.entries()).filter(([key]) => key.startsWith(prefix))\n }\n\n isRunning(action: PageAction): boolean {\n return this.running.has(this.scoped(actionKey(action)))\n }\n\n /** Another action holds the page: one of the same group, or any while the policy is exclusive. */\n isHeld(action: PageAction): boolean {\n if (this.isRunning(action)) return false\n const others = this.here\n if (!others.length) return false\n if (policy.exclusive) return true\n return !!action.group && others.some(([, one]) => one.group === action.group)\n }\n\n /** Whether the action may start now - not running, not held, and not disabled by the page. */\n mayRun(action: PageAction): boolean {\n return !action.disabled && !this.isRunning(action) && !this.isHeld(action) && typeof action.action === 'function'\n }\n\n /**\n * Runs the action unless it may not start now. Resolves when it is no longer running; an error the action throws is\n * the action's to report and is passed on to the caller.\n */\n async run(action: PageAction, event?: Event): Promise<void> {\n if (!this.mayRun(action)) return\n const key = this.scoped(actionKey(action))\n this.running.set(key, { group: action.group })\n this.dispatchEvent(new Event('change'))\n try {\n const result = action.action!(event)\n if (result && typeof (result as Promise<unknown>).then === 'function') await result\n else await new Promise(resolve => setTimeout(resolve, SETTLE_MS))\n } finally {\n this.running.delete(key)\n this.dispatchEvent(new Event('change'))\n }\n }\n}\n\nexport const pageActionRunner = new PageActionRunner()\n"]}
@@ -0,0 +1,2 @@
1
+ import '../src/tools/ox-page-action-context-bar.js';
2
+ import '../src/tools/ox-page-action-overlay-template.js';
@@ -0,0 +1,179 @@
1
+ import { expect, fixture } from '@open-wc/testing';
2
+ import { html } from 'lit';
3
+ import '../src/tools/ox-page-action-context-bar.js';
4
+ import '../src/tools/ox-page-action-overlay-template.js';
5
+ import { arrangePageActions, configurePageActions, pageActionRunner, roleOf } from '../src/tools/page-action.js';
6
+ const settle = async (el, rounds = 4) => {
7
+ for (let i = 0; i < rounds; i++) {
8
+ await new Promise(resolve => setTimeout(resolve, 60));
9
+ await el.updateComplete;
10
+ }
11
+ };
12
+ async function barIn(width, actions) {
13
+ const host = await fixture(html `<div style="display:flex; justify-content:flex-end; overflow:hidden; width:${width}px"><ox-page-action-context-bar .actions=${actions}></ox-page-action-context-bar></div>`);
14
+ const el = host.querySelector('ox-page-action-context-bar');
15
+ await settle(el);
16
+ return { host: host, el };
17
+ }
18
+ const LONG = [
19
+ { title: '차수 관리 열기와 아주 긴 번역 문구', action: () => { } },
20
+ { title: '거래처로 등록', action: () => { } },
21
+ { title: '실적 배분', action: () => { } },
22
+ { title: '저장', icon: 'save', action: () => { }, emphasis: { raised: true } }
23
+ ];
24
+ describe('동작 줄 — 부모 폭으로 넘침을 잰다 (F01)', () => {
25
+ for (const width of [320, 360, 390, 768]) {
26
+ it(`${width}px: 잘린 단추가 없고 주 동작이 보이며 나머지는 더보기로 닿는다`, async () => {
27
+ var _a, _b;
28
+ const { host, el } = await barIn(width, LONG);
29
+ const box = host.getBoundingClientRect();
30
+ const buttons = Array.from(el.renderRoot.querySelectorAll('[container] > button'));
31
+ const shown = buttons.filter(one => getComputedStyle(one).display !== 'none');
32
+ for (const one of shown) {
33
+ const rect = one.getBoundingClientRect();
34
+ expect(rect.left >= box.left - 0.5, `「${(_a = one.textContent) === null || _a === void 0 ? void 0 : _a.trim()}」 왼쪽이 잘렸다`).to.equal(true);
35
+ expect(rect.right <= box.right + 0.5, `「${(_b = one.textContent) === null || _b === void 0 ? void 0 : _b.trim()}」 오른쪽이 잘렸다`).to.equal(true);
36
+ }
37
+ const primary = shown.find(one => one.hasAttribute('raised'));
38
+ expect(primary, '주 동작이 보이지 않는다').to.not.equal(undefined);
39
+ if (shown.length < buttons.length) {
40
+ const more = el.renderRoot.querySelector('[more]');
41
+ expect(more, '숨은 동작이 있는데 더보기가 없다').to.not.equal(null);
42
+ expect(more.getAttribute('tabindex')).to.equal('0');
43
+ expect(more.getBoundingClientRect().right <= box.right + 0.5).to.equal(true);
44
+ for (const one of shown)
45
+ expect(one.getBoundingClientRect().right <= more.getBoundingClientRect().left + 0.5).to.equal(true);
46
+ }
47
+ });
48
+ }
49
+ it('부모가 넓어지면 숨겼던 동작을 다시 보인다', async () => {
50
+ const { host, el } = await barIn(320, LONG);
51
+ host.style.width = '1400px';
52
+ await settle(el, 6);
53
+ expect(el.renderRoot.querySelector('[more]')).to.equal(null);
54
+ expect(el.renderRoot.querySelectorAll('[container] > [overflowed]').length).to.equal(0);
55
+ });
56
+ });
57
+ describe('동작의 역할과 순서 (F02 F05)', () => {
58
+ afterEach(() => configurePageActions({ arrange: false, exclusive: false }));
59
+ it('삭제는 raised 여도 위험 보조, 저장은 주 동작이다', () => {
60
+ expect(roleOf({ title: '삭제', emphasis: { raised: true, danger: true } })).to.equal('danger');
61
+ expect(roleOf({ title: '저장', emphasis: { raised: true } })).to.equal('primary');
62
+ expect(roleOf({ title: '상신', priority: 'primary' })).to.equal('primary');
63
+ });
64
+ it('arrange: 위험 동작은 앞, 주 동작은 오른쪽 끝, 주 동작은 하나', () => {
65
+ configurePageActions({ arrange: true });
66
+ const arranged = arrangePageActions([
67
+ { title: '저장', emphasis: { raised: true } },
68
+ { title: '삭제', emphasis: { raised: true, danger: true } },
69
+ { title: '상신', emphasis: { raised: true } },
70
+ { title: '첨부' }
71
+ ]);
72
+ expect(arranged.map(one => `${one.action.title}:${one.role}`)).to.deep.equal(['삭제:danger', '저장:secondary', '첨부:secondary', '상신:primary']);
73
+ });
74
+ it('기본(arrange 없음)은 선언 순서를 그대로 둔다', () => {
75
+ const arranged = arrangePageActions([{ title: 'a', emphasis: { raised: true } }, { title: 'b', emphasis: { danger: true } }]);
76
+ expect(arranged.map(one => one.action.title)).to.deep.equal(['a', 'b']);
77
+ });
78
+ });
79
+ describe('더보기는 기본 줄과 같은 렌더러로 그린다 (F04)', () => {
80
+ it('주 동작·위험·비활성·이유·아이콘이 같다', async () => {
81
+ const actions = [
82
+ { title: '삭제', icon: 'delete', emphasis: { danger: true }, action: () => { } },
83
+ { title: '발행', action: () => { }, disabled: true, disabledTitle: '먼저 저장하세요.' },
84
+ { title: '저장', icon: 'save', emphasis: { raised: true }, action: () => { } }
85
+ ];
86
+ const { el } = await barIn(1200, actions);
87
+ const overlay = (await fixture(html `<ox-page-action-overlay-template></ox-page-action-overlay-template>`));
88
+ overlay._route = { context: { actions } };
89
+ overlay.requestUpdate();
90
+ await overlay.updateComplete;
91
+ const describe = (root) => Array.from(root.querySelectorAll('button')).map(b => {
92
+ var _a;
93
+ return ({
94
+ text: (_a = b.textContent) === null || _a === void 0 ? void 0 : _a.replace(/\s+/g, ' ').trim(),
95
+ raised: b.hasAttribute('raised'),
96
+ danger: b.hasAttribute('danger'),
97
+ ariaDisabled: b.getAttribute('aria-disabled'),
98
+ title: b.getAttribute('title')
99
+ });
100
+ });
101
+ expect(describe(overlay.renderRoot)).to.deep.equal(describe(el.renderRoot));
102
+ expect(overlay.renderRoot.querySelector('md-assist-chip')).to.equal(null);
103
+ });
104
+ });
105
+ describe('실행 상태는 공유된다 (F09)', () => {
106
+ afterEach(() => configurePageActions({ exclusive: false }));
107
+ it('같은 동작은 진행 중에 다시 시작하지 않는다 — 기본 줄과 더보기 사이에서도', async () => {
108
+ let runs = 0;
109
+ let release;
110
+ const action = { id: 'save', title: '저장', action: () => (runs++, new Promise(resolve => (release = resolve))) };
111
+ const { el } = await barIn(1200, [action]);
112
+ const button = el.renderRoot.querySelector('button');
113
+ button.click();
114
+ await el.updateComplete;
115
+ expect(button.getAttribute('aria-busy')).to.equal('true');
116
+ button.click();
117
+ pageActionRunner.run({ ...action });
118
+ expect(runs).to.equal(1);
119
+ release();
120
+ await new Promise(resolve => setTimeout(resolve, 10));
121
+ await el.updateComplete;
122
+ expect(button.getAttribute('aria-busy')).to.equal('false');
123
+ });
124
+ it('끝난 뒤 disabled 를 풀지 않는다 — 진행 중 업무 조건이 바뀌면 그 조건을 따른다', async () => {
125
+ let release;
126
+ const make = (disabled) => ({ id: 'issue', title: '발행', disabled, action: () => new Promise(resolve => (release = resolve)) });
127
+ const { el } = await barIn(1200, [make(false)]);
128
+ el.renderRoot.querySelector('button').click();
129
+ await el.updateComplete;
130
+ el.actions = [make(true)];
131
+ await el.updateComplete;
132
+ release();
133
+ await new Promise(resolve => setTimeout(resolve, 10));
134
+ await el.updateComplete;
135
+ const button = el.renderRoot.querySelector('button');
136
+ expect(button.disabled || button.getAttribute('aria-disabled') === 'true').to.equal(true);
137
+ });
138
+ it('exclusive: 한 동작이 도는 동안 다른 동작은 시작하지 않는다', async () => {
139
+ configurePageActions({ exclusive: true });
140
+ let release;
141
+ let submitted = 0;
142
+ const save = { id: 'save', title: '저장', action: () => new Promise(resolve => (release = resolve)) };
143
+ const submit = { id: 'submit', title: '상신', action: () => void submitted++ };
144
+ const { el } = await barIn(1200, [save, submit]);
145
+ const [saveButton, submitButton] = Array.from(el.renderRoot.querySelectorAll('button'));
146
+ saveButton.click();
147
+ await el.updateComplete;
148
+ expect(submitButton.disabled).to.equal(true);
149
+ submitButton.click();
150
+ expect(submitted).to.equal(0);
151
+ release();
152
+ await new Promise(resolve => setTimeout(resolve, 10));
153
+ await el.updateComplete;
154
+ expect(submitButton.disabled).to.equal(false);
155
+ });
156
+ it('group: 같은 묶음끼리만 막는다', async () => {
157
+ let release;
158
+ const a = { id: 'a', title: 'A', group: 'change', action: () => new Promise(resolve => (release = resolve)) };
159
+ const b = { id: 'b', title: 'B', group: 'change', action: () => { } };
160
+ const c = { id: 'c', title: 'C', action: () => { } };
161
+ pageActionRunner.run(a);
162
+ expect(pageActionRunner.mayRun(b)).to.equal(false);
163
+ expect(pageActionRunner.mayRun(c)).to.equal(true);
164
+ release();
165
+ await new Promise(resolve => setTimeout(resolve, 10));
166
+ expect(pageActionRunner.mayRun(b)).to.equal(true);
167
+ });
168
+ it('이유가 있는 비활성 동작은 초점을 받고 누르면 실행하지 않는다', async () => {
169
+ let runs = 0;
170
+ const { el } = await barIn(1200, [{ title: '발행', disabled: true, disabledTitle: '먼저 저장하세요.', action: () => void runs++ }]);
171
+ const button = el.renderRoot.querySelector('button');
172
+ expect(button.disabled).to.equal(false);
173
+ expect(button.getAttribute('aria-disabled')).to.equal('true');
174
+ expect(button.title).to.equal('먼저 저장하세요.');
175
+ button.click();
176
+ expect(runs).to.equal(0);
177
+ });
178
+ });
179
+ //# sourceMappingURL=action-bar-contract.test.js.map