Skip to content

Commit 2596cb5

Browse files
authored
Merge pull request #217 from orgapp/website
build the new website
2 parents 10c7a25 + fe156d6 commit 2596cb5

File tree

110 files changed

+3116
-847
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+3116
-847
lines changed

.changeset/twelve-radios-clap.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
'text-kit': minor
3+
'@orgajs/loader': minor
4+
'orga': minor
5+
'@orgajs/orgx': minor
6+
'@orgajs/cm-lang': patch
7+
'@orgajs/example-editor': patch
8+
'@orgajs/editor': patch
9+
'@orgajs/astro': patch
10+
'@orgajs/lezer': patch
11+
'website': patch
12+
'@orgajs/next': patch
13+
---
14+
15+
implement editor

.ignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

README.org

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#+title: Orga
22
#+subtitle: org-mode < JavaScript
3-
#+layout: './website/src/components/landing'
43

54
* What Is It
65

packages/astro/index.js

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88
import orga from '@orgajs/rollup'
99
import { parse as parseMetadata } from '@orgajs/metadata'
10+
import astroJSXRenderer from 'astro/jsx/renderer.js'
1011
import { addAstroFragment } from './lib/plugin/recma-add-astro-fragment.js'
1112

1213
/**
@@ -19,8 +20,14 @@ export default function org({ recmaPlugins, ...options }) {
1920
hooks: {
2021
// @ts-ignore - addPageExtension, addContentEntryType are internal APIs
2122
'astro:config:setup': async (/** @type {SetupHookParams} */ params) => {
22-
const { addPageExtension, addContentEntryType, updateConfig } = params
23+
const {
24+
addPageExtension,
25+
addContentEntryType,
26+
updateConfig,
27+
addRenderer,
28+
} = params
2329
addPageExtension('.org')
30+
addRenderer(astroJSXRenderer)
2431

2532
addContentEntryType({
2633
extensions: ['.org'],
@@ -34,20 +41,44 @@ export default function org({ recmaPlugins, ...options }) {
3441
slug: Array.isArray(data.slug) ? data.slug[0] : data.slug,
3542
}
3643
},
44+
handlePropagation: true,
3745
})
3846

47+
// TODO: add org-components support
48+
// const components = new URL('org-components', config.srcDir)
49+
3950
updateConfig({
4051
vite: {
52+
/** @type {import('vite').Plugin[]} */
4153
plugins: [
4254
{
4355
enforce: 'pre',
4456
...orga({
4557
...options,
4658
jsxImportSource: 'astro',
59+
// providerImportSource: components.pathname,
4760
recmaPlugins: [...(recmaPlugins ?? []), addAstroFragment],
4861
elementAttributeNameCase: 'html',
4962
development: false,
5063
}),
64+
configResolved(resolved) {
65+
// HACK: move ourselves before Astro's JSX plugin to transform things in the right order
66+
const jsxPluginIndex = resolved.plugins.findIndex(
67+
(p) => p.name === 'astro:jsx'
68+
)
69+
if (jsxPluginIndex !== -1) {
70+
const myPluginIndex = resolved.plugins.findIndex(
71+
(p) => p.name === '@orgajs/rollup'
72+
)
73+
if (myPluginIndex !== -1) {
74+
const myPlugin = resolved.plugins[myPluginIndex]
75+
// @ts-ignore-error ignore readonly annotation
76+
resolved.plugins.splice(myPluginIndex, 1)
77+
// @ts-ignore-error ignore readonly annotation
78+
resolved.plugins.splice(jsxPluginIndex, 0, myPlugin)
79+
}
80+
}
81+
},
5182
},
5283
{
5384
name: '@orgajs/org-postprocess',
@@ -57,7 +88,6 @@ export default function org({ recmaPlugins, ...options }) {
5788
*/
5889
transform(code, id) {
5990
if (!id.endsWith('.org')) return
60-
// console.log(code)
6191
return { code, map: null }
6292
},
6393
},

packages/astro/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"@types/estree": "^1.0.1",
3939
"@types/estree-jsx": "^1.0.0",
4040
"astro": "^2.10.15",
41-
"unified": "^10.1.2"
41+
"unified": "^10.1.2",
42+
"vite": "^4.4.9"
4243
}
4344
}

packages/codemirror-lang/index.js

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,89 @@
1+
/** @typedef {import('@lezer/common').SyntaxNode} SyntaxNode */
2+
13
import {
4+
defineLanguageFacet,
5+
foldNodeProp,
6+
foldService,
27
Language,
38
LanguageSupport,
4-
defineLanguageFacet,
9+
syntaxTree,
510
} from '@codemirror/language'
6-
import { parser, tags as t } from '@orgajs/lezer'
11+
import { NodeProp } from '@lezer/common'
12+
import { parser as baseParser, tags as t } from '@orgajs/lezer'
713

814
export const tags = t
915

1016
const data = defineLanguageFacet({})
1117

18+
// --- folding ---
19+
/** @type {NodeProp<number>} */
20+
const headlineProp = new NodeProp()
21+
22+
/**
23+
* @param {import('@lezer/common').NodeType} type
24+
*/
25+
function isHeadline(type) {
26+
let match = /^headline(\d)$/.exec(type.name)
27+
return match ? +match[1] : undefined
28+
}
29+
30+
/**
31+
* @param {SyntaxNode} headerNode
32+
* @param {number} level
33+
*/
34+
function findSectionEnd(headerNode, level) {
35+
let last = headerNode
36+
for (;;) {
37+
let next = last.nextSibling
38+
if (!next) break
39+
const headline = isHeadline(next.type)
40+
if (headline != null) {
41+
if (headline <= level) {
42+
return next.from - 1 // escape the newline. TODO: is this safe?
43+
}
44+
}
45+
last = next
46+
}
47+
return last.to
48+
}
49+
50+
const headerIndent = foldService.of((state, start, end) => {
51+
for (
52+
let /** @type {SyntaxNode | null} */ node = syntaxTree(state).resolveInner(
53+
end,
54+
-1
55+
);
56+
node;
57+
node = node.parent
58+
) {
59+
if (node.from < start) break
60+
let headline = node.type.prop(headlineProp)
61+
if (headline == null) continue
62+
let upto = findSectionEnd(node, headline)
63+
if (upto > end) return { from: end, to: upto }
64+
}
65+
return null
66+
})
67+
68+
const parser = baseParser.configure({
69+
props: [
70+
foldNodeProp.add((type) => {
71+
const m = isHeadline(type)
72+
if (!m) return undefined
73+
return (tree, state) => ({
74+
from: state.doc.lineAt(tree.from).to,
75+
to: state.doc.lineAt(tree.from).to,
76+
})
77+
}),
78+
headlineProp.add(isHeadline),
79+
],
80+
})
81+
1282
/**
1383
* @param {any} parser
1484
*/
1585
function mkLang(parser) {
16-
return new Language(data, parser, [], 'org')
86+
return new Language(data, parser, [headerIndent], 'org')
1787
}
1888

1989
export function org() {

packages/codemirror-lang/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,8 @@
3030
"dependencies": {
3131
"@codemirror/language": "^6.9.0",
3232
"@orgajs/lezer": "workspace:^"
33+
},
34+
"devDependencies": {
35+
"@lezer/common": "^1.1.0"
3336
}
3437
}

packages/editor/lib/editor.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,32 @@ import { EditorView } from '@codemirror/view'
22
import { setup } from './setup.js'
33
import { Compartment, EditorState } from '@codemirror/state'
44

5+
/**
6+
* @callback OnChange
7+
* @param {EditorState} state
8+
*/
9+
510
/**
611
* @typedef Config
712
* @property {Element} target
813
* @property {string} [content='']
914
* @property {import('@codemirror/state').Extension} [extensions=[]]
1015
* @property {boolean} [dark=false]
16+
* @property {OnChange} [onChange=() => {}]
1117
*/
1218

1319
/**
1420
* @param {Config} config
1521
*/
1622
export function makeEditor(config) {
1723
const themeConfig = new Compartment()
18-
const { target, content = '', extensions = [], dark = false } = config
24+
const {
25+
target,
26+
content = '',
27+
extensions = [],
28+
dark = false,
29+
onChange,
30+
} = config
1931
const state = EditorState.create({
2032
doc: content,
2133
extensions: [
@@ -27,6 +39,10 @@ export function makeEditor(config) {
2739
const editor = new EditorView({
2840
state,
2941
parent: target,
42+
dispatch: (tr) => {
43+
editor.update([tr])
44+
tr.docChanged && onChange && onChange(editor.state)
45+
},
3046
})
3147

3248
/** @param {boolean} dark */

packages/editor/lib/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* @typedef {import('./editor.js').Config} EditorConfig
3+
*/
4+
15
export { makeEditor } from './editor.js'
26
export { setup } from './setup.js'
37
export { tags } from '@orgajs/cm-lang'

0 commit comments

Comments
 (0)