@dxos/plugin-debug 0.6.8-main.046e6cf

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 (80) hide show
  1. package/LICENSE +8 -0
  2. package/README.md +15 -0
  3. package/dist/lib/browser/DebugGlobal-H37KGFEG.mjs +179 -0
  4. package/dist/lib/browser/DebugGlobal-H37KGFEG.mjs.map +7 -0
  5. package/dist/lib/browser/DebugSpace-ZZ2JLU6F.mjs +407 -0
  6. package/dist/lib/browser/DebugSpace-ZZ2JLU6F.mjs.map +7 -0
  7. package/dist/lib/browser/DevtoolsMain-DTAWVF22.mjs +16 -0
  8. package/dist/lib/browser/DevtoolsMain-DTAWVF22.mjs.map +7 -0
  9. package/dist/lib/browser/chunk-ED5L5YYI.mjs +27 -0
  10. package/dist/lib/browser/chunk-ED5L5YYI.mjs.map +7 -0
  11. package/dist/lib/browser/chunk-RYK3J66D.mjs +24 -0
  12. package/dist/lib/browser/chunk-RYK3J66D.mjs.map +7 -0
  13. package/dist/lib/browser/chunk-WEGYHXMB.mjs +21 -0
  14. package/dist/lib/browser/chunk-WEGYHXMB.mjs.map +7 -0
  15. package/dist/lib/browser/index.mjs +658 -0
  16. package/dist/lib/browser/index.mjs.map +7 -0
  17. package/dist/lib/browser/meta.json +1 -0
  18. package/dist/lib/browser/meta.mjs +9 -0
  19. package/dist/lib/browser/meta.mjs.map +7 -0
  20. package/dist/types/src/DebugPlugin.d.ts +5 -0
  21. package/dist/types/src/DebugPlugin.d.ts.map +1 -0
  22. package/dist/types/src/components/DebugGlobal.d.ts +7 -0
  23. package/dist/types/src/components/DebugGlobal.d.ts.map +1 -0
  24. package/dist/types/src/components/DebugPanel.d.ts +5 -0
  25. package/dist/types/src/components/DebugPanel.d.ts.map +1 -0
  26. package/dist/types/src/components/DebugSettings.d.ts +6 -0
  27. package/dist/types/src/components/DebugSettings.d.ts.map +1 -0
  28. package/dist/types/src/components/DebugSpace.d.ts +9 -0
  29. package/dist/types/src/components/DebugSpace.d.ts.map +1 -0
  30. package/dist/types/src/components/DebugSpace.stories.d.ts +16 -0
  31. package/dist/types/src/components/DebugSpace.stories.d.ts.map +1 -0
  32. package/dist/types/src/components/DebugStatus.d.ts +3 -0
  33. package/dist/types/src/components/DebugStatus.d.ts.map +1 -0
  34. package/dist/types/src/components/DevtoolsMain.d.ts +4 -0
  35. package/dist/types/src/components/DevtoolsMain.d.ts.map +1 -0
  36. package/dist/types/src/components/ObjectCreator.d.ts +17 -0
  37. package/dist/types/src/components/ObjectCreator.d.ts.map +1 -0
  38. package/dist/types/src/components/ObjectCreator.stories.d.ts +17 -0
  39. package/dist/types/src/components/ObjectCreator.stories.d.ts.map +1 -0
  40. package/dist/types/src/components/Tree.d.ts +20 -0
  41. package/dist/types/src/components/Tree.d.ts.map +1 -0
  42. package/dist/types/src/components/Wireframe.d.ts +7 -0
  43. package/dist/types/src/components/Wireframe.d.ts.map +1 -0
  44. package/dist/types/src/components/index.d.ts +13 -0
  45. package/dist/types/src/components/index.d.ts.map +1 -0
  46. package/dist/types/src/index.d.ts +4 -0
  47. package/dist/types/src/index.d.ts.map +1 -0
  48. package/dist/types/src/meta.d.ts +15 -0
  49. package/dist/types/src/meta.d.ts.map +1 -0
  50. package/dist/types/src/scaffolding/generator.d.ts +11 -0
  51. package/dist/types/src/scaffolding/generator.d.ts.map +1 -0
  52. package/dist/types/src/scaffolding/index.d.ts +2 -0
  53. package/dist/types/src/scaffolding/index.d.ts.map +1 -0
  54. package/dist/types/src/translations.d.ts +29 -0
  55. package/dist/types/src/translations.d.ts.map +1 -0
  56. package/dist/types/src/types.d.ts +19 -0
  57. package/dist/types/src/types.d.ts.map +1 -0
  58. package/dist/types/src/types.test.d.ts +2 -0
  59. package/dist/types/src/types.test.d.ts.map +1 -0
  60. package/package.json +92 -0
  61. package/src/DebugPlugin.tsx +270 -0
  62. package/src/components/DebugGlobal.tsx +80 -0
  63. package/src/components/DebugPanel.tsx +34 -0
  64. package/src/components/DebugSettings.tsx +159 -0
  65. package/src/components/DebugSpace.stories.tsx +40 -0
  66. package/src/components/DebugSpace.tsx +195 -0
  67. package/src/components/DebugStatus.tsx +221 -0
  68. package/src/components/DevtoolsMain.tsx +16 -0
  69. package/src/components/ObjectCreator.stories.tsx +44 -0
  70. package/src/components/ObjectCreator.tsx +100 -0
  71. package/src/components/Tree.tsx +113 -0
  72. package/src/components/Wireframe.tsx +35 -0
  73. package/src/components/index.ts +14 -0
  74. package/src/index.ts +9 -0
  75. package/src/meta.tsx +19 -0
  76. package/src/scaffolding/generator.ts +143 -0
  77. package/src/scaffolding/index.ts +5 -0
  78. package/src/translations.ts +36 -0
  79. package/src/types.test.ts +13 -0
  80. package/src/types.ts +45 -0
@@ -0,0 +1,35 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import React from 'react';
6
+ import { useResizeDetector } from 'react-resize-detector';
7
+
8
+ import { createAttendableAttributes } from '@dxos/react-ui-attention';
9
+ import { mx } from '@dxos/react-ui-theme';
10
+
11
+ // TODO(burdon): Make focusable and attendable with input.
12
+ export const Wireframe = ({ label, data, className }: { label?: string; data?: any; className?: string }) => {
13
+ const attendableAttrs = createAttendableAttributes(data);
14
+ const { width, height, ref } = useResizeDetector();
15
+ return (
16
+ <div ref={ref} className={mx('relative grow', className)} {...attendableAttrs}>
17
+ <div className='absolute inset-2 flex flex-col overflow-hidden font-mono'>
18
+ <div className='flex justify-between'>
19
+ <div>{label}</div>
20
+ <div>{`[${width}x${height}]`}</div>
21
+ </div>
22
+ <div className='flex grow overflow-auto'>
23
+ {data && (
24
+ <pre className='text-neutral-500 text-sm whitespace-pre-line'>{JSON.stringify(data, undefined, 1)}</pre>
25
+ )}
26
+ </div>
27
+ </div>
28
+ <svg width={width} height={height} className='bg-transparent [&>*]:stroke-neutral-500'>
29
+ <rect x={0} y={0} width={width} height={height} strokeWidth={1} fill='none' />
30
+ <line x1={0} y1={0} x2={width} y2={height} strokeWidth={1} />
31
+ <line x1={0} y1={height} x2={width} y2={0} strokeWidth={1} />
32
+ </svg>
33
+ </div>
34
+ );
35
+ };
@@ -0,0 +1,14 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import React from 'react';
6
+
7
+ // Lazily load components for content surfaces.
8
+ export const DebugGlobal = React.lazy(() => import('./DebugGlobal'));
9
+ export const DebugSpace = React.lazy(() => import('./DebugSpace'));
10
+ export const DevtoolsMain = React.lazy(() => import('./DevtoolsMain'));
11
+
12
+ export * from './DebugSettings';
13
+ export * from './DebugStatus';
14
+ export * from './Wireframe';
package/src/index.ts ADDED
@@ -0,0 +1,9 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { DebugPlugin } from './DebugPlugin';
6
+
7
+ export * from './DebugPlugin';
8
+
9
+ export default DebugPlugin;
package/src/meta.tsx ADDED
@@ -0,0 +1,19 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { Bug, type IconProps } from '@phosphor-icons/react';
6
+ import React from 'react';
7
+
8
+ import { pluginMeta } from '@dxos/app-framework';
9
+
10
+ export const DEBUG_PLUGIN = 'dxos.org/plugin/debug';
11
+
12
+ export default pluginMeta({
13
+ id: DEBUG_PLUGIN,
14
+ name: 'Debug',
15
+ description: 'DXOS debugging tools.',
16
+ tags: ['experimental'],
17
+ iconComponent: (props: IconProps) => <Bug {...props} />,
18
+ iconSymbol: 'ph--bug--regular',
19
+ });
@@ -0,0 +1,143 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import {
6
+ createShapeId,
7
+ defaultBindingUtils,
8
+ defaultShapeUtils,
9
+ defaultTools,
10
+ Editor,
11
+ type TLParentId,
12
+ } from '@tldraw/tldraw';
13
+
14
+ import { sleep } from '@dxos/async';
15
+ import { next as A } from '@dxos/automerge/automerge';
16
+ import {
17
+ SpaceObjectGenerator,
18
+ type TestGeneratorMap,
19
+ type TestMutationsMap,
20
+ type TestSchemaMap,
21
+ } from '@dxos/echo-generator';
22
+ import { create } from '@dxos/echo-schema';
23
+ import { log } from '@dxos/log';
24
+ import { DocumentType, TextType } from '@dxos/plugin-markdown/types';
25
+ import { TLDrawStoreAdapter } from '@dxos/plugin-sketch';
26
+ import { CanvasType, DiagramType, TLDRAW_SCHEMA } from '@dxos/plugin-sketch/types';
27
+ import { faker } from '@dxos/random';
28
+ import { createDocAccessor, type Space } from '@dxos/react-client/echo';
29
+
30
+ export enum SchemasNames {
31
+ document = 'dxos.org/type/Document',
32
+ diagram = 'dxos.org/type/Diagram',
33
+ }
34
+
35
+ export const SchemasMap: TestSchemaMap<SchemasNames> = {
36
+ [SchemasNames.document]: DocumentType,
37
+ [SchemasNames.diagram]: DiagramType,
38
+ };
39
+
40
+ export const ObjectGenerators: TestGeneratorMap<SchemasNames> = {
41
+ [SchemasNames.document]: () => {
42
+ const name = faker.lorem.sentence();
43
+ return { name, content: create(TextType, { content: '' }), threads: [] };
44
+ },
45
+
46
+ [SchemasNames.diagram]: () => {
47
+ const name = faker.lorem.sentence();
48
+ return {
49
+ name,
50
+ canvas: create(CanvasType, { schema: TLDRAW_SCHEMA, content: {} }),
51
+ };
52
+ },
53
+ };
54
+
55
+ export const MutationsGenerators: TestMutationsMap<SchemasNames> = {
56
+ [SchemasNames.document]: async (object, params) => {
57
+ const accessor = createDocAccessor<DocumentType>(object.content, ['content']);
58
+
59
+ for (let i = 0; i < params.count; i++) {
60
+ const length = object.content?.content?.length ?? 0;
61
+ accessor.handle.change((doc) => {
62
+ A.splice(
63
+ doc,
64
+ accessor.path.slice(),
65
+ 0,
66
+ params.maxContentLength >= length ? 0 : params.mutationSize,
67
+ faker.string.hexadecimal({ length: params.mutationSize - 1 }) + ' ',
68
+ );
69
+ });
70
+
71
+ // Release the event loop.
72
+ if (i % 100 === 0 || i === params.count - 1) {
73
+ log.info('Mutation:', { mutationIdx: i });
74
+ await sleep(1);
75
+ }
76
+ }
77
+ },
78
+
79
+ [SchemasNames.diagram]: async (object, params) => {
80
+ const store = new TLDrawStoreAdapter();
81
+ await store.open(createDocAccessor<CanvasType>(object.canvas, ['content']));
82
+ const app = new Editor({
83
+ store: store.store!,
84
+ shapeUtils: defaultShapeUtils,
85
+ bindingUtils: defaultBindingUtils,
86
+ tools: defaultTools,
87
+ getContainer: () => document.getElementsByTagName('body')[0],
88
+ });
89
+
90
+ //
91
+ // Draw spiral.
92
+ //
93
+ const r = 100;
94
+ const a = 0.05;
95
+ const cx = 200;
96
+ const cy = 200;
97
+
98
+ for (let i = 0; i < params.count; i++) {
99
+ const t = i;
100
+ const t1 = i + 1;
101
+ const x = cx + a * t * r * Math.cos(t);
102
+ const y = cy + a * t * r * Math.sin(t);
103
+ const x1 = cx + a * t1 * r * Math.cos(t1);
104
+ const y1 = cy + a * t1 * r * Math.sin(t1);
105
+
106
+ app.createShape({
107
+ id: createShapeId(),
108
+ isLocked: false,
109
+ meta: {},
110
+ opacity: 1,
111
+ parentId: 'page:page' as TLParentId,
112
+ props: {
113
+ arrowheadEnd: 'none',
114
+ arrowheadStart: 'none',
115
+ bend: 0,
116
+ color: 'black',
117
+ dash: 'draw',
118
+ start: { x, y },
119
+ end: { x: x1, y: y1 },
120
+ fill: 'none',
121
+ font: 'draw',
122
+ labelColor: 'black',
123
+ labelPosition: 0.5,
124
+ scale: 1,
125
+ size: 'm',
126
+ },
127
+ rotation: 0,
128
+ type: 'arrow',
129
+ typeName: 'shape',
130
+ x: 0,
131
+ y: 0,
132
+ });
133
+
134
+ // Release the event loop.
135
+ if (i % 100 === 0) {
136
+ await sleep(1);
137
+ }
138
+ }
139
+ },
140
+ };
141
+
142
+ export const createSpaceObjectGenerator = (space: Space) =>
143
+ new SpaceObjectGenerator(space, SchemasMap, ObjectGenerators, MutationsGenerators);
@@ -0,0 +1,5 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ export * from './generator';
@@ -0,0 +1,36 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { DEBUG_PLUGIN } from './meta';
6
+
7
+ export default [
8
+ {
9
+ 'en-US': {
10
+ [DEBUG_PLUGIN]: {
11
+ 'plugin name': 'Debug',
12
+ 'mutation count': 'Number of mutations',
13
+ 'mutation period': 'Mutation period',
14
+ 'open devtools label': 'Open DevTools',
15
+ 'devtools label': 'DevTools',
16
+ 'debug label': 'Debug',
17
+ 'settings show debug panel': 'Show Debug panel.',
18
+ 'settings show devtools panel': 'Show DevTools panel.',
19
+ 'settings wireframe': 'Show wireframes.',
20
+ 'settings repair': 'Run repair tool.',
21
+ 'settings download diagnostics': 'Download diagnostics.',
22
+ 'settings uploaded': 'Uploaded to IPFS',
23
+ 'settings uploaded to clipboard': 'URL copied to clipboard.',
24
+ 'settings repair success': 'Repair succeeded',
25
+ 'settings repair failed': 'Repair failed',
26
+ 'settings choose storage adaptor': 'Storage adaptor (worker reload required).',
27
+ 'settings storage adaptor idb label': 'IndexedDB',
28
+ 'settings storage adaptor opfs label': 'OPFS',
29
+ 'settings data store label': 'Data Store',
30
+ 'settings storage adapter changed alert':
31
+ 'Warning: Swapping the storage adapter will make your data unavailable.',
32
+ 'settings space fragmentation': 'Enable AM space fragmentation',
33
+ },
34
+ },
35
+ },
36
+ ];
@@ -0,0 +1,13 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { expect } from 'chai';
6
+
7
+ import { describe, test } from '@dxos/test';
8
+
9
+ describe('sanity', () => {
10
+ test('basic', () => {
11
+ expect(true).to.be.true;
12
+ });
13
+ });
package/src/types.ts ADDED
@@ -0,0 +1,45 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { type Context, createContext } from 'react';
6
+
7
+ import type {
8
+ GraphBuilderProvides,
9
+ IntentResolverProvides,
10
+ SettingsProvides,
11
+ SurfaceProvides,
12
+ TranslationsProvides,
13
+ } from '@dxos/app-framework';
14
+ import type { TimerCallback, TimerOptions } from '@dxos/async';
15
+
16
+ import { DEBUG_PLUGIN } from './meta';
17
+
18
+ const DEBUG_ACTION = `${DEBUG_PLUGIN}/action`;
19
+ export enum DebugAction {
20
+ OPEN_DEVTOOLS = `${DEBUG_ACTION}/open-devtools`,
21
+ }
22
+
23
+ export type DebugContextType = {
24
+ running: boolean;
25
+ start: (cb: TimerCallback, options: TimerOptions) => void;
26
+ stop: () => void;
27
+ };
28
+
29
+ export const DebugContext: Context<DebugContextType> = createContext<DebugContextType>({
30
+ running: false,
31
+ start: () => {},
32
+ stop: () => {},
33
+ });
34
+
35
+ export type DebugSettingsProps = {
36
+ devtools?: boolean;
37
+ debug?: boolean;
38
+ wireframe?: boolean;
39
+ };
40
+
41
+ export type DebugPluginProvides = SurfaceProvides &
42
+ IntentResolverProvides &
43
+ GraphBuilderProvides &
44
+ SettingsProvides<DebugSettingsProps> &
45
+ TranslationsProvides;