@netless/fastboard 0.0.1 → 0.0.5

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.
Files changed (43) hide show
  1. package/README.md +8 -10
  2. package/dist/index.cjs.js +4 -4
  3. package/dist/index.cjs.js.map +1 -1
  4. package/dist/index.es.js +478 -168
  5. package/dist/index.es.js.map +1 -1
  6. package/dist/svelte.cjs.js +2 -0
  7. package/dist/svelte.cjs.js.map +1 -0
  8. package/dist/svelte.es.js +31 -0
  9. package/dist/svelte.es.js.map +1 -0
  10. package/dist/vue.cjs.js +2 -0
  11. package/dist/vue.cjs.js.map +1 -0
  12. package/dist/vue.es.js +42 -0
  13. package/dist/vue.es.js.map +1 -0
  14. package/package.json +25 -41
  15. package/src/WhiteboardApp.ts +39 -3
  16. package/src/behaviors/style.ts +1 -1
  17. package/src/components/PlayerControl/PlayerControl.scss +145 -0
  18. package/src/components/PlayerControl/PlayerControl.tsx +158 -0
  19. package/src/components/PlayerControl/components/Button.tsx +55 -0
  20. package/src/components/PlayerControl/hooks.ts +95 -0
  21. package/src/components/PlayerControl/icons/Loading.tsx +13 -0
  22. package/src/components/PlayerControl/icons/Pause.tsx +13 -0
  23. package/src/components/PlayerControl/icons/Play.tsx +13 -0
  24. package/src/components/PlayerControl/icons/index.ts +10 -0
  25. package/src/components/PlayerControl/index.ts +1 -0
  26. package/src/components/Root.tsx +1 -2
  27. package/src/components/Toolbar/Content.tsx +28 -15
  28. package/src/components/Toolbar/components/ColorBox.tsx +3 -3
  29. package/src/components/Toolbar/components/UpDownButtons.tsx +7 -10
  30. package/src/components/Toolbar/hooks.ts +1 -1
  31. package/src/components/ZoomControl.tsx +1 -1
  32. package/src/hooks.ts +18 -60
  33. package/src/i18n/en.json +2 -1
  34. package/src/i18n/zh-CN.json +2 -1
  35. package/src/index.ts +9 -2
  36. package/src/internal/Instance.tsx +40 -19
  37. package/src/internal/helpers.ts +15 -0
  38. package/src/internal/index.ts +1 -0
  39. package/src/internal/mount-whiteboard.ts +13 -5
  40. package/src/style.scss +1 -0
  41. package/src/svelte.ts +45 -0
  42. package/src/vue.ts +74 -0
  43. package/src/helpers/index.ts +0 -18
package/src/svelte.ts ADDED
@@ -0,0 +1,45 @@
1
+ import { readable, type Readable } from "svelte/store";
2
+ import { createWhiteboardApp } from "./index";
3
+
4
+ import type { WhiteboardApp, WhiteboardAppConfig } from "./WhiteboardApp";
5
+
6
+ export type FastBoardConfig = WhiteboardAppConfig;
7
+
8
+ /**
9
+ * @example
10
+ * ```svelte
11
+ * <script>
12
+ * let ref = writable(null)
13
+ * let app = useFastboard(ref, { sdkConfig, joinRoom })
14
+ * if (app) {
15
+ * app.insertDocs({...})
16
+ * }
17
+ * </script>
18
+ * <div style="width: 100%; height: 100%" bind:this={$ref} />
19
+ * ```
20
+ */
21
+ export function useFastboard(
22
+ ref: Readable<HTMLElement | null>,
23
+ config: FastBoardConfig
24
+ ): Readable<WhiteboardApp | null> {
25
+ return readable<WhiteboardApp | null>(null, set => {
26
+ let app_: WhiteboardApp | null = null;
27
+
28
+ createWhiteboardApp(config).then(app => {
29
+ set((app_ = app));
30
+ });
31
+
32
+ const dispose = ref.subscribe(div => {
33
+ if (div && app_) {
34
+ app_.bindElement(div);
35
+ }
36
+ });
37
+
38
+ return () => {
39
+ dispose();
40
+ if (app_) {
41
+ app_.dispose();
42
+ }
43
+ };
44
+ });
45
+ }
package/src/vue.ts ADDED
@@ -0,0 +1,74 @@
1
+ import type { ComponentPublicInstance, Ref } from "vue-demi";
2
+ import {
3
+ computed,
4
+ getCurrentScope,
5
+ onScopeDispose,
6
+ shallowRef,
7
+ unref,
8
+ watchEffect,
9
+ } from "vue-demi";
10
+ import { createWhiteboardApp } from "./index";
11
+
12
+ import type { WhiteboardApp, WhiteboardAppConfig } from "./WhiteboardApp";
13
+
14
+ export type FastBoardConfig = WhiteboardAppConfig;
15
+
16
+ export type MaybeRef<T> = T | Ref<T>;
17
+ export type VueInstance = ComponentPublicInstance;
18
+ export type MaybeElementRef = MaybeRef<
19
+ HTMLElement | SVGElement | VueInstance | undefined | null
20
+ >;
21
+
22
+ /**
23
+ * Get the dom element of a ref of element or Vue component instance
24
+ */
25
+ export function unrefElement(elRef: MaybeElementRef) {
26
+ const plain = unref(elRef);
27
+ return (plain as VueInstance)?.$el ?? plain;
28
+ }
29
+
30
+ function tryOnScopeDispose(fn: () => void) {
31
+ if (getCurrentScope()) {
32
+ onScopeDispose(fn);
33
+ return true;
34
+ }
35
+ return false;
36
+ }
37
+
38
+ /**
39
+ * @example
40
+ * ```vue
41
+ * <script setup>
42
+ * const el = ref(null)
43
+ * const app = useFastboard(el, { sdkConfig, joinRoom })
44
+ * if (app.value) {
45
+ * app.value.insertDocs({...})
46
+ * }
47
+ * </script>
48
+ * <template>
49
+ * <div style="width: 100%; height: 100%" ref="el"></div>
50
+ * </template>
51
+ * ```
52
+ */
53
+ export function useFastboard(el: MaybeElementRef, config: FastBoardConfig) {
54
+ const app = shallowRef<WhiteboardApp | null>(null);
55
+ const target = computed(() => unrefElement(el));
56
+
57
+ createWhiteboardApp(config).then(app_ => {
58
+ app.value = app_;
59
+ });
60
+
61
+ watchEffect(() => {
62
+ if (target.value && app.value) {
63
+ app.value.bindElement(target.value);
64
+ }
65
+ });
66
+
67
+ tryOnScopeDispose(() => {
68
+ if (app.value) {
69
+ app.value.dispose();
70
+ }
71
+ });
72
+
73
+ return app;
74
+ }
@@ -1,18 +0,0 @@
1
- export function applyStyles(css: string) {
2
- const el = document.createElement("style");
3
- el.appendChild(document.createTextNode(css));
4
- document.head.appendChild(el);
5
- return el;
6
- }
7
-
8
- export function clamp(value: number, min: number, max: number) {
9
- return Math.min(Math.max(value, min), max);
10
- }
11
-
12
- export function capitalize(str: string) {
13
- return str[0].toUpperCase() + str.slice(1);
14
- }
15
-
16
- export function isEqualArray<T>(a: T[], b: T[]) {
17
- return a.length === b.length && a.every((e, i) => e === b[i]);
18
- }