@gratux/sdk 0.0.0-stage → 1.0.1

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.
@@ -0,0 +1,147 @@
1
+ /**
2
+ * Core primitives shared by every Gratux SDK module.
3
+ *
4
+ * Everything here is plain TypeScript with no runtime dependency, so the SDK can
5
+ * be bundled into an extension with esbuild without pulling Node.js polyfills.
6
+ */
7
+ export interface Disposable {
8
+ dispose(): void;
9
+ }
10
+ export declare function dispose(disposable: Disposable | undefined | null): void;
11
+ export declare function disposeAll(disposables: readonly Disposable[]): void;
12
+ export interface Event<T> {
13
+ (listener: (event: T) => void, thisArg?: unknown, disposables?: Disposable[]): Disposable;
14
+ }
15
+ /** Minimal event emitter; the same shape the API returns everywhere. */
16
+ export declare class EventEmitter<T> implements Disposable {
17
+ private listeners;
18
+ readonly event: Event<T>;
19
+ fire(event: T): void;
20
+ dispose(): void;
21
+ }
22
+ export declare class CancellationTokenSource implements Disposable {
23
+ private readonly emitter;
24
+ private cancelled;
25
+ readonly token: CancellationToken;
26
+ cancel(): void;
27
+ dispose(): void;
28
+ }
29
+ export interface CancellationToken {
30
+ readonly isCancellationRequested: boolean;
31
+ readonly onCancellationRequested: Event<void>;
32
+ }
33
+ export declare class Position {
34
+ readonly line: number;
35
+ readonly character: number;
36
+ constructor(line: number, character: number);
37
+ with(line?: number, character?: number): Position;
38
+ isBefore(other: Position): boolean;
39
+ toJSON(): {
40
+ line: number;
41
+ character: number;
42
+ };
43
+ static from(value: {
44
+ line: number;
45
+ character: number;
46
+ } | Position): Position;
47
+ }
48
+ export declare class Range {
49
+ readonly start: Position;
50
+ readonly end: Position;
51
+ constructor(start: Position, end: Position);
52
+ get isEmpty(): boolean;
53
+ toJSON(): {
54
+ start: {
55
+ line: number;
56
+ character: number;
57
+ };
58
+ end: {
59
+ line: number;
60
+ character: number;
61
+ };
62
+ };
63
+ static from(value: RangeLike): Range;
64
+ }
65
+ export interface RangeLike {
66
+ start: {
67
+ line: number;
68
+ character: number;
69
+ };
70
+ end: {
71
+ line: number;
72
+ character: number;
73
+ };
74
+ }
75
+ export declare class Selection extends Range {
76
+ readonly anchor: Position;
77
+ readonly active: Position;
78
+ constructor(anchor: Position, active: Position);
79
+ }
80
+ export interface UriComponents {
81
+ scheme: string;
82
+ path: string;
83
+ authority?: string;
84
+ query?: string;
85
+ fragment?: string;
86
+ }
87
+ /** Small URI helper; the native side works with absolute paths and content URIs. */
88
+ export declare class Uri {
89
+ private readonly value;
90
+ private constructor();
91
+ static file(path: string): Uri;
92
+ static parse(value: string): Uri;
93
+ static joinPath(base: Uri, ...segments: string[]): Uri;
94
+ get scheme(): string;
95
+ get path(): string;
96
+ get fsPath(): string;
97
+ toString(): string;
98
+ with(change: Partial<UriComponents>): Uri;
99
+ }
100
+ export interface TextEdit {
101
+ range: RangeLike;
102
+ newText: string;
103
+ }
104
+ /** Convert a (line, character) position into a document offset. */
105
+ export declare function offsetAt(text: string, position: {
106
+ line: number;
107
+ character: number;
108
+ }): number;
109
+ export declare function positionAt(text: string, offset: number): Position;
110
+ export declare enum StatusBarAlignment {
111
+ Left = 0,
112
+ Right = 1
113
+ }
114
+ export interface StatusBarItem extends Disposable {
115
+ id: string;
116
+ text: string;
117
+ tooltip: string | undefined;
118
+ command: string | undefined;
119
+ show(): void;
120
+ hide(): void;
121
+ }
122
+ export interface OutputChannel extends Disposable {
123
+ readonly name: string;
124
+ append(value: string): void;
125
+ appendLine(value: string): void;
126
+ clear(): void;
127
+ show(preserveFocus?: boolean): void;
128
+ hide(): void;
129
+ }
130
+ export interface LogOutputChannel extends OutputChannel {
131
+ info(message: string): void;
132
+ warn(message: string): void;
133
+ error(message: string | Error): void;
134
+ debug(message: string): void;
135
+ }
136
+ export interface ProgressOptions {
137
+ title: string;
138
+ cancellable?: boolean;
139
+ }
140
+ export interface Progress<T> {
141
+ report(value: T): void;
142
+ }
143
+ export interface Memento {
144
+ get<T>(key: string, defaultValue?: T): T | undefined;
145
+ update(key: string, value: unknown): Promise<void>;
146
+ keys(): readonly string[];
147
+ }
package/dist/types.js ADDED
@@ -0,0 +1,206 @@
1
+ "use strict";
2
+ /**
3
+ * Core primitives shared by every Gratux SDK module.
4
+ *
5
+ * Everything here is plain TypeScript with no runtime dependency, so the SDK can
6
+ * be bundled into an extension with esbuild without pulling Node.js polyfills.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.StatusBarAlignment = exports.Uri = exports.Selection = exports.Range = exports.Position = exports.CancellationTokenSource = exports.EventEmitter = void 0;
10
+ exports.dispose = dispose;
11
+ exports.disposeAll = disposeAll;
12
+ exports.offsetAt = offsetAt;
13
+ exports.positionAt = positionAt;
14
+ function dispose(disposable) {
15
+ if (!disposable)
16
+ return;
17
+ try {
18
+ disposable.dispose();
19
+ }
20
+ catch {
21
+ /* disposal must never break the caller */
22
+ }
23
+ }
24
+ function disposeAll(disposables) {
25
+ const copy = disposables.slice();
26
+ for (let i = copy.length - 1; i >= 0; i--)
27
+ dispose(copy[i]);
28
+ }
29
+ /** Minimal event emitter; the same shape the API returns everywhere. */
30
+ class EventEmitter {
31
+ constructor() {
32
+ this.listeners = [];
33
+ this.event = (listener, thisArg, disposables) => {
34
+ const bound = thisArg ? listener.bind(thisArg) : listener;
35
+ this.listeners.push(bound);
36
+ const disposable = {
37
+ dispose: () => {
38
+ const index = this.listeners.indexOf(bound);
39
+ if (index >= 0)
40
+ this.listeners.splice(index, 1);
41
+ },
42
+ };
43
+ disposables?.push(disposable);
44
+ return disposable;
45
+ };
46
+ }
47
+ fire(event) {
48
+ for (const listener of this.listeners.slice()) {
49
+ try {
50
+ listener(event);
51
+ }
52
+ catch (error) {
53
+ // An extension event handler must not break other subscribers.
54
+ console.error("Gratux event handler failed", error);
55
+ }
56
+ }
57
+ }
58
+ dispose() {
59
+ this.listeners = [];
60
+ }
61
+ }
62
+ exports.EventEmitter = EventEmitter;
63
+ class CancellationTokenSource {
64
+ constructor() {
65
+ this.emitter = new EventEmitter();
66
+ this.cancelled = false;
67
+ this.token = {
68
+ isCancellationRequested: false,
69
+ onCancellationRequested: this.emitter.event,
70
+ };
71
+ }
72
+ cancel() {
73
+ if (this.cancelled)
74
+ return;
75
+ this.cancelled = true;
76
+ this.token.isCancellationRequested = true;
77
+ this.emitter.fire();
78
+ }
79
+ dispose() {
80
+ this.emitter.dispose();
81
+ }
82
+ }
83
+ exports.CancellationTokenSource = CancellationTokenSource;
84
+ class Position {
85
+ constructor(line, character) {
86
+ this.line = line;
87
+ this.character = character;
88
+ }
89
+ with(line, character) {
90
+ return new Position(line ?? this.line, character ?? this.character);
91
+ }
92
+ isBefore(other) {
93
+ return this.line < other.line || (this.line === other.line && this.character < other.character);
94
+ }
95
+ toJSON() {
96
+ return { line: this.line, character: this.character };
97
+ }
98
+ static from(value) {
99
+ return value instanceof Position ? value : new Position(value.line, value.character);
100
+ }
101
+ }
102
+ exports.Position = Position;
103
+ class Range {
104
+ constructor(start, end) {
105
+ this.start = start;
106
+ this.end = end;
107
+ }
108
+ get isEmpty() {
109
+ return this.start.line === this.end.line && this.start.character === this.end.character;
110
+ }
111
+ toJSON() {
112
+ return { start: this.start.toJSON(), end: this.end.toJSON() };
113
+ }
114
+ static from(value) {
115
+ if (value instanceof Range)
116
+ return value;
117
+ return new Range(Position.from(value.start), Position.from(value.end));
118
+ }
119
+ }
120
+ exports.Range = Range;
121
+ class Selection extends Range {
122
+ constructor(anchor, active) {
123
+ super(anchor.isBefore(active) ? anchor : active, anchor.isBefore(active) ? active : anchor);
124
+ this.anchor = anchor;
125
+ this.active = active;
126
+ }
127
+ }
128
+ exports.Selection = Selection;
129
+ /** Small URI helper; the native side works with absolute paths and content URIs. */
130
+ class Uri {
131
+ constructor(value) {
132
+ this.value = value;
133
+ }
134
+ static file(path) {
135
+ return new Uri(path.startsWith("file:") ? path : `file://${encodeURI(path)}`);
136
+ }
137
+ static parse(value) {
138
+ return new Uri(value);
139
+ }
140
+ static joinPath(base, ...segments) {
141
+ const joined = [base.value.replace(/\/+$/, ""), ...segments.map((s) => s.replace(/^\/+|\/+$/g, ""))]
142
+ .filter(Boolean)
143
+ .join("/");
144
+ return new Uri(joined);
145
+ }
146
+ get scheme() {
147
+ const match = /^([a-zA-Z][a-zA-Z0-9+.-]*):/.exec(this.value);
148
+ return match ? match[1].toLowerCase() : "file";
149
+ }
150
+ get path() {
151
+ if (this.scheme === "file") {
152
+ try {
153
+ return decodeURI(this.value.replace(/^file:\/\//, ""));
154
+ }
155
+ catch {
156
+ return this.value.replace(/^file:\/\//, "");
157
+ }
158
+ }
159
+ return this.value;
160
+ }
161
+ get fsPath() {
162
+ return this.path;
163
+ }
164
+ toString() {
165
+ return this.value;
166
+ }
167
+ with(change) {
168
+ if (change.path !== undefined) {
169
+ return this.scheme === "file" ? Uri.file(change.path) : new Uri(`${this.scheme}:${change.path}`);
170
+ }
171
+ return new Uri(this.value);
172
+ }
173
+ }
174
+ exports.Uri = Uri;
175
+ /** Convert a (line, character) position into a document offset. */
176
+ function offsetAt(text, position) {
177
+ let line = 0;
178
+ let offset = 0;
179
+ while (line < position.line) {
180
+ const next = text.indexOf("\n", offset);
181
+ if (next < 0)
182
+ return text.length;
183
+ offset = next + 1;
184
+ line++;
185
+ }
186
+ const lineEnd = text.indexOf("\n", offset);
187
+ const max = lineEnd < 0 ? text.length : lineEnd;
188
+ return Math.min(offset + Math.max(0, position.character), max);
189
+ }
190
+ function positionAt(text, offset) {
191
+ let line = 0;
192
+ let lastLineStart = 0;
193
+ const max = Math.max(0, Math.min(offset, text.length));
194
+ for (let i = 0; i < max; i++) {
195
+ if (text.charCodeAt(i) === 10) {
196
+ line++;
197
+ lastLineStart = i + 1;
198
+ }
199
+ }
200
+ return new Position(line, max - lastLineStart);
201
+ }
202
+ var StatusBarAlignment;
203
+ (function (StatusBarAlignment) {
204
+ StatusBarAlignment[StatusBarAlignment["Left"] = 0] = "Left";
205
+ StatusBarAlignment[StatusBarAlignment["Right"] = 1] = "Right";
206
+ })(StatusBarAlignment || (exports.StatusBarAlignment = StatusBarAlignment = {}));
package/package.json CHANGED
@@ -1,6 +1,57 @@
1
1
  {
2
2
  "name": "@gratux/sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.1",
4
+ "description": "TypeScript-first SDK for building Gratux Native extensions",
5
+ "license": "MIT",
6
+ "keywords": [
7
+ "gratux",
8
+ "extension",
9
+ "android",
10
+ "ide"
11
+ ],
12
+ "main": "dist/index.js",
13
+ "types": "dist/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "require": "./dist/index.js",
18
+ "default": "./dist/index.js"
19
+ },
20
+ "./manifest": {
21
+ "types": "./dist/manifest.d.ts",
22
+ "require": "./dist/manifest.js",
23
+ "default": "./dist/manifest.js"
24
+ },
25
+ "./host": {
26
+ "types": "./dist/host-entry.d.ts",
27
+ "require": "./dist/host-entry.js",
28
+ "default": "./dist/host-entry.js"
29
+ }
30
+ },
31
+ "files": [
32
+ "dist",
33
+ "README.md",
34
+ "templates"
35
+ ],
36
+ "scripts": {
37
+ "build": "tsc -p tsconfig.json",
38
+ "build:host": "npm run build && node scripts/build-host-asset.mjs",
39
+ "build:assets": "npm run build && node scripts/build-host-asset.mjs && node scripts/build-samples.mjs",
40
+ "test": "tsc -p tsconfig.test.json && node --test dist-test/test/*.test.js",
41
+ "validate": "node scripts/validate-extension.mjs",
42
+ "build:samples": "node scripts/build-samples.mjs",
43
+ "typecheck:samples": "tsc -p tsconfig.samples.json"
44
+ },
45
+ "devDependencies": {
46
+ "@types/node": "^22.20.7",
47
+ "esbuild": "^0.24.0",
48
+ "typescript": "^5.6.3"
49
+ },
50
+ "engines": {
51
+ "node": ">=18"
52
+ },
53
+ "repository": {
54
+ "type": "git",
55
+ "url": "git+https://github.com/PanditSiddharth/gratux-sdk.git"
56
+ }
57
+ }
@@ -0,0 +1,17 @@
1
+ # Hello Gratux (basic template)
2
+
3
+ A minimal code extension: one command, one notification.
4
+
5
+ ## Build
6
+
7
+ ```bash
8
+ cd gratux-sdk
9
+ npm run build # builds the SDK once
10
+ npx esbuild templates/basic/src/extension.ts --bundle --format=cjs \
11
+ --platform=neutral --external:@gratux/sdk \
12
+ --outfile=templates/basic/dist/extension.js
13
+ node scripts/validate-extension.mjs templates/basic
14
+ ```
15
+
16
+ To produce a `.gxpkg`, zip `gratux.json` and `dist/extension.js` at the archive
17
+ root (or copy the folder into `samples/` and run `npm run build:samples`).
@@ -0,0 +1,19 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "your-name.hello-gratux",
4
+ "name": "Hello Gratux",
5
+ "description": "A minimal Gratux Native extension.",
6
+ "version": "0.1.0",
7
+ "publisher": "your-name",
8
+ "license": "MIT",
9
+ "type": "typescript",
10
+ "main": "dist/extension.js",
11
+ "engines": { "gratux": "^1.0.0" },
12
+ "permissions": ["commands.register", "ui.notifications"],
13
+ "activationEvents": ["onCommand:helloGratux.run"],
14
+ "contributes": {
15
+ "commands": [
16
+ { "id": "helloGratux.run", "title": "Hello: Greet", "category": "Hello" }
17
+ ]
18
+ }
19
+ }
@@ -0,0 +1,7 @@
1
+ import { commands, window } from "@gratux/sdk";
2
+
3
+ export function activate(): void {
4
+ commands.registerCommand("helloGratux.run", () =>
5
+ window.showInformationMessage("Hello from a Gratux extension!"),
6
+ );
7
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "commonjs",
5
+ "moduleResolution": "node",
6
+ "strict": true,
7
+ "skipLibCheck": true,
8
+ "lib": ["ES2020", "DOM"],
9
+ "noEmit": true,
10
+ "paths": {
11
+ "@gratux/sdk": ["../../src/index.ts"]
12
+ }
13
+ },
14
+ "include": ["src/**/*.ts"]
15
+ }
@@ -0,0 +1,17 @@
1
+ # Hello View (WebView template)
2
+
3
+ A WebView view that exchanges messages with the extension.
4
+
5
+ ## Build
6
+
7
+ ```bash
8
+ cd gratux-sdk
9
+ npm run build # builds the SDK once
10
+ npx esbuild templates/webview/src/extension.ts --bundle --format=cjs \
11
+ --platform=neutral --external:@gratux/sdk \
12
+ --outfile=templates/webview/dist/extension.js
13
+ node scripts/validate-extension.mjs templates/webview
14
+ ```
15
+
16
+ To produce a `.gxpkg`, zip `gratux.json` and `dist/extension.js` at the archive
17
+ root (or copy the folder into `samples/` and run `npm run build:samples`).
@@ -0,0 +1,19 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "your-name.hello-view",
4
+ "name": "Hello View",
5
+ "description": "A minimal WebView view contribution.",
6
+ "version": "0.1.0",
7
+ "publisher": "your-name",
8
+ "license": "MIT",
9
+ "type": "typescript",
10
+ "main": "dist/extension.js",
11
+ "engines": { "gratux": "^1.0.0" },
12
+ "permissions": ["ui.sidebar", "ui.panel", "ui.notifications"],
13
+ "activationEvents": ["onStartupFinished"],
14
+ "contributes": {
15
+ "views": [
16
+ { "id": "helloView", "title": "Hello View", "location": "panel" }
17
+ ]
18
+ }
19
+ }
@@ -0,0 +1,43 @@
1
+ import { window } from "@gratux/sdk";
2
+ import type { WebviewViewProvider } from "@gratux/sdk";
3
+
4
+ export function activate(): void {
5
+ const provider: WebviewViewProvider = {
6
+ resolveWebviewView(view) {
7
+ view.webview.html = `<!doctype html>
8
+ <html>
9
+ <head><meta name="viewport" content="width=device-width, initial-scale=1">
10
+ <style>body{background:#1e1e1e;color:#d4d4d4;font-family:sans-serif;padding:16px}</style>
11
+ </head>
12
+ <body>
13
+ <h2>Hello View</h2>
14
+ <p id="out">Waiting for a message…</p>
15
+ <button id="ping">Ping extension</button>
16
+ <script>
17
+ function send(message) {
18
+ if (typeof acquireGratuxApi === "function") acquireGratuxApi().postMessage(message);
19
+ }
20
+ document.getElementById("ping").addEventListener("click", function () {
21
+ send({ type: "ping" });
22
+ });
23
+ window.addEventListener("message", function (event) {
24
+ if (event.data && event.data.type === "pong") {
25
+ document.getElementById("out").textContent = event.data.text;
26
+ }
27
+ });
28
+ </script>
29
+ </body>
30
+ </html>`;
31
+
32
+ view.webview.onDidReceiveMessage(async (raw) => {
33
+ const message = raw as { type?: string };
34
+ if (message?.type === "ping") {
35
+ await view.webview.postMessage({ type: "pong", text: "Hello from the extension!" });
36
+ await window.showInformationMessage("Hello View: ping received.");
37
+ }
38
+ });
39
+ },
40
+ };
41
+
42
+ window.registerWebviewViewProvider("helloView", provider);
43
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "commonjs",
5
+ "moduleResolution": "node",
6
+ "strict": true,
7
+ "skipLibCheck": true,
8
+ "lib": ["ES2020", "DOM"],
9
+ "noEmit": true,
10
+ "paths": {
11
+ "@gratux/sdk": ["../../src/index.ts"]
12
+ }
13
+ },
14
+ "include": ["src/**/*.ts"]
15
+ }