@yurikilian/lex4 0.1.2 → 0.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.
Files changed (79) hide show
  1. package/README.md +236 -20
  2. package/dist/ast/block-mapper.d.ts +24 -0
  3. package/dist/ast/block-mapper.d.ts.map +1 -0
  4. package/dist/ast/content-mapper.d.ts +16 -0
  5. package/dist/ast/content-mapper.d.ts.map +1 -0
  6. package/dist/ast/document-serializer.d.ts +11 -0
  7. package/dist/ast/document-serializer.d.ts.map +1 -0
  8. package/dist/ast/index.d.ts +9 -0
  9. package/dist/ast/index.d.ts.map +1 -0
  10. package/dist/ast/inline-mapper.d.ts +41 -0
  11. package/dist/ast/inline-mapper.d.ts.map +1 -0
  12. package/dist/ast/payload-builder.d.ts +18 -0
  13. package/dist/ast/payload-builder.d.ts.map +1 -0
  14. package/dist/ast/types.d.ts +112 -0
  15. package/dist/ast/types.d.ts.map +1 -0
  16. package/dist/components/EditorSidebar.d.ts +1 -0
  17. package/dist/components/EditorSidebar.d.ts.map +1 -1
  18. package/dist/components/HistorySidebar.d.ts.map +1 -1
  19. package/dist/components/Lex4Editor.d.ts +9 -1
  20. package/dist/components/Lex4Editor.d.ts.map +1 -1
  21. package/dist/components/PageBody.d.ts +1 -2
  22. package/dist/components/PageBody.d.ts.map +1 -1
  23. package/dist/components/PageFooter.d.ts.map +1 -1
  24. package/dist/components/PageHeader.d.ts.map +1 -1
  25. package/dist/components/Toolbar.d.ts.map +1 -1
  26. package/dist/components/VariablePanel.d.ts +15 -0
  27. package/dist/components/VariablePanel.d.ts.map +1 -0
  28. package/dist/components/VariablePicker.d.ts +14 -0
  29. package/dist/components/VariablePicker.d.ts.map +1 -0
  30. package/dist/extensions/ast-extension.d.ts +16 -0
  31. package/dist/extensions/ast-extension.d.ts.map +1 -0
  32. package/dist/extensions/extension-context.d.ts +29 -0
  33. package/dist/extensions/extension-context.d.ts.map +1 -0
  34. package/dist/extensions/index.d.ts +6 -0
  35. package/dist/extensions/index.d.ts.map +1 -0
  36. package/dist/extensions/types.d.ts +74 -0
  37. package/dist/extensions/types.d.ts.map +1 -0
  38. package/dist/extensions/variables-extension.d.ts +31 -0
  39. package/dist/extensions/variables-extension.d.ts.map +1 -0
  40. package/dist/i18n/context.d.ts +28 -0
  41. package/dist/i18n/context.d.ts.map +1 -0
  42. package/dist/i18n/defaults.d.ts +3 -0
  43. package/dist/i18n/defaults.d.ts.map +1 -0
  44. package/dist/i18n/index.d.ts +4 -0
  45. package/dist/i18n/index.d.ts.map +1 -0
  46. package/dist/i18n/types.d.ts +82 -0
  47. package/dist/i18n/types.d.ts.map +1 -0
  48. package/dist/index.d.ts +10 -0
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/lex4-editor.cjs +1113 -101
  51. package/dist/lex4-editor.cjs.map +1 -1
  52. package/dist/lex4-editor.js +1116 -104
  53. package/dist/lex4-editor.js.map +1 -1
  54. package/dist/lexical/editor-setup.d.ts +5 -1
  55. package/dist/lexical/editor-setup.d.ts.map +1 -1
  56. package/dist/lexical/plugins/font-plugin.d.ts +1 -1
  57. package/dist/lexical/plugins/font-plugin.d.ts.map +1 -1
  58. package/dist/lexical/plugins/font-size-plugin.d.ts +19 -0
  59. package/dist/lexical/plugins/font-size-plugin.d.ts.map +1 -0
  60. package/dist/lexical/plugins/index.d.ts +2 -0
  61. package/dist/lexical/plugins/index.d.ts.map +1 -1
  62. package/dist/style.css +532 -160
  63. package/dist/types/editor-handle.d.ts +14 -0
  64. package/dist/types/editor-handle.d.ts.map +1 -0
  65. package/dist/types/editor-props.d.ts +23 -0
  66. package/dist/types/editor-props.d.ts.map +1 -1
  67. package/dist/variables/index.d.ts +5 -0
  68. package/dist/variables/index.d.ts.map +1 -0
  69. package/dist/variables/types.d.ts +26 -0
  70. package/dist/variables/types.d.ts.map +1 -0
  71. package/dist/variables/variable-commands.d.ts +11 -0
  72. package/dist/variables/variable-commands.d.ts.map +1 -0
  73. package/dist/variables/variable-context.d.ts +21 -0
  74. package/dist/variables/variable-context.d.ts.map +1 -0
  75. package/dist/variables/variable-node.d.ts +34 -0
  76. package/dist/variables/variable-node.d.ts.map +1 -0
  77. package/dist/variables/variable-plugin.d.ts +8 -0
  78. package/dist/variables/variable-plugin.d.ts.map +1 -0
  79. package/package.json +1 -1
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Base imperative handle exposed by Lex4Editor via React ref.
3
+ *
4
+ * This is always empty — all methods are contributed by extensions.
5
+ * The actual handle type is dynamic based on which extensions are loaded.
6
+ *
7
+ * Common extension-provided methods:
8
+ * - astExtension: getDocumentAst(), getDocumentJson(), buildSavePayload()
9
+ * - variablesExtension: insertVariable(), refreshVariables()
10
+ */
11
+ export interface Lex4EditorHandle {
12
+ [key: string]: (...args: any[]) => any;
13
+ }
14
+ //# sourceMappingURL=editor-handle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"editor-handle.d.ts","sourceRoot":"","sources":["../../src/types/editor-handle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,WAAW,gBAAgB;IAE/B,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;CACxC"}
@@ -1,4 +1,10 @@
1
1
  import { Lex4Document } from './document';
2
+ import { Lex4Extension } from '../extensions/types';
3
+ import { DocumentAst } from '../ast/types';
4
+ import { Lex4Translations } from '../i18n/types';
5
+ type DeepPartial<T> = {
6
+ [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
7
+ };
2
8
  /** Public props for the Lex4Editor component */
3
9
  export interface Lex4EditorProps {
4
10
  /** Initial document state. Defaults to a single empty page. */
@@ -13,7 +19,24 @@ export interface Lex4EditorProps {
13
19
  readOnly?: boolean;
14
20
  /** Capture undo/redo shortcuts at the window level, even when focus is outside the document. Defaults to true. */
15
21
  captureHistoryShortcutsOnWindow?: boolean;
22
+ /** Called when the user triggers save/export. Provides both the AST and its JSON serialization. */
23
+ onSave?: (payload: {
24
+ ast: DocumentAst;
25
+ json: string;
26
+ }) => void;
27
+ /**
28
+ * Extensions to load into the editor.
29
+ * Each extension can contribute nodes, plugins, toolbar items, side panels, and imperative handle methods.
30
+ * @example extensions={[defaultTheme(), astExtension(), variablesExtension(defs)]}
31
+ */
32
+ extensions?: Lex4Extension[];
33
+ /**
34
+ * Translation overrides for i18n. Partial overrides are deep-merged with defaults (English).
35
+ * @example translations={{ toolbar: { undo: 'Desfazer' } }}
36
+ */
37
+ translations?: DeepPartial<Lex4Translations>;
16
38
  /** Additional CSS class for the editor root element */
17
39
  className?: string;
18
40
  }
41
+ export {};
19
42
  //# sourceMappingURL=editor-props.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"editor-props.d.ts","sourceRoot":"","sources":["../../src/types/editor-props.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,gDAAgD;AAChD,MAAM,WAAW,eAAe;IAC9B,+DAA+D;IAC/D,eAAe,CAAC,EAAE,YAAY,CAAC;IAE/B,iDAAiD;IACjD,gBAAgB,CAAC,EAAE,CAAC,GAAG,EAAE,YAAY,KAAK,IAAI,CAAC;IAE/C,6DAA6D;IAC7D,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAE9B,mDAAmD;IACnD,oBAAoB,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IAElD,sCAAsC;IACtC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,kHAAkH;IAClH,+BAA+B,CAAC,EAAE,OAAO,CAAC;IAE1C,uDAAuD;IACvD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}
1
+ {"version":3,"file":"editor-props.d.ts","sourceRoot":"","sources":["../../src/types/editor-props.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEtD,KAAK,WAAW,CAAC,CAAC,IAAI;KACnB,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAChE,CAAC;AAEF,gDAAgD;AAChD,MAAM,WAAW,eAAe;IAC9B,+DAA+D;IAC/D,eAAe,CAAC,EAAE,YAAY,CAAC;IAE/B,iDAAiD;IACjD,gBAAgB,CAAC,EAAE,CAAC,GAAG,EAAE,YAAY,KAAK,IAAI,CAAC;IAE/C,6DAA6D;IAC7D,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAE9B,mDAAmD;IACnD,oBAAoB,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IAElD,sCAAsC;IACtC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,kHAAkH;IAClH,+BAA+B,CAAC,EAAE,OAAO,CAAC;IAE1C,mGAAmG;IACnG,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE;QAAE,GAAG,EAAE,WAAW,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IAE/D;;;;OAIG;IACH,UAAU,CAAC,EAAE,aAAa,EAAE,CAAC;IAE7B;;;OAGG;IACH,YAAY,CAAC,EAAE,WAAW,CAAC,gBAAgB,CAAC,CAAC;IAE7C,uDAAuD;IACvD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}
@@ -0,0 +1,5 @@
1
+ export type { VariableDefinition, VariableContextValue } from './types';
2
+ export { VariableNode, $createVariableNode, $isVariableNode, type SerializedVariableNode, } from './variable-node';
3
+ export { INSERT_VARIABLE_COMMAND, insertVariable, } from './variable-commands';
4
+ export { VariablePlugin } from './variable-plugin';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/variables/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAExE,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,eAAe,EACf,KAAK,sBAAsB,GAC5B,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,uBAAuB,EACvB,cAAc,GACf,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Variable system types.
3
+ *
4
+ * These types define the variable catalog, definitions,
5
+ * and source interface used by the editor UI and serializer.
6
+ */
7
+ /** Describes a single variable that can be inserted into the document. */
8
+ export interface VariableDefinition {
9
+ /** Dot-notation key, e.g. "customer.name" */
10
+ key: string;
11
+ /** Human-readable label shown in the picker */
12
+ label: string;
13
+ /** Optional description for tooltips */
14
+ description?: string;
15
+ /** Expected runtime value type */
16
+ valueType?: 'string' | 'number' | 'date' | 'boolean';
17
+ /** Grouping key for the picker UI, e.g. "Customer", "Proposal" */
18
+ group?: string;
19
+ }
20
+ /** Context value exposed by the VariableProvider. */
21
+ export interface VariableContextValue {
22
+ definitions: VariableDefinition[];
23
+ getDefinition(key: string): VariableDefinition | undefined;
24
+ refreshDefinitions(newDefs: VariableDefinition[]): void;
25
+ }
26
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/variables/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,0EAA0E;AAC1E,MAAM,WAAW,kBAAkB;IACjC,6CAA6C;IAC7C,GAAG,EAAE,MAAM,CAAC;IACZ,+CAA+C;IAC/C,KAAK,EAAE,MAAM,CAAC;IACd,wCAAwC;IACxC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kCAAkC;IAClC,SAAS,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,SAAS,CAAC;IACrD,kEAAkE;IAClE,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,qDAAqD;AACrD,MAAM,WAAW,oBAAoB;IACnC,WAAW,EAAE,kBAAkB,EAAE,CAAC;IAClC,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS,CAAC;IAC3D,kBAAkB,CAAC,OAAO,EAAE,kBAAkB,EAAE,GAAG,IAAI,CAAC;CACzD"}
@@ -0,0 +1,11 @@
1
+ import { LexicalEditor } from 'lexical';
2
+ /**
3
+ * Command to insert a variable node at the current selection.
4
+ * Payload is the variable key string (e.g. "customer.name").
5
+ */
6
+ export declare const INSERT_VARIABLE_COMMAND: import('lexical').LexicalCommand<string>;
7
+ /**
8
+ * Inserts a variable node at the current cursor position.
9
+ */
10
+ export declare function insertVariable(editor: LexicalEditor, variableKey: string): void;
11
+ //# sourceMappingURL=variable-commands.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"variable-commands.d.ts","sourceRoot":"","sources":["../../src/variables/variable-commands.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,aAAa,EACnB,MAAM,SAAS,CAAC;AAEjB;;;GAGG;AACH,eAAO,MAAM,uBAAuB,0CAA2C,CAAC;AAEhF;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI,CAE/E"}
@@ -0,0 +1,21 @@
1
+ import { default as React } from 'react';
2
+ import { VariableDefinition, VariableContextValue } from './types';
3
+ interface VariableProviderProps {
4
+ initialDefinitions?: VariableDefinition[];
5
+ children: React.ReactNode;
6
+ }
7
+ /**
8
+ * VariableProvider — Manages the variable catalog.
9
+ *
10
+ * Host apps provide variable definitions via props.
11
+ * The picker reads from this context. Definitions can be refreshed
12
+ * at runtime without re-mounting the editor.
13
+ */
14
+ export declare const VariableProvider: React.FC<VariableProviderProps>;
15
+ /**
16
+ * Hook to access the variable catalog from within the editor tree.
17
+ * Returns empty defaults when called outside a VariableProvider.
18
+ */
19
+ export declare function useVariables(): VariableContextValue;
20
+ export {};
21
+ //# sourceMappingURL=variable-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"variable-context.d.ts","sourceRoot":"","sources":["../../src/variables/variable-context.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoE,MAAM,OAAO,CAAC;AACzF,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAUxE,UAAU,qBAAqB;IAC7B,kBAAkB,CAAC,EAAE,kBAAkB,EAAE,CAAC;IAC1C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAED;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,qBAAqB,CA2B5D,CAAC;AAEF;;;GAGG;AACH,wBAAgB,YAAY,IAAI,oBAAoB,CAEnD"}
@@ -0,0 +1,34 @@
1
+ import { DecoratorNode, DOMConversionMap, DOMExportOutput, LexicalNode, NodeKey, SerializedLexicalNode, Spread } from 'lexical';
2
+ export type SerializedVariableNode = Spread<{
3
+ variableKey: string;
4
+ }, SerializedLexicalNode>;
5
+ /**
6
+ * VariableNode — a custom Lexical DecoratorNode that represents
7
+ * a document variable/placeholder (e.g. "customer.name").
8
+ *
9
+ * Variables are atomic, non-editable inline tokens that:
10
+ * - Display as styled chips in the editor
11
+ * - Serialize to a structured node in JSON (not plain text)
12
+ * - Participate in copy/paste, undo/redo, and overflow
13
+ * - Return {{key}} as text content for clipboard
14
+ */
15
+ export declare class VariableNode extends DecoratorNode<JSX.Element> {
16
+ __variableKey: string;
17
+ static getType(): string;
18
+ static clone(node: VariableNode): VariableNode;
19
+ constructor(variableKey: string, key?: NodeKey);
20
+ getVariableKey(): string;
21
+ static importJSON(serializedNode: SerializedVariableNode): VariableNode;
22
+ exportJSON(): SerializedVariableNode;
23
+ createDOM(): HTMLElement;
24
+ updateDOM(): false;
25
+ exportDOM(): DOMExportOutput;
26
+ static importDOM(): DOMConversionMap | null;
27
+ isInline(): boolean;
28
+ isKeyboardSelectable(): boolean;
29
+ getTextContent(): string;
30
+ decorate(): JSX.Element;
31
+ }
32
+ export declare function $createVariableNode(variableKey: string): VariableNode;
33
+ export declare function $isVariableNode(node: LexicalNode | null | undefined): node is VariableNode;
34
+ //# sourceMappingURL=variable-node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"variable-node.d.ts","sourceRoot":"","sources":["../../src/variables/variable-node.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,aAAa,EACb,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,OAAO,EACZ,KAAK,qBAAqB,EAC1B,KAAK,MAAM,EACZ,MAAM,SAAS,CAAC;AAEjB,MAAM,MAAM,sBAAsB,GAAG,MAAM,CACzC;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,EACvB,qBAAqB,CACtB,CAAC;AAEF;;;;;;;;;GASG;AACH,qBAAa,YAAa,SAAQ,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC;IAC1D,aAAa,EAAE,MAAM,CAAC;IAEtB,MAAM,CAAC,OAAO,IAAI,MAAM;IAIxB,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,YAAY,GAAG,YAAY;gBAIlC,WAAW,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,OAAO;IAK9C,cAAc,IAAI,MAAM;IAMxB,MAAM,CAAC,UAAU,CAAC,cAAc,EAAE,sBAAsB,GAAG,YAAY;IAIvE,UAAU,IAAI,sBAAsB;IAUpC,SAAS,IAAI,WAAW;IASxB,SAAS,IAAI,KAAK;IAIlB,SAAS,IAAI,eAAe;IAO5B,MAAM,CAAC,SAAS,IAAI,gBAAgB,GAAG,IAAI;IAM3C,QAAQ,IAAI,OAAO;IAInB,oBAAoB,IAAI,OAAO;IAI/B,cAAc,IAAI,MAAM;IAMxB,QAAQ,IAAI,GAAG,CAAC,OAAO;CAaxB;AAED,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,YAAY,CAErE;AAED,wBAAgB,eAAe,CAC7B,IAAI,EAAE,WAAW,GAAG,IAAI,GAAG,SAAS,GACnC,IAAI,IAAI,YAAY,CAEtB"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * VariablePlugin — registers the INSERT_VARIABLE_COMMAND handler.
3
+ *
4
+ * When the command fires, a VariableNode is created and inserted
5
+ * at the current selection position.
6
+ */
7
+ export declare const VariablePlugin: React.FC;
8
+ //# sourceMappingURL=variable-plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"variable-plugin.d.ts","sourceRoot":"","sources":["../../src/variables/variable-plugin.tsx"],"names":[],"mappings":"AAWA;;;;;GAKG;AACH,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAqBlC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yurikilian/lex4",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",