@jotx-labs/registry 2.2.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.
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./types"), exports);
18
+ __exportStar(require("./registry"), exports);
@@ -0,0 +1,2 @@
1
+ export * from './types';
2
+ export * from './registry';
@@ -0,0 +1,2 @@
1
+ export * from './types';
2
+ export * from './registry';
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./types"), exports);
18
+ __exportStar(require("./registry"), exports);
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registry = exports.BlockRegistry = void 0;
4
+ class BlockRegistry {
5
+ constructor() {
6
+ this.blocks = new Map();
7
+ this.keywords = new Map(); // keyword -> type
8
+ this.prefixes = new Map(); // prefix -> type
9
+ }
10
+ static getInstance() {
11
+ if (!BlockRegistry.instance) {
12
+ BlockRegistry.instance = new BlockRegistry();
13
+ }
14
+ return BlockRegistry.instance;
15
+ }
16
+ /**
17
+ * Register a new block definition
18
+ */
19
+ register(definition) {
20
+ if (this.blocks.has(definition.type)) {
21
+ console.warn(`Block type "${definition.type}" is already registered. Overwriting.`);
22
+ }
23
+ this.blocks.set(definition.type, definition);
24
+ // Index by keyword
25
+ if (definition.syntax.keyword) {
26
+ this.keywords.set(definition.syntax.keyword, definition.type);
27
+ }
28
+ // Index by markdown prefix
29
+ if (definition.syntax.markdownPrefix) {
30
+ this.prefixes.set(definition.syntax.markdownPrefix, definition.type);
31
+ }
32
+ }
33
+ /**
34
+ * Get block definition by type
35
+ */
36
+ get(type) {
37
+ return this.blocks.get(type);
38
+ }
39
+ /**
40
+ * Get block definition by keyword (e.g. "video")
41
+ */
42
+ getByKeyword(keyword) {
43
+ const type = this.keywords.get(keyword);
44
+ return type ? this.blocks.get(type) : undefined;
45
+ }
46
+ /**
47
+ * Get block definition by prefix (e.g. "# ")
48
+ */
49
+ getByPrefix(prefix) {
50
+ // Find longest matching prefix
51
+ // (This is a naive implementation, optimize with Trie later if needed)
52
+ for (const [p, type] of this.prefixes.entries()) {
53
+ if (prefix.startsWith(p)) {
54
+ return this.blocks.get(type);
55
+ }
56
+ }
57
+ return undefined;
58
+ }
59
+ /**
60
+ * Get all registered blocks
61
+ */
62
+ getAll() {
63
+ return Array.from(this.blocks.values());
64
+ }
65
+ /**
66
+ * Clear registry (useful for tests)
67
+ */
68
+ clear() {
69
+ this.blocks.clear();
70
+ this.keywords.clear();
71
+ this.prefixes.clear();
72
+ }
73
+ }
74
+ exports.BlockRegistry = BlockRegistry;
75
+ // Export singleton instance for convenience
76
+ exports.registry = BlockRegistry.getInstance();
@@ -0,0 +1,34 @@
1
+ import { BlockDefinition } from './types';
2
+ export declare class BlockRegistry {
3
+ private static instance;
4
+ private blocks;
5
+ private keywords;
6
+ private prefixes;
7
+ private constructor();
8
+ static getInstance(): BlockRegistry;
9
+ /**
10
+ * Register a new block definition
11
+ */
12
+ register(definition: BlockDefinition): void;
13
+ /**
14
+ * Get block definition by type
15
+ */
16
+ get(type: string): BlockDefinition | undefined;
17
+ /**
18
+ * Get block definition by keyword (e.g. "video")
19
+ */
20
+ getByKeyword(keyword: string): BlockDefinition | undefined;
21
+ /**
22
+ * Get block definition by prefix (e.g. "# ")
23
+ */
24
+ getByPrefix(prefix: string): BlockDefinition | undefined;
25
+ /**
26
+ * Get all registered blocks
27
+ */
28
+ getAll(): BlockDefinition[];
29
+ /**
30
+ * Clear registry (useful for tests)
31
+ */
32
+ clear(): void;
33
+ }
34
+ export declare const registry: BlockRegistry;
@@ -0,0 +1,34 @@
1
+ import { BlockDefinition } from './types';
2
+ export declare class BlockRegistry {
3
+ private static instance;
4
+ private blocks;
5
+ private keywords;
6
+ private prefixes;
7
+ private constructor();
8
+ static getInstance(): BlockRegistry;
9
+ /**
10
+ * Register a new block definition
11
+ */
12
+ register(definition: BlockDefinition): void;
13
+ /**
14
+ * Get block definition by type
15
+ */
16
+ get(type: string): BlockDefinition | undefined;
17
+ /**
18
+ * Get block definition by keyword (e.g. "video")
19
+ */
20
+ getByKeyword(keyword: string): BlockDefinition | undefined;
21
+ /**
22
+ * Get block definition by prefix (e.g. "# ")
23
+ */
24
+ getByPrefix(prefix: string): BlockDefinition | undefined;
25
+ /**
26
+ * Get all registered blocks
27
+ */
28
+ getAll(): BlockDefinition[];
29
+ /**
30
+ * Clear registry (useful for tests)
31
+ */
32
+ clear(): void;
33
+ }
34
+ export declare const registry: BlockRegistry;
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registry = exports.BlockRegistry = void 0;
4
+ class BlockRegistry {
5
+ constructor() {
6
+ this.blocks = new Map();
7
+ this.keywords = new Map(); // keyword -> type
8
+ this.prefixes = new Map(); // prefix -> type
9
+ }
10
+ static getInstance() {
11
+ if (!BlockRegistry.instance) {
12
+ BlockRegistry.instance = new BlockRegistry();
13
+ }
14
+ return BlockRegistry.instance;
15
+ }
16
+ /**
17
+ * Register a new block definition
18
+ */
19
+ register(definition) {
20
+ if (this.blocks.has(definition.type)) {
21
+ console.warn(`Block type "${definition.type}" is already registered. Overwriting.`);
22
+ }
23
+ this.blocks.set(definition.type, definition);
24
+ // Index by keyword
25
+ if (definition.syntax.keyword) {
26
+ this.keywords.set(definition.syntax.keyword, definition.type);
27
+ }
28
+ // Index by markdown prefix
29
+ if (definition.syntax.markdownPrefix) {
30
+ this.prefixes.set(definition.syntax.markdownPrefix, definition.type);
31
+ }
32
+ }
33
+ /**
34
+ * Get block definition by type
35
+ */
36
+ get(type) {
37
+ return this.blocks.get(type);
38
+ }
39
+ /**
40
+ * Get block definition by keyword (e.g. "video")
41
+ */
42
+ getByKeyword(keyword) {
43
+ const type = this.keywords.get(keyword);
44
+ return type ? this.blocks.get(type) : undefined;
45
+ }
46
+ /**
47
+ * Get block definition by prefix (e.g. "# ")
48
+ */
49
+ getByPrefix(prefix) {
50
+ // Find longest matching prefix
51
+ // (This is a naive implementation, optimize with Trie later if needed)
52
+ for (const [p, type] of this.prefixes.entries()) {
53
+ if (prefix.startsWith(p)) {
54
+ return this.blocks.get(type);
55
+ }
56
+ }
57
+ return undefined;
58
+ }
59
+ /**
60
+ * Get all registered blocks
61
+ */
62
+ getAll() {
63
+ return Array.from(this.blocks.values());
64
+ }
65
+ /**
66
+ * Clear registry (useful for tests)
67
+ */
68
+ clear() {
69
+ this.blocks.clear();
70
+ this.keywords.clear();
71
+ this.prefixes.clear();
72
+ }
73
+ }
74
+ exports.BlockRegistry = BlockRegistry;
75
+ // Export singleton instance for convenience
76
+ exports.registry = BlockRegistry.getInstance();
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Block Definition Interface
3
+ * The contract that all blocks must fulfill (Core, UI, and Parsing)
4
+ */
5
+ export interface BlockDefinition<Props = any> {
6
+ type: string;
7
+ syntax: {
8
+ keyword?: string;
9
+ markdownPrefix?: string;
10
+ hasChildren?: boolean;
11
+ hasText?: boolean;
12
+ };
13
+ schema: {
14
+ properties: Record<keyof Props, PropertyDefinition>;
15
+ };
16
+ ui?: {
17
+ icon?: string;
18
+ label?: string;
19
+ description?: string;
20
+ component?: () => Promise<any>;
21
+ };
22
+ }
23
+ export interface PropertyDefinition {
24
+ type: 'string' | 'number' | 'boolean' | 'enum';
25
+ default?: any;
26
+ required?: boolean;
27
+ options?: string[];
28
+ description?: string;
29
+ }
30
+ export interface BlockFn<Props = any> {
31
+ (props: Props): any;
32
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Block Definition Interface
3
+ * The contract that all blocks must fulfill (Core, UI, and Parsing)
4
+ */
5
+ export interface BlockDefinition<Props = any> {
6
+ type: string;
7
+ syntax: {
8
+ keyword?: string;
9
+ markdownPrefix?: string;
10
+ hasChildren?: boolean;
11
+ hasText?: boolean;
12
+ };
13
+ schema: {
14
+ properties: Record<keyof Props, PropertyDefinition>;
15
+ };
16
+ ui?: {
17
+ icon?: string;
18
+ label?: string;
19
+ description?: string;
20
+ component?: () => Promise<any>;
21
+ };
22
+ }
23
+ export interface PropertyDefinition {
24
+ type: 'string' | 'number' | 'boolean' | 'enum';
25
+ default?: any;
26
+ required?: boolean;
27
+ options?: string[];
28
+ description?: string;
29
+ }
30
+ export interface BlockFn<Props = any> {
31
+ (props: Props): any;
32
+ }
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@jotx-labs/registry",
3
+ "version": "2.2.0",
4
+ "files": [
5
+ "dist"
6
+ ],
7
+ "description": "Block definition registry for jotx 3.0",
8
+ "main": "dist/index.js",
9
+ "types": "dist/index.d.ts",
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "watch": "tsc -w"
13
+ },
14
+ "keywords": [
15
+ "jotx",
16
+ "registry",
17
+ "plugin"
18
+ ],
19
+ "author": "balajiboominathan",
20
+ "license": "Apache-2.0",
21
+ "devDependencies": {
22
+ "typescript": "^5.0.0"
23
+ },
24
+ "dependencies": {}
25
+ }