@things-factory/figure-library 10.1.312 → 10.1.314

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.312",
3
+ "version": "10.1.314",
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.29",
44
+ "@hatiolab/figure-model": "^0.12.31",
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.312",
63
- "@things-factory/setting-base": "^10.1.304",
62
+ "@things-factory/figure-viewer": "^10.1.314",
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": "b7992e0298b0b0efcf88d1649d3b21bb8ee20997"
72
+ "gitHead": "8d74df0a0618131ff17309638a6aa0affbd4c77d"
73
73
  }