@things-factory/figure-library 10.1.313 → 10.1.315

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.
@@ -0,0 +1,9 @@
1
+ import './viewparts/figure-import-result.js';
2
+ import type { FigureSourceAdapter, FigureSourceItem } from '@things-factory/figure-viewer/dist-client/source-adapter.js';
3
+ import type { ImportResult } from './viewparts/figure-import-result.js';
4
+ export type LibraryCatalogItem = FigureSourceItem & {
5
+ category?: string | null;
6
+ installedVersion?: number | null;
7
+ status: 'not-installed' | 'installed' | 'newer' | 'archived' | 'format-unsupported';
8
+ };
9
+ export declare const librarySourceAdapter: FigureSourceAdapter<LibraryCatalogItem, ImportResult>;
@@ -0,0 +1,125 @@
1
+ import './viewparts/figure-import-result.js';
2
+ import gql from 'graphql-tag';
3
+ import { html } from 'lit';
4
+ import { client } from '@operato/graphql';
5
+ import { i18next } from '@operato/i18n';
6
+ import { announceLibraryChanged } from './figure-library-changed.js';
7
+ import { figureSourceThumbnailUrl } from './figure-library-file.js';
8
+ const FIELDS = 'url domain tokenSet tokenHint capabilityModule { provider version pushed error }';
9
+ const CATALOG = gql `
10
+ query ($search: String, $pagination: Pagination) {
11
+ figureSourceCatalog(search: $search, pagination: $pagination) {
12
+ items {
13
+ figureId
14
+ fullName
15
+ ref
16
+ version
17
+ name
18
+ names
19
+ category
20
+ deprecated
21
+ thumbnailHash
22
+ installedVersion
23
+ status
24
+ }
25
+ total
26
+ }
27
+ }
28
+ `;
29
+ const INSTALL = gql `
30
+ mutation ($refs: [String!]!) {
31
+ installFigures(refs: $refs) {
32
+ problems {
33
+ code
34
+ path
35
+ }
36
+ outcomes {
37
+ ref
38
+ outcome
39
+ code
40
+ differs
41
+ archived
42
+ }
43
+ }
44
+ }
45
+ `;
46
+ /** The status chip of a row: how loud it is. */
47
+ const STATUS_TONE = {
48
+ 'not-installed': 'plain',
49
+ installed: 'muted',
50
+ newer: 'warn',
51
+ archived: 'muted',
52
+ 'format-unsupported': 'crit'
53
+ };
54
+ /*
55
+ * The board server's side of the figure-server window (ADR-0114): it installs releases into this domain's library,
56
+ * through the library's own doors -- the same calls and words the window had when it lived here.
57
+ */
58
+ export const librarySourceAdapter = {
59
+ async readConnection() {
60
+ const response = await client.query({ query: gql(`query { figureLibrarySource { ${FIELDS} } }`), fetchPolicy: 'no-cache' });
61
+ return response.data?.figureLibrarySource ?? { tokenSet: false };
62
+ },
63
+ async saveConnection(patch) {
64
+ const response = await client.mutate({
65
+ mutation: gql(`mutation ($patch: FigureSourceSettingPatch!) { updateFigureLibrarySource(patch: $patch) { ${FIELDS} } }`),
66
+ variables: { patch }
67
+ });
68
+ if (response.errors?.length)
69
+ throw new Error(response.errors[0].message);
70
+ return response.data.updateFigureLibrarySource;
71
+ },
72
+ async checkConnection() {
73
+ const response = await client.mutate({ mutation: gql `mutation { checkFigureLibrarySource { ok code message total } }` });
74
+ const answer = response.data.checkFigureLibrarySource;
75
+ return { ok: answer.ok, total: answer.total, message: answer.message ?? answer.code };
76
+ },
77
+ async catalog({ search, page, limit }) {
78
+ const response = await client.query({ query: CATALOG, fetchPolicy: 'no-cache', variables: { search, pagination: { page, limit } } });
79
+ if (response.errors?.length)
80
+ throw new Error(response.errors[0].message);
81
+ return response.data.figureSourceCatalog;
82
+ },
83
+ async install(items) {
84
+ try {
85
+ const response = await client.mutate({ mutation: INSTALL, variables: { refs: items.map(item => item.ref) } });
86
+ if (response.errors?.length)
87
+ throw new Error(response.errors[0].message);
88
+ const result = response.data.installFigures;
89
+ if (result.outcomes.some(one => one.outcome === 'added'))
90
+ announceLibraryChanged();
91
+ return result;
92
+ }
93
+ catch (e) {
94
+ return { problems: [{ code: e?.message ?? 'error' }], outcomes: [] };
95
+ }
96
+ },
97
+ thumbnailUrl: item => (item.thumbnailHash ? figureSourceThumbnailUrl(item.figureId, item.thumbnailHash) : null),
98
+ status: item => ({ label: i18next.t(`figure-library.source-status.${item.status}`), tone: STATUS_TONE[item.status] }),
99
+ version: item => item.installedVersion && item.installedVersion !== item.version
100
+ ? i18next.t('figure-library.text.source-version-here', { version: item.version, here: item.installedVersion })
101
+ : i18next.t('figure-library.text.source-version', { version: item.version }),
102
+ renderResult: result => html `<figure-import-result .result=${result}></figure-import-result>`,
103
+ changed: result => !!result.outcomes?.some(one => one.outcome === 'added'),
104
+ /*
105
+ This app's capability module on the linked domain (ADR-0172 amendment 1): pushed when the link is saved or checked
106
+ and when the server starts. A push that failed is said here; the app works on.
107
+ */
108
+ renderConnectionNote(connection) {
109
+ const push = connection.capabilityModule;
110
+ if (!push)
111
+ return undefined;
112
+ const { provider, version } = push;
113
+ const style = 'text-transform: none; font-size: var(--ui-t-small, 11.5px); color: var(--md-sys-color-on-surface-variant);';
114
+ if (push.error)
115
+ return html `<small style="${style} color: var(--ui-crit, var(--md-sys-color-error));" role="status"
116
+ >${i18next.t('figure-library.setting.capability-push-failed', { provider, version, reason: push.error })}</small
117
+ >`;
118
+ return html `<small style=${style}
119
+ >${push.pushed
120
+ ? i18next.t('figure-library.setting.capability-pushed', { provider, version })
121
+ : i18next.t('figure-library.setting.capability-not-pushed', { provider, version })}</small
122
+ >`;
123
+ }
124
+ };
125
+ //# sourceMappingURL=library-source-adapter.js.map
@@ -5,7 +5,7 @@ import '@operato/data-grist/ox-card-thumb.js';
5
5
  import '@things-factory/figure-viewer/dist-client/figure-thumb-mark.js';
6
6
  import '../viewparts/figure-releases-popup.js';
7
7
  import '../viewparts/figure-package-import.js';
8
- import '../viewparts/figure-source-install.js';
8
+ import '@things-factory/figure-viewer/dist-client/source-install.js';
9
9
  import { PageView } from '@operato/shell';
10
10
  declare const FigureLibraryPage_base: (new (...args: any[]) => import("lit").LitElement) & typeof PageView;
11
11
  export declare class FigureLibraryPage extends FigureLibraryPage_base {
@@ -6,7 +6,7 @@ import '@operato/data-grist/ox-card-thumb.js';
6
6
  import '@things-factory/figure-viewer/dist-client/figure-thumb-mark.js';
7
7
  import '../viewparts/figure-releases-popup.js';
8
8
  import '../viewparts/figure-package-import.js';
9
- import '../viewparts/figure-source-install.js';
9
+ import '@things-factory/figure-viewer/dist-client/source-install.js';
10
10
  import { versionText } from '../viewparts/figure-version.js';
11
11
  import gql from 'graphql-tag';
12
12
  import { css, html, nothing } from 'lit';
@@ -18,6 +18,7 @@ import { openPopup } from '@operato/popup';
18
18
  import { PageView } from '@operato/shell';
19
19
  import { CardCatalogStyles, CommonGristStyles, CommonHeaderStyles, ScrollbarStyles, WorkSurfacePageStyles } from '@operato/styles';
20
20
  import { figureLibraryFileUrl, figureSourceOnLibrary } from '../figure-library-file.js';
21
+ import { librarySourceAdapter } from '../library-source-adapter.js';
21
22
  /*
22
23
  * The board server's figures (ADR-0114, amended 2026-10-12), as a card catalogue with the board catalog's card: the
23
24
  * thumbnail, the name, and one line - the full name and the version it draws with. The one thing to know before opening
@@ -324,6 +325,8 @@ let FigureLibraryPage = class FigureLibraryPage extends localize(i18next)(PageVi
324
325
  }
325
326
  openSourceInstall() {
326
327
  const popup = openPopup(html `<figure-source-install
328
+ .adapter=${librarySourceAdapter}
329
+ .holdsConnection=${figureSourceOnLibrary()}
327
330
  @imported=${async () => {
328
331
  await this.configure();
329
332
  this.grist.fetch();
@@ -1,28 +1,16 @@
1
- import '@material/web/button/outlined-button.js';
2
- import '@material/web/button/text-button.js';
3
- import '@things-factory/setting-base';
1
+ import '@things-factory/figure-viewer/dist-client/source-connection.js';
4
2
  import { LitElement, nothing } from 'lit';
5
3
  declare const FigureSourceSettingLet_base: (new (...args: any[]) => LitElement) & typeof LitElement;
6
4
  /**
7
- * 「피규어 서버 연결」 (ADR-0114 decision 21) - the figure server this domain installs figures from: its address, the
8
- * domain on it and the access token it issued. Domain attributes, so shown to whoever may change them (privilege
9
- * `env-var`). The token is never read back - the card says whether it is set, and a new one replaces it.
5
+ * 「피규어 서버 연결」 (ADR-0114 decision 21) - the figure server this domain installs figures from. The card is the
6
+ * shared one (figure-viewer, ADR-0231 decision 15), reading and writing the library's connection. Domain attributes,
7
+ * so shown to whoever may change them (privilege `env-var`).
10
8
  */
11
9
  export declare class FigureSourceSettingLet extends FigureSourceSettingLet_base {
12
- static styles: import("lit").CSSResult[];
13
- /** Set by a host that has already decided this person keeps the connection (the install window on the library). */
10
+ /** Set by a host that has already decided this person keeps the connection. */
14
11
  editable: boolean;
15
12
  private keeps;
16
- private draft;
17
- private checking;
18
- private checked?;
19
- private settingRead;
20
- private saving;
21
13
  connectedCallback(): Promise<void>;
22
- private get setting();
23
14
  render(): import("lit-html").TemplateResult<1> | typeof nothing;
24
- private renderCapabilityModule;
25
- private check;
26
- private save;
27
15
  }
28
16
  export {};
@@ -1,211 +1,28 @@
1
1
  import { __decorate, __metadata } from "tslib";
2
- import '@material/web/button/outlined-button.js';
3
- import '@material/web/button/text-button.js';
4
- import '@things-factory/setting-base';
5
- import gql from 'graphql-tag';
6
- import { css, html, LitElement, nothing } from 'lit';
2
+ import '@things-factory/figure-viewer/dist-client/source-connection.js';
3
+ import { html, LitElement, nothing } from 'lit';
7
4
  import { customElement, property, state } from 'lit/decorators.js';
8
- import { client, MutationController, QueryController } from '@operato/graphql';
9
5
  import { i18next, localize } from '@operato/i18n';
10
- import { notify } from '@operato/layout';
11
- import { FieldHintStyles } from '@operato/styles';
12
6
  import { hasPrivilege } from '@things-factory/auth-base/dist-client';
13
- const FIELDS = 'url domain tokenSet tokenHint capabilityModule { provider version pushed error }';
7
+ import { librarySourceAdapter } from '../library-source-adapter.js';
14
8
  /**
15
- * 「피규어 서버 연결」 (ADR-0114 decision 21) - the figure server this domain installs figures from: its address, the
16
- * domain on it and the access token it issued. Domain attributes, so shown to whoever may change them (privilege
17
- * `env-var`). The token is never read back - the card says whether it is set, and a new one replaces it.
9
+ * 「피규어 서버 연결」 (ADR-0114 decision 21) - the figure server this domain installs figures from. The card is the
10
+ * shared one (figure-viewer, ADR-0231 decision 15), reading and writing the library's connection. Domain attributes,
11
+ * so shown to whoever may change them (privilege `env-var`).
18
12
  */
19
13
  let FigureSourceSettingLet = class FigureSourceSettingLet extends localize(i18next)(LitElement) {
20
14
  constructor() {
21
15
  super(...arguments);
22
- /** Set by a host that has already decided this person keeps the connection (the install window on the library). */
16
+ /** Set by a host that has already decided this person keeps the connection. */
23
17
  this.editable = false;
24
18
  this.keeps = false;
25
- this.draft = {};
26
- this.checking = false;
27
- this.settingRead = new QueryController(this, gql(`query { figureLibrarySource { ${FIELDS} } }`), {
28
- variables: () => (this.keeps ? {} : undefined)
29
- });
30
- this.saving = new MutationController(this, gql(`mutation ($patch: FigureSourceSettingPatch!) { updateFigureLibrarySource(patch: $patch) { ${FIELDS} } }`), { refetch: () => [this.settingRead] });
31
19
  }
32
- static { this.styles = [
33
- FieldHintStyles,
34
- css `
35
- div[content] {
36
- display: grid;
37
- grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
38
- align-items: start;
39
- gap: var(--spacing-medium, 8px) var(--spacing-large, 12px);
40
- }
41
- @media (max-width: 600px) {
42
- div[content] {
43
- grid-template-columns: minmax(0, 1fr);
44
- }
45
- }
46
- label {
47
- display: flex;
48
- flex-direction: column;
49
- gap: var(--spacing-small, 4px);
50
- font: var(--label-font);
51
- color: var(--md-sys-color-on-surface);
52
- text-transform: var(--label-text-transform);
53
- }
54
- label.wide {
55
- grid-column: 1 / -1;
56
- }
57
- input {
58
- box-sizing: border-box;
59
- width: 100%;
60
- height: var(--form-element-height-medium, 32px);
61
- background-color: var(--input-field-background, var(--md-sys-color-surface-container-highest));
62
- color: var(--input-field-color, var(--md-sys-color-on-surface));
63
- border: var(--border-dim-color);
64
- border-radius: var(--border-radius);
65
- padding: var(--input-padding);
66
- font: var(--input-font);
67
- text-transform: none;
68
- }
69
- div[actions] {
70
- grid-column: 1 / -1;
71
- display: flex;
72
- justify-content: flex-end;
73
- align-items: center;
74
- gap: var(--spacing-small, 4px);
75
- }
76
- [checked] {
77
- margin-right: auto;
78
- font-size: var(--ui-t-small, 11.5px);
79
- }
80
- small[missing] {
81
- color: var(--ui-warn, #b26b00);
82
- }
83
- [checked][failed],
84
- small[capability][failed] {
85
- color: var(--ui-crit, var(--md-sys-color-error));
86
- }
87
- small[capability] {
88
- grid-column: 1 / -1;
89
- /* A provider name is lower-case by rule: the card's capitalised words must not reach it. */
90
- text-transform: none;
91
- font-size: var(--ui-t-small, 11.5px);
92
- color: var(--md-sys-color-on-surface-variant);
93
- }
94
- `
95
- ]; }
96
20
  async connectedCallback() {
97
21
  super.connectedCallback();
98
22
  this.keeps = this.editable || !!(await hasPrivilege({ category: 'env-var', privilege: 'mutation', domainOwnerGranted: true }));
99
23
  }
100
- get setting() {
101
- return this.settingRead.data?.figureLibrarySource || undefined;
102
- }
103
24
  render() {
104
- const setting = this.setting;
105
- if (!setting)
106
- return nothing;
107
- const busy = this.saving.pending;
108
- const value = (name) => this.draft[name] ?? setting[name] ?? '';
109
- /* Once any part is saved, a part still empty says the connection waits for it - an example is not a value. */
110
- const begun = !!(setting.url || setting.domain || setting.tokenSet);
111
- const missing = (name) => begun && !setting[name] ? html `<small class="hint" missing>${i18next.t('figure-library.setting.missing')}</small>` : nothing;
112
- const set = (name, text) => (this.draft = { ...this.draft, [name]: text });
113
- return html `
114
- <setting-let>
115
- <span slot="title">${i18next.t('figure-library.setting.title')}</span>
116
- <div slot="content" content>
117
- <label
118
- >${i18next.t('figure-library.setting.url')}
119
- <input type="url" autocomplete="off" placeholder=${i18next.t('figure-library.setting.example', { value: 'https://figure.hatiolab.com' })}
120
- .value=${value('url')}
121
- ?disabled=${busy}
122
- @input=${(e) => set('url', e.target.value)}
123
- />${missing('url')}</label
124
- >
125
- <label
126
- >${i18next.t('figure-library.setting.domain')}
127
- <input autocomplete="off" placeholder=${i18next.t('figure-library.setting.example', { value: 'system' })}
128
- .value=${value('domain')}
129
- ?disabled=${busy}
130
- @input=${(e) => set('domain', e.target.value)}
131
- />${missing('domain')}</label
132
- >
133
- <label class="wide"
134
- >${i18next.t('figure-library.setting.token')}
135
- <input type="password" autocomplete="off" .value=${this.draft.token ?? ''} ?disabled=${busy} @input=${(e) => set('token', e.target.value)} />
136
- <small class="hint"
137
- >${setting.tokenSet
138
- ? i18next.t('figure-library.setting.token-set', { hint: setting.tokenHint ?? '' })
139
- : i18next.t('figure-library.setting.token-unset')}</small
140
- ></label
141
- >
142
- ${this.renderCapabilityModule(setting.capabilityModule)}
143
- <div actions>
144
- ${this.checked ? html `<span checked ?failed=${!this.checked.ok} role="status">${this.checked.text}</span>` : nothing}
145
- <md-text-button ?disabled=${busy || this.checking || !setting.url || !setting.tokenSet} @click=${() => this.check()}
146
- >${i18next.t('figure-library.setting.check')}</md-text-button
147
- >
148
- <md-outlined-button ?disabled=${busy || !Object.keys(this.draft).length} @click=${() => this.save()}>${i18next.t('figure-library.button.save')}</md-outlined-button>
149
- </div>
150
- </div>
151
- </setting-let>
152
- `;
153
- }
154
- /*
155
- This app's capability module on the linked domain (ADR-0172 amendment 1): pushed when the link is saved or checked
156
- and when the server starts. A push that failed is said here; the app works on.
157
- */
158
- renderCapabilityModule(push) {
159
- if (!push)
160
- return nothing;
161
- const { provider, version } = push;
162
- if (push.error)
163
- return html `<small capability failed role="status">${i18next.t('figure-library.setting.capability-push-failed', { provider, version, reason: push.error })}</small>`;
164
- if (push.pushed)
165
- return html `<small capability>${i18next.t('figure-library.setting.capability-pushed', { provider, version })}</small>`;
166
- return html `<small capability>${i18next.t('figure-library.setting.capability-not-pushed', { provider, version })}</small>`;
167
- }
168
- /* One catalog row asked with the saved setting: the answer says what to fix. */
169
- async check() {
170
- this.checking = true;
171
- this.checked = undefined;
172
- try {
173
- const response = await client.mutate({
174
- mutation: gql `
175
- mutation {
176
- checkFigureLibrarySource {
177
- ok
178
- code
179
- message
180
- total
181
- }
182
- }
183
- `
184
- });
185
- const answer = response.data.checkFigureLibrarySource;
186
- /* The check pushes the capability module too: read where it stands again. */
187
- this.settingRead.refetch?.();
188
- this.checked = answer.ok
189
- ? { ok: true, text: i18next.t('figure-library.setting.check-ok', { count: answer.total ?? 0 }) }
190
- : { ok: false, text: answer.message ?? answer.code };
191
- }
192
- catch (e) {
193
- this.checked = { ok: false, text: e?.message ?? String(e) };
194
- }
195
- finally {
196
- this.checking = false;
197
- }
198
- }
199
- async save() {
200
- /* A token left blank stays as it is - the card never holds the token it read. */
201
- const { token, ...rest } = this.draft;
202
- const patch = { ...rest, ...(token?.trim() ? { token } : {}) };
203
- if (!(await this.saving.run({ patch })))
204
- return;
205
- this.draft = {};
206
- this.checked = undefined;
207
- notify({ message: i18next.t('figure-library.setting.saved') });
208
- this.dispatchEvent(new CustomEvent('saved', { bubbles: true, composed: true }));
25
+ return this.keeps ? html `<figure-source-connection .adapter=${librarySourceAdapter}></figure-source-connection>` : nothing;
209
26
  }
210
27
  };
211
28
  __decorate([
@@ -216,18 +33,6 @@ __decorate([
216
33
  state(),
217
34
  __metadata("design:type", Object)
218
35
  ], FigureSourceSettingLet.prototype, "keeps", void 0);
219
- __decorate([
220
- state(),
221
- __metadata("design:type", Object)
222
- ], FigureSourceSettingLet.prototype, "draft", void 0);
223
- __decorate([
224
- state(),
225
- __metadata("design:type", Object)
226
- ], FigureSourceSettingLet.prototype, "checking", void 0);
227
- __decorate([
228
- state(),
229
- __metadata("design:type", Object)
230
- ], FigureSourceSettingLet.prototype, "checked", void 0);
231
36
  FigureSourceSettingLet = __decorate([
232
37
  customElement('figure-source-setting-let')
233
38
  ], FigureSourceSettingLet);
@@ -21,7 +21,7 @@ export * from './source/source-client';
21
21
  export * from './source/source-install';
22
22
  export * from './source/figure-source-resolver';
23
23
  export * from './source/capability-push';
24
- export declare const entities: (typeof FigureTypeMapEntry | typeof FigureLibraryRelease)[];
24
+ export declare const entities: (typeof FigureLibraryRelease | typeof FigureTypeMapEntry)[];
25
25
  export declare const schema: {
26
26
  resolverClasses: (typeof FigureSourceResolver | typeof FigureLibraryResolver)[];
27
27
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/figure-library",
3
- "version": "10.1.313",
3
+ "version": "10.1.315",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "dist-client/index.js",
6
6
  "files": [
@@ -41,7 +41,7 @@
41
41
  "test": "node --import ./test/resolve-ts-siblings.mjs --test test/*.test.ts"
42
42
  },
43
43
  "dependencies": {
44
- "@hatiolab/figure-model": "^0.12.30",
44
+ "@hatiolab/figure-model": "^0.12.32",
45
45
  "@hatiolab/things-scene": "^10.1.123",
46
46
  "@material/web": "^2.0.0",
47
47
  "@operato/data-grist": "^10.29.69",
@@ -55,12 +55,12 @@
55
55
  "@operato/slot-layout-editor": "^10.29.87",
56
56
  "@operato/styles": "^10.29.23",
57
57
  "@operato/utils": "^10.0.0",
58
- "@things-factory/attachment-base": "^10.1.304",
59
- "@things-factory/auth-base": "^10.1.304",
60
- "@things-factory/board-service": "^10.1.305",
58
+ "@things-factory/attachment-base": "^10.1.314",
59
+ "@things-factory/auth-base": "^10.1.314",
60
+ "@things-factory/board-service": "^10.1.314",
61
61
  "@things-factory/env": "^10.1.298",
62
- "@things-factory/figure-viewer": "^10.1.313",
63
- "@things-factory/setting-base": "^10.1.304",
62
+ "@things-factory/figure-viewer": "^10.1.315",
63
+ "@things-factory/setting-base": "^10.1.314",
64
64
  "@things-factory/shell": "^10.1.304",
65
65
  "graphql-scalars": "^1.22.4",
66
66
  "graphql-tag": "^2.12.6",
@@ -69,5 +69,5 @@
69
69
  "koa-router": "^7.4.0",
70
70
  "lit": "^3.1.2"
71
71
  },
72
- "gitHead": "dd6234d77e322c6de3f2a264b157ac6428189edc"
72
+ "gitHead": "69d8495a54f4c1f91276b66cb50fe7d7cdda8f3f"
73
73
  }
@@ -1,31 +0,0 @@
1
- import '@material/web/button/text-button.js';
2
- import '@material/web/button/filled-button.js';
3
- import '@operato/popup/ox-popup-actions.js';
4
- import './figure-import-result.js';
5
- import '../settings/figure-source-setting-let.js';
6
- import { LitElement } from 'lit';
7
- declare const FigureSourceInstall_base: (new (...args: any[]) => LitElement) & typeof LitElement;
8
- export declare class FigureSourceInstall extends FigureSourceInstall_base {
9
- static styles: import("lit").CSSResult[];
10
- private search;
11
- private items;
12
- private total;
13
- private reading;
14
- private installing;
15
- private failure;
16
- private chosen;
17
- private result?;
18
- /** The connection, when this window holds it (setFigureSourceOnLibrary). */
19
- private source?;
20
- private connecting;
21
- connectedCallback(): void;
22
- private get connected();
23
- private readSource;
24
- private renderConnection;
25
- render(): import("lit-html").TemplateResult<1>;
26
- private renderItem;
27
- private choose;
28
- private read;
29
- private install;
30
- }
31
- export {};
@@ -1,393 +0,0 @@
1
- import { __decorate, __metadata } from "tslib";
2
- import '@material/web/button/text-button.js';
3
- import '@material/web/button/filled-button.js';
4
- import '@operato/popup/ox-popup-actions.js';
5
- import './figure-import-result.js';
6
- import '../settings/figure-source-setting-let.js';
7
- import gql from 'graphql-tag';
8
- import { css, html, LitElement, nothing } from 'lit';
9
- import { customElement, state } from 'lit/decorators.js';
10
- import { client } from '@operato/graphql';
11
- import { i18next, localize } from '@operato/i18n';
12
- import { CommonPopupStyles, FormFieldStyles, PopupBodyStyles, PopupFieldStyles } from '@operato/styles';
13
- import { announceLibraryChanged } from '../figure-library-changed.js';
14
- import { figureSourceOnLibrary, figureSourceThumbnailUrl } from '../figure-library-file.js';
15
- const SOURCE = gql `
16
- query {
17
- figureLibrarySource {
18
- url
19
- domain
20
- tokenSet
21
- }
22
- }
23
- `;
24
- /** How many figures one read brings; 「더 보기」 reads the next. */
25
- const PAGE = 50;
26
- const CATALOG = gql `
27
- query ($search: String, $pagination: Pagination) {
28
- figureSourceCatalog(search: $search, pagination: $pagination) {
29
- items {
30
- figureId
31
- fullName
32
- ref
33
- version
34
- name
35
- names
36
- category
37
- deprecated
38
- thumbnailHash
39
- installedVersion
40
- status
41
- }
42
- total
43
- }
44
- }
45
- `;
46
- const INSTALL = gql `
47
- mutation ($refs: [String!]!) {
48
- installFigures(refs: $refs) {
49
- problems {
50
- code
51
- path
52
- }
53
- outcomes {
54
- ref
55
- outcome
56
- code
57
- differs
58
- archived
59
- }
60
- }
61
- }
62
- `;
63
- /** The status chip of a row: its words and how loud it is. */
64
- const STATUS_TONE = {
65
- 'not-installed': 'plain',
66
- installed: 'muted',
67
- newer: 'warn',
68
- archived: 'muted',
69
- 'format-unsupported': 'crit'
70
- };
71
- /*
72
- * Installing figures straight from the figure server set in Settings (ADR-0114 amendment 2026-11-14). The board server
73
- * reads the figure server's catalog and installs the chosen releases through the same import a package file goes
74
- * through, so the result reads as a file import's does. The browser never talks to the figure server: the catalog, the
75
- * pictures and the install are this server's doors.
76
- *
77
- * In an app with no Settings screen (`setFigureSourceOnLibrary`) the window also holds the connection: the connection
78
- * card while none is set, and the server it installs from with 「연결 바꾸기」 once it is.
79
- */
80
- let FigureSourceInstall = class FigureSourceInstall extends localize(i18next)(LitElement) {
81
- constructor() {
82
- super(...arguments);
83
- this.search = '';
84
- this.items = [];
85
- this.total = 0;
86
- this.reading = false;
87
- this.installing = false;
88
- this.failure = '';
89
- this.chosen = new Set();
90
- this.connecting = false;
91
- }
92
- static { this.styles = [
93
- CommonPopupStyles,
94
- PopupBodyStyles,
95
- FormFieldStyles,
96
- PopupFieldStyles,
97
- css `
98
- ul[figures] {
99
- list-style: none;
100
- margin: 0;
101
- padding: 0;
102
- display: flex;
103
- flex-direction: column;
104
- }
105
- ul[figures] li {
106
- display: grid;
107
- grid-template-columns: auto 48px minmax(0, 1fr) auto;
108
- align-items: center;
109
- gap: var(--spacing-medium, 8px);
110
- padding: var(--spacing-small, 4px) 0;
111
- border-bottom: 1px solid var(--ui-line-soft, var(--md-sys-color-surface-container));
112
- }
113
- [thumb] {
114
- width: 48px;
115
- height: 36px;
116
- object-fit: contain;
117
- border-radius: var(--border-radius, 4px);
118
- background: var(--ui-line-soft, var(--md-sys-color-surface-container));
119
- }
120
- [title] {
121
- display: flex;
122
- flex-direction: column;
123
- min-width: 0;
124
- }
125
- [title] strong,
126
- [title] small {
127
- overflow: hidden;
128
- text-overflow: ellipsis;
129
- white-space: nowrap;
130
- }
131
- [title] small {
132
- color: var(--ui-muted);
133
- font-family: var(--ui-mono, monospace);
134
- font-size: var(--ui-t-small, 11.5px);
135
- }
136
- [chips] {
137
- display: flex;
138
- gap: var(--spacing-small, 4px);
139
- justify-content: flex-end;
140
- flex-wrap: wrap;
141
- }
142
- [chip] {
143
- padding: 1px 6px;
144
- border-radius: 999px;
145
- font-size: var(--ui-t-small, 11.5px);
146
- white-space: nowrap;
147
- border: 1px solid currentColor;
148
- }
149
- [chip='plain'] {
150
- color: var(--ui-ink, var(--md-sys-color-on-surface));
151
- }
152
- [chip='muted'] {
153
- color: var(--ui-muted);
154
- }
155
- [chip='warn'] {
156
- color: var(--ui-warn, #b26b00);
157
- }
158
- [chip='crit'] {
159
- color: var(--ui-crit, var(--md-sys-color-error));
160
- }
161
- [refused] {
162
- color: var(--ui-crit, var(--md-sys-color-error));
163
- margin: 0;
164
- }
165
- [more] {
166
- align-self: center;
167
- }
168
- [connection] {
169
- display: flex;
170
- align-items: center;
171
- gap: var(--spacing-small, 4px);
172
- color: var(--ui-muted);
173
- font-size: var(--ui-t-small, 11.5px);
174
- }
175
- [connection] md-text-button {
176
- margin-left: auto;
177
- }
178
- `
179
- ]; }
180
- connectedCallback() {
181
- super.connectedCallback();
182
- figureSourceOnLibrary() ? this.readSource() : this.read(true);
183
- }
184
- get connected() {
185
- return !!(this.source?.url && this.source?.domain && this.source?.tokenSet);
186
- }
187
- /* The connection this window holds: the catalog is read once it is complete. */
188
- async readSource() {
189
- try {
190
- const response = await client.query({ query: SOURCE, fetchPolicy: 'no-cache' });
191
- this.source = response.data?.figureLibrarySource ?? { tokenSet: false };
192
- }
193
- catch {
194
- this.source = { tokenSet: false };
195
- }
196
- this.connecting = !this.connected;
197
- if (this.connected)
198
- await this.read(true);
199
- }
200
- renderConnection() {
201
- if (!figureSourceOnLibrary() || !this.source)
202
- return nothing;
203
- const host = this.source.url ? this.source.url.replace(/^https?:\/\//, '') : '';
204
- return html `
205
- ${this.connected
206
- ? html `<div connection>
207
- <span>${host} · ${this.source.domain}</span>
208
- <md-text-button @click=${() => (this.connecting = !this.connecting)}>${i18next.t('figure-library.button.change-source')}</md-text-button>
209
- </div>`
210
- : nothing}
211
- ${this.connecting
212
- ? html `<figure-source-setting-let
213
- editable
214
- @saved=${(e) => {
215
- e.stopPropagation();
216
- this.readSource();
217
- }}
218
- ></figure-source-setting-let>`
219
- : nothing}
220
- `;
221
- }
222
- render() {
223
- const count = this.chosen.size;
224
- if (figureSourceOnLibrary() && !this.connected) {
225
- return html `
226
- <div class="body">${this.renderConnection()}</div>
227
- <ox-popup-actions>
228
- <md-text-button slot="cancel" @click=${() => this.dispatchEvent(new CustomEvent('close'))}>${i18next.t('figure-library.button.close')}</md-text-button>
229
- </ox-popup-actions>
230
- `;
231
- }
232
- return html `
233
- <div class="body">
234
- ${this.renderConnection()}
235
- <label class="field">
236
- <span>${i18next.t('figure-library.label.search-source')}</span>
237
- <input
238
- type="search"
239
- .value=${this.search}
240
- placeholder=${i18next.t('figure-library.text.search')}
241
- @change=${(e) => {
242
- this.search = e.target.value.trim();
243
- this.read(true);
244
- }}
245
- />
246
- </label>
247
-
248
- ${this.failure ? html `<p refused role="alert">${this.failure}</p>` : nothing}
249
- ${!this.failure && !this.reading && !this.items.length ? html `<div class="note">${i18next.t('figure-library.text.source-empty')}</div>` : nothing}
250
-
251
- <ul figures>
252
- ${this.items.map(item => this.renderItem(item))}
253
- </ul>
254
- ${this.items.length < this.total
255
- ? html `<md-text-button more ?disabled=${this.reading} @click=${() => this.read(false)}>${i18next.t('figure-library.button.more')}</md-text-button>`
256
- : nothing}
257
-
258
- <figure-import-result .result=${this.result}></figure-import-result>
259
- </div>
260
-
261
- <ox-popup-actions>
262
- <md-text-button slot="cancel" @click=${() => this.dispatchEvent(new CustomEvent('close'))}>${i18next.t('figure-library.button.close')}</md-text-button>
263
- <md-filled-button slot="confirm" ?disabled=${!count || this.installing} @click=${() => this.install()}>
264
- ${i18next.t('figure-library.button.install', { count })}
265
- </md-filled-button>
266
- </ox-popup-actions>
267
- `;
268
- }
269
- renderItem(item) {
270
- const name = item.names?.[i18next.language] ?? item.name ?? item.fullName;
271
- const picture = item.thumbnailHash ? figureSourceThumbnailUrl(item.figureId, item.thumbnailHash) : null;
272
- const version = item.installedVersion && item.installedVersion !== item.version
273
- ? i18next.t('figure-library.text.source-version-here', { version: item.version, here: item.installedVersion })
274
- : i18next.t('figure-library.text.source-version', { version: item.version });
275
- return html `<li>
276
- <input
277
- type="checkbox"
278
- aria-label=${name}
279
- .checked=${this.chosen.has(item.ref)}
280
- ?disabled=${this.installing}
281
- @change=${(e) => this.choose(item.ref, e.target.checked)}
282
- />
283
- ${picture ? html `<img thumb src=${picture} alt="" loading="lazy" />` : html `<span thumb></span>`}
284
- <span title>
285
- <strong>${name}</strong>
286
- <small>${item.fullName} · ${version}</small>
287
- </span>
288
- <span chips>
289
- ${item.deprecated ? html `<span chip="muted">${i18next.t('figure-library.text.deprecated')}</span>` : nothing}
290
- <span chip=${STATUS_TONE[item.status]}>${i18next.t(`figure-library.source-status.${item.status}`)}</span>
291
- </span>
292
- </li>`;
293
- }
294
- choose(ref, on) {
295
- const next = new Set(this.chosen);
296
- on ? next.add(ref) : next.delete(ref);
297
- this.chosen = next;
298
- }
299
- async read(fresh) {
300
- this.reading = true;
301
- this.failure = '';
302
- const page = fresh ? 1 : Math.floor(this.items.length / PAGE) + 1;
303
- try {
304
- const response = await client.query({
305
- query: CATALOG,
306
- fetchPolicy: 'no-cache',
307
- variables: {
308
- search: this.search || null,
309
- pagination: { page, limit: PAGE }
310
- }
311
- });
312
- if (response.errors?.length)
313
- throw new Error(response.errors[0].message);
314
- const { items, total } = response.data.figureSourceCatalog;
315
- this.items = fresh ? items : [...this.items, ...items];
316
- this.total = total;
317
- }
318
- catch (e) {
319
- this.failure = e?.message ?? String(e);
320
- if (fresh)
321
- this.items = [];
322
- }
323
- finally {
324
- this.reading = false;
325
- }
326
- }
327
- async install() {
328
- this.installing = true;
329
- this.result = undefined;
330
- try {
331
- const response = await client.mutate({ mutation: INSTALL, variables: { refs: [...this.chosen] } });
332
- if (response.errors?.length)
333
- throw new Error(response.errors[0].message);
334
- this.result = response.data.installFigures;
335
- if (this.result.outcomes.some(one => one.outcome === 'added'))
336
- announceLibraryChanged();
337
- this.chosen = new Set();
338
- this.dispatchEvent(new CustomEvent('imported', { detail: this.result }));
339
- await this.read(true);
340
- }
341
- catch (e) {
342
- this.result = { problems: [{ code: e?.message ?? 'error' }], outcomes: [] };
343
- }
344
- finally {
345
- this.installing = false;
346
- }
347
- }
348
- };
349
- __decorate([
350
- state(),
351
- __metadata("design:type", Object)
352
- ], FigureSourceInstall.prototype, "search", void 0);
353
- __decorate([
354
- state(),
355
- __metadata("design:type", Array)
356
- ], FigureSourceInstall.prototype, "items", void 0);
357
- __decorate([
358
- state(),
359
- __metadata("design:type", Object)
360
- ], FigureSourceInstall.prototype, "total", void 0);
361
- __decorate([
362
- state(),
363
- __metadata("design:type", Object)
364
- ], FigureSourceInstall.prototype, "reading", void 0);
365
- __decorate([
366
- state(),
367
- __metadata("design:type", Object)
368
- ], FigureSourceInstall.prototype, "installing", void 0);
369
- __decorate([
370
- state(),
371
- __metadata("design:type", Object)
372
- ], FigureSourceInstall.prototype, "failure", void 0);
373
- __decorate([
374
- state(),
375
- __metadata("design:type", Object)
376
- ], FigureSourceInstall.prototype, "chosen", void 0);
377
- __decorate([
378
- state(),
379
- __metadata("design:type", Object)
380
- ], FigureSourceInstall.prototype, "result", void 0);
381
- __decorate([
382
- state(),
383
- __metadata("design:type", Object)
384
- ], FigureSourceInstall.prototype, "source", void 0);
385
- __decorate([
386
- state(),
387
- __metadata("design:type", Object)
388
- ], FigureSourceInstall.prototype, "connecting", void 0);
389
- FigureSourceInstall = __decorate([
390
- customElement('figure-source-install')
391
- ], FigureSourceInstall);
392
- export { FigureSourceInstall };
393
- //# sourceMappingURL=figure-source-install.js.map