@operato/board 10.17.0 → 10.20.0
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/CHANGELOG.md +22 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +191 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +210 -0
- package/coverage/lcov.info +3383 -0
- package/dist/src/board-provider.js +9 -3
- package/dist/src/board-provider.js.map +1 -1
- package/dist/src/figure-provider.d.ts +15 -0
- package/dist/src/figure-provider.js +98 -0
- package/dist/src/figure-provider.js.map +1 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.js +10 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/modeller/scene-viewer/ox-scene-viewer.d.ts +1 -1
- package/dist/src/modeller/scene-viewer/ox-scene-viewer.js +10 -4
- package/dist/src/modeller/scene-viewer/ox-scene-viewer.js.map +1 -1
- package/dist/src/ox-board-preview.js +13 -6
- package/dist/src/ox-board-preview.js.map +1 -1
- package/dist/src/ox-board-template-viewer.d.ts +1 -1
- package/dist/src/ox-board-template-viewer.js +12 -6
- package/dist/src/ox-board-template-viewer.js.map +1 -1
- package/dist/src/ox-board-viewer.d.ts +1 -1
- package/dist/src/ox-board-viewer.js +13 -7
- package/dist/src/ox-board-viewer.js.map +1 -1
- package/dist/src/player/ox-board-wrapper.js +12 -6
- package/dist/src/player/ox-board-wrapper.js.map +1 -1
- package/dist/src/resolved-scene.d.ts +10 -0
- package/dist/src/resolved-scene.js +22 -0
- package/dist/src/resolved-scene.js.map +1 -0
- package/dist/test/figure-provider.test.d.ts +1 -0
- package/dist/test/figure-provider.test.js +139 -0
- package/dist/test/figure-provider.test.js.map +1 -0
- package/dist/test/resolved-scene.test.d.ts +1 -0
- package/dist/test/resolved-scene.test.js +88 -0
- package/dist/test/resolved-scene.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -8
- package/test/figure-provider.test.ts +163 -0
- package/test/resolved-scene.test.ts +114 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import gql from 'graphql-tag';
|
|
2
|
-
import {
|
|
2
|
+
import { error, ReferenceMap } from '@hatiolab/things-scene';
|
|
3
|
+
import { createResolvedScene } from './resolved-scene.js';
|
|
3
4
|
import { BoardDataStorage } from './data-storage/data-storage.js';
|
|
4
5
|
import { BoardModelCache } from './data-storage/board-model-cache.js';
|
|
5
6
|
import { client, gqlContext, subscribe } from '@operato/graphql';
|
|
@@ -41,7 +42,12 @@ export function createBoardProvider() {
|
|
|
41
42
|
scene = await provider.get(boardId);
|
|
42
43
|
}
|
|
43
44
|
catch (e) {
|
|
44
|
-
|
|
45
|
+
/*
|
|
46
|
+
No staleness check here: what this scene is for is the boardId, and the ReferenceMap
|
|
47
|
+
owns that key — a second request for the same board waits on this one instead of
|
|
48
|
+
starting another.
|
|
49
|
+
*/
|
|
50
|
+
scene = (await createResolvedScene({
|
|
45
51
|
model,
|
|
46
52
|
mode: 0,
|
|
47
53
|
refProvider: provider,
|
|
@@ -72,7 +78,7 @@ export function createBoardProvider() {
|
|
|
72
78
|
},
|
|
73
79
|
dispose() { }
|
|
74
80
|
}
|
|
75
|
-
});
|
|
81
|
+
}));
|
|
76
82
|
// s.app.baseUrl = undefined;
|
|
77
83
|
}
|
|
78
84
|
resolve(scene);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"board-provider.js","sourceRoot":"","sources":["../../src/board-provider.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,aAAa,CAAA;AAE7B,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"board-provider.js","sourceRoot":"","sources":["../../src/board-provider.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG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AC,CAAA;QAChB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,KAAK,CAAC,CAAC,CAAC,CAAA;YACR,MAAM,CAAC,CAAC,CAAC,CAAA;QACX,CAAC;IACH,CAAC,EACD,KAAK,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE;QAChB,GAAG,CAAC,OAAO,EAAE,CAAA;IACf,CAAC,CACF,CAAA;IAED,OAAO,SAAS,CAAA;AAClB,CAAC;AAED,MAAM,CAAC,MAAM,QAAQ,GAAG,mBAAmB,EAAE,CAAA","sourcesContent":["import gql from 'graphql-tag'\n\nimport { error, ReferenceMap, Scene } from '@hatiolab/things-scene'\nimport { createResolvedScene } from './resolved-scene.js'\nimport { BoardDataStorage } from './data-storage/data-storage.js'\nimport { BoardModelCache } from './data-storage/board-model-cache.js'\nimport { client, gqlContext, subscribe } from '@operato/graphql'\n\nexport function createBoardProvider() {\n const _provider = new ReferenceMap(\n async (boardId, resolve, reject): Promise<any> => {\n const startTime = performance.now()\n try {\n const cached = await BoardModelCache.get(boardId)\n\n const response = await client.query({\n query: gql`\n query FetchBoardById($id: String!, $cachedUpdatedAt: String) {\n board(id: $id, cachedUpdatedAt: $cachedUpdatedAt) {\n model\n updatedAt\n }\n }\n `,\n variables: { id: boardId, cachedUpdatedAt: cached?.updatedAt },\n context: gqlContext()\n })\n\n const board = response.data?.board\n\n if (!board) {\n reject(new Error('Failed to get the requested board.'))\n return\n }\n\n let model: any\n if (board.model === null && cached) {\n // 캐시 유효\n model = cached.model\n } else {\n // 새 모델\n model = JSON.parse(board.model)\n await BoardModelCache.put(boardId, '', board.model, board.updatedAt)\n }\n\n let scene: Scene\n\n try {\n scene = await provider.get(boardId)\n } catch (e) {\n /*\n No staleness check here: what this scene is for is the boardId, and the ReferenceMap\n owns that key — a second request for the same board waits on this one instead of\n starting another.\n */\n scene = (await createResolvedScene({\n model,\n mode: 0,\n refProvider: provider as any,\n dataStorage: new BoardDataStorage(boardId),\n loading: { startTime },\n dataSubscriptionProvider: {\n subscribe: async (tag: string, component: any) => {\n return await subscribe(\n {\n query: gql`\n subscription {\n data(tag: \"${tag}\") {\n tag\n data\n ts\n }\n }\n `\n },\n {\n next: async ({ data }: any) => {\n if (data) {\n const payload = data.data\n // 전달 지연 기록 (scene/app 레벨 트래커) — ts 는 component.data 에 넣지 않음.\n ;(component as any).app?.lagTracker?.record?.(payload.tag, payload.ts)\n component.data = payload.data\n }\n }\n }\n )\n },\n\n dispose() {}\n }\n } as any))!\n\n // s.app.baseUrl = undefined;\n }\n\n resolve(scene)\n } catch (e) {\n error(e)\n reject(e)\n }\n },\n async (id, ref) => {\n ref.dispose()\n }\n )\n\n return _provider\n}\n\nexport const provider = createBoardProvider()\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Asks for one type's blueprint. Null when no released figure carries that name. */
|
|
2
|
+
export type BlueprintFetch = (type: string) => Promise<any | null>;
|
|
3
|
+
export declare const fetchFigureBlueprint: BlueprintFetch;
|
|
4
|
+
/**
|
|
5
|
+
* Builds the resolver that fills things-scene's seat.
|
|
6
|
+
*
|
|
7
|
+
* `fetch` is a seam for tests — the default one talks to the server.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createFigureResolver(fetch?: BlueprintFetch): (types: readonly string[]) => Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Takes the seat. The package entry (`index.ts`) calls this, so an app that has `@operato/board`
|
|
12
|
+
* gets published figures on its boards without registering anything itself. Returns the function
|
|
13
|
+
* that takes the seat back.
|
|
14
|
+
*/
|
|
15
|
+
export declare function installFigureResolver(fetch?: BlueprintFetch): () => void;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright © HatioLab Inc. All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
import gql from 'graphql-tag';
|
|
5
|
+
import { Component, registerFigure, registerTypeResolver } from '@hatiolab/things-scene';
|
|
6
|
+
import { client, gqlContext } from '@operato/graphql';
|
|
7
|
+
/*
|
|
8
|
+
* Where a board gets the figures somebody authored.
|
|
9
|
+
*
|
|
10
|
+
* ── Why the seat is filled here ─────────────────────────────────────────────
|
|
11
|
+
* things-scene keeps the seat (`registerTypeResolver`) and knows nothing about figures, GraphQL or
|
|
12
|
+
* who published what. The board package is where a saved model already gets its values from the
|
|
13
|
+
* server — `board-provider.ts` reads a board by id the same way — so this is where the types a
|
|
14
|
+
* model names, and nobody has registered, get fetched. Putting it in the authoring package would
|
|
15
|
+
* make every consumer drag the modeller along, and putting it in each app would make every app
|
|
16
|
+
* build the same thing (ADR-0063 결정 2 · ADR-0045).
|
|
17
|
+
*
|
|
18
|
+
* ── What it asks for, and what it does not ──────────────────────────────────
|
|
19
|
+
* Uppercase names are the figure namespace, so those are the only ones asked about: a model that
|
|
20
|
+
* names `rect` or a mistyped `Conveyor` never reaches the server. A type that is already
|
|
21
|
+
* registered is left alone — a figure never replaces a component that is already drawing.
|
|
22
|
+
*
|
|
23
|
+
* ── An answer of "nobody published this" is not a failure ───────────────────
|
|
24
|
+
* `figureBlueprint` returns null for a type that has no released figure, and that type stays
|
|
25
|
+
* unregistered on purpose: the scene draws it as a stand-in and saves it back untouched
|
|
26
|
+
* (ADR-0063 결정 1). Being unable to ask at all is a different fact, so a transport or server
|
|
27
|
+
* error rejects — `resolveUnknownTypes` reports those in `failed` and the board still opens.
|
|
28
|
+
*/
|
|
29
|
+
/** The figure namespace: `EQ_MIXER`, `CONVEYOR`, `VEH_AGV_01`. */
|
|
30
|
+
const FIGURE_TYPE = /^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$/;
|
|
31
|
+
const FETCH_FIGURE_BLUEPRINT = gql `
|
|
32
|
+
query FetchFigureBlueprint($type: String!) {
|
|
33
|
+
figureBlueprint(type: $type)
|
|
34
|
+
}
|
|
35
|
+
`;
|
|
36
|
+
export const fetchFigureBlueprint = async (type) => {
|
|
37
|
+
var _a, _b;
|
|
38
|
+
const response = await client.query({
|
|
39
|
+
query: FETCH_FIGURE_BLUEPRINT,
|
|
40
|
+
variables: { type },
|
|
41
|
+
context: gqlContext()
|
|
42
|
+
});
|
|
43
|
+
/*
|
|
44
|
+
The client runs with errorPolicy 'all', so a rejected query comes back as a resolved response
|
|
45
|
+
carrying `errors` and a null field. Without this the caller cannot tell "no such figure" from
|
|
46
|
+
"the door said no".
|
|
47
|
+
*/
|
|
48
|
+
const errors = response.errors;
|
|
49
|
+
if (errors === null || errors === void 0 ? void 0 : errors.length) {
|
|
50
|
+
throw new Error(errors.map(e => { var _a; return (_a = e === null || e === void 0 ? void 0 : e.message) !== null && _a !== void 0 ? _a : String(e); }).join('\n'));
|
|
51
|
+
}
|
|
52
|
+
return (_b = (_a = response.data) === null || _a === void 0 ? void 0 : _a.figureBlueprint) !== null && _b !== void 0 ? _b : null;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Builds the resolver that fills things-scene's seat.
|
|
56
|
+
*
|
|
57
|
+
* `fetch` is a seam for tests — the default one talks to the server.
|
|
58
|
+
*/
|
|
59
|
+
export function createFigureResolver(fetch = fetchFigureBlueprint) {
|
|
60
|
+
return async function resolveFigureTypes(types) {
|
|
61
|
+
const asking = types.filter(type => FIGURE_TYPE.test(type) && !Component.register(type));
|
|
62
|
+
if (asking.length === 0) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const failures = [];
|
|
66
|
+
await Promise.all(asking.map(async (type) => {
|
|
67
|
+
try {
|
|
68
|
+
const blueprint = await fetch(type);
|
|
69
|
+
if (!blueprint) {
|
|
70
|
+
/* Nobody published this type. It stays a stand-in. */
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
registerFigure(blueprint);
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
failures.push({ type, error });
|
|
77
|
+
}
|
|
78
|
+
}));
|
|
79
|
+
if (failures.length > 0) {
|
|
80
|
+
/*
|
|
81
|
+
What did register stays registered — the seat reads the registry back, not what this says.
|
|
82
|
+
The throw is how "could not ask" reaches `TypeResolution.failed`.
|
|
83
|
+
*/
|
|
84
|
+
throw new Error(`Figure 청사진을 가져오지 못했다:\n${failures
|
|
85
|
+
.map(({ type, error }) => ` - ${type}: ${error instanceof Error ? error.message : String(error)}`)
|
|
86
|
+
.join('\n')}`);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Takes the seat. The package entry (`index.ts`) calls this, so an app that has `@operato/board`
|
|
92
|
+
* gets published figures on its boards without registering anything itself. Returns the function
|
|
93
|
+
* that takes the seat back.
|
|
94
|
+
*/
|
|
95
|
+
export function installFigureResolver(fetch = fetchFigureBlueprint) {
|
|
96
|
+
return registerTypeResolver(createFigureResolver(fetch));
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=figure-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"figure-provider.js","sourceRoot":"","sources":["../../src/figure-provider.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,GAAG,MAAM,aAAa,CAAA;AAE7B,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AACxF,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAErD;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,kEAAkE;AAClE,MAAM,WAAW,GAAG,+BAA+B,CAAA;AAKnD,MAAM,sBAAsB,GAAG,GAAG,CAAA;;;;CAIjC,CAAA;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAmB,KAAK,EAAE,IAAY,EAAE,EAAE;;IACzE,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC;QAClC,KAAK,EAAE,sBAAsB;QAC7B,SAAS,EAAE,EAAE,IAAI,EAAE;QACnB,OAAO,EAAE,UAAU,EAAE;KACtB,CAAC,CAAA;IAEF;;;;MAIE;IACF,MAAM,MAAM,GAAI,QAAyD,CAA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,CACH,CAAA;QAED,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACxB;;;cAGE;YACF,MAAM,IAAI,KAAK,CACb,0BAA0B,QAAQ;iBAC/B,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,OAAO,IAAI,KAAK,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;iBAClG,IAAI,CAAC,IAAI,CAAC,EAAE,CAChB,CAAA;QACH,CAAC;IACH,CAAC,CAAA;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,QAAwB,oBAAoB;IAChF,OAAO,oBAAoB,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC,CAAA;AAC1D,CAAC","sourcesContent":["/*\n * Copyright © HatioLab Inc. All rights reserved.\n */\n\nimport gql from 'graphql-tag'\n\nimport { Component, registerFigure, registerTypeResolver } from '@hatiolab/things-scene'\nimport { client, gqlContext } from '@operato/graphql'\n\n/*\n * Where a board gets the figures somebody authored.\n *\n * ── Why the seat is filled here ─────────────────────────────────────────────\n * things-scene keeps the seat (`registerTypeResolver`) and knows nothing about figures, GraphQL or\n * who published what. The board package is where a saved model already gets its values from the\n * server — `board-provider.ts` reads a board by id the same way — so this is where the types a\n * model names, and nobody has registered, get fetched. Putting it in the authoring package would\n * make every consumer drag the modeller along, and putting it in each app would make every app\n * build the same thing (ADR-0063 결정 2 · ADR-0045).\n *\n * ── What it asks for, and what it does not ──────────────────────────────────\n * Uppercase names are the figure namespace, so those are the only ones asked about: a model that\n * names `rect` or a mistyped `Conveyor` never reaches the server. A type that is already\n * registered is left alone — a figure never replaces a component that is already drawing.\n *\n * ── An answer of \"nobody published this\" is not a failure ───────────────────\n * `figureBlueprint` returns null for a type that has no released figure, and that type stays\n * unregistered on purpose: the scene draws it as a stand-in and saves it back untouched\n * (ADR-0063 결정 1). Being unable to ask at all is a different fact, so a transport or server\n * error rejects — `resolveUnknownTypes` reports those in `failed` and the board still opens.\n */\n\n/** The figure namespace: `EQ_MIXER`, `CONVEYOR`, `VEH_AGV_01`. */\nconst FIGURE_TYPE = /^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$/\n\n/** Asks for one type's blueprint. Null when no released figure carries that name. */\nexport type BlueprintFetch = (type: string) => Promise<any | null>\n\nconst FETCH_FIGURE_BLUEPRINT = gql`\n query FetchFigureBlueprint($type: String!) {\n figureBlueprint(type: $type)\n }\n`\n\nexport const fetchFigureBlueprint: BlueprintFetch = async (type: string) => {\n const response = await client.query({\n query: FETCH_FIGURE_BLUEPRINT,\n variables: { type },\n context: gqlContext()\n })\n\n /*\n The client runs with errorPolicy 'all', so a rejected query comes back as a resolved response\n carrying `errors` and a null field. Without this the caller cannot tell \"no such figure\" from\n \"the door said no\".\n */\n const errors = (response as { errors?: readonly { message?: string }[] }).errors\n if (errors?.length) {\n throw new Error(errors.map(e => e?.message ?? String(e)).join('\\n'))\n }\n\n return response.data?.figureBlueprint ?? null\n}\n\n/**\n * Builds the resolver that fills things-scene's seat.\n *\n * `fetch` is a seam for tests — the default one talks to the server.\n */\nexport function createFigureResolver(fetch: BlueprintFetch = fetchFigureBlueprint) {\n return async function resolveFigureTypes(types: readonly string[]): Promise<void> {\n const asking = types.filter(type => FIGURE_TYPE.test(type) && !Component.register(type))\n if (asking.length === 0) {\n return\n }\n\n const failures: { type: string; error: unknown }[] = []\n\n await Promise.all(\n asking.map(async type => {\n try {\n const blueprint = await fetch(type)\n if (!blueprint) {\n /* Nobody published this type. It stays a stand-in. */\n return\n }\n\n registerFigure(blueprint)\n } catch (error) {\n failures.push({ type, error })\n }\n })\n )\n\n if (failures.length > 0) {\n /*\n What did register stays registered — the seat reads the registry back, not what this says.\n The throw is how \"could not ask\" reaches `TypeResolution.failed`.\n */\n throw new Error(\n `Figure 청사진을 가져오지 못했다:\\n${failures\n .map(({ type, error }) => ` - ${type}: ${error instanceof Error ? error.message : String(error)}`)\n .join('\\n')}`\n )\n }\n }\n}\n\n/**\n * Takes the seat. The package entry (`index.ts`) calls this, so an app that has `@operato/board`\n * gets published figures on its boards without registering anything itself. Returns the function\n * that takes the seat back.\n */\nexport function installFigureResolver(fetch: BlueprintFetch = fetchFigureBlueprint): () => void {\n return registerTypeResolver(createFigureResolver(fetch))\n}\n"]}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export { BoardDataStorage, PlaylistStorage } from './data-storage/data-storage.j
|
|
|
4
4
|
export { BoardModelCache } from './data-storage/board-model-cache.js';
|
|
5
5
|
export type { CachedBoard } from './data-storage/board-model-cache.js';
|
|
6
6
|
export * from './board-provider.js';
|
|
7
|
+
export * from './resolved-scene.js';
|
|
8
|
+
export * from './figure-provider.js';
|
|
7
9
|
export * from './board-placement-palette.js';
|
|
8
10
|
export * from './ox-board-viewer.js';
|
|
9
11
|
export * from './ox-board-preview.js';
|
|
@@ -11,3 +13,4 @@ export * from './ox-board-player.js';
|
|
|
11
13
|
export * from './ox-board-modeller.js';
|
|
12
14
|
export * from './ox-board-list.js';
|
|
13
15
|
export * from './ox-board-template-viewer.js';
|
|
16
|
+
export declare const uninstallFigureResolver: () => void;
|
package/dist/src/index.js
CHANGED
|
@@ -4,6 +4,10 @@ export { BoardDataStorage, PlaylistStorage } from './data-storage/data-storage.j
|
|
|
4
4
|
export { BoardModelCache } from './data-storage/board-model-cache.js';
|
|
5
5
|
/* Loading a saved board by id, and keeping its data bindings live. */
|
|
6
6
|
export * from './board-provider.js';
|
|
7
|
+
/* The one way to turn a model into a scene — it resolves the types the model names first. */
|
|
8
|
+
export * from './resolved-scene.js';
|
|
9
|
+
/* Published figures a board model names — the package takes things-scene's resolver seat on load. */
|
|
10
|
+
export * from './figure-provider.js';
|
|
7
11
|
/* The modeller tray asks a host app what it has to place; this is where the host registers. */
|
|
8
12
|
export * from './board-placement-palette.js';
|
|
9
13
|
export * from './ox-board-viewer.js';
|
|
@@ -12,4 +16,10 @@ export * from './ox-board-player.js';
|
|
|
12
16
|
export * from './ox-board-modeller.js';
|
|
13
17
|
export * from './ox-board-list.js';
|
|
14
18
|
export * from './ox-board-template-viewer.js';
|
|
19
|
+
import { installFigureResolver } from './figure-provider.js';
|
|
20
|
+
/*
|
|
21
|
+
Having this package IS the declaration that figure types resolve. An app that must not reach the
|
|
22
|
+
figure door takes the seat back with the returned function (ADR-0063 결정 2 — 앱이 채우지 않는다).
|
|
23
|
+
*/
|
|
24
|
+
export const uninstallFigureResolver = installFigureResolver();
|
|
15
25
|
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAE1B,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAA;AAC9E,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAClF,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAA;AAGrE,sEAAsE;AACtE,cAAc,qBAAqB,CAAA;AACnC,+FAA+F;AAC/F,cAAc,8BAA8B,CAAA;AAE5C,cAAc,sBAAsB,CAAA;AACpC,cAAc,uBAAuB,CAAA;AACrC,cAAc,sBAAsB,CAAA;AACpC,cAAc,wBAAwB,CAAA;AACtC,cAAc,oBAAoB,CAAA;AAClC,cAAc,+BAA+B,CAAA","sourcesContent":["export * from './types.js'\n\nexport { registerDefaultGroups } from './component/register-default-groups.js'\nexport { BoardDataStorage, PlaylistStorage } from './data-storage/data-storage.js'\nexport { BoardModelCache } from './data-storage/board-model-cache.js'\nexport type { CachedBoard } from './data-storage/board-model-cache.js'\n\n/* Loading a saved board by id, and keeping its data bindings live. */\nexport * from './board-provider.js'\n/* The modeller tray asks a host app what it has to place; this is where the host registers. */\nexport * from './board-placement-palette.js'\n\nexport * from './ox-board-viewer.js'\nexport * from './ox-board-preview.js'\nexport * from './ox-board-player.js'\nexport * from './ox-board-modeller.js'\nexport * from './ox-board-list.js'\nexport * from './ox-board-template-viewer.js'\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAE1B,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAA;AAC9E,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAClF,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAA;AAGrE,sEAAsE;AACtE,cAAc,qBAAqB,CAAA;AACnC,6FAA6F;AAC7F,cAAc,qBAAqB,CAAA;AACnC,qGAAqG;AACrG,cAAc,sBAAsB,CAAA;AACpC,+FAA+F;AAC/F,cAAc,8BAA8B,CAAA;AAE5C,cAAc,sBAAsB,CAAA;AACpC,cAAc,uBAAuB,CAAA;AACrC,cAAc,sBAAsB,CAAA;AACpC,cAAc,wBAAwB,CAAA;AACtC,cAAc,oBAAoB,CAAA;AAClC,cAAc,+BAA+B,CAAA;AAE7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AAE5D;;;EAGE;AACF,MAAM,CAAC,MAAM,uBAAuB,GAAG,qBAAqB,EAAE,CAAA","sourcesContent":["export * from './types.js'\n\nexport { registerDefaultGroups } from './component/register-default-groups.js'\nexport { BoardDataStorage, PlaylistStorage } from './data-storage/data-storage.js'\nexport { BoardModelCache } from './data-storage/board-model-cache.js'\nexport type { CachedBoard } from './data-storage/board-model-cache.js'\n\n/* Loading a saved board by id, and keeping its data bindings live. */\nexport * from './board-provider.js'\n/* The one way to turn a model into a scene — it resolves the types the model names first. */\nexport * from './resolved-scene.js'\n/* Published figures a board model names — the package takes things-scene's resolver seat on load. */\nexport * from './figure-provider.js'\n/* The modeller tray asks a host app what it has to place; this is where the host registers. */\nexport * from './board-placement-palette.js'\n\nexport * from './ox-board-viewer.js'\nexport * from './ox-board-preview.js'\nexport * from './ox-board-player.js'\nexport * from './ox-board-modeller.js'\nexport * from './ox-board-list.js'\nexport * from './ox-board-template-viewer.js'\n\nimport { installFigureResolver } from './figure-provider.js'\n\n/*\n Having this package IS the declaration that figure types resolve. An app that must not reach the\n figure door takes the seat back with the returned function (ADR-0063 결정 2 — 앱이 채우지 않는다).\n*/\nexport const uninstallFigureResolver = installFigureResolver()\n"]}
|
|
@@ -30,7 +30,7 @@ export default class OxSceneViewer extends LitElement {
|
|
|
30
30
|
_setSelected(selected: Component[]): void;
|
|
31
31
|
_disposeScene(): void;
|
|
32
32
|
resize(force: boolean): void;
|
|
33
|
-
_onModelChanged(model?: Model): void
|
|
33
|
+
_onModelChanged(model?: Model): Promise<void>;
|
|
34
34
|
_onDisplayChanged(screenSize: string | number): void;
|
|
35
35
|
_onModeChanged(mode: SceneMode): void;
|
|
36
36
|
_onDataChanged(data: any): void;
|
|
@@ -4,7 +4,8 @@ import './ox-scene-layer.js';
|
|
|
4
4
|
import './ox-scene-handler.js';
|
|
5
5
|
import { css, html, LitElement } from 'lit';
|
|
6
6
|
import { customElement, property } from 'lit/decorators.js';
|
|
7
|
-
import {
|
|
7
|
+
import { SCENE_MODE } from '@hatiolab/things-scene';
|
|
8
|
+
import { createResolvedScene } from '../../resolved-scene.js';
|
|
8
9
|
let OxSceneViewer = class OxSceneViewer extends LitElement {
|
|
9
10
|
constructor() {
|
|
10
11
|
super(...arguments);
|
|
@@ -106,7 +107,7 @@ let OxSceneViewer = class OxSceneViewer extends LitElement {
|
|
|
106
107
|
this.lastOffsetWidth = this.offsetWidth;
|
|
107
108
|
}
|
|
108
109
|
}
|
|
109
|
-
_onModelChanged(model) {
|
|
110
|
+
async _onModelChanged(model) {
|
|
110
111
|
this._disposeScene();
|
|
111
112
|
if (!model) {
|
|
112
113
|
return;
|
|
@@ -114,7 +115,8 @@ let OxSceneViewer = class OxSceneViewer extends LitElement {
|
|
|
114
115
|
const layers = Array.from(this.querySelectorAll('ox-scene-layer')).map(layer => layer.getModel());
|
|
115
116
|
const handlers = Array.from(this.querySelectorAll('ox-scene-handler')).map(handler => handler.getAttribute('type'));
|
|
116
117
|
// tracker: 외부에서 전달받았으면 재사용, 없으면 자동 생성
|
|
117
|
-
|
|
118
|
+
/* Resolving the model's types is a wait; the modeller can be handed another model meanwhile. */
|
|
119
|
+
const scene = await createResolvedScene({
|
|
118
120
|
target: this,
|
|
119
121
|
model: JSON.parse(JSON.stringify(model)),
|
|
120
122
|
layers,
|
|
@@ -122,7 +124,11 @@ let OxSceneViewer = class OxSceneViewer extends LitElement {
|
|
|
122
124
|
mode: this.mode,
|
|
123
125
|
refProvider: this.provider,
|
|
124
126
|
loading: this.loadTracker ? { tracker: this.loadTracker } : undefined
|
|
125
|
-
}));
|
|
127
|
+
}, () => this.model === model && this.isConnected);
|
|
128
|
+
if (!scene) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
this._setScene(scene);
|
|
126
132
|
if (this.provider) {
|
|
127
133
|
this.provider.add(this.name, this.scene);
|
|
128
134
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ox-scene-viewer.js","sourceRoot":"","sources":["../../../../src/modeller/scene-viewer/ox-scene-viewer.ts"],"names":[],"mappings":";AAAA,OAAO,2BAA2B,CAAA;AAClC,OAAO,qBAAqB,CAAA;AAC5B,OAAO,uBAAuB,CAAA;AAE9B,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAkB,MAAM,KAAK,CAAA;AAC3D,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAE3D,OAAO,EAAa,MAAM,IAAI,WAAW,EAAkE,UAAU,EAAa,MAAM,wBAAwB,CAAA;AAKjJ,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,UAAU;IAAtC;;QAOb,UAAK,GAAiB,IAAI,CAAA;QAE1B,8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B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;2CAAwB;AACtB;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;sDAAgC;AAC/B;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;oDAA+B;AAhCxC,aAAa;IADjC,aAAa,CAAC,iBAAiB,CAAC;GACZ,aAAa,CA6PjC;eA7PoB,aAAa","sourcesContent":["import './confidential-overlay.js'\nimport './ox-scene-layer.js'\nimport './ox-scene-handler.js'\n\nimport { css, html, LitElement, PropertyValues } from 'lit'\nimport { customElement, property } from 'lit/decorators.js'\n\nimport { Component, create as createScene, FITMODE, LoadTracker, LoadingOverlay, Model, Properties, Scene, SCENE_MODE, SceneMode } from '@hatiolab/things-scene'\n\nimport OxSceneLayer from './ox-scene-layer.js'\n\n@customElement('ox-scene-viewer')\nexport default class OxSceneViewer extends LitElement {\n static styles = css`\n :host {\n outline: none;\n }\n `\n\n scene: Scene | null = null\n @property({ type: Object }) model?: Model\n /* Scene Mode - mode 0 : view mode, mode 1 : edit mode, mode 2 : shift mode */\n @property({ type: Number }) mode: SceneMode = SCENE_MODE.VIEW\n @property({ type: Number }) screenSize: number = 13.3\n variables: Properties = {}\n @property({ type: Object }) data: any\n /*\n * 캔바스에 모델을 어떻게 적절하게 보여줄 것인지를 설정한다.\n *\n * @none 가로, 세로 스케일을 1로 고정하고, {0, 0}좌표로 translate시킨다.\n * @both 캔바스에 모델을 꼭 채우도록 가로, 세로 스케일을 조정하고, {0, 0}좌표로 translate시킨다.\n * @width 캔바스의 폭에 모델의 폭을 일치하도록 가로, 세로 스케일을 동일하게 조정하고, {0, 0}좌표로 translate시킨다.\n * @height 캔바스의 높이에 모델의 높이를 일치하도록 가로, 세로 스케일을 동일하게 조정하고, {0, 0}좌표로 translate시킨다.\n * @center 가로, 세로 스케일을 1로 고정하고 모델이 화면의 중앙에 위치하도록 translate시킨다.\n * @ratio 모델의 모든 부분이 캔바스에 최대 크기로 표현될 수 있도록 가로, 세로 동일한 스케일로 조정하고, {0, 0}좌표로 translate시킨다.\n */\n @property({ type: String }) fit: FITMODE = 'none'\n selected: Component[] = []\n @property({ type: Boolean }) disposeWhenDetached: boolean = false\n @property({ type: String }) baseUrl: string = ''\n @property({ type: Object }) provider: any\n @property({ type: Object }) loadTracker?: LoadTracker\n @property({ type: String }) name: string = 'noname'\n @property({ type: Boolean }) enableInspector: boolean = true\n @property({ type: Boolean }) showInspector: boolean = false\n\n private lastOffsetWidth?: number\n\n disconnectedCallback() {\n super.disconnectedCallback()\n\n if (this.scene && this.disposeWhenDetached) {\n this._disposeScene()\n }\n }\n\n render() {\n return html` <slot></slot> `\n }\n\n updated(change: PropertyValues<this>) {\n change.has('model') && this._onModelChanged(this.model)\n change.has('mode') && this._onModeChanged(this.mode)\n change.has('screenSize') && this._onDisplayChanged(this.screenSize)\n change.has('data') && this._onDataChanged(this.data)\n change.has('baseUrl') && this._onBaseUrlChanged(this.baseUrl)\n }\n\n _setScene(scene: Scene | null) {\n this.scene = scene\n this.dispatchEvent(\n new CustomEvent('scene-changed', {\n bubbles: true,\n composed: true,\n detail: { value: scene }\n })\n )\n }\n\n _setMode(mode: SceneMode) {\n this.mode = mode\n this.dispatchEvent(\n new CustomEvent('mode-changed', {\n bubbles: true,\n composed: true,\n detail: { value: mode }\n })\n )\n }\n\n _setVariables(variables: Properties) {\n this.variables = variables\n this.dispatchEvent(\n new CustomEvent('variables-changed', {\n bubbles: true,\n composed: true,\n detail: { value: variables }\n })\n )\n }\n\n _setSelected(selected: Component[]) {\n this.selected = selected\n this.dispatchEvent(\n new CustomEvent('selected-changed', {\n bubbles: true,\n composed: true,\n detail: { value: selected }\n })\n )\n }\n\n _disposeScene() {\n if (this.scene) {\n this.scene.off('selected', this._onSelectedChanged, this)\n this.scene.off('mode', this._onSceneModeChanged, this)\n\n if (this.provider) {\n this.scene.release && this.scene.release()\n } else {\n this.scene.dispose()\n }\n\n this._setScene(null)\n this._setSelected([])\n }\n }\n\n resize(force: boolean) {\n if (typeof this.scene == 'object') {\n if (force || this.fit === 'both' || Math.abs(this.offsetWidth - (this.lastOffsetWidth || 0)) >= 1) {\n requestAnimationFrame(() => {\n if (this.scene) {\n this.scene.resize()\n this.scene.fit(this.fit)\n }\n })\n }\n\n this.lastOffsetWidth = this.offsetWidth\n }\n }\n\n _onModelChanged(model?: Model) {\n this._disposeScene()\n\n if (!model) {\n return\n }\n\n const layers: any[] = Array.from(this.querySelectorAll('ox-scene-layer')).map(layer => (layer as OxSceneLayer).getModel())\n\n const handlers: any[] = Array.from(this.querySelectorAll('ox-scene-handler')).map(handler => handler.getAttribute('type'))\n\n // tracker: 외부에서 전달받았으면 재사용, 없으면 자동 생성\n this._setScene(\n createScene({\n target: this,\n model: JSON.parse(JSON.stringify(model)),\n layers,\n handlers,\n mode: this.mode,\n refProvider: this.provider,\n loading: this.loadTracker ? { tracker: this.loadTracker } : undefined\n })\n )\n\n if (this.provider) {\n this.provider.add(this.name, this.scene)\n }\n\n this.scene!.screen = this.screenSize\n\n /* 이 컴포넌트의 폭이 값을 가지고 있으면 - 화면상에 자리를 잡고 보여지고 있음을 의미한다.\n * 이 때는 정상적으로 그려주고,\n * 그렇지 않으면, 다음 Resize Handling시에 처리하도록 한다.\n */\n this.resize(true)\n\n this._setVariables(model.variables || (this.scene! as any).variables)\n\n this.scene!.on('selected', this._onSelectedChanged, this)\n this.scene!.on('mode', this._onSceneModeChanged, this)\n\n this._onModeChanged(this.mode)\n this._onDisplayChanged(this.screenSize)\n this._onBaseUrlChanged(this.baseUrl)\n\n this.focus()\n }\n\n _onDisplayChanged(screenSize: string | number) {\n if (!this.scene) {\n return\n }\n\n if (screenSize) {\n this.scene.screen = parseFloat(String(screenSize))\n }\n }\n\n _onModeChanged(mode: SceneMode) {\n if (!this.scene) {\n return\n }\n this.scene.mode = Number(mode)\n }\n\n _onDataChanged(data: any) {\n if (!this.scene || !data) {\n return\n }\n\n this.scene.data = data\n }\n\n _onSelectedChanged(after: Component[]) {\n /*\n scene 컴포넌트의 속성을 속성 에디터(input box등)에서 변경하다가,\n scene의 다른 컴포넌트를 클릭해서 포커스(선택) 컴포넌트를 변경하게되면,\n 속성 에디터(input box등)의 value change 이벤트의 처리와 충돌(레이스)하게된다.\n \n 기대하는 순서는 먼저 속성 에디터의 value change 이벤트를 처리한 후에,\n selected 이벤트를 처리할 수 있도록 requestAnimationFrame으로 한 프레임을 지연하도록 하였다.\n */\n requestAnimationFrame(() => {\n this._setSelected(after)\n })\n }\n\n _onSceneModeChanged(after: SceneMode) {\n if (!this.scene) {\n return\n }\n\n if (this.mode !== after) {\n this._setMode(after)\n }\n\n switch (after) {\n case 1:\n this.style.cursor = 'default'\n break\n case 2:\n this.style.cursor = 'grab'\n break\n case 3:\n this.style.cursor = 'crosshair'\n break\n case 4:\n this.style.cursor = 'copy'\n break\n case 5:\n this.style.cursor = 'context-menu'\n break\n }\n }\n\n _onBaseUrlChanged(after: string) {\n if (!this.scene) {\n return\n }\n\n this.scene.baseUrl = after\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ox-scene-viewer.js","sourceRoot":"","sources":["../../../../src/modeller/scene-viewer/ox-scene-viewer.ts"],"names":[],"mappings":";AAAA,OAAO,2BAA2B,CAAA;AAClC,OAAO,qBAAqB,CAAA;AAC5B,OAAO,uBAAuB,CAAA;AAE9B,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAkB,MAAM,KAAK,CAAA;AAC3D,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAE3D,OAAO,EAA6E,UAAU,EAAa,MAAM,wBAAwB,CAAA;AAEzI,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAK9C,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,UAAU;IAAtC;;QAOb,UAAK,GAAiB,IAAI,CAAA;QAE1B,8EAA8E;QAClD,SAAI,GAAc,U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E,MAAM,EAAE,CAAC;8CAAqB;AACpB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;+CAAc;AACb;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;kDAA0B;AACzB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;2CAAwB;AACtB;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;sDAAgC;AAC/B;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;oDAA+B;AAhCxC,aAAa;IADjC,aAAa,CAAC,iBAAiB,CAAC;GACZ,aAAa,CAqQjC;eArQoB,aAAa","sourcesContent":["import './confidential-overlay.js'\nimport './ox-scene-layer.js'\nimport './ox-scene-handler.js'\n\nimport { css, html, LitElement, PropertyValues } from 'lit'\nimport { customElement, property } from 'lit/decorators.js'\n\nimport { Component, FITMODE, LoadTracker, LoadingOverlay, Model, Properties, Scene, SCENE_MODE, SceneMode } from '@hatiolab/things-scene'\n\nimport { createResolvedScene } from '../../resolved-scene.js'\n\nimport OxSceneLayer from './ox-scene-layer.js'\n\n@customElement('ox-scene-viewer')\nexport default class OxSceneViewer extends LitElement {\n static styles = css`\n :host {\n outline: none;\n }\n `\n\n scene: Scene | null = null\n @property({ type: Object }) model?: Model\n /* Scene Mode - mode 0 : view mode, mode 1 : edit mode, mode 2 : shift mode */\n @property({ type: Number }) mode: SceneMode = SCENE_MODE.VIEW\n @property({ type: Number }) screenSize: number = 13.3\n variables: Properties = {}\n @property({ type: Object }) data: any\n /*\n * 캔바스에 모델을 어떻게 적절하게 보여줄 것인지를 설정한다.\n *\n * @none 가로, 세로 스케일을 1로 고정하고, {0, 0}좌표로 translate시킨다.\n * @both 캔바스에 모델을 꼭 채우도록 가로, 세로 스케일을 조정하고, {0, 0}좌표로 translate시킨다.\n * @width 캔바스의 폭에 모델의 폭을 일치하도록 가로, 세로 스케일을 동일하게 조정하고, {0, 0}좌표로 translate시킨다.\n * @height 캔바스의 높이에 모델의 높이를 일치하도록 가로, 세로 스케일을 동일하게 조정하고, {0, 0}좌표로 translate시킨다.\n * @center 가로, 세로 스케일을 1로 고정하고 모델이 화면의 중앙에 위치하도록 translate시킨다.\n * @ratio 모델의 모든 부분이 캔바스에 최대 크기로 표현될 수 있도록 가로, 세로 동일한 스케일로 조정하고, {0, 0}좌표로 translate시킨다.\n */\n @property({ type: String }) fit: FITMODE = 'none'\n selected: Component[] = []\n @property({ type: Boolean }) disposeWhenDetached: boolean = false\n @property({ type: String }) baseUrl: string = ''\n @property({ type: Object }) provider: any\n @property({ type: Object }) loadTracker?: LoadTracker\n @property({ type: String }) name: string = 'noname'\n @property({ type: Boolean }) enableInspector: boolean = true\n @property({ type: Boolean }) showInspector: boolean = false\n\n private lastOffsetWidth?: number\n\n disconnectedCallback() {\n super.disconnectedCallback()\n\n if (this.scene && this.disposeWhenDetached) {\n this._disposeScene()\n }\n }\n\n render() {\n return html` <slot></slot> `\n }\n\n updated(change: PropertyValues<this>) {\n change.has('model') && this._onModelChanged(this.model)\n change.has('mode') && this._onModeChanged(this.mode)\n change.has('screenSize') && this._onDisplayChanged(this.screenSize)\n change.has('data') && this._onDataChanged(this.data)\n change.has('baseUrl') && this._onBaseUrlChanged(this.baseUrl)\n }\n\n _setScene(scene: Scene | null) {\n this.scene = scene\n this.dispatchEvent(\n new CustomEvent('scene-changed', {\n bubbles: true,\n composed: true,\n detail: { value: scene }\n })\n )\n }\n\n _setMode(mode: SceneMode) {\n this.mode = mode\n this.dispatchEvent(\n new CustomEvent('mode-changed', {\n bubbles: true,\n composed: true,\n detail: { value: mode }\n })\n )\n }\n\n _setVariables(variables: Properties) {\n this.variables = variables\n this.dispatchEvent(\n new CustomEvent('variables-changed', {\n bubbles: true,\n composed: true,\n detail: { value: variables }\n })\n )\n }\n\n _setSelected(selected: Component[]) {\n this.selected = selected\n this.dispatchEvent(\n new CustomEvent('selected-changed', {\n bubbles: true,\n composed: true,\n detail: { value: selected }\n })\n )\n }\n\n _disposeScene() {\n if (this.scene) {\n this.scene.off('selected', this._onSelectedChanged, this)\n this.scene.off('mode', this._onSceneModeChanged, this)\n\n if (this.provider) {\n this.scene.release && this.scene.release()\n } else {\n this.scene.dispose()\n }\n\n this._setScene(null)\n this._setSelected([])\n }\n }\n\n resize(force: boolean) {\n if (typeof this.scene == 'object') {\n if (force || this.fit === 'both' || Math.abs(this.offsetWidth - (this.lastOffsetWidth || 0)) >= 1) {\n requestAnimationFrame(() => {\n if (this.scene) {\n this.scene.resize()\n this.scene.fit(this.fit)\n }\n })\n }\n\n this.lastOffsetWidth = this.offsetWidth\n }\n }\n\n async _onModelChanged(model?: Model) {\n this._disposeScene()\n\n if (!model) {\n return\n }\n\n const layers: any[] = Array.from(this.querySelectorAll('ox-scene-layer')).map(layer => (layer as OxSceneLayer).getModel())\n\n const handlers: any[] = Array.from(this.querySelectorAll('ox-scene-handler')).map(handler => handler.getAttribute('type'))\n\n // tracker: 외부에서 전달받았으면 재사용, 없으면 자동 생성\n /* Resolving the model's types is a wait; the modeller can be handed another model meanwhile. */\n const scene = await createResolvedScene(\n {\n target: this,\n model: JSON.parse(JSON.stringify(model)),\n layers,\n handlers,\n mode: this.mode,\n refProvider: this.provider,\n loading: this.loadTracker ? { tracker: this.loadTracker } : undefined\n },\n () => this.model === model && this.isConnected\n )\n\n if (!scene) {\n return\n }\n\n this._setScene(scene)\n\n if (this.provider) {\n this.provider.add(this.name, this.scene)\n }\n\n this.scene!.screen = this.screenSize\n\n /* 이 컴포넌트의 폭이 값을 가지고 있으면 - 화면상에 자리를 잡고 보여지고 있음을 의미한다.\n * 이 때는 정상적으로 그려주고,\n * 그렇지 않으면, 다음 Resize Handling시에 처리하도록 한다.\n */\n this.resize(true)\n\n this._setVariables(model.variables || (this.scene! as any).variables)\n\n this.scene!.on('selected', this._onSelectedChanged, this)\n this.scene!.on('mode', this._onSceneModeChanged, this)\n\n this._onModeChanged(this.mode)\n this._onDisplayChanged(this.screenSize)\n this._onBaseUrlChanged(this.baseUrl)\n\n this.focus()\n }\n\n _onDisplayChanged(screenSize: string | number) {\n if (!this.scene) {\n return\n }\n\n if (screenSize) {\n this.scene.screen = parseFloat(String(screenSize))\n }\n }\n\n _onModeChanged(mode: SceneMode) {\n if (!this.scene) {\n return\n }\n this.scene.mode = Number(mode)\n }\n\n _onDataChanged(data: any) {\n if (!this.scene || !data) {\n return\n }\n\n this.scene.data = data\n }\n\n _onSelectedChanged(after: Component[]) {\n /*\n scene 컴포넌트의 속성을 속성 에디터(input box등)에서 변경하다가,\n scene의 다른 컴포넌트를 클릭해서 포커스(선택) 컴포넌트를 변경하게되면,\n 속성 에디터(input box등)의 value change 이벤트의 처리와 충돌(레이스)하게된다.\n \n 기대하는 순서는 먼저 속성 에디터의 value change 이벤트를 처리한 후에,\n selected 이벤트를 처리할 수 있도록 requestAnimationFrame으로 한 프레임을 지연하도록 하였다.\n */\n requestAnimationFrame(() => {\n this._setSelected(after)\n })\n }\n\n _onSceneModeChanged(after: SceneMode) {\n if (!this.scene) {\n return\n }\n\n if (this.mode !== after) {\n this._setMode(after)\n }\n\n switch (after) {\n case 1:\n this.style.cursor = 'default'\n break\n case 2:\n this.style.cursor = 'grab'\n break\n case 3:\n this.style.cursor = 'crosshair'\n break\n case 4:\n this.style.cursor = 'copy'\n break\n case 5:\n this.style.cursor = 'context-menu'\n break\n }\n }\n\n _onBaseUrlChanged(after: string) {\n if (!this.scene) {\n return\n }\n\n this.scene.baseUrl = after\n }\n}\n"]}
|
|
@@ -16,7 +16,8 @@ import { __decorate } from "tslib";
|
|
|
16
16
|
*/
|
|
17
17
|
import { css, html, LitElement } from 'lit';
|
|
18
18
|
import { customElement, property, query } from 'lit/decorators.js';
|
|
19
|
-
import {
|
|
19
|
+
import { SCENE_MODE } from '@hatiolab/things-scene';
|
|
20
|
+
import { createResolvedScene } from './resolved-scene.js';
|
|
20
21
|
let BoardPreview = class BoardPreview extends LitElement {
|
|
21
22
|
constructor() {
|
|
22
23
|
super(...arguments);
|
|
@@ -48,20 +49,26 @@ let BoardPreview = class BoardPreview extends LitElement {
|
|
|
48
49
|
super.disconnectedCallback();
|
|
49
50
|
}
|
|
50
51
|
/** Scene 새로 만들고 target 에 부착. 기존 Scene 은 dispose. */
|
|
51
|
-
_rebuild() {
|
|
52
|
+
async _rebuild() {
|
|
52
53
|
var _a, _b;
|
|
53
54
|
this._dispose();
|
|
54
55
|
if (!this.boardModel || !this._target)
|
|
55
56
|
return;
|
|
57
|
+
/* Resolving the model's types is a wait; this preview may be handed another model meanwhile. */
|
|
58
|
+
const boardModel = this.boardModel;
|
|
59
|
+
const target = this._target;
|
|
56
60
|
try {
|
|
57
|
-
|
|
58
|
-
model: { ...
|
|
61
|
+
const scene = await createResolvedScene({
|
|
62
|
+
model: { ...boardModel },
|
|
59
63
|
mode: SCENE_MODE.VIEW,
|
|
60
64
|
handlers: []
|
|
61
|
-
});
|
|
65
|
+
}, () => this.boardModel === boardModel && this._target === target && this.isConnected);
|
|
66
|
+
if (!scene)
|
|
67
|
+
return;
|
|
68
|
+
this._scene = scene;
|
|
62
69
|
// 컴포넌트 모두 보이도록 fit
|
|
63
70
|
(_b = (_a = this._scene).fit) === null || _b === void 0 ? void 0 : _b.call(_a, this._scene.fitMode);
|
|
64
|
-
this._scene.target =
|
|
71
|
+
this._scene.target = target;
|
|
65
72
|
}
|
|
66
73
|
catch (e) {
|
|
67
74
|
console.warn('[ox-board-preview] failed to render boardModel:', e);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ox-board-preview.js","sourceRoot":"","sources":["../../src/ox-board-preview.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAuB,MAAM,KAAK,CAAA;AAChE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,C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AAGrB;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;iDAA6B;AAE/B;IAAzB,KAAK,CAAC,SAAS,CAAC;6CAA8B;AA3BpC,YAAY;IADxB,aAAa,CAAC,kBAAkB,CAAC;GACrB,YAAY,CA6FxB","sourcesContent":["/**\n * @license Copyright © HatioLab Inc. All rights reserved.\n *\n * `<ox-board-preview>` — boardModel JSON 을 read-only 시각으로 띄우는 lightweight 컴포넌트.\n *\n * 용도:\n * - board-import wizard 의 review 단계에서 시안 (variant) 별 썸네일 + 큰 미리보기\n * - 그 외 인터랙션 없이 보드를 살짝 보여주는 경우 (board card hover preview 등)\n *\n * 차이 (`<ox-board-viewer>` 대비):\n * - 데이터 바인딩 / playback / fullscreen / 검색 / popup / scenario 모두 X\n * - boardModel prop 직접 받음 (Board entity 가 필요 없음 — 미저장 model 도 지원)\n * - dataSubscription 미연결 — 정적 시각만\n * - 사용자 입력 미수용 (selectable, dragable 모두 비활성)\n */\nimport { css, html, LitElement, type PropertyValues } from 'lit'\nimport { customElement, property, query } from 'lit/decorators.js'\n\nimport { SCENE_MODE } from '@hatiolab/things-scene'\n\nimport { createResolvedScene } from './resolved-scene.js'\n\n@customElement('ox-board-preview')\nexport class BoardPreview extends LitElement {\n static styles = [\n css`\n :host {\n display: block;\n position: relative;\n width: 100%;\n height: 100%;\n overflow: hidden;\n }\n #target {\n position: absolute;\n inset: 0;\n outline: 0;\n }\n `\n ]\n\n /**\n * 보드 모델 JSON. 변경 시 Scene 재생성 (cheap operation).\n * Object reference 가 같아도 deep 변경은 감지 못 하므로, 호출자가 새 객체로 갱신.\n */\n @property({ type: Object }) boardModel: any = null\n\n /** 사용자 클릭 / 휠 등 인터랙션 차단 (썸네일 모드용). */\n @property({ type: Boolean }) interactive: boolean = false\n\n @query('#target') private _target!: HTMLElement\n private _scene: any = null\n\n render() {\n return html`<div\n id=\"target\"\n style=${this.interactive ? '' : 'pointer-events: none;'}\n ></div>`\n }\n\n firstUpdated() {\n this._rebuild()\n }\n\n updated(changes: PropertyValues<this>) {\n if (changes.has('boardModel') && this._target) {\n this._rebuild()\n }\n }\n\n disconnectedCallback() {\n this._dispose()\n super.disconnectedCallback()\n }\n\n /** Scene 새로 만들고 target 에 부착. 기존 Scene 은 dispose. */\n private async _rebuild() {\n this._dispose()\n if (!this.boardModel || !this._target) return\n\n /* Resolving the model's types is a wait; this preview may be handed another model meanwhile. */\n const boardModel = this.boardModel\n const target = this._target\n\n try {\n const scene = await createResolvedScene(\n {\n model: { ...boardModel },\n mode: SCENE_MODE.VIEW,\n handlers: []\n } as any,\n () => this.boardModel === boardModel && this._target === target && this.isConnected\n )\n\n if (!scene) return\n\n this._scene = scene\n // 컴포넌트 모두 보이도록 fit\n this._scene.fit?.(this._scene.fitMode)\n this._scene.target = target\n } catch (e) {\n console.warn('[ox-board-preview] failed to render boardModel:', e)\n }\n }\n\n /** Scene release + target 분리. */\n private _dispose() {\n if (!this._scene) return\n try {\n this._scene.target = null\n this._scene.release?.()\n } catch {\n /* swallow — preview 정리는 best effort */\n }\n this._scene = null\n }\n}\n"]}
|
|
@@ -11,7 +11,7 @@ export declare class BoardTemplateViewer extends LitElement {
|
|
|
11
11
|
connectedCallback(): void;
|
|
12
12
|
disconnectedCallback(): void;
|
|
13
13
|
updated(changes: PropertyValues<this>): void;
|
|
14
|
-
initScene(): void
|
|
14
|
+
initScene(): Promise<void>;
|
|
15
15
|
closeScene(): void;
|
|
16
16
|
releaseScene(): void;
|
|
17
17
|
setupScene({ id, scene }: {
|
|
@@ -3,7 +3,8 @@ import '@material/web/icon/icon.js';
|
|
|
3
3
|
import '@material/web/fab/fab.js';
|
|
4
4
|
import { css, html, LitElement } from 'lit';
|
|
5
5
|
import { customElement, property, query, state } from 'lit/decorators.js';
|
|
6
|
-
import {
|
|
6
|
+
import { SCENE_MODE } from '@hatiolab/things-scene';
|
|
7
|
+
import { createResolvedScene } from './resolved-scene.js';
|
|
7
8
|
import { ScrollbarStyles } from '@operato/styles';
|
|
8
9
|
let BoardTemplateViewer = class BoardTemplateViewer extends LitElement {
|
|
9
10
|
constructor() {
|
|
@@ -36,16 +37,21 @@ let BoardTemplateViewer = class BoardTemplateViewer extends LitElement {
|
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
|
-
initScene() {
|
|
40
|
+
async initScene() {
|
|
40
41
|
if (!this.boardTemplate || !this.boardTemplate.id)
|
|
41
42
|
return;
|
|
42
|
-
|
|
43
|
+
/* Resolving the model's types is a wait, and `boardTemplate` can be replaced while it runs. */
|
|
44
|
+
const boardTemplate = this.boardTemplate;
|
|
45
|
+
const scene = await createResolvedScene({
|
|
43
46
|
model: {
|
|
44
|
-
...
|
|
47
|
+
...boardTemplate.model
|
|
45
48
|
},
|
|
46
49
|
mode: SCENE_MODE.VIEW
|
|
47
|
-
});
|
|
48
|
-
|
|
50
|
+
}, () => this.boardTemplate === boardTemplate && this.isConnected);
|
|
51
|
+
if (!scene)
|
|
52
|
+
return;
|
|
53
|
+
this._scene = scene;
|
|
54
|
+
this.setupScene({ id: boardTemplate.id, scene: this._scene });
|
|
49
55
|
}
|
|
50
56
|
closeScene() {
|
|
51
57
|
if (this._scene) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ox-board-template-viewer.js","sourceRoot":"","sources":["../../src/ox-board-template-viewer.ts"],"names":[],"mappings":";AAAA,OAAO,4BAA4B,CAAA;AACnC,OAAO,0BAA0B,CAAA;AAEjC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAkB,MAAM,KAAK,CAAA;AAC3D,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAEzE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAG1C,IAAM,mBAAmB,GAAzB,MAAM,m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AC,QAAQ,EAAE,CAAC,CAAC,CAAA;QAC9C,CAAC;IACH,CAAC;;AAxLM,0BAAM,GAAG;IACd,eAAe;IACf,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;KAyBF;CACF,AA5BY,CA4BZ;AAE2B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;0DAAwB;AAE1C;IAAR,KAAK,EAAE;mDAAmB;AAET;IAAjB,KAAK,CAAC,SAAS,CAAC;oDAAsB;AAnC5B,mBAAmB;IAD/B,aAAa,CAAC,0BAA0B,CAAC;GAC7B,mBAAmB,CA0L/B","sourcesContent":["import '@material/web/icon/icon.js'\nimport '@material/web/fab/fab.js'\n\nimport { css, html, LitElement, PropertyValues } from 'lit'\nimport { customElement, property, query, state } from 'lit/decorators.js'\n\nimport { create, SCENE_MODE } from '@hatiolab/things-scene'\nimport { ScrollbarStyles } from '@operato/styles'\n\n@customElement('ox-board-template-viewer')\nexport class BoardTemplateViewer extends LitElement {\n static styles = [\n ScrollbarStyles,\n css`\n :host {\n display: flex;\n flex-direction: column;\n\n position: relative;\n\n width: 100%; /* 전체화면보기를 위해서 필요함. */\n overflow: hidden;\n }\n\n #target {\n flex: 1;\n\n width: 100%; /* 전체화면보기를 위해서 필요함. */\n height: 100%;\n\n outline: 0;\n }\n\n @media print {\n md-icon {\n display: none;\n }\n }\n `\n ]\n\n @property({ type: Object }) boardTemplate: any = {}\n\n @state() _scene: any = null\n\n @query('#target') _target!: HTMLElement\n\n render() {\n return html` <div id=\"target\"></div> `\n }\n\n private resizeHandler = () => {\n this._scene && this._scene.fit()\n }\n\n connectedCallback() {\n super.connectedCallback()\n\n window.addEventListener('resize', this.resizeHandler)\n\n window.addEventListener('orientationchange', this.resizeHandler)\n }\n\n disconnectedCallback() {\n window.removeEventListener('resize', this.resizeHandler)\n window.removeEventListener('orientationchange', this.resizeHandler)\n\n super.disconnectedCallback()\n\n this.closeScene()\n }\n\n updated(changes: PropertyValues<this>) {\n if (changes.has('boardTemplate')) {\n this.closeScene()\n\n if (this.boardTemplate && this.boardTemplate.id) {\n this.initScene()\n }\n }\n }\n\n initScene() {\n if (!this.boardTemplate || !this.boardTemplate.id) return\n\n this._scene = create({\n model: {\n ...this.boardTemplate.model\n },\n mode: SCENE_MODE.VIEW\n })\n\n this.setupScene({ id: this.boardTemplate.id, scene: this._scene })\n }\n\n closeScene() {\n if (this._scene) {\n this._scene.target = null\n this._scene.release && this._scene.release()\n\n this._scene = null\n }\n }\n\n releaseScene() {\n this.closeScene()\n }\n\n setupScene({ id, scene }: { id: string; scene: any }) {\n this._scene = scene\n\n const backgroundColor = this._scene?.root.state.fillStyle\n if (typeof backgroundColor === 'string') {\n this.style.backgroundColor = backgroundColor\n } else {\n this.style.backgroundColor = 'initial'\n }\n\n /* scene의 기존 target을 보관한다. */\n\n this._scene.fit(this._scene.fitMode)\n this._scene.target = this._target\n }\n\n /* event handlers */\n async getSceneImageData(base64 = false) {\n if (!this._scene) {\n return\n }\n\n var { width, height } = this._scene.model\n var pixelRatio = window.devicePixelRatio\n\n // 1. Scene의 바운드에 근거하여, 오프스크린 캔바스를 만든다.\n var canvas = document.createElement('canvas')\n canvas.width = Number(width)\n canvas.height = Number(height)\n\n var root = this._scene.root\n // 2. 모델레이어의 원래 위치와 스케일을 저장한다.\n var translate = root.get('translate')\n var scale = root.get('scale')\n\n // 3. 위치와 스케일 기본 설정.\n root.set('translate', { x: 0, y: 0 })\n root.set('scale', { x: 1 / pixelRatio, y: 1 / pixelRatio })\n\n // 4. 오프스크린 캔바스의 Context2D를 구한뒤, 모델레이어를 그 위에 그린다.\n var context = canvas.getContext('2d')\n\n root.draw(context)\n\n root.set('translate', translate)\n root.set('scale', scale)\n\n var data = base64 ? canvas.toDataURL() : context!.getImageData(0, 0, width, height).data\n\n return {\n width,\n height,\n data\n }\n }\n\n async printTrick(image: string) {\n var viewTarget: HTMLElement | null = null\n var printTarget: HTMLImageElement | null = null\n\n if (!image) {\n image = (await this.getSceneImageData(true))?.data as string\n }\n\n printTarget = document.createElement('img')\n printTarget.id = 'target'\n printTarget.src = image\n printTarget.style.width = '100%'\n printTarget.style.height = '100%'\n\n const x = (mql: MediaQueryListEvent) => {\n if (mql.matches) {\n if (!viewTarget) {\n viewTarget = (this.renderRoot as ShadowRoot)!.getElementById('target')\n this.renderRoot.replaceChild(printTarget!, viewTarget!)\n }\n } else {\n this.renderRoot.replaceChild(viewTarget!, printTarget!)\n printTarget!.remove()\n mediaQueryList.removeEventListener('change', x)\n }\n }\n\n if (window.matchMedia) {\n var mediaQueryList = window.matchMedia('print')\n mediaQueryList.addEventListener('change', x)\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ox-board-template-viewer.js","sourceRoot":"","sources":["../../src/ox-board-template-viewer.ts"],"names":[],"mappings":";AAAA,OAAO,4BAA4B,CAAA;AACnC,OAAO,0BAA0B,CAAA;AAEjC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAkB,MAAM,KAAK,CAAA;AAC3D,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAEzE,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAEnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAG1C,IAAM,mBAAmB,GAAzB,MAAM,mBAAoB,SAAQ,UAAU;IAA5C;;QA+BuB,kBAAa,GAAQ,EAAE,CAAA;QAE1C,WAAM,GAAQ,IAAI,CAAA;QAQnB,kBAAa,GAAG,GAAG,EAAE;YAC3B,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAA;QAClC,CAAC,CAAA;IAyJH,CAAC;IA/JC,MAAM;QACJ,OAAO,IAAI,CAAA,2BAA2B,CAAA;IACxC,CAAC;IAMD,iBAAiB;QACf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AA;;;;;;;;;;;;;;;;;;;;;;;;;KAyBF;CACF,AA5BY,CA4BZ;AAE2B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;0DAAwB;AAE1C;IAAR,KAAK,EAAE;mDAAmB;AAET;IAAjB,KAAK,CAAC,SAAS,CAAC;oDAAsB;AAnC5B,mBAAmB;IAD/B,aAAa,CAAC,0BAA0B,CAAC;GAC7B,mBAAmB,CAoM/B","sourcesContent":["import '@material/web/icon/icon.js'\nimport '@material/web/fab/fab.js'\n\nimport { css, html, LitElement, PropertyValues } from 'lit'\nimport { customElement, property, query, state } from 'lit/decorators.js'\n\nimport { SCENE_MODE } from '@hatiolab/things-scene'\n\nimport { createResolvedScene } from './resolved-scene.js'\nimport { ScrollbarStyles } from '@operato/styles'\n\n@customElement('ox-board-template-viewer')\nexport class BoardTemplateViewer extends LitElement {\n static styles = [\n ScrollbarStyles,\n css`\n :host {\n display: flex;\n flex-direction: column;\n\n position: relative;\n\n width: 100%; /* 전체화면보기를 위해서 필요함. */\n overflow: hidden;\n }\n\n #target {\n flex: 1;\n\n width: 100%; /* 전체화면보기를 위해서 필요함. */\n height: 100%;\n\n outline: 0;\n }\n\n @media print {\n md-icon {\n display: none;\n }\n }\n `\n ]\n\n @property({ type: Object }) boardTemplate: any = {}\n\n @state() _scene: any = null\n\n @query('#target') _target!: HTMLElement\n\n render() {\n return html` <div id=\"target\"></div> `\n }\n\n private resizeHandler = () => {\n this._scene && this._scene.fit()\n }\n\n connectedCallback() {\n super.connectedCallback()\n\n window.addEventListener('resize', this.resizeHandler)\n\n window.addEventListener('orientationchange', this.resizeHandler)\n }\n\n disconnectedCallback() {\n window.removeEventListener('resize', this.resizeHandler)\n window.removeEventListener('orientationchange', this.resizeHandler)\n\n super.disconnectedCallback()\n\n this.closeScene()\n }\n\n updated(changes: PropertyValues<this>) {\n if (changes.has('boardTemplate')) {\n this.closeScene()\n\n if (this.boardTemplate && this.boardTemplate.id) {\n this.initScene()\n }\n }\n }\n\n async initScene() {\n if (!this.boardTemplate || !this.boardTemplate.id) return\n\n /* Resolving the model's types is a wait, and `boardTemplate` can be replaced while it runs. */\n const boardTemplate = this.boardTemplate\n\n const scene = await createResolvedScene(\n {\n model: {\n ...boardTemplate.model\n },\n mode: SCENE_MODE.VIEW\n },\n () => this.boardTemplate === boardTemplate && this.isConnected\n )\n\n if (!scene) return\n\n this._scene = scene\n\n this.setupScene({ id: boardTemplate.id, scene: this._scene })\n }\n\n closeScene() {\n if (this._scene) {\n this._scene.target = null\n this._scene.release && this._scene.release()\n\n this._scene = null\n }\n }\n\n releaseScene() {\n this.closeScene()\n }\n\n setupScene({ id, scene }: { id: string; scene: any }) {\n this._scene = scene\n\n const backgroundColor = this._scene?.root.state.fillStyle\n if (typeof backgroundColor === 'string') {\n this.style.backgroundColor = backgroundColor\n } else {\n this.style.backgroundColor = 'initial'\n }\n\n /* scene의 기존 target을 보관한다. */\n\n this._scene.fit(this._scene.fitMode)\n this._scene.target = this._target\n }\n\n /* event handlers */\n async getSceneImageData(base64 = false) {\n if (!this._scene) {\n return\n }\n\n var { width, height } = this._scene.model\n var pixelRatio = window.devicePixelRatio\n\n // 1. Scene의 바운드에 근거하여, 오프스크린 캔바스를 만든다.\n var canvas = document.createElement('canvas')\n canvas.width = Number(width)\n canvas.height = Number(height)\n\n var root = this._scene.root\n // 2. 모델레이어의 원래 위치와 스케일을 저장한다.\n var translate = root.get('translate')\n var scale = root.get('scale')\n\n // 3. 위치와 스케일 기본 설정.\n root.set('translate', { x: 0, y: 0 })\n root.set('scale', { x: 1 / pixelRatio, y: 1 / pixelRatio })\n\n // 4. 오프스크린 캔바스의 Context2D를 구한뒤, 모델레이어를 그 위에 그린다.\n var context = canvas.getContext('2d')\n\n root.draw(context)\n\n root.set('translate', translate)\n root.set('scale', scale)\n\n var data = base64 ? canvas.toDataURL() : context!.getImageData(0, 0, width, height).data\n\n return {\n width,\n height,\n data\n }\n }\n\n async printTrick(image: string) {\n var viewTarget: HTMLElement | null = null\n var printTarget: HTMLImageElement | null = null\n\n if (!image) {\n image = (await this.getSceneImageData(true))?.data as string\n }\n\n printTarget = document.createElement('img')\n printTarget.id = 'target'\n printTarget.src = image\n printTarget.style.width = '100%'\n printTarget.style.height = '100%'\n\n const x = (mql: MediaQueryListEvent) => {\n if (mql.matches) {\n if (!viewTarget) {\n viewTarget = (this.renderRoot as ShadowRoot)!.getElementById('target')\n this.renderRoot.replaceChild(printTarget!, viewTarget!)\n }\n } else {\n this.renderRoot.replaceChild(viewTarget!, printTarget!)\n printTarget!.remove()\n mediaQueryList.removeEventListener('change', x)\n }\n }\n\n if (window.matchMedia) {\n var mediaQueryList = window.matchMedia('print')\n mediaQueryList.addEventListener('change', x)\n }\n }\n}\n"]}
|
|
@@ -53,7 +53,7 @@ export declare class BoardViewer extends LitElement {
|
|
|
53
53
|
disconnectedCallback(): void;
|
|
54
54
|
updated(changes: PropertyValues<this>): void;
|
|
55
55
|
initSceneAsync(): Promise<void>;
|
|
56
|
-
initScene(): void
|
|
56
|
+
initScene(): Promise<void>;
|
|
57
57
|
private _ensureOverlay;
|
|
58
58
|
closeScene(): void;
|
|
59
59
|
releaseScene(): void;
|
|
@@ -4,9 +4,10 @@ import '@material/web/fab/fab.js';
|
|
|
4
4
|
import { css, html, LitElement, nothing } from 'lit';
|
|
5
5
|
import { customElement, property, query, state } from 'lit/decorators.js';
|
|
6
6
|
import * as XLSX from 'xlsx';
|
|
7
|
-
import {
|
|
7
|
+
import { LoadTracker, LoadingOverlay, SCENE_MODE } from '@hatiolab/things-scene';
|
|
8
8
|
import { isIOS, togglefullscreen } from '@operato/utils';
|
|
9
9
|
import { ScrollbarStyles } from '@operato/styles';
|
|
10
|
+
import { createResolvedScene } from './resolved-scene.js';
|
|
10
11
|
import { BoardDataStorage } from './data-storage/data-storage.js';
|
|
11
12
|
import { DataSubscriptionProviderImpl } from './graphql/data-subscription.js';
|
|
12
13
|
import { PlaybackProvider } from './graphql/playback-subscription.js';
|
|
@@ -199,25 +200,30 @@ let BoardViewer = class BoardViewer extends LitElement {
|
|
|
199
200
|
this._scene = await this.provider.create(this.board.id);
|
|
200
201
|
this.setupScene({ id: this.board.id, scene: this._scene });
|
|
201
202
|
}
|
|
202
|
-
initScene() {
|
|
203
|
+
async initScene() {
|
|
203
204
|
if (!this.board || !this.board.id)
|
|
204
205
|
return;
|
|
205
|
-
|
|
206
|
+
/* Resolving the model's types is a wait, and `board` can be replaced while it runs. */
|
|
207
|
+
const board = this.board;
|
|
208
|
+
const scene = await createResolvedScene({
|
|
206
209
|
model: {
|
|
207
|
-
...
|
|
210
|
+
...board.model
|
|
208
211
|
},
|
|
209
212
|
mode: SCENE_MODE.VIEW,
|
|
210
213
|
refProvider: this.provider,
|
|
211
|
-
dataStorage:
|
|
214
|
+
dataStorage: board.id !== 'preview' ? new BoardDataStorage(board.id) : undefined,
|
|
212
215
|
dataSubscriptionProvider: new DataSubscriptionProviderImpl(),
|
|
213
216
|
handlers: ['waypoint-handler'],
|
|
214
217
|
loading: { tracker: this.loadTracker }
|
|
215
|
-
});
|
|
218
|
+
}, () => this.board === board && this.isConnected);
|
|
219
|
+
if (!scene)
|
|
220
|
+
return;
|
|
221
|
+
this._scene = scene;
|
|
216
222
|
if (this.baseUrl) {
|
|
217
223
|
this._scene.baseUrl = this.baseUrl;
|
|
218
224
|
}
|
|
219
225
|
// this.provider!.add(this.board.id, this._scene)
|
|
220
|
-
this.setupScene({ id:
|
|
226
|
+
this.setupScene({ id: board.id, scene: this._scene });
|
|
221
227
|
}
|
|
222
228
|
_ensureOverlay(tracker) {
|
|
223
229
|
if (!this._loadingOverlay) {
|