@lapis-notes/source-editor 0.1.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.
- package/CHANGELOG.md +6 -0
- package/LICENSE.md +8 -0
- package/README.md +20 -0
- package/dist/index.d.ts +70 -0
- package/dist/index.js +137 -0
- package/dist/styles.css +1 -0
- package/manifest.json +30 -0
- package/package.json +66 -0
- package/styles.css +1 -0
package/CHANGELOG.md
ADDED
package/LICENSE.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# License
|
|
2
|
+
|
|
3
|
+
Copyright (c) LapisMD contributors.
|
|
4
|
+
|
|
5
|
+
This software is licensed under the GNU Affero General Public License, version
|
|
6
|
+
3 or (at your option) any later version (`AGPL-3.0-or-later`). The complete
|
|
7
|
+
license text is available from the
|
|
8
|
+
[GNU Project](https://www.gnu.org/licenses/agpl-3.0.html).
|
package/README.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Source Editor
|
|
2
|
+
|
|
3
|
+
Source editing for text, JSON, and YAML files
|
|
4
|
+
|
|
5
|
+
## Install for static composition
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm add @lapis-notes/source-editor
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Register the exported plugin class in the application's `PluginProfile`. Import
|
|
12
|
+
`@lapis-notes/source-editor/styles.css?inline` and pass the CSS through the static
|
|
13
|
+
registration so the host owns its lifecycle.
|
|
14
|
+
|
|
15
|
+
The runtime plugin ID is `lapis-source-editor`. A matching signed
|
|
16
|
+
`lapis-source-editor-0.1.0.lapis-plugin` archive is attached to the
|
|
17
|
+
package-scoped GitHub release for manual or registry installation.
|
|
18
|
+
|
|
19
|
+
See the [repository README](https://github.com/lapismd/lapis-plugins#readme) for
|
|
20
|
+
development, validation, and release-gate details.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Plugin, type App, type ExtType, type PluginManifest } from "@lapis-notes/api";
|
|
2
|
+
import "./styles.css";
|
|
3
|
+
export { default as manifest } from "../manifest.json";
|
|
4
|
+
export declare const SOURCE_EDITOR_SETTING_FIELDS: ({
|
|
5
|
+
id: string;
|
|
6
|
+
type: "boolean";
|
|
7
|
+
title: string;
|
|
8
|
+
description: string;
|
|
9
|
+
default: false;
|
|
10
|
+
minimum?: undefined;
|
|
11
|
+
maximum?: undefined;
|
|
12
|
+
} | {
|
|
13
|
+
id: string;
|
|
14
|
+
type: "boolean";
|
|
15
|
+
title: string;
|
|
16
|
+
description: string;
|
|
17
|
+
default: true;
|
|
18
|
+
minimum?: undefined;
|
|
19
|
+
maximum?: undefined;
|
|
20
|
+
} | {
|
|
21
|
+
id: string;
|
|
22
|
+
type: "integer";
|
|
23
|
+
title: string;
|
|
24
|
+
description: string;
|
|
25
|
+
minimum: number;
|
|
26
|
+
maximum: number;
|
|
27
|
+
default: number;
|
|
28
|
+
})[];
|
|
29
|
+
export declare const SOURCE_EDITOR_SCHEMA: {
|
|
30
|
+
readonly id: "editor";
|
|
31
|
+
readonly title: "Editor";
|
|
32
|
+
readonly type: "object";
|
|
33
|
+
readonly properties: {
|
|
34
|
+
[k: string]: {
|
|
35
|
+
type: "boolean";
|
|
36
|
+
title: string;
|
|
37
|
+
description: string;
|
|
38
|
+
default: false;
|
|
39
|
+
minimum?: undefined;
|
|
40
|
+
maximum?: undefined;
|
|
41
|
+
} | {
|
|
42
|
+
type: "boolean";
|
|
43
|
+
title: string;
|
|
44
|
+
description: string;
|
|
45
|
+
default: true;
|
|
46
|
+
minimum?: undefined;
|
|
47
|
+
maximum?: undefined;
|
|
48
|
+
} | {
|
|
49
|
+
type: "integer";
|
|
50
|
+
title: string;
|
|
51
|
+
description: string;
|
|
52
|
+
minimum: number;
|
|
53
|
+
maximum: number;
|
|
54
|
+
default: number;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
export interface SourceEditorViewDefinition {
|
|
59
|
+
type: "text" | "json" | "yaml";
|
|
60
|
+
label: string;
|
|
61
|
+
extensions: readonly string[];
|
|
62
|
+
patterns: readonly string[];
|
|
63
|
+
createExtension(app: App): ExtType;
|
|
64
|
+
}
|
|
65
|
+
export declare const SOURCE_EDITOR_VIEW_DEFINITIONS: readonly SourceEditorViewDefinition[];
|
|
66
|
+
export declare class SourceEditorPlugin extends Plugin {
|
|
67
|
+
constructor(app: App, manifest?: PluginManifest);
|
|
68
|
+
onload(): Promise<void>;
|
|
69
|
+
}
|
|
70
|
+
export default SourceEditorPlugin;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { json } from "@codemirror/lang-json";
|
|
2
|
+
import { yaml } from "@codemirror/lang-yaml";
|
|
3
|
+
import { Plugin, SourceTextFileView, } from "@lapis-notes/api";
|
|
4
|
+
import { markupEditor } from "@lapis-notes/api/editor";
|
|
5
|
+
import { getWorkspaceHostBinding } from "@lapis-notes/api/workspace-host";
|
|
6
|
+
import manifestSpec from "../manifest.json";
|
|
7
|
+
import "./styles.css";
|
|
8
|
+
export { default as manifest } from "../manifest.json";
|
|
9
|
+
export const SOURCE_EDITOR_SETTING_FIELDS = [
|
|
10
|
+
{
|
|
11
|
+
id: "editor.alwaysFocusNewTabs",
|
|
12
|
+
type: "boolean",
|
|
13
|
+
title: "Always focus new tabs",
|
|
14
|
+
description: "Switch to newly created tabs immediately. Turn this off to create them in the background.",
|
|
15
|
+
default: false,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
id: "editor.display.showLineNumbers",
|
|
19
|
+
type: "boolean",
|
|
20
|
+
title: "Show line numbers",
|
|
21
|
+
description: "Show line numbers in the editor gutter.",
|
|
22
|
+
default: true,
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
id: "editor.display.foldIndent",
|
|
26
|
+
type: "boolean",
|
|
27
|
+
title: "Code folding",
|
|
28
|
+
description: "Show the fold gutter for language-defined ranges such as headings and objects.",
|
|
29
|
+
default: true,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
id: "editor.display.wrapLines",
|
|
33
|
+
type: "boolean",
|
|
34
|
+
title: "Wrap lines",
|
|
35
|
+
description: "Wrap long source lines to the editor width.",
|
|
36
|
+
default: true,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: "editor.display.showIndentationGuides",
|
|
40
|
+
type: "boolean",
|
|
41
|
+
title: "Show indentation guides",
|
|
42
|
+
description: "Show vertical guides for indented source.",
|
|
43
|
+
default: true,
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
id: "editor.behaviour.spellCheck",
|
|
47
|
+
type: "boolean",
|
|
48
|
+
title: "Spellcheck",
|
|
49
|
+
description: "Use the browser spellchecker in source editors.",
|
|
50
|
+
default: true,
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
id: "editor.behaviour.indentUsingTabs",
|
|
54
|
+
type: "boolean",
|
|
55
|
+
title: "Indent using tabs",
|
|
56
|
+
description: "Turn this off to insert spaces when indenting.",
|
|
57
|
+
default: true,
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
id: "editor.behaviour.indentVisualWidth",
|
|
61
|
+
type: "integer",
|
|
62
|
+
title: "Indent width",
|
|
63
|
+
description: "Number of columns used by a tab or space indent.",
|
|
64
|
+
minimum: 2,
|
|
65
|
+
maximum: 8,
|
|
66
|
+
default: 4,
|
|
67
|
+
},
|
|
68
|
+
];
|
|
69
|
+
export const SOURCE_EDITOR_SCHEMA = {
|
|
70
|
+
id: "editor",
|
|
71
|
+
title: "Editor",
|
|
72
|
+
type: "object",
|
|
73
|
+
properties: Object.fromEntries(SOURCE_EDITOR_SETTING_FIELDS.map(({ id, ...definition }) => [
|
|
74
|
+
id,
|
|
75
|
+
definition,
|
|
76
|
+
])),
|
|
77
|
+
};
|
|
78
|
+
export const SOURCE_EDITOR_VIEW_DEFINITIONS = [
|
|
79
|
+
{
|
|
80
|
+
type: "text",
|
|
81
|
+
label: "Text",
|
|
82
|
+
extensions: ["txt", "text"],
|
|
83
|
+
patterns: [".txt", ".text", "*.txt", "*.text"],
|
|
84
|
+
createExtension: (app) => markupEditor({ language: "text", app }),
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
type: "json",
|
|
88
|
+
label: "JSON",
|
|
89
|
+
extensions: ["json", "data"],
|
|
90
|
+
patterns: [".json", ".data", "*.json", "*.data"],
|
|
91
|
+
createExtension: (app) => markupEditor({ language: "json", app }, json()),
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
type: "yaml",
|
|
95
|
+
label: "YAML",
|
|
96
|
+
extensions: ["yaml", "yml"],
|
|
97
|
+
patterns: [".yaml", ".yml", "*.yaml", "*.yml"],
|
|
98
|
+
createExtension: (app) => markupEditor({ language: "yaml", app }, yaml()),
|
|
99
|
+
},
|
|
100
|
+
];
|
|
101
|
+
export class SourceEditorPlugin extends Plugin {
|
|
102
|
+
constructor(app, manifest = manifestSpec) {
|
|
103
|
+
super(app, manifest);
|
|
104
|
+
}
|
|
105
|
+
async onload() {
|
|
106
|
+
this.app.configuration.schema.register(SOURCE_EDITOR_SCHEMA);
|
|
107
|
+
this.register(() => {
|
|
108
|
+
this.app.configuration.schema.unregister(SOURCE_EDITOR_SCHEMA);
|
|
109
|
+
});
|
|
110
|
+
const { controller } = getWorkspaceHostBinding(this.app.workspace);
|
|
111
|
+
this.register(controller.registerSettingsSection({
|
|
112
|
+
id: "lapis-source-editor",
|
|
113
|
+
title: "Editor",
|
|
114
|
+
description: "Source editor behavior shared by Markdown, text, JSON, and YAML files.",
|
|
115
|
+
icon: "file-pen-line",
|
|
116
|
+
order: 20,
|
|
117
|
+
navigationGroupId: "core-plugins",
|
|
118
|
+
sourcePluginId: this.id,
|
|
119
|
+
fields: SOURCE_EDITOR_SETTING_FIELDS.map((field) => ({ ...field })),
|
|
120
|
+
}));
|
|
121
|
+
for (const definition of SOURCE_EDITOR_VIEW_DEFINITIONS) {
|
|
122
|
+
this.registerView(definition.type, (leaf) => new SourceTextFileView(leaf, definition.type, definition.extensions), { kind: "file" });
|
|
123
|
+
this.registerEditorView({
|
|
124
|
+
id: definition.type,
|
|
125
|
+
viewType: definition.type,
|
|
126
|
+
label: definition.label,
|
|
127
|
+
description: `${definition.label} source editor`,
|
|
128
|
+
filenamePatterns: [...definition.patterns],
|
|
129
|
+
priority: "default",
|
|
130
|
+
});
|
|
131
|
+
this.registerExtensions([...definition.extensions], definition.type);
|
|
132
|
+
this.registerEditorExtension(definition.createExtension(this.app), definition.type);
|
|
133
|
+
}
|
|
134
|
+
await this.app.configuration.materializeSchemaDefaults();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
export default SourceEditorPlugin;
|
package/dist/styles.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/* Source Editor currently uses host and component-scoped styles only. */
|
package/manifest.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "lapis-source-editor",
|
|
3
|
+
"name": "Source Editor",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"minAppVersion": "0.1.0",
|
|
6
|
+
"description": "Source editing for text, JSON, and YAML files",
|
|
7
|
+
"author": "Lapis Notes",
|
|
8
|
+
"authorUrl": "https://app.lapis.md",
|
|
9
|
+
"isDesktopOnly": false,
|
|
10
|
+
"lapis": {
|
|
11
|
+
"manifestVersion": 1,
|
|
12
|
+
"source": "official",
|
|
13
|
+
"locked": false,
|
|
14
|
+
"enabledByDefault": true,
|
|
15
|
+
"runtime": {
|
|
16
|
+
"entries": {
|
|
17
|
+
"workspace": {
|
|
18
|
+
"path": "main.mjs",
|
|
19
|
+
"format": "esm",
|
|
20
|
+
"sharedDependencies": [
|
|
21
|
+
"@lapis-notes/api",
|
|
22
|
+
"@lapis-notes/api/editor",
|
|
23
|
+
"@lapis-notes/api/workspace-host"
|
|
24
|
+
],
|
|
25
|
+
"requiresReloadOnUpdate": false
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lapis-notes/source-editor",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "AGPL-3.0-or-later",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"svelte": "./dist/index.js",
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./manifest.json": "./manifest.json",
|
|
14
|
+
"./styles.css": "./styles.css"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@codemirror/lang-json": "^6.0.2",
|
|
18
|
+
"@codemirror/lang-yaml": "^6.1.2",
|
|
19
|
+
"@lapis-notes/api": "^0.1.0",
|
|
20
|
+
"@lapismd/design-core": "^0.1.0"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@sveltejs/package": "^2.5.0",
|
|
24
|
+
"svelte": "^5.38.2",
|
|
25
|
+
"svelte-check": "^4.3.1",
|
|
26
|
+
"typescript": "~5.9.3",
|
|
27
|
+
"vite": "^6.4.2",
|
|
28
|
+
"vitest": "^4.1.8"
|
|
29
|
+
},
|
|
30
|
+
"description": "Source editing for text, JSON, and YAML files",
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+https://github.com/lapismd/lapis-plugins.git",
|
|
34
|
+
"directory": "packages/source-editor"
|
|
35
|
+
},
|
|
36
|
+
"homepage": "https://github.com/lapismd/lapis-plugins/tree/main/packages/source-editor#readme",
|
|
37
|
+
"bugs": {
|
|
38
|
+
"url": "https://github.com/lapismd/lapis-plugins/issues"
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
},
|
|
43
|
+
"files": [
|
|
44
|
+
"dist",
|
|
45
|
+
"manifest.json",
|
|
46
|
+
"styles.css",
|
|
47
|
+
"README.md",
|
|
48
|
+
"CHANGELOG.md",
|
|
49
|
+
"LICENSE.md",
|
|
50
|
+
"!dist/**/*.test.*",
|
|
51
|
+
"!dist/**/*.spec.*"
|
|
52
|
+
],
|
|
53
|
+
"sideEffects": [
|
|
54
|
+
"**/*.css"
|
|
55
|
+
],
|
|
56
|
+
"svelte": "./dist/index.js",
|
|
57
|
+
"types": "./dist/index.d.ts",
|
|
58
|
+
"scripts": {
|
|
59
|
+
"build": "pnpm run prepack",
|
|
60
|
+
"check": "pnpm check:types",
|
|
61
|
+
"check:types": "svelte-check --tsconfig ./tsconfig.json --fail-on-warnings --output human",
|
|
62
|
+
"test": "vitest run",
|
|
63
|
+
"publint": "publint",
|
|
64
|
+
"pack": "pnpm pack --pack-destination ../../.release/npm"
|
|
65
|
+
}
|
|
66
|
+
}
|
package/styles.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import "./dist/styles.css";
|