@difizen/libro-core 0.2.40-next.4 → 0.2.41-next.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.
Files changed (51) hide show
  1. package/es/cell/libro-cell-view.js +1 -3
  2. package/es/cell/libro-executable-cell-view.d.ts +2 -0
  3. package/es/cell/libro-executable-cell-view.d.ts.map +1 -1
  4. package/es/cell/libro-executable-cell-view.js +15 -0
  5. package/es/components/cell-protocol.d.ts +4 -0
  6. package/es/components/cell-protocol.d.ts.map +1 -1
  7. package/es/components/cell-protocol.js +1 -0
  8. package/es/components/dnd-cell-item-render.d.ts +2 -1
  9. package/es/components/dnd-cell-item-render.d.ts.map +1 -1
  10. package/es/components/dnd-cell-item-render.js +7 -1
  11. package/es/index.d.ts +1 -0
  12. package/es/index.d.ts.map +1 -1
  13. package/es/index.js +2 -1
  14. package/es/index.less +4 -7
  15. package/es/libro-model.d.ts +3 -0
  16. package/es/libro-model.d.ts.map +1 -1
  17. package/es/libro-model.js +25 -0
  18. package/es/libro-protocol.d.ts +1 -0
  19. package/es/libro-protocol.d.ts.map +1 -1
  20. package/es/libro-setting.js +1 -1
  21. package/es/libro-view.d.ts +2 -0
  22. package/es/libro-view.d.ts.map +1 -1
  23. package/es/libro-view.js +21 -1
  24. package/es/module.d.ts.map +1 -1
  25. package/es/module.js +4 -1
  26. package/es/slot/libro-slot-view.d.ts +4 -0
  27. package/es/slot/libro-slot-view.d.ts.map +1 -1
  28. package/es/slot/libro-slot-view.js +56 -5
  29. package/es/theme/libro-color-registry.d.ts.map +1 -1
  30. package/es/theme/libro-color-registry.js +7 -0
  31. package/es/utils/index.d.ts +8 -0
  32. package/es/utils/index.d.ts.map +1 -0
  33. package/es/utils/index.js +53 -0
  34. package/package.json +5 -5
  35. package/src/cell/libro-cell-view.tsx +1 -1
  36. package/src/cell/libro-executable-cell-view.ts +11 -0
  37. package/src/components/cell-protocol.ts +4 -0
  38. package/src/components/dnd-cell-item-render.tsx +12 -1
  39. package/src/components/dnd-component/default-dnd-content.tsx +15 -5
  40. package/src/components/dnd-component/dnd-list.tsx +23 -9
  41. package/src/components/libro-virtualized-render.tsx +14 -2
  42. package/src/index.less +14 -9
  43. package/src/index.tsx +1 -0
  44. package/src/libro-model.ts +10 -0
  45. package/src/libro-protocol.ts +3 -0
  46. package/src/libro-setting.ts +1 -1
  47. package/src/libro-view.tsx +30 -4
  48. package/src/module.ts +6 -0
  49. package/src/slot/libro-slot-view.tsx +32 -5
  50. package/src/theme/libro-color-registry.ts +5 -0
  51. package/src/utils/index.ts +48 -0
package/src/module.ts CHANGED
@@ -15,11 +15,13 @@ import {
15
15
  CellExecutionTimeProvider,
16
16
  CellInputBottonBlankProvider,
17
17
  CellOutputBottomBlankProvider,
18
+ CellOutputTopProvider,
18
19
  CellOutputVisulizationProvider,
19
20
  LibroBetweenCellContent,
20
21
  LibroCellExecutionTime,
21
22
  LibroCellInputBottonBlank,
22
23
  LibroCellOutputBottomBlank,
24
+ LibroCellTopBlank,
23
25
  LibroCellVisualization,
24
26
  } from './components/index.js';
25
27
  import { LibroContentModule } from './content/index.js';
@@ -99,6 +101,10 @@ export const LibroModule = ManaModule.create()
99
101
  token: CellOutputBottomBlankProvider,
100
102
  useValue: LibroCellOutputBottomBlank,
101
103
  },
104
+ {
105
+ token: CellOutputTopProvider,
106
+ useValue: LibroCellTopBlank,
107
+ },
102
108
  {
103
109
  token: CellOutputVisulizationProvider,
104
110
  useValue: LibroCellVisualization,
@@ -1,3 +1,4 @@
1
+ import type { View, ViewOpenOption, Disposable } from '@difizen/mana-app';
1
2
  import { DefaultSlotView, view, ViewRender, ViewInstance } from '@difizen/mana-app';
2
3
  import { transient } from '@difizen/mana-app';
3
4
  import { equals, prop, useInject } from '@difizen/mana-app';
@@ -21,13 +22,12 @@ export const LibroExtensionViewComponent = forwardRef(
21
22
  </div>
22
23
  );
23
24
  } else {
24
- const activeView =
25
- filteredChildren.find(
26
- (item) => instance.active && equals(item, instance.active),
27
- ) || filteredChildren[filteredChildren.length - 1];
25
+ const activeView = filteredChildren.find(
26
+ (item) => instance.active && equals(item, instance.active),
27
+ );
28
28
  return (
29
29
  <div className={'libro-slot-container'} ref={ref}>
30
- <ViewRender view={activeView} />
30
+ {activeView && <ViewRender view={activeView} />}
31
31
  {instance.children.map(
32
32
  (item) => !isDisplayView(item) && <ViewRender view={item} key={item.id} />,
33
33
  )}
@@ -45,4 +45,31 @@ export class LibroSlotView extends DefaultSlotView {
45
45
  @prop()
46
46
  override sort?: boolean = false;
47
47
  // sort?: boolean = true;
48
+
49
+ protected history: View[] = [];
50
+
51
+ override async addView(
52
+ viewInstance: View,
53
+ option?: ViewOpenOption,
54
+ ): Promise<Disposable> {
55
+ if (option?.reveal) {
56
+ this.history.push(viewInstance);
57
+ }
58
+ const toDispose = super.addView(viewInstance, option);
59
+ return toDispose;
60
+ }
61
+
62
+ revertActive() {
63
+ const index = this.history.findIndex((item) => item.id === this.active?.id);
64
+ if (index < 0) {
65
+ return;
66
+ }
67
+ this.history.splice(index, 1);
68
+ if (this.history.length > 0) {
69
+ const last = this.history[this.history.length - 1];
70
+ this.active = last;
71
+ } else {
72
+ this.active = undefined;
73
+ }
74
+ }
48
75
  }
@@ -308,6 +308,11 @@ export class LibroColorRegistry implements ColorContribution {
308
308
  defaults: { dark: '#E3E4E6', light: '#212121' },
309
309
  description: '',
310
310
  },
311
+ {
312
+ id: 'libro.editor.class.color',
313
+ defaults: { dark: '#6868f3', light: '#0000ff' },
314
+ description: '',
315
+ },
311
316
  {
312
317
  id: 'libro.editor.def.color',
313
318
  defaults: { dark: '#187DFF', light: '#003CFF' },
@@ -0,0 +1,48 @@
1
+ import { useUnmount } from '@difizen/mana-app';
2
+ import type { RefObject } from 'react';
3
+ import { useCallback, useLayoutEffect, useRef, useState } from 'react';
4
+
5
+ function useRafState<S>(initialState?: S) {
6
+ const ref = useRef(0);
7
+ const [state, setState] = useState<S | undefined>(initialState);
8
+
9
+ const setRafState = useCallback((value: S) => {
10
+ cancelAnimationFrame(ref.current);
11
+
12
+ ref.current = requestAnimationFrame(() => {
13
+ setState(value);
14
+ });
15
+ }, []);
16
+
17
+ useUnmount(() => {
18
+ cancelAnimationFrame(ref.current);
19
+ });
20
+
21
+ return [state, setRafState] as const;
22
+ }
23
+
24
+ type Size = { width: number; height: number };
25
+ export function useSize(ref: RefObject<HTMLDivElement>): Size | undefined {
26
+ const [size, setSize] = useRafState<Size>();
27
+ useLayoutEffect(() => {
28
+ const el = ref?.current;
29
+ if (!el) {
30
+ return;
31
+ }
32
+ const resizeObserver = new ResizeObserver((entries) => {
33
+ entries.forEach((entry) => {
34
+ const { clientWidth, clientHeight } = entry.target;
35
+ setSize({
36
+ width: clientWidth,
37
+ height: clientHeight,
38
+ });
39
+ });
40
+ });
41
+
42
+ resizeObserver.observe(el);
43
+ return () => {
44
+ resizeObserver.disconnect();
45
+ };
46
+ }, [ref, setSize]);
47
+ return size;
48
+ }