lakelib 0.1.15 → 0.1.17

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 (36) hide show
  1. package/README.md +12 -2
  2. package/dist/lake.css +155 -5
  3. package/dist/lake.min.js +38 -31
  4. package/dist/lake.min.js.map +1 -1
  5. package/lib/lake.css +155 -5
  6. package/lib/lake.js +338 -108
  7. package/lib/lake.js.map +1 -1
  8. package/lib/types/boxes/equation.d.ts +2 -0
  9. package/lib/types/css/index.d.ts +2 -0
  10. package/lib/types/editor.d.ts +4 -5
  11. package/lib/types/i18n/en-US/index.d.ts +5 -0
  12. package/lib/types/i18n/ja/index.d.ts +5 -0
  13. package/lib/types/i18n/ko/index.d.ts +5 -0
  14. package/lib/types/i18n/types.d.ts +28 -0
  15. package/lib/types/i18n/zh-CN/index.d.ts +5 -0
  16. package/lib/types/index.d.ts +1 -1
  17. package/lib/types/models/box.d.ts +1 -2
  18. package/lib/types/models/fragment.d.ts +1 -2
  19. package/lib/types/models/nodes.d.ts +11 -14
  20. package/lib/types/models/range.d.ts +1 -1
  21. package/lib/types/operations/insert-node.d.ts +1 -2
  22. package/lib/types/parsers/html-parser.d.ts +0 -1
  23. package/lib/types/plugins/equation.d.ts +3 -0
  24. package/lib/types/plugins/special-character.d.ts +3 -0
  25. package/lib/types/types/commands.d.ts +20 -0
  26. package/lib/types/types/dropdown.d.ts +2 -1
  27. package/lib/types/types/native.d.ts +0 -23
  28. package/lib/types/ui/commands-popup.d.ts +24 -0
  29. package/lib/types/ui/toolbar.d.ts +1 -2
  30. package/lib/types/utils/from-base64.d.ts +1 -0
  31. package/lib/types/utils/get-box.d.ts +1 -2
  32. package/lib/types/utils/index.d.ts +2 -0
  33. package/lib/types/utils/query.d.ts +1 -2
  34. package/lib/types/utils/to-base64.d.ts +1 -0
  35. package/lib/types/utils/to-node-list.d.ts +1 -2
  36. package/package.json +20 -20
@@ -0,0 +1,2 @@
1
+ import { BoxComponent } from '../types/box';
2
+ export declare const equationBox: BoxComponent;
@@ -19,4 +19,6 @@ import './image.css';
19
19
  import './video.css';
20
20
  import './file.css';
21
21
  import './emoji.css';
22
+ import './equation.css';
22
23
  import './toolbar.css';
24
+ import './commands-popup.css';
@@ -1,5 +1,4 @@
1
1
  import EventEmitter from 'eventemitter3';
2
- import { NativeNode } from './types/native';
3
2
  import { TranslationFunctions } from './i18n/types';
4
3
  import { Nodes } from './models/nodes';
5
4
  import { Selection } from './managers/selection';
@@ -9,7 +8,7 @@ import { Keystroke } from './managers/keystroke';
9
8
  import { BoxManager } from './managers/box-manager';
10
9
  import { Plugin } from './managers/plugin';
11
10
  import { Toolbar } from './ui/toolbar';
12
- type MessageCallback = (type: 'success' | 'error' | 'warning', message: string) => void;
11
+ type OnMessage = (type: 'success' | 'error' | 'warning', message: string) => void;
13
12
  type Config = {
14
13
  value: string;
15
14
  readonly: boolean;
@@ -20,11 +19,11 @@ type Config = {
20
19
  lang: string;
21
20
  minChangeSize: number;
22
21
  historySize: number;
23
- onMessage: MessageCallback;
22
+ onMessage: OnMessage;
24
23
  [name: string]: any;
25
24
  };
26
25
  type EditorConfig = {
27
- root: string | Nodes | NativeNode;
26
+ root: string | Node | Nodes;
28
27
  toolbar?: Toolbar;
29
28
  value?: string;
30
29
  readonly?: boolean;
@@ -34,7 +33,7 @@ type EditorConfig = {
34
33
  indentWithTab?: boolean;
35
34
  lang?: string;
36
35
  minChangeSize?: number;
37
- onMessage?: MessageCallback;
36
+ onMessage?: OnMessage;
38
37
  [name: string]: any;
39
38
  };
40
39
  export declare class Editor {
@@ -45,6 +45,7 @@ declare const _default: {
45
45
  image: string;
46
46
  file: string;
47
47
  emoji: string;
48
+ equation: string;
48
49
  removeColor: string;
49
50
  };
50
51
  link: {
@@ -80,5 +81,9 @@ declare const _default: {
80
81
  codeBlock: {
81
82
  langType: string;
82
83
  };
84
+ equation: {
85
+ save: string;
86
+ placeholder: string;
87
+ };
83
88
  };
84
89
  export default _default;
@@ -45,6 +45,7 @@ declare const _default: {
45
45
  image: string;
46
46
  file: string;
47
47
  emoji: string;
48
+ equation: string;
48
49
  removeColor: string;
49
50
  };
50
51
  link: {
@@ -80,5 +81,9 @@ declare const _default: {
80
81
  codeBlock: {
81
82
  langType: string;
82
83
  };
84
+ equation: {
85
+ save: string;
86
+ placeholder: string;
87
+ };
83
88
  };
84
89
  export default _default;
@@ -45,6 +45,7 @@ declare const _default: {
45
45
  image: string;
46
46
  file: string;
47
47
  emoji: string;
48
+ equation: string;
48
49
  removeColor: string;
49
50
  };
50
51
  link: {
@@ -80,5 +81,9 @@ declare const _default: {
80
81
  codeBlock: {
81
82
  langType: string;
82
83
  };
84
+ equation: {
85
+ save: string;
86
+ placeholder: string;
87
+ };
83
88
  };
84
89
  export default _default;
@@ -186,6 +186,10 @@ type RootTranslation = {
186
186
  * E​m​o​j​i
187
187
  */
188
188
  emoji: string;
189
+ /**
190
+ * E​q​u​a​t​i​o​n
191
+ */
192
+ equation: string;
189
193
  /**
190
194
  * R​e​m​o​v​e​ ​c​o​l​o​r
191
195
  */
@@ -293,6 +297,16 @@ type RootTranslation = {
293
297
  */
294
298
  langType: string;
295
299
  };
300
+ equation: {
301
+ /**
302
+ * D​o​n​e
303
+ */
304
+ save: string;
305
+ /**
306
+ * T​y​p​e​ ​a​n​ ​e​x​p​r​e​s​s​i​o​n
307
+ */
308
+ placeholder: string;
309
+ };
296
310
  };
297
311
  export type TranslationFunctions = {
298
312
  toolbar: {
@@ -476,6 +490,10 @@ export type TranslationFunctions = {
476
490
  * Emoji
477
491
  */
478
492
  emoji: () => LocalizedString;
493
+ /**
494
+ * Equation
495
+ */
496
+ equation: () => LocalizedString;
479
497
  /**
480
498
  * Remove color
481
499
  */
@@ -583,6 +601,16 @@ export type TranslationFunctions = {
583
601
  */
584
602
  langType: () => LocalizedString;
585
603
  };
604
+ equation: {
605
+ /**
606
+ * Done
607
+ */
608
+ save: () => LocalizedString;
609
+ /**
610
+ * Type an expression
611
+ */
612
+ placeholder: () => LocalizedString;
613
+ };
586
614
  };
587
615
  export type Formatters = {};
588
616
  export {};
@@ -45,6 +45,7 @@ declare const _default: {
45
45
  image: string;
46
46
  file: string;
47
47
  emoji: string;
48
+ equation: string;
48
49
  removeColor: string;
49
50
  };
50
51
  link: {
@@ -80,5 +81,9 @@ declare const _default: {
80
81
  codeBlock: {
81
82
  langType: string;
82
83
  };
84
+ equation: {
85
+ save: string;
86
+ placeholder: string;
87
+ };
83
88
  };
84
89
  export default _default;
@@ -30,4 +30,4 @@ import { Button } from './ui/button';
30
30
  import { Dropdown } from './ui/dropdown';
31
31
  import { Editor } from './editor';
32
32
  import { Toolbar } from './ui/toolbar';
33
- export { Editor, Toolbar, ToolbarItem, DropdownMenuItem, BoxComponent, icons, Utils, Nodes, Fragment, Range, Box, HTMLParser, TextParser, insertBookmark, toBookmark, insertNode, insertFragment, deleteContents, setBlocks, splitBlock, splitMarks, addMark, removeMark, fixList, insertLink, insertBox, removeBox, Button, Dropdown, };
33
+ export { Editor, Toolbar, ToolbarItem, DropdownMenuItem, BoxComponent, Button, Dropdown, icons, Utils, Nodes, Fragment, Range, Box, HTMLParser, TextParser, insertBookmark, toBookmark, insertNode, insertFragment, deleteContents, setBlocks, splitBlock, splitMarks, addMark, removeMark, fixList, insertLink, insertBox, removeBox, };
@@ -1,13 +1,12 @@
1
1
  import EventEmitter from 'eventemitter3';
2
2
  import type { Editor } from '../editor';
3
- import { NativeNode } from '../types/native';
4
3
  import { BoxType, BoxValue } from '../types/box';
5
4
  import { BoxToolbarItem } from '../types/box-toolbar';
6
5
  import { Nodes } from './nodes';
7
6
  export declare class Box {
8
7
  node: Nodes;
9
8
  event: EventEmitter;
10
- constructor(node: string | Nodes | NativeNode);
9
+ constructor(node: string | Node | Nodes);
11
10
  private addFramework;
12
11
  get type(): BoxType;
13
12
  get name(): string;
@@ -1,9 +1,8 @@
1
- import { NativeNode } from '../types/native';
2
1
  import { Nodes } from './nodes';
3
2
  export declare class Fragment {
4
3
  private fragment;
5
4
  constructor(fragment?: DocumentFragment);
6
5
  get(): DocumentFragment;
7
6
  find(selector: string): Nodes;
8
- append(node: string | NativeNode | Nodes): void;
7
+ append(node: string | Node | Nodes): void;
9
8
  }
@@ -1,8 +1,5 @@
1
1
  import { KeyValue } from '../types/object';
2
- import { NativeNode } from '../types/native';
3
2
  import { NodePath } from '../types/node';
4
- type EachCallback = (element: NativeNode, index: number) => boolean | void;
5
- type EachElementCallback = (element: Element, index: number) => boolean | void;
6
3
  type EventItem = {
7
4
  type: string;
8
5
  listener: EventListener;
@@ -10,7 +7,7 @@ type EventItem = {
10
7
  export declare class Nodes {
11
8
  private nodeList;
12
9
  length: number;
13
- constructor(node?: NativeNode | NativeNode[] | null);
10
+ constructor(node?: Node | Node[] | null);
14
11
  get id(): number;
15
12
  get name(): string;
16
13
  get isElement(): boolean;
@@ -33,11 +30,11 @@ export declare class Nodes {
33
30
  get isIndivisible(): boolean;
34
31
  get isEmpty(): boolean;
35
32
  isSibling(target: Nodes): boolean;
36
- get(index: number): NativeNode;
37
- getAll(): NativeNode[];
33
+ get(index: number): Node;
34
+ getAll(): Node[];
38
35
  eq(index: number): Nodes;
39
- each(callback: EachCallback): this;
40
- eachElement(callback: EachElementCallback): this;
36
+ each(callback: (element: Node, index: number) => boolean | void): this;
37
+ eachElement(callback: (element: Element, index: number) => boolean | void): this;
41
38
  reverse(): Nodes;
42
39
  matches(selector: string): boolean;
43
40
  find(selector: string | NodePath): Nodes;
@@ -85,14 +82,14 @@ export declare class Nodes {
85
82
  text(value: string): this;
86
83
  outerHTML(): string;
87
84
  empty(): this;
88
- prepend(content: string | NativeNode | DocumentFragment | Nodes): this;
89
- append(content: string | NativeNode | DocumentFragment | Nodes): this;
90
- before(content: string | NativeNode | DocumentFragment | Nodes): this;
91
- after(content: string | NativeNode | DocumentFragment | Nodes): this;
92
- replaceWith(newContent: string | NativeNode | Nodes): this;
85
+ prepend(content: string | Node | DocumentFragment | Nodes): this;
86
+ append(content: string | Node | DocumentFragment | Nodes): this;
87
+ before(content: string | Node | DocumentFragment | Nodes): this;
88
+ after(content: string | Node | DocumentFragment | Nodes): this;
89
+ replaceWith(newContent: string | Node | Nodes): this;
93
90
  remove(keepChildren?: boolean): this;
94
91
  splitText(offset: number): Nodes;
95
92
  toString(): string;
96
- debug(): void;
93
+ info(): void;
97
94
  }
98
95
  export {};
@@ -50,5 +50,5 @@ export declare class Range {
50
50
  getEndText(): string;
51
51
  clone(): Range;
52
52
  cloneContents(): DocumentFragment;
53
- debug(): void;
53
+ info(): void;
54
54
  }
@@ -1,4 +1,3 @@
1
- import { NativeNode } from '../types/native';
2
1
  import { Nodes } from '../models/nodes';
3
2
  import { Range } from '../models/range';
4
- export declare function insertNode(range: Range, node: NativeNode | Nodes): void;
3
+ export declare function insertNode(range: Range, node: Node | Nodes): void;
@@ -9,6 +9,5 @@ export declare class HTMLParser {
9
9
  private static getClosedTagString;
10
10
  private static getTrimmedText;
11
11
  getHTML(): string;
12
- getNodeList(): Nodes[];
13
12
  getFragment(): DocumentFragment;
14
13
  }
@@ -0,0 +1,3 @@
1
+ import type { Editor } from '..';
2
+ declare const _default: (editor: Editor) => void;
3
+ export default _default;
@@ -0,0 +1,3 @@
1
+ import type { Editor } from '..';
2
+ declare const _default: (editor: Editor) => void;
3
+ export default _default;
@@ -0,0 +1,20 @@
1
+ import type { Editor } from '../editor';
2
+ import { TranslationFunctions } from '../i18n/types';
3
+ export type CommandButtonItem = {
4
+ name: string;
5
+ type: 'button';
6
+ icon?: string;
7
+ title: string | ((locale: TranslationFunctions) => string);
8
+ description: string | ((locale: TranslationFunctions) => string);
9
+ onClick: (editor: Editor, value: string) => void;
10
+ };
11
+ export type CommandUploadItem = {
12
+ name: string;
13
+ type: 'upload';
14
+ icon: string;
15
+ title: string | ((locale: TranslationFunctions) => string);
16
+ description: string | ((locale: TranslationFunctions) => string);
17
+ accept?: string;
18
+ multiple?: boolean;
19
+ };
20
+ export type CommandItem = CommandButtonItem | CommandUploadItem;
@@ -12,7 +12,8 @@ export type DropdownItem = {
12
12
  defaultValue?: string;
13
13
  tooltip: string | ((locale: TranslationFunctions) => string);
14
14
  width?: string;
15
- menuType: 'list' | 'icon' | 'color';
15
+ menuType: 'list' | 'icon' | 'character' | 'color';
16
16
  menuItems: DropdownMenuItem[];
17
17
  menuWidth?: string;
18
+ menuHeight?: string;
18
19
  };
@@ -1,26 +1,3 @@
1
- export type NativeNode = Node;
2
- export declare const NativeNode: {
3
- new (): Node;
4
- prototype: Node;
5
- readonly ELEMENT_NODE: 1;
6
- readonly ATTRIBUTE_NODE: 2;
7
- readonly TEXT_NODE: 3;
8
- readonly CDATA_SECTION_NODE: 4;
9
- readonly ENTITY_REFERENCE_NODE: 5;
10
- readonly ENTITY_NODE: 6;
11
- readonly PROCESSING_INSTRUCTION_NODE: 7;
12
- readonly COMMENT_NODE: 8;
13
- readonly DOCUMENT_NODE: 9;
14
- readonly DOCUMENT_TYPE_NODE: 10;
15
- readonly DOCUMENT_FRAGMENT_NODE: 11;
16
- readonly NOTATION_NODE: 12;
17
- readonly DOCUMENT_POSITION_DISCONNECTED: 1;
18
- readonly DOCUMENT_POSITION_PRECEDING: 2;
19
- readonly DOCUMENT_POSITION_FOLLOWING: 4;
20
- readonly DOCUMENT_POSITION_CONTAINS: 8;
21
- readonly DOCUMENT_POSITION_CONTAINED_BY: 16;
22
- readonly DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC: 32;
23
- };
24
1
  export type NativeRange = Range;
25
2
  export declare const NativeRange: {
26
3
  new (): Range;
@@ -0,0 +1,24 @@
1
+ import type { Editor } from '../editor';
2
+ import { TranslationFunctions } from '../i18n/types';
3
+ import { CommandItem } from '../types/commands';
4
+ import { Nodes } from '../models/nodes';
5
+ import { Range } from '../models/range';
6
+ type CommandsPopupConfig = {
7
+ editor: Editor;
8
+ locale?: TranslationFunctions;
9
+ items?: (string | CommandItem)[];
10
+ };
11
+ export declare class CommandsPopup {
12
+ private editor;
13
+ private items;
14
+ private root;
15
+ private range;
16
+ container: Nodes;
17
+ constructor(config: CommandsPopupConfig);
18
+ private appendButton;
19
+ updatePosition(): void;
20
+ render(): void;
21
+ show(range: Range): void;
22
+ hide(): void;
23
+ }
24
+ export {};
@@ -1,11 +1,10 @@
1
1
  import type { Editor } from '../editor';
2
- import { NativeNode } from '../types/native';
3
2
  import { SelectionState } from '../types/object';
4
3
  import { ToolbarItem } from '../types/toolbar';
5
4
  import { Nodes } from '../models/nodes';
6
5
  type ToolbarPlacement = 'top' | 'bottom';
7
6
  type ToolbarConfig = {
8
- root: string | Nodes | NativeNode;
7
+ root: string | Node | Nodes;
9
8
  items?: (string | ToolbarItem)[];
10
9
  placement?: ToolbarPlacement;
11
10
  };
@@ -0,0 +1 @@
1
+ export declare function fromBase64(value: string): string;
@@ -1,4 +1,3 @@
1
- import { NativeNode } from '../types/native';
2
1
  import { Nodes } from '../models/nodes';
3
2
  import { Box } from '../models/box';
4
- export declare function getBox(boxNode: string | Nodes | NativeNode): Box;
3
+ export declare function getBox(boxNode: string | Node | Nodes): Box;
@@ -3,6 +3,8 @@ export * from './safe-template';
3
3
  export * from './camel-case';
4
4
  export * from './in-string';
5
5
  export * from './encode';
6
+ export * from './to-base64';
7
+ export * from './from-base64';
6
8
  export * from './to-hex';
7
9
  export * from './parse-style';
8
10
  export * from './normalize-value';
@@ -1,3 +1,2 @@
1
- import { NativeNode } from '../types/native';
2
1
  import { Nodes } from '../models/nodes';
3
- export declare function query(content: string | NativeNode | Nodes): Nodes;
2
+ export declare function query(content: string | Node | Nodes): Nodes;
@@ -0,0 +1 @@
1
+ export declare function toBase64(value: string): string;
@@ -1,2 +1 @@
1
- import { NativeNode } from '../types/native';
2
- export declare function toNodeList(content: string | NativeNode, valueType?: 'text' | 'html'): NativeNode[];
1
+ export declare function toNodeList(content: string | Node, valueType?: 'text' | 'html'): Node[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lakelib",
3
- "version": "0.1.15",
3
+ "version": "0.1.17",
4
4
  "description": "Rich text editor based on the browser",
5
5
  "keywords": [
6
6
  "rich text",
@@ -27,53 +27,52 @@
27
27
  "pre-commit": "pnpm sort:package && pnpm lint"
28
28
  },
29
29
  "dependencies": {
30
- "@types/blueimp-md5": "^2.18.2",
31
- "@types/lodash": "^4.17.0",
32
- "blueimp-md5": "^2.19.0",
30
+ "@types/is-hotkey": "^0.1.10",
31
+ "debounce": "^2.1.0",
33
32
  "eventemitter3": "^5.0.1",
34
- "js-base64": "^3.7.7",
35
- "lodash": "^4.17.21",
36
- "photoswipe": "^5.4.3",
37
- "tinykeys": "^2.1.0",
33
+ "fast-deep-equal": "^3.1.3",
34
+ "is-hotkey": "^0.2.0",
35
+ "photoswipe": "^5.4.4",
38
36
  "typesafe-i18n": "^5.26.2"
39
37
  },
40
38
  "devDependencies": {
41
- "@rollup/plugin-commonjs": "^25.0.7",
39
+ "@rollup/plugin-commonjs": "^26.0.1",
42
40
  "@rollup/plugin-json": "^6.1.0",
43
41
  "@rollup/plugin-node-resolve": "^15.2.3",
44
42
  "@rollup/plugin-terser": "^0.4.4",
45
43
  "@rollup/plugin-typescript": "^11.1.6",
46
- "@types/chai": "^4.3.14",
44
+ "@types/chai": "^4.3.16",
47
45
  "@types/mocha": "^10.0.6",
48
46
  "@types/sinon": "^17.0.3",
49
- "@typescript-eslint/eslint-plugin": "^7.7.0",
50
- "@typescript-eslint/parser": "^7.7.0",
47
+ "@typescript-eslint/eslint-plugin": "^7.13.1",
48
+ "@typescript-eslint/parser": "^7.13.1",
49
+ "bundle-phobia-cli": "^0.14.14",
51
50
  "chai": "^4.4.1",
52
51
  "eslint": "^8.57.0",
53
52
  "eslint-config-airbnb-base": "^15.0.0",
54
53
  "eslint-config-prettier": "^9.1.0",
55
54
  "execa": "^8.0.1",
56
55
  "express": "^4.19.2",
56
+ "katex": "^0.16.10",
57
57
  "lake-codemirror": "^2.0.0",
58
58
  "mocha": "^10.4.0",
59
59
  "multer": "1.4.5-lts.1",
60
60
  "npm-run-all": "^4.1.5",
61
- "picocolors": "^1.0.0",
61
+ "picocolors": "^1.0.1",
62
62
  "prompts": "^2.4.2",
63
- "puppeteer": "^22.6.5",
64
- "rimraf": "^5.0.5",
65
- "rollup": "^4.14.3",
63
+ "puppeteer": "^22.11.2",
64
+ "rimraf": "^5.0.7",
65
+ "rollup": "^4.18.0",
66
66
  "rollup-plugin-import-css": "^3.5.0",
67
67
  "rollup-plugin-svg-import": "^3.0.0",
68
- "semver": "^7.6.0",
68
+ "semver": "^7.6.2",
69
69
  "simple-git-hooks": "^2.11.1",
70
- "sinon": "^17.0.1",
70
+ "sinon": "^18.0.0",
71
71
  "sort-package-json": "^2.10.0",
72
- "tslib": "^2.6.2",
72
+ "tslib": "^2.6.3",
73
73
  "typescript": "^5.4.5",
74
74
  "wait-on": "^7.2.0"
75
75
  },
76
- "packageManager": "pnpm@8.15.6",
77
76
  "scripts": {
78
77
  "dev": "npm-run-all --parallel --print-label dev:express dev:rollup",
79
78
  "dev:express": "node ./scripts/start-server.mjs",
@@ -81,6 +80,7 @@
81
80
  "dev:lib": "rollup --watch --config rollup.config.mjs --es",
82
81
  "build": "rimraf ./dist ./lib && rollup --config rollup.config.mjs --iife --es",
83
82
  "i18n": "typesafe-i18n --no-watch",
83
+ "cost": "bundle-phobia debounce eventemitter3 fast-deep-equal photoswipe tinykeys typesafe-i18n",
84
84
  "sort:package": "sort-package-json",
85
85
  "lint": "eslint . --config .eslintrc.cjs --ext \".ts,.js,.cjs,.mjs\"",
86
86
  "test": "node ./scripts/run-tests.mjs",