@netless/fastboard-ui 0.3.3 → 0.3.4-canary.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netless/fastboard-ui",
3
- "version": "0.3.3",
3
+ "version": "0.3.4-canary.2",
4
4
  "description": "The front-end of @netless/fastboard-core.",
5
5
  "main": "dist/index.js",
6
6
  "svelte": "dist/index.svelte.mjs",
@@ -10,14 +10,14 @@
10
10
  ],
11
11
  "repository": "netless-io/fastboard",
12
12
  "peerDependencies": {
13
- "@netless/fastboard-core": "0.3.3"
13
+ "@netless/fastboard-core": "0.3.4-canary.2"
14
14
  },
15
15
  "dependencies": {
16
16
  "tippy.js": "^6.3.7"
17
17
  },
18
18
  "devDependencies": {
19
19
  "@netless/esbuild-plugin-inline-sass": "0.1.0",
20
- "@netless/fastboard-core": "0.3.3"
20
+ "@netless/fastboard-core": "0.3.4-canary.2"
21
21
  },
22
22
  "scripts": {
23
23
  "cleanup": "rimraf dist",
@@ -52,7 +52,10 @@ export const apps = new AppsInToolbar([
52
52
  icon: code_editor_svg,
53
53
  label: "Code Editor",
54
54
  onClick(app) {
55
- app.insertCodeEditor();
55
+ app.manager.addApp({
56
+ kind: "Monaco",
57
+ options: { title: "Code Editor" },
58
+ });
56
59
  },
57
60
  },
58
61
  {
@@ -60,7 +63,10 @@ export const apps = new AppsInToolbar([
60
63
  icon: geogebra_svg,
61
64
  label: "GeoGebra",
62
65
  onClick(app) {
63
- app.insertGeoGebra();
66
+ app.manager.addApp({
67
+ kind: "GeoGebra",
68
+ options: { title: "GeoGebra" },
69
+ });
64
70
  },
65
71
  },
66
72
  {
@@ -68,7 +74,10 @@ export const apps = new AppsInToolbar([
68
74
  icon: countdown_svg,
69
75
  label: "Countdown",
70
76
  onClick(app) {
71
- app.insertCountdown();
77
+ app.manager.addApp({
78
+ kind: "Countdown",
79
+ options: { title: "Countdown" },
80
+ });
72
81
  },
73
82
  },
74
83
  ]);
@@ -1,3 +1,5 @@
1
+ <svelte:options immutable />
2
+
1
3
  <script lang="ts">
2
4
  import type { FastboardApp } from "@netless/fastboard-core";
3
5
  import type { Language, Theme, FastboardUIConfig } from "../../typings";
@@ -19,6 +21,7 @@
19
21
 
20
22
  let container: HTMLDivElement;
21
23
  let layout: "hidden" | "toolbar-only" | "visible" = "hidden";
24
+ let mounted = false;
22
25
 
23
26
  $: writable = app?.writable;
24
27
  $: boxState = app?.boxState;
@@ -37,13 +40,16 @@
37
40
  }
38
41
 
39
42
  $: try {
40
- if (app && container) app.bindContainer(container);
43
+ if (app && container) {
44
+ app.bindContainer(container);
45
+ mounted = true;
46
+ }
41
47
  } catch (err) {
42
48
  console.error("[fastboard] An error occurred while binding container");
43
49
  console.error(err);
44
50
  }
45
51
 
46
- $: if (app && theme) {
52
+ $: if (app && theme && mounted) {
47
53
  app.manager.setPrefersColorScheme(theme);
48
54
  }
49
55
 
@@ -1,3 +1,5 @@
1
+ <svelte:options immutable />
2
+
1
3
  <script lang="ts">
2
4
  import type { FastboardPlayer } from "@netless/fastboard-core";
3
5
  import type { Language, Theme } from "../../typings";
@@ -13,15 +15,19 @@
13
15
  const name = "fastboard";
14
16
 
15
17
  let container: HTMLDivElement;
18
+ let mounted = false;
16
19
 
17
20
  $: try {
18
- if (player && container) player.bindContainer(container);
21
+ if (player && container) {
22
+ player.bindContainer(container);
23
+ mounted = true;
24
+ }
19
25
  } catch (err) {
20
26
  console.error("[fastboard] An error occurred while binding container");
21
27
  console.error(err);
22
28
  }
23
29
 
24
- $: if (player && theme) {
30
+ $: if (player && theme && mounted) {
25
31
  player.manager.setPrefersColorScheme(theme);
26
32
  }
27
33
 
@@ -7,10 +7,24 @@
7
7
 
8
8
  <svg fill="none" viewBox="0 0 24 24" class="fastboard-icon {theme}" class:is-active={active}>
9
9
  <path
10
+ d="M19.6567 4.34323L13.9999 10.0001"
10
11
  stroke="#5D6066"
12
+ stroke-width="1.25"
13
+ stroke-linejoin="round"
14
+ class="fastboard-icon-stroke-color"
15
+ />
16
+ <path
17
+ d="M8.34296 10.0001C9.90506 8.43799 12.4377 8.43799 13.9998 10.0001V10.0001C15.5619 11.5622 15.5619 14.0948 13.9998 15.6569V15.6569L8.34296 10.0001V10.0001Z"
18
+ stroke="#5D6066"
19
+ stroke-width="1.25"
11
20
  stroke-linejoin="round"
21
+ class="fastboard-icon-stroke-color"
22
+ />
23
+ <path
24
+ d="M8.34292 10.0001L13.9998 15.6569L11.5856 19.8996L4.10028 11.4143L8.34292 10.0001Z"
25
+ stroke="#5D6066"
12
26
  stroke-width="1.25"
13
- d="m17.95 4.636-2.83 2.828-1.413-1.414a2 2 0 0 0-2.829 0l-.707.707 7.071 7.071.707-.707a2 2 0 0 0 0-2.828l-1.414-1.414 2.829-2.829-1.415-1.414Zm-1.415 9.9-5.656 5.656-.707-.707 1.767-3.182-3.182 1.768.707-2.121-2.121.707 1.768-3.182-3.182 1.768.707-2.122-2.121.707-.707-.707 5.656-5.657"
27
+ stroke-linejoin="round"
14
28
  class="fastboard-icon-stroke-color"
15
29
  />
16
30
  </svg>
@@ -5,7 +5,6 @@ import Balloon from "./Balloon.svelte";
5
5
  import BalloonBolded from "./BalloonBolded.svelte";
6
6
  import Circle from "./Circle.svelte";
7
7
  import CircleBolded from "./CircleBolded.svelte";
8
- import Clean from "./Clean.svelte";
9
8
  import Clear from "./Clear.svelte";
10
9
  import Click from "./Click.svelte";
11
10
  import ClickFilled from "./ClickFilled.svelte";
@@ -51,7 +50,6 @@ const Icons = {
51
50
  BalloonBolded,
52
51
  Circle,
53
52
  CircleBolded,
54
- Clean,
55
53
  Clear,
56
54
  Click,
57
55
  ClickFilled,
@@ -0,0 +1,94 @@
1
+ import type { FastboardApp, FastboardPlayer } from "@netless/fastboard-core";
2
+ import type { FastboardProps, ReplayFastboardProps } from "../components/Fastboard";
3
+
4
+ import { Fastboard, ReplayFastboard } from "../components/Fastboard";
5
+
6
+ export interface UI {
7
+ /** render UI to div */
8
+ mount(div: Element, props?: Omit<FastboardProps, "app">): UI;
9
+ /** update UI (theme, language, etc.) */
10
+ update(props?: Omit<FastboardProps, "app">): void;
11
+ /** remove UI */
12
+ destroy(): void;
13
+ }
14
+
15
+ /**
16
+ * @example
17
+ * let ui = createUI(fastboardApp, document.getElementById("whiteboard"));
18
+ * ui.update({ theme: "dark" })
19
+ */
20
+ export function createUI(app: FastboardApp, div?: Element): UI {
21
+ let fastboard: Fastboard | undefined;
22
+
23
+ const ui: UI = {
24
+ mount(div: Element, props?: Omit<FastboardProps, "app">) {
25
+ if (fastboard) {
26
+ fastboard.$destroy();
27
+ }
28
+ fastboard = new Fastboard({ target: div, props: { app, ...props } });
29
+ return ui;
30
+ },
31
+ update(props?: Omit<FastboardProps, "app">) {
32
+ if (fastboard) {
33
+ fastboard.$set(props);
34
+ }
35
+ },
36
+ destroy() {
37
+ if (fastboard) {
38
+ fastboard.$destroy();
39
+ }
40
+ fastboard = undefined;
41
+ },
42
+ };
43
+
44
+ if (div) {
45
+ ui.mount(div);
46
+ }
47
+
48
+ return ui;
49
+ }
50
+
51
+ export interface ReplayUI {
52
+ /** render UI to div */
53
+ mount(div: Element, props?: Omit<ReplayFastboardProps, "player">): ReplayUI;
54
+ /** update UI (theme, language, etc.) */
55
+ update(props?: Omit<ReplayFastboardProps, "player">): void;
56
+ /** remove UI */
57
+ destroy(): void;
58
+ }
59
+
60
+ /**
61
+ * @example
62
+ * let ui = createReplayUI(fastboardPlayer, document.getElementById("whiteboard"));
63
+ * ui.update({ theme: "dark" })
64
+ */
65
+ export function createReplayUI(player: FastboardPlayer, div?: Element): ReplayUI {
66
+ let fastboard: ReplayFastboard | undefined;
67
+
68
+ const ui: ReplayUI = {
69
+ mount(div: Element, props?: Omit<ReplayFastboardProps, "player">) {
70
+ if (fastboard) {
71
+ fastboard.$destroy();
72
+ }
73
+ fastboard = new ReplayFastboard({ target: div, props: { player, ...props } });
74
+ return ui;
75
+ },
76
+ update(props?: Omit<ReplayFastboardProps, "player">) {
77
+ if (fastboard) {
78
+ fastboard.$set(props);
79
+ }
80
+ },
81
+ destroy() {
82
+ if (fastboard) {
83
+ fastboard.$destroy();
84
+ }
85
+ fastboard = undefined;
86
+ },
87
+ };
88
+
89
+ if (div) {
90
+ ui.mount(div);
91
+ }
92
+
93
+ return ui;
94
+ }
package/src/index.ts CHANGED
@@ -8,6 +8,7 @@ export { default as PlayerControl, type PlayerControlProps } from "./components/
8
8
  export { Fastboard, ReplayFastboard } from "./components/Fastboard";
9
9
  export type { FastboardProps, ReplayFastboardProps } from "./components/Fastboard";
10
10
 
11
+ export * from "./helpers";
11
12
  export * from "./behaviors";
12
13
 
13
14
  import "./style.scss";
@@ -1,14 +0,0 @@
1
- <script lang="ts">
2
- import type { Theme } from "../../typings";
3
-
4
- export let theme: Theme = "light";
5
- export let active = false;
6
- </script>
7
-
8
- <svg fill="none" viewBox="0 0 24 24" class="fastboard-icon {theme}" class:is-active={active}>
9
- <path
10
- fill="#5D6066"
11
- d="M9.754 11.99c0 1.856-.711 3.62-1.96 4.951l-.151.155h1.403l.855-.853h.707l.853.853h2.635l.094-.064a6.237 6.237 0 0 0 2.559-4.781l.005-.26h1a7.237 7.237 0 0 1-2.994 5.862l-.229.16-.277.083h-3l-.353-.146-.647-.647-.646.647-.354.146h-3l-.286-.91.214-.148a6.237 6.237 0 0 0 2.567-4.787l.005-.26h1Zm4.772-6.502v2l.35.039a2.98 2.98 0 0 1 2.644 2.78l.006.181h-8a2.98 2.98 0 0 1 2.65-2.961l.35-.039v-2h2Z"
12
- class="fastboard-icon-fill-color"
13
- />
14
- </svg>