@things-factory/figure-library 10.1.247 → 10.1.250
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-client/figure-library-changed.d.ts +8 -0
- package/dist-client/figure-library-changed.js +33 -0
- package/dist-client/figure-library-changed.js.map +1 -0
- package/dist-client/figure-palette.d.ts +4 -2
- package/dist-client/figure-palette.js +25 -17
- package/dist-client/figure-palette.js.map +1 -1
- package/dist-client/tsconfig.tsbuildinfo +1 -1
- package/dist-client/viewparts/figure-package-import.js +3 -0
- package/dist-client/viewparts/figure-package-import.js.map +1 -1
- package/dist-client/viewparts/figure-releases-popup.js +3 -0
- package/dist-client/viewparts/figure-releases-popup.js.map +1 -1
- package/package.json +5 -5
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const FIGURE_LIBRARY_CHANGED = "figure-library-changed";
|
|
2
|
+
/** Said after the server accepted a change to the domain's type map. */
|
|
3
|
+
export declare function announceLibraryChanged(target?: EventTarget): void;
|
|
4
|
+
/**
|
|
5
|
+
* Runs `read` on every change. Changes that arrive while a read is under way fold into one more read after it, so
|
|
6
|
+
* the last read always sees the last change and two reads never race to register the tray.
|
|
7
|
+
*/
|
|
8
|
+
export declare function keepCurrentWithLibrary(read: () => Promise<void>, target?: EventTarget): () => void;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The library's type map changed: a package was imported, a figure was archived or brought back, or another release
|
|
3
|
+
* was chosen to draw with (ADR-0114). The modeller tray was read once at boot, so a figure imported later stayed out of
|
|
4
|
+
* it until the page reloaded. Whatever changes the type map says so here, and the tray reads it again.
|
|
5
|
+
*/
|
|
6
|
+
export const FIGURE_LIBRARY_CHANGED = 'figure-library-changed';
|
|
7
|
+
/** Said after the server accepted a change to the domain's type map. */
|
|
8
|
+
export function announceLibraryChanged(target = window) {
|
|
9
|
+
target.dispatchEvent(new Event(FIGURE_LIBRARY_CHANGED));
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Runs `read` on every change. Changes that arrive while a read is under way fold into one more read after it, so
|
|
13
|
+
* the last read always sees the last change and two reads never race to register the tray.
|
|
14
|
+
*/
|
|
15
|
+
export function keepCurrentWithLibrary(read, target = window) {
|
|
16
|
+
let running;
|
|
17
|
+
let again = false;
|
|
18
|
+
const run = async () => {
|
|
19
|
+
if (running) {
|
|
20
|
+
again = true;
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
do {
|
|
24
|
+
again = false;
|
|
25
|
+
running = read().catch(() => { });
|
|
26
|
+
await running;
|
|
27
|
+
} while (again);
|
|
28
|
+
running = undefined;
|
|
29
|
+
};
|
|
30
|
+
target.addEventListener(FIGURE_LIBRARY_CHANGED, run);
|
|
31
|
+
return () => target.removeEventListener(FIGURE_LIBRARY_CHANGED, run);
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=figure-library-changed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"figure-library-changed.js","sourceRoot":"","sources":["../client/figure-library-changed.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,CAAC,MAAM,sBAAsB,GAAG,wBAAwB,CAAA;AAE9D,wEAAwE;AACxE,MAAM,UAAU,sBAAsB,CAAC,SAAsB,MAAM;IACjE,MAAM,CAAC,aAAa,CAAC,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC,CAAA;AACzD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CAAC,IAAyB,EAAE,SAAsB,MAAM;IAC5F,IAAI,OAAkC,CAAA;IACtC,IAAI,KAAK,GAAG,KAAK,CAAA;IACjB,MAAM,GAAG,GAAG,KAAK,IAAI,EAAE;QACrB,IAAI,OAAO,EAAE,CAAC;YACZ,KAAK,GAAG,IAAI,CAAA;YACZ,OAAM;QACR,CAAC;QACD,GAAG,CAAC;YACF,KAAK,GAAG,KAAK,CAAA;YACb,OAAO,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;YAChC,MAAM,OAAO,CAAA;QACf,CAAC,QAAQ,KAAK,EAAC;QACf,OAAO,GAAG,SAAS,CAAA;IACrB,CAAC,CAAA;IACD,MAAM,CAAC,gBAAgB,CAAC,sBAAsB,EAAE,GAAG,CAAC,CAAA;IACpD,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,sBAAsB,EAAE,GAAG,CAAC,CAAA;AACtE,CAAC","sourcesContent":["/*\n * The library's type map changed: a package was imported, a figure was archived or brought back, or another release\n * was chosen to draw with (ADR-0114). The modeller tray was read once at boot, so a figure imported later stayed out of\n * it until the page reloaded. Whatever changes the type map says so here, and the tray reads it again.\n */\n\nexport const FIGURE_LIBRARY_CHANGED = 'figure-library-changed'\n\n/** Said after the server accepted a change to the domain's type map. */\nexport function announceLibraryChanged(target: EventTarget = window): void {\n target.dispatchEvent(new Event(FIGURE_LIBRARY_CHANGED))\n}\n\n/**\n * Runs `read` on every change. Changes that arrive while a read is under way fold into one more read after it, so\n * the last read always sees the last change and two reads never race to register the tray.\n */\nexport function keepCurrentWithLibrary(read: () => Promise<void>, target: EventTarget = window): () => void {\n let running: Promise<void> | undefined\n let again = false\n const run = async () => {\n if (running) {\n again = true\n return\n }\n do {\n again = false\n running = read().catch(() => {})\n await running\n } while (again)\n running = undefined\n }\n target.addEventListener(FIGURE_LIBRARY_CHANGED, run)\n return () => target.removeEventListener(FIGURE_LIBRARY_CHANGED, run)\n}\n"]}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { type FigurePaletteGroup } from './figure-palette-group.js';
|
|
2
2
|
export * from './figure-palette-group.js';
|
|
3
3
|
/**
|
|
4
|
-
* Asks the type map, registers the figures that can be placed, and gives the tray its "Figure" group
|
|
5
|
-
*
|
|
4
|
+
* Asks the type map, registers the figures that can be placed, and gives the tray its "Figure" group -- now, and again
|
|
5
|
+
* whenever the library changes (an import, an archive, another release chosen), so a figure imported while the app is
|
|
6
|
+
* open is in the tray without a reload. A server with no figure library, or a user with no right to read it, gets no
|
|
7
|
+
* group and no error: the tray simply has none.
|
|
6
8
|
*/
|
|
7
9
|
export declare function registerFigurePalette(registerGroup: (group: FigurePaletteGroup) => void): Promise<void>;
|
|
@@ -9,6 +9,7 @@ import { client } from '@operato/graphql';
|
|
|
9
9
|
import { i18next } from '@operato/i18n';
|
|
10
10
|
import { getPathInfo } from '@operato/utils';
|
|
11
11
|
import { figurePaletteGroupOf, placeableFigureTypes } from './figure-palette-group.js';
|
|
12
|
+
import { keepCurrentWithLibrary } from './figure-library-changed.js';
|
|
12
13
|
export * from './figure-palette-group.js';
|
|
13
14
|
const TYPE_MAP = gql `
|
|
14
15
|
query {
|
|
@@ -27,24 +28,31 @@ const TYPE_MAP = gql `
|
|
|
27
28
|
}
|
|
28
29
|
`;
|
|
29
30
|
/**
|
|
30
|
-
* Asks the type map, registers the figures that can be placed, and gives the tray its "Figure" group
|
|
31
|
-
*
|
|
31
|
+
* Asks the type map, registers the figures that can be placed, and gives the tray its "Figure" group -- now, and again
|
|
32
|
+
* whenever the library changes (an import, an archive, another release chosen), so a figure imported while the app is
|
|
33
|
+
* open is in the tray without a reload. A server with no figure library, or a user with no right to read it, gets no
|
|
34
|
+
* group and no error: the tray simply has none.
|
|
32
35
|
*/
|
|
33
36
|
export async function registerFigurePalette(registerGroup) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
37
|
+
const read = async () => {
|
|
38
|
+
try {
|
|
39
|
+
const lines = (await client.query({ query: TYPE_MAP, fetchPolicy: 'network-only' })).data?.figureTypeMap ?? [];
|
|
40
|
+
/*
|
|
41
|
+
A figure placed from the tray must already be registered: the scene resolves types only when a board opens, and
|
|
42
|
+
a type nobody registered is placed as the stand-in that cannot move. The figure provider registers them now.
|
|
43
|
+
*/
|
|
44
|
+
const placeable = placeableFigureTypes(lines);
|
|
45
|
+
if (placeable.length)
|
|
46
|
+
await resolveUnknownTypes({ components: placeable.map(type => ({ type })) });
|
|
47
|
+
const { contextPath } = getPathInfo(location.pathname);
|
|
48
|
+
/* The modeller replaces a group registered under the same name, so a second read updates the tray in place. */
|
|
49
|
+
registerGroup(figurePaletteGroupOf(lines, { contextPath, t: (key, options) => i18next.t(key, options) }));
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
/* No figure library on this server or no right to read it: the tray has no Figure group. */
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
await read();
|
|
56
|
+
keepCurrentWithLibrary(read);
|
|
49
57
|
}
|
|
50
58
|
//# sourceMappingURL=figure-palette.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"figure-palette.js","sourceRoot":"","sources":["../client/figure-palette.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,GAAG,MAAM,aAAa,CAAA;AAE7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE5C,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAmD,MAAM,2BAA2B,CAAA;
|
|
1
|
+
{"version":3,"file":"figure-palette.js","sourceRoot":"","sources":["../client/figure-palette.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,GAAG,MAAM,aAAa,CAAA;AAE7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,eAA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IAAI,CAAC,CAAA;AAC9B,CAAC","sourcesContent":["/*\n * The figures this board server imported (ADR-0114), in a board modeller's tray. Every app whose boards place library\n * figures calls this once from its bootstrap and hands it its modeller's `registerGroup` -- the tray belongs to the\n * modeller the app uses, and an app may carry its own (fmsim).\n */\nimport gql from 'graphql-tag'\n\nimport { resolveUnknownTypes } from '@hatiolab/things-scene'\nimport { client } from '@operato/graphql'\nimport { i18next } from '@operato/i18n'\nimport { getPathInfo } from '@operato/utils'\n\nimport { figurePaletteGroupOf, placeableFigureTypes, type FigurePaletteGroup, type FigureTypeMapLine } from './figure-palette-group.js'\nimport { keepCurrentWithLibrary } from './figure-library-changed.js'\n\nexport * from './figure-palette-group.js'\n\nconst TYPE_MAP = gql`\n query {\n figureTypeMap {\n name\n release {\n ref\n name\n formatSupported\n item\n holder\n assetFormat\n dependencies\n }\n }\n }\n`\n\n/**\n * Asks the type map, registers the figures that can be placed, and gives the tray its \"Figure\" group -- now, and again\n * whenever the library changes (an import, an archive, another release chosen), so a figure imported while the app is\n * open is in the tray without a reload. A server with no figure library, or a user with no right to read it, gets no\n * group and no error: the tray simply has none.\n */\nexport async function registerFigurePalette(registerGroup: (group: FigurePaletteGroup) => void): Promise<void> {\n const read = async () => {\n try {\n const lines: FigureTypeMapLine[] = (await client.query({ query: TYPE_MAP, fetchPolicy: 'network-only' })).data?.figureTypeMap ?? []\n /*\n A figure placed from the tray must already be registered: the scene resolves types only when a board opens, and\n a type nobody registered is placed as the stand-in that cannot move. The figure provider registers them now.\n */\n const placeable = placeableFigureTypes(lines)\n if (placeable.length) await resolveUnknownTypes({ components: placeable.map(type => ({ type })) })\n\n const { contextPath } = getPathInfo(location.pathname)\n /* The modeller replaces a group registered under the same name, so a second read updates the tray in place. */\n registerGroup(figurePaletteGroupOf(lines, { contextPath, t: (key, options) => i18next.t(key, options) }))\n } catch {\n /* No figure library on this server or no right to read it: the tray has no Figure group. */\n }\n }\n await read()\n keepCurrentWithLibrary(read)\n}\n"]}
|