@jackuait/blok 0.1.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.
Files changed (71) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +23 -0
  3. package/dist/blok.mjs +5 -0
  4. package/dist/blok.umd.js +53 -0
  5. package/dist/bundle-6e604287.mjs +340 -0
  6. package/dist/codex-7de6c88e.mjs +15668 -0
  7. package/dist/vendor.LICENSE.txt +545 -0
  8. package/package.json +108 -0
  9. package/types/api/block.d.ts +87 -0
  10. package/types/api/blocks.d.ts +136 -0
  11. package/types/api/caret.d.ts +67 -0
  12. package/types/api/events.d.ts +28 -0
  13. package/types/api/i18n.d.ts +11 -0
  14. package/types/api/index.d.ts +17 -0
  15. package/types/api/inline-toolbar.d.ts +15 -0
  16. package/types/api/listeners.d.ts +32 -0
  17. package/types/api/notifier.d.ts +14 -0
  18. package/types/api/readonly.d.ts +17 -0
  19. package/types/api/sanitizer.d.ts +14 -0
  20. package/types/api/saver.d.ts +13 -0
  21. package/types/api/selection.d.ts +41 -0
  22. package/types/api/styles.d.ts +44 -0
  23. package/types/api/toolbar.d.ts +26 -0
  24. package/types/api/tools.d.ts +11 -0
  25. package/types/api/tooltip.d.ts +30 -0
  26. package/types/api/ui.d.ts +24 -0
  27. package/types/block-tunes/block-tune-data.d.ts +1 -0
  28. package/types/block-tunes/block-tune.d.ts +60 -0
  29. package/types/block-tunes/index.d.ts +1 -0
  30. package/types/configs/conversion-config.ts +26 -0
  31. package/types/configs/editor-config.d.ts +107 -0
  32. package/types/configs/i18n-config.d.ts +16 -0
  33. package/types/configs/i18n-dictionary.d.ts +93 -0
  34. package/types/configs/index.d.ts +7 -0
  35. package/types/configs/log-levels.d.ts +9 -0
  36. package/types/configs/paste-config.d.ts +38 -0
  37. package/types/configs/sanitizer-config.d.ts +43 -0
  38. package/types/data-formats/block-data.d.ts +23 -0
  39. package/types/data-formats/block-id.ts +4 -0
  40. package/types/data-formats/index.d.ts +2 -0
  41. package/types/data-formats/output-data.d.ts +46 -0
  42. package/types/events/block/Base.ts +11 -0
  43. package/types/events/block/BlockAdded.ts +21 -0
  44. package/types/events/block/BlockChanged.ts +21 -0
  45. package/types/events/block/BlockMoved.ts +26 -0
  46. package/types/events/block/BlockRemoved.ts +21 -0
  47. package/types/events/block/index.ts +44 -0
  48. package/types/index.d.ts +191 -0
  49. package/types/tools/adapters/base-tool-adapter.d.ts +76 -0
  50. package/types/tools/adapters/block-tool-adapter.d.ts +78 -0
  51. package/types/tools/adapters/block-tune-adapter.d.ts +14 -0
  52. package/types/tools/adapters/inline-tool-adapter.d.ts +10 -0
  53. package/types/tools/adapters/tool-factory.d.ts +5 -0
  54. package/types/tools/adapters/tool-type.ts +18 -0
  55. package/types/tools/adapters/tools-collection.d.ts +34 -0
  56. package/types/tools/block-tool-data.d.ts +5 -0
  57. package/types/tools/block-tool.d.ts +121 -0
  58. package/types/tools/hook-events.d.ts +23 -0
  59. package/types/tools/index.d.ts +16 -0
  60. package/types/tools/inline-tool.d.ts +37 -0
  61. package/types/tools/menu-config.d.ts +46 -0
  62. package/types/tools/paste-events.d.ts +52 -0
  63. package/types/tools/tool-config.d.ts +4 -0
  64. package/types/tools/tool-settings.d.ts +79 -0
  65. package/types/tools/tool.d.ts +65 -0
  66. package/types/utils/popover/hint.d.ts +29 -0
  67. package/types/utils/popover/index.d.ts +5 -0
  68. package/types/utils/popover/popover-event.ts +15 -0
  69. package/types/utils/popover/popover-item-type.ts +13 -0
  70. package/types/utils/popover/popover-item.d.ts +253 -0
  71. package/types/utils/popover/popover.d.ts +112 -0
@@ -0,0 +1,60 @@
1
+ import {API, BlockAPI, ToolConfig} from '../index';
2
+ import { BlockTuneData } from './block-tune-data';
3
+ import { BaseToolConstructable, MenuConfig } from '../tools';
4
+
5
+ /**
6
+ * Describes BLockTune blueprint
7
+ */
8
+ export interface BlockTune {
9
+ /**
10
+ * Returns BlockTune's UI.
11
+ * Should return either MenuConfig (recommended) (@see https://editorjs.io/menu-config/)
12
+ * or an HTMLElement (UI consistency is not guaranteed)
13
+ */
14
+ render(): HTMLElement | MenuConfig;
15
+
16
+ /**
17
+ * Method called on Tool render. Pass Tool content as an argument.
18
+ *
19
+ * You can wrap Tool's content with any wrapper you want to provide Tune's UI
20
+ *
21
+ * @param {HTMLElement} pluginsContent — Tool's content wrapper
22
+ */
23
+ wrap?(pluginsContent: HTMLElement): HTMLElement;
24
+
25
+ /**
26
+ * Called on Tool's saving. Should return any data Tune needs to save
27
+ *
28
+ * @return {BlockTuneData}
29
+ */
30
+ save?(): BlockTuneData;
31
+ }
32
+
33
+ /**
34
+ * Describes BlockTune class constructor function
35
+ */
36
+ export interface BlockTuneConstructable extends BaseToolConstructable {
37
+
38
+ /**
39
+ * Flag show Tool is Block Tune
40
+ */
41
+ isTune: boolean;
42
+
43
+ /**
44
+ * @constructor
45
+ *
46
+ * @param config - Block Tune config
47
+ */
48
+ new(config: {
49
+ api: API,
50
+ config?: ToolConfig,
51
+ block: BlockAPI,
52
+ data: BlockTuneData,
53
+ }): BlockTune;
54
+
55
+ /**
56
+ * Tune`s prepare method. Can be async
57
+ * @param data
58
+ */
59
+ prepare?(data: { toolName: string; config: ToolConfig }): Promise<void> | void;
60
+ }
@@ -0,0 +1 @@
1
+ export * from './block-tune';
@@ -0,0 +1,26 @@
1
+ import type { BlockToolData, ToolConfig } from '../tools';
2
+
3
+ /**
4
+ * Config allows Tool to specify how it can be converted into/from another Tool
5
+ */
6
+ export interface ConversionConfig {
7
+ /**
8
+ * How to import string to this Tool.
9
+ *
10
+ * Can be a String or Function:
11
+ *
12
+ * 1. String — the key of Tool data object to fill it with imported string on render.
13
+ * 2. Function — method that accepts importing string and composes Tool data to render.
14
+ */
15
+ import?: ((data: string, config: ToolConfig) => BlockToolData) | string;
16
+
17
+ /**
18
+ * How to export this Tool to make other Block.
19
+ *
20
+ * Can be a String or Function:
21
+ *
22
+ * 1. String — which property of saved Tool data should be used as exported string.
23
+ * 2. Function — accepts saved Tool data and create a string to export
24
+ */
25
+ export?: ((data: BlockToolData) => string) | string;
26
+ }
@@ -0,0 +1,107 @@
1
+ import {ToolConstructable, ToolSettings} from '../tools';
2
+ import {API, LogLevels, OutputData} from '../index';
3
+ import {SanitizerConfig} from './sanitizer-config';
4
+ import {I18nConfig} from './i18n-config';
5
+ import { BlockMutationEvent } from '../events/block';
6
+
7
+ export interface EditorConfig {
8
+ /**
9
+ * Element where Editor will be appended
10
+ */
11
+ holder?: string | HTMLElement;
12
+
13
+ /**
14
+ * If true, set caret at the first Block after Editor is ready
15
+ */
16
+ autofocus?: boolean;
17
+
18
+ /**
19
+ * This Tool will be used as default
20
+ * Name should be equal to one of Tool`s keys of passed tools
21
+ * If not specified, Paragraph Tool will be used
22
+ */
23
+ defaultBlock?: string;
24
+
25
+
26
+
27
+ /**
28
+ * First Block placeholder
29
+ */
30
+ placeholder?: string|false;
31
+
32
+ /**
33
+ * Define default sanitizer configuration
34
+ * @see {@link sanitizer}
35
+ */
36
+ sanitizer?: SanitizerConfig;
37
+
38
+ /**
39
+ * If true, toolbar won't be shown
40
+ */
41
+ hideToolbar?: boolean;
42
+
43
+ /**
44
+ * Map of Tools to use
45
+ */
46
+ tools?: {
47
+ [toolName: string]: ToolConstructable|ToolSettings;
48
+ }
49
+
50
+ /**
51
+ * Data to render on Editor start
52
+ */
53
+ data?: OutputData;
54
+
55
+ /**
56
+ * Height of Editor's bottom area that allows to set focus on the last Block
57
+ */
58
+ minHeight?: number;
59
+
60
+ /**
61
+ * Editors log level (how many logs you want to see)
62
+ */
63
+ logLevel?: LogLevels;
64
+
65
+ /**
66
+ * Enable read-only mode
67
+ */
68
+ readOnly?: boolean;
69
+
70
+ /**
71
+ * Internalization config
72
+ */
73
+ i18n?: I18nConfig;
74
+
75
+ /**
76
+ * Fires when Editor is ready to work
77
+ */
78
+ onReady?(): void;
79
+
80
+ /**
81
+ * Fires when something changed in DOM
82
+ * @param api - editor.js api
83
+ * @param event - custom event describing mutation. If several mutations happened at once, they will be batched and you'll get an array of events here.
84
+ */
85
+ onChange?(api: API, event: BlockMutationEvent | BlockMutationEvent[]): void;
86
+
87
+ /**
88
+ * Defines default toolbar for all tools.
89
+ */
90
+ inlineToolbar?: string[]|boolean;
91
+
92
+ /**
93
+ * Common Block Tunes list. Will be added to all the blocks which do not specify their own 'tunes' set
94
+ */
95
+ tunes?: string[];
96
+
97
+ /**
98
+ * Section for style-related settings
99
+ */
100
+ style?: {
101
+ /**
102
+ * A random value to handle Content Security Policy "style-src" policy
103
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/nonce
104
+ */
105
+ nonce?: string;
106
+ }
107
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Available options of i18n config property
3
+ */
4
+ import { I18nDictionary } from './i18n-dictionary';
5
+
6
+ export interface I18nConfig {
7
+ /**
8
+ * Dictionary used for translation
9
+ */
10
+ messages?: I18nDictionary;
11
+
12
+ /**
13
+ * Text direction. If not set, uses ltr
14
+ */
15
+ direction?: 'ltr' | 'rtl';
16
+ }
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Structure of the i18n dictionary
3
+ */
4
+ export interface I18nDictionary {
5
+ /**
6
+ * Section for translation Tool Names: both block and inline tools
7
+ * Example:
8
+ * "toolNames": {
9
+ * "Text": "Параграф",
10
+ * "Heading": "Заголовок",
11
+ * "List": "Список",
12
+ * ...
13
+ * },
14
+ */
15
+ toolNames?: Dictionary;
16
+
17
+ /**
18
+ * Section for passing translations to the external tools classes
19
+ * The first-level keys of this object should be equal of keys ot the 'tools' property of EditorConfig
20
+ * Includes internal tools: "paragraph", "stub"
21
+ *
22
+ * Example:
23
+ * "tools": {
24
+ * "warning": {
25
+ * "Title": "Название",
26
+ * "Message": "Сообщение",
27
+ * },
28
+ * "link": {
29
+ * "Add a link": "Вставьте ссылку"
30
+ * },
31
+ * },
32
+ */
33
+ tools?: Dictionary;
34
+
35
+ /**
36
+ * Section allows to translate Block Tunes
37
+ * The first-level keys of this object should be equal of 'name' ot the 'tools.<toolName>.tunes' property of EditorConfig
38
+ * Including some internal block-tunes: "delete", "moveUp", "moveDown
39
+ *
40
+ * Example:
41
+ * "blockTunes": {
42
+ * "delete": {
43
+ * "Delete": "Удалить"
44
+ * },
45
+ * "moveUp": {
46
+ * "Move up": "Переместить вверх"
47
+ * },
48
+ * "moveDown": {
49
+ * "Move down": "Переместить вниз"
50
+ * }
51
+ * },
52
+ */
53
+ blockTunes?: Dictionary;
54
+
55
+ /**
56
+ * Translation of internal UI components of the editor.js core
57
+ */
58
+ ui?: Dictionary;
59
+ }
60
+
61
+ /**
62
+ * Represent item of the I18nDictionary config
63
+ */
64
+ export interface Dictionary {
65
+ /**
66
+ * The keys of the object can represent two entities:
67
+ * 1. Dictionary key usually is an original string from default locale, like "Convert to"
68
+ * 2. Sub-namespace section, like "toolbar.converter.<...>"
69
+ *
70
+ * Example of 1:
71
+ * toolbox: {
72
+ * "Add": "Добавить",
73
+ * }
74
+ *
75
+ * Example of 2:
76
+ * ui: {
77
+ * toolbar: {
78
+ * toolbox: { <-- Example of 1
79
+ * "Add": "Добавить"
80
+ * }
81
+ * }
82
+ * }
83
+ */
84
+ [key: string]: DictValue;
85
+ }
86
+
87
+ /**
88
+ * The value of the dictionary can be:
89
+ * - other dictionary
90
+ * - result translate string
91
+ */
92
+ export type DictValue = {[key: string]: Dictionary | string} | string;
93
+
@@ -0,0 +1,7 @@
1
+ export * from './editor-config';
2
+ export * from './sanitizer-config';
3
+ export * from './paste-config';
4
+ export * from './conversion-config';
5
+ export * from './log-levels';
6
+ export * from './i18n-config';
7
+ export * from './i18n-dictionary';
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Available log levels
3
+ */
4
+ export enum LogLevels {
5
+ VERBOSE = 'VERBOSE',
6
+ INFO = 'INFO',
7
+ WARN = 'WARN',
8
+ ERROR = 'ERROR',
9
+ }
@@ -0,0 +1,38 @@
1
+ import { SanitizerConfig } from './sanitizer-config';
2
+
3
+ /**
4
+ * Tool onPaste configuration object
5
+ */
6
+ interface PasteConfigSpecified {
7
+ /**
8
+ * Array of tags Tool can substitute.
9
+ *
10
+ * Could also contain a sanitize-config if you need to save some tag's attribute.
11
+ * For example:
12
+ * [
13
+ * {
14
+ * img: { src: true },
15
+ * }
16
+ * ],
17
+ * @type string[]
18
+ */
19
+ tags?: (string | SanitizerConfig)[];
20
+
21
+ /**
22
+ * Object of string patterns Tool can substitute.
23
+ * Key is your internal key and value is RegExp
24
+ *
25
+ * @type {{[key: string]: RegExp}}
26
+ */
27
+ patterns?: {[key: string]: RegExp};
28
+
29
+ /**
30
+ * Object with arrays of extensions and MIME types Tool can substitute
31
+ */
32
+ files?: {extensions?: string[], mimeTypes?: string[]};
33
+ }
34
+
35
+ /**
36
+ * Alias for PasteConfig with false
37
+ */
38
+ export type PasteConfig = PasteConfigSpecified | false;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Sanitizer config of each HTML element
3
+ * @see {@link https://github.com/guardian/html-janitor#options}
4
+ */
5
+ export type TagConfig = boolean | { [attr: string]: boolean | string };
6
+
7
+ export type SanitizerRule = TagConfig | ((el: Element) => TagConfig)
8
+
9
+ export interface SanitizerConfig {
10
+ /**
11
+ * Tag name and params not to be stripped off
12
+ * @see {@link https://github.com/guardian/html-janitor}
13
+ *
14
+ * @example Save P tags
15
+ * p: true
16
+ *
17
+ * @example Save A tags and do not strip HREF attribute
18
+ * a: {
19
+ * href: true
20
+ * }
21
+ *
22
+ * @example Save A tags with TARGET="_blank" attribute
23
+ * a: function (aTag) {
24
+ * return aTag.target === '_black';
25
+ * }
26
+ *
27
+ * @example Save U tags that are not empty
28
+ * u: function(el){
29
+ * return el.textContent !== '';
30
+ * }
31
+ *
32
+ * @example For blockquote with class 'indent' save CLASS and STYLE attributes
33
+ * Otherwise strip all attributes
34
+ * blockquote: function(el) {
35
+ * if (el.classList.contains('indent')) {
36
+ * return { 'class': true, 'style': true };
37
+ * } else {
38
+ * return {};
39
+ * }
40
+ * }
41
+ */
42
+ [key: string]: SanitizerRule;
43
+ }
@@ -0,0 +1,23 @@
1
+ import {BlockToolData} from '../tools';
2
+ import { BlockId } from './block-id';
3
+
4
+ /**
5
+ * Tool's saved data
6
+ */
7
+ export interface SavedData {
8
+ id: BlockId;
9
+ tool: string;
10
+ data: BlockToolData;
11
+ time: number;
12
+ }
13
+
14
+ /**
15
+ * Tool's data after validation
16
+ */
17
+ export interface ValidatedData {
18
+ id?: BlockId;
19
+ tool?: string;
20
+ data?: BlockToolData;
21
+ time?: number;
22
+ isValid: boolean;
23
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Unique identifier of a block
3
+ */
4
+ export type BlockId = string;
@@ -0,0 +1,2 @@
1
+ export * from './block-data';
2
+ export * from './output-data';
@@ -0,0 +1,46 @@
1
+ import {BlockToolData} from '../tools';
2
+ import {BlockTuneData} from '../block-tunes/block-tune-data';
3
+ import { BlockId } from './block-id';
4
+
5
+ /**
6
+ * Output of one Tool
7
+ *
8
+ * @template Type - the string literal describing a tool type
9
+ * @template Data - the structure describing a data object supported by the tool
10
+ */
11
+ export interface OutputBlockData<Type extends string = string, Data extends object = any> {
12
+ /**
13
+ * Unique Id of the block
14
+ */
15
+ id?: BlockId;
16
+ /**
17
+ * Tool type
18
+ */
19
+ type: Type;
20
+ /**
21
+ * Saved Block data
22
+ */
23
+ data: BlockToolData<Data>;
24
+
25
+ /**
26
+ * Block Tunes data
27
+ */
28
+ tunes?: {[name: string]: BlockTuneData};
29
+ }
30
+
31
+ export interface OutputData {
32
+ /**
33
+ * Editor's version
34
+ */
35
+ version?: string;
36
+
37
+ /**
38
+ * Timestamp of saving in milliseconds
39
+ */
40
+ time?: number;
41
+
42
+ /**
43
+ * Saved Blocks
44
+ */
45
+ blocks: OutputBlockData[];
46
+ }
@@ -0,0 +1,11 @@
1
+ import type { BlockAPI } from '../../api';
2
+
3
+ /**
4
+ * Details of CustomEvent fired on block mutation
5
+ */
6
+ export interface BlockMutationEventDetail {
7
+ /**
8
+ * Affected block
9
+ */
10
+ target: BlockAPI;
11
+ }
@@ -0,0 +1,21 @@
1
+ import type { BlockMutationEventDetail } from './Base';
2
+
3
+ /**
4
+ * Type name of CustomEvent related to block added event
5
+ */
6
+ export const BlockAddedMutationType = 'block-added';
7
+
8
+ /**
9
+ * Information about added block
10
+ */
11
+ interface BlockAddedEventDetail extends BlockMutationEventDetail {
12
+ /**
13
+ * Index of added block
14
+ */
15
+ index: number;
16
+ }
17
+
18
+ /**
19
+ * Event will be fired when the new block is added to the editor
20
+ */
21
+ export type BlockAddedEvent = CustomEvent<BlockAddedEventDetail>;
@@ -0,0 +1,21 @@
1
+ import type { BlockMutationEventDetail } from './Base';
2
+
3
+ /**
4
+ * Type name of CustomEvent related to block changed event
5
+ */
6
+ export const BlockChangedMutationType = 'block-changed';
7
+
8
+ /**
9
+ * Information about changed block
10
+ */
11
+ interface BlockChangedEventDetail extends BlockMutationEventDetail {
12
+ /**
13
+ * Index of changed block
14
+ */
15
+ index: number;
16
+ }
17
+
18
+ /**
19
+ * Event will be fired when some block is changed
20
+ */
21
+ export type BlockChangedEvent = CustomEvent<BlockChangedEventDetail>;
@@ -0,0 +1,26 @@
1
+ import type { BlockMutationEventDetail } from './Base';
2
+
3
+ /**
4
+ * Type name of CustomEvent related to block moved event
5
+ */
6
+ export const BlockMovedMutationType = 'block-moved';
7
+
8
+ /**
9
+ * Information about moved block
10
+ */
11
+ interface BlockMovedEventDetail extends BlockMutationEventDetail {
12
+ /**
13
+ * Previous block position
14
+ */
15
+ fromIndex: number;
16
+
17
+ /**
18
+ * New block position
19
+ */
20
+ toIndex: number;
21
+ }
22
+
23
+ /**
24
+ * Event will be fired when some block is moved to another position
25
+ */
26
+ export type BlockMovedEvent = CustomEvent<BlockMovedEventDetail>;
@@ -0,0 +1,21 @@
1
+ import type { BlockMutationEventDetail } from './Base';
2
+
3
+ /**
4
+ * Type name of CustomEvent related to block removed event
5
+ */
6
+ export const BlockRemovedMutationType = 'block-removed';
7
+
8
+ /**
9
+ * Information about removed block
10
+ */
11
+ interface BlockRemovedEventDetail extends BlockMutationEventDetail {
12
+ /**
13
+ * Index of removed block
14
+ */
15
+ index: number;
16
+ }
17
+
18
+ /**
19
+ * Event will be fired when some block is removed
20
+ */
21
+ export type BlockRemovedEvent = CustomEvent<BlockRemovedEventDetail>;
@@ -0,0 +1,44 @@
1
+ import type { BlockAddedEvent, BlockAddedMutationType } from './BlockAdded';
2
+ import type { BlockChangedEvent, BlockChangedMutationType } from './BlockChanged';
3
+ import type { BlockMovedEvent, BlockMovedMutationType } from './BlockMoved';
4
+ import type { BlockRemovedEvent, BlockRemovedMutationType } from './BlockRemoved';
5
+
6
+ /**
7
+ * Map for Custom Events related to block mutation types
8
+ */
9
+ export interface BlockMutationEventMap {
10
+ /**
11
+ * New Block added
12
+ */
13
+ [BlockAddedMutationType]: BlockAddedEvent;
14
+
15
+ /**
16
+ * On Block deletion
17
+ */
18
+ [BlockRemovedMutationType]: BlockRemovedEvent;
19
+
20
+ /**
21
+ * Moving of a Block
22
+ */
23
+ [BlockMovedMutationType]: BlockMovedEvent;
24
+
25
+ /**
26
+ * Any changes inside the Block
27
+ */
28
+ [BlockChangedMutationType]: BlockChangedEvent;
29
+ }
30
+
31
+ /**
32
+ * What kind of modification happened with the Block
33
+ */
34
+ export type BlockMutationType = keyof BlockMutationEventMap;
35
+
36
+ /**
37
+ * Returns a union type of values of passed object
38
+ */
39
+ type ValueOf<T> = T[keyof T];
40
+
41
+ /**
42
+ * CustomEvent describing a change related to a block
43
+ */
44
+ export type BlockMutationEvent = ValueOf<BlockMutationEventMap>;