From 40d84d9f052702fec7b392f4b3c4d530400d3bec Mon Sep 17 00:00:00 2001 From: Ben Merckx Date: Fri, 9 Feb 2024 14:57:49 +0100 Subject: [PATCH] Include dashboard sources, exclude CreateSelection --- .madgerc | 15 +++++++++------ build.js | 11 ++++------- package.json | 4 ++-- src/core/pages/Expr.ts | 2 +- src/dashboard/view/diff/FieldDiff.tsx | 24 ++++++++++++++++++++---- src/dashboard/view/diff/FieldsDiff.tsx | 1 + src/dashboard/view/diff/ListDiff.tsx | 6 ++++-- src/dashboard/view/diff/RichTextDiff.tsx | 12 +++++++++--- 8 files changed, 50 insertions(+), 25 deletions(-) diff --git a/.madgerc b/.madgerc index 4a7c7253b..a4d165c0f 100644 --- a/.madgerc +++ b/.madgerc @@ -1,7 +1,10 @@ { - "detectiveOptions": { - "ts": { - "skipTypeImports": true - } - } -} \ No newline at end of file + "excludeRegExp": [ + "CreateSelection" + ], + "detectiveOptions": { + "ts": { + "skipTypeImports": true + } + } +} diff --git a/build.js b/build.js index 1c454009e..ba8dbcbd8 100644 --- a/build.js +++ b/build.js @@ -121,6 +121,7 @@ const bundleTs = { } } +const checkCycles = process.env.CHECK_CYCLES /** @type {import('esbuild').Plugin} */ const internalPlugin = { name: 'internal', @@ -128,26 +129,22 @@ const internalPlugin = { const cwd = process.cwd() const src = path.join(cwd, 'src') build.onResolve({filter: /^alinea\/.*/}, args => { - const checkCycles = process.env.CHECK_CYCLES if (checkCycles) { // Make this a relative path const file = args.path.slice('alinea/'.length) - if (args.kind === 'entry-point') return const localFile = path.join(src, file) const target = checkCycles === 'browser' ? BROWSER_TARGET : SERVER_TARGET const targetFile = `${localFile}.${target}` - const hasTargetFile = fs.existsSync(`${targetFile}.tsx`) + const hasTargetFile = + fs.existsSync(`${targetFile}.tsx`) || + fs.existsSync(`${targetFile}.ts`) const relative = hasTargetFile ? `./${path.relative(args.resolveDir, targetFile)}.js` : `./${path.relative(args.resolveDir, localFile)}.js` return {path: relative, external: true} } return {path: args.path, external: true} - /*return build.resolve('./' + path.join('src', file), { - kind: args.kind, - resolveDir: cwd - })*/ }) } } diff --git a/package.json b/package.json index 820e52889..e7679bc29 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,8 @@ "stories": "ladle serve", "demo": "node build.js --watch -- node dev.js --dir apps/demo --config src/cms -- yarn workspace @alinea/demo dev", "build": "tsc && node build.js", - "cycles:server": "CHECK_CYCLES=server node build.js && madge --circular dist/index.js", - "cycles:browser": "CHECK_CYCLES=browser node build.js && madge --circular dist/index.js", + "cycles:server": "CHECK_CYCLES=server node build.js && madge --circular dist/index.js dist/backend.js", + "cycles:browser": "CHECK_CYCLES=browser node build.js && madge --circular dist/index.js dist/ui.js dist/dashboard/App.js", "alinea": "node build.js && node dist/cli.js", "build:alinea": "node build.js", "release:types": "tsc", diff --git a/src/core/pages/Expr.ts b/src/core/pages/Expr.ts index c97298c7a..97e1a2cae 100644 --- a/src/core/pages/Expr.ts +++ b/src/core/pages/Expr.ts @@ -1,6 +1,6 @@ import {entries, fromEntries} from '../util/Objects.js' import {createSelection} from './CreateSelection.js' -import {Cursor} from './Cursor.js' +import type {Cursor} from './Cursor.js' import type {Projection} from './Projection.js' import { BinaryOp, diff --git a/src/dashboard/view/diff/FieldDiff.tsx b/src/dashboard/view/diff/FieldDiff.tsx index 8d1c74b7a..dd85c6355 100644 --- a/src/dashboard/view/diff/FieldDiff.tsx +++ b/src/dashboard/view/diff/FieldDiff.tsx @@ -4,25 +4,41 @@ import {RecordShape} from 'alinea/core/shape/RecordShape' import {RichTextShape} from 'alinea/core/shape/RichTextShape' import {ScalarShape} from 'alinea/core/shape/ScalarShape' import {UnionShape} from 'alinea/core/shape/UnionShape' +import {ComponentType} from 'react' import {diffRecord} from './DiffUtils.js' -import {FieldsDiff} from './FieldsDiff.js' +import {FieldsDiffProps} from './FieldsDiff.js' import {ListDiff} from './ListDiff.js' import {RichTextDiff} from './RichTextDiff.js' import {ScalarDiff} from './ScalarDiff.js' export type FieldDiffProps = { + FieldsDiff: ComponentType shape: Shape valueA: any valueB: any } -export function FieldDiff({shape, valueA, valueB}: FieldDiffProps) { +export function FieldDiff({FieldsDiff, shape, valueA, valueB}: FieldDiffProps) { if (shape instanceof ScalarShape) { return } else if (shape instanceof RichTextShape) { - return + return ( + + ) } else if (shape instanceof ListShape) { - return + return ( + + ) } else if (shape instanceof RecordShape) { const changes = diffRecord(shape as RecordShape, valueA, valueB) return diff --git a/src/dashboard/view/diff/FieldsDiff.tsx b/src/dashboard/view/diff/FieldsDiff.tsx index 8c7e64ce1..96d9d5dec 100644 --- a/src/dashboard/view/diff/FieldsDiff.tsx +++ b/src/dashboard/view/diff/FieldsDiff.tsx @@ -19,6 +19,7 @@ export function FieldsDiff({changes, targetA, targetB}: FieldsDiffProps) {
shape: ListShape valueA: Array valueB: Array } -export function ListDiff({shape, valueA, valueB}: ListDiffProps) { +export function ListDiff({FieldsDiff, shape, valueA, valueB}: ListDiffProps) { const equals = (itemA: ListRow, itemB: ListRow) => { return itemA.id === itemB.id } diff --git a/src/dashboard/view/diff/RichTextDiff.tsx b/src/dashboard/view/diff/RichTextDiff.tsx index 0a88d7a01..d3298bd5c 100644 --- a/src/dashboard/view/diff/RichTextDiff.tsx +++ b/src/dashboard/view/diff/RichTextDiff.tsx @@ -2,10 +2,10 @@ import type {TextDoc} from 'alinea/core/TextDoc' import {RecordShape} from 'alinea/core/shape/RecordShape' import {RichTextShape} from 'alinea/core/shape/RichTextShape' import {Sink} from 'alinea/ui/Sink' -import {ReactNode, useMemo} from 'react' +import {ComponentType, ReactNode, useMemo} from 'react' import {ChangeBox} from './ChangeBox.js' import {diffList, diffRecord} from './DiffUtils.js' -import {FieldsDiff} from './FieldsDiff.js' +import {FieldsDiffProps} from './FieldsDiff.js' import {ScalarDiff} from './ScalarDiff.js' type Block = { @@ -60,12 +60,18 @@ function textDocParts(textDoc: TextDoc): Array { } export type RichTextDiffProps = { + FieldsDiff: ComponentType shape: RichTextShape valueA: TextDoc valueB: TextDoc } -export function RichTextDiff({shape, valueA, valueB}: RichTextDiffProps) { +export function RichTextDiff({ + FieldsDiff, + shape, + valueA, + valueB +}: RichTextDiffProps) { const parts = useMemo(() => { return {a: textDocParts(valueA), b: textDocParts(valueB)} }, [valueA, valueB])