Skip to content

Commit

Permalink
Include dashboard sources, exclude CreateSelection
Browse files Browse the repository at this point in the history
  • Loading branch information
benmerckx committed Feb 9, 2024
1 parent 7bebfeb commit 40d84d9
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 25 deletions.
15 changes: 9 additions & 6 deletions .madgerc
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"detectiveOptions": {
"ts": {
"skipTypeImports": true
}
}
}
"excludeRegExp": [
"CreateSelection"
],
"detectiveOptions": {
"ts": {
"skipTypeImports": true
}
}
}
11 changes: 4 additions & 7 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,33 +121,30 @@ const bundleTs = {
}
}

const checkCycles = process.env.CHECK_CYCLES
/** @type {import('esbuild').Plugin} */
const internalPlugin = {
name: 'internal',
setup(build) {
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
})*/
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/core/pages/Expr.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
24 changes: 20 additions & 4 deletions src/dashboard/view/diff/FieldDiff.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<FieldsDiffProps>
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 <ScalarDiff valueA={valueA} valueB={valueB} />
} else if (shape instanceof RichTextShape) {
return <RichTextDiff shape={shape} valueA={valueA} valueB={valueB} />
return (
<RichTextDiff
FieldsDiff={FieldsDiff}
shape={shape}
valueA={valueA}
valueB={valueB}
/>
)
} else if (shape instanceof ListShape) {
return <ListDiff shape={shape} valueA={valueA} valueB={valueB} />
return (
<ListDiff
FieldsDiff={FieldsDiff}
shape={shape}
valueA={valueA}
valueB={valueB}
/>
)
} else if (shape instanceof RecordShape) {
const changes = diffRecord(shape as RecordShape, valueA, valueB)
return <FieldsDiff changes={changes} targetA={valueA} targetB={valueB} />
Expand Down
1 change: 1 addition & 0 deletions src/dashboard/view/diff/FieldsDiff.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function FieldsDiff({changes, targetA, targetB}: FieldsDiffProps) {
<div key={key}>
<InputLabel label={type.label}>
<FieldDiff
FieldsDiff={FieldsDiff}
shape={type}
valueA={targetA?.[key]}
valueB={targetB?.[key]}
Expand Down
6 changes: 4 additions & 2 deletions src/dashboard/view/diff/ListDiff.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import {ListRow, ListShape} from 'alinea/core/shape/ListShape'
import {Sink} from 'alinea/ui/Sink'
import {ComponentType} from 'react'
import {ChangeBox} from './ChangeBox.js'
import {diffList, diffRecord} from './DiffUtils.js'
import {FieldsDiff} from './FieldsDiff.js'
import {FieldsDiffProps} from './FieldsDiff.js'

export type ListDiffProps = {
FieldsDiff: ComponentType<FieldsDiffProps>
shape: ListShape<any>
valueA: Array<ListRow>
valueB: Array<ListRow>
}

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
}
Expand Down
12 changes: 9 additions & 3 deletions src/dashboard/view/diff/RichTextDiff.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -60,12 +60,18 @@ function textDocParts(textDoc: TextDoc<any>): Array<Part> {
}

export type RichTextDiffProps = {
FieldsDiff: ComponentType<FieldsDiffProps>
shape: RichTextShape<any>
valueA: TextDoc<any>
valueB: TextDoc<any>
}

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])
Expand Down

0 comments on commit 40d84d9

Please sign in to comment.