Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read only mode #1035

Merged
merged 107 commits into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from 100 commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
e78b22d
init readonly module
hboylan Feb 12, 2020
e40c591
expose toggleReadOnly method in public api
hboylan Feb 12, 2020
2a32659
alias readonly api on editor
hboylan Feb 13, 2020
b710e5e
include readonly toggle button in dev example
hboylan Feb 13, 2020
d259339
unbind ui events in readonly mode
hboylan Feb 13, 2020
0586a81
switch to setReadOnly method in ui and paste modules
hboylan Feb 13, 2020
cb2622e
reset paste module in readonly mode
hboylan Feb 13, 2020
fac51fd
update internal prepare methods with setReadOnly
hboylan Feb 14, 2020
7b1cffe
destroy mutation observer when read-only enabled
hboylan Feb 14, 2020
f2b4018
rename readonly toggle methods
hboylan Feb 16, 2020
1a4fff1
unbind events
khaydarov Apr 11, 2020
f5e9a66
[Improvements] ESLint action (#1099)
neSpecc Apr 11, 2020
7c726d4
generate id on event listeners
khaydarov Apr 11, 2020
552d090
Merge remote-tracking branch 'origin/release/2.18' into pr/1035
khaydarov Apr 11, 2020
4c0d806
[Refactor] ESLint fixed (#1100)
gohabereg Apr 18, 2020
d42042d
save
khaydarov Apr 20, 2020
1a6f9a1
Merge remote-tracking branch 'origin/release/2.18' into pr/1035
khaydarov Apr 20, 2020
ffa78fd
resolve conflicts
khaydarov Apr 20, 2020
e671a6e
fix event handlers
khaydarov Apr 20, 2020
0680c4d
add read only flag everywhere
khaydarov Apr 20, 2020
21cac86
[Feature] i18n (#1106)
neSpecc Apr 20, 2020
b32b2cb
Merge remote-tracking branch 'origin/release/2.18' into pr/1035
khaydarov Apr 20, 2020
968280a
resolve conflicts
khaydarov Apr 20, 2020
775ccbc
Remove unused submodule
tasuku-s Apr 23, 2020
f4c4051
Fixed: icon centering in Firefox
neSpecc Apr 25, 2020
2997ed0
Do not load styles twice (#1112)
gohabereg Apr 25, 2020
c66105b
ready for testing
khaydarov Apr 25, 2020
4a81699
Show warning if Block to delete is not found (#1111)
gohabereg Apr 25, 2020
7eb642d
Save Tools' order in the Toolbox (#1113)
gohabereg Apr 25, 2020
72213f2
fix $.isEmpty performance (#1096)
tasuku-s Apr 25, 2020
7f876e8
Add issue templates (#1114)
gohabereg Apr 25, 2020
8456da7
requested changes
khaydarov Apr 25, 2020
66e70fa
Update issue templates (#1121)
neSpecc Apr 25, 2020
5941ef0
ready for testing. hurr-ah
khaydarov Apr 25, 2020
9b92e6c
Merge remote-tracking branch 'origin/release/2.18' into pr/1035
khaydarov Apr 25, 2020
77534fe
update changelog
khaydarov Apr 25, 2020
4f6164c
fix copy and cut
khaydarov Apr 25, 2020
5218a6a
Allowing deleting block by block id (#1108)
athul7744 Apr 25, 2020
ae8591c
Allow navigate next from last non-initial block (#1110)
gohabereg Apr 25, 2020
c3ba372
update
khaydarov Apr 26, 2020
f291aa0
Merge branch 'release/2.18' into pr/1035
khaydarov Apr 26, 2020
ec63dcd
update
khaydarov Apr 26, 2020
6edb7bc
fix eslint problems
khaydarov Apr 26, 2020
05766a6
update
khaydarov Apr 26, 2020
65f51c2
fix paste
khaydarov Apr 26, 2020
b90b8c5
update
khaydarov Apr 28, 2020
6e79df6
upgrade
khaydarov Apr 30, 2020
b90532e
update
khaydarov Apr 30, 2020
f6b7b2e
Create CODE_OF_CONDUCT.md (#1171)
talyguryn May 27, 2020
e3410be
Update dependencies (#1122)
gohabereg May 27, 2020
b0ddb10
Feature/disable tab event config (#1164)
flaming-cl May 27, 2020
1eb6d81
Highlight first block on autofocus (#1127)
gohabereg May 27, 2020
5fe8b08
Fix shortcut for external tools (#1141)
sonnn May 27, 2020
7c3bf76
Hotfix/issue1133 selection shortcut removed on editor destroy (#1140)
sis-dk May 27, 2020
ffe5bbc
[Feature] BlockAPI Interface (#1075)
gohabereg May 27, 2020
ff6bd2d
Fix BlockManager.insert method (#1172)
gohabereg Jun 2, 2020
e1500f7
Update tools master branches (#1180)
talyguryn Jun 2, 2020
26b19a3
Fix behaviour of inputs editing in block settings (#1123)
gohabereg Jun 2, 2020
8341c33
Merge branch 'master' into release/2.18
neSpecc Jun 2, 2020
239aaf6
lint code
neSpecc Jun 3, 2020
4cea66f
Update CHANGELOG.md
neSpecc Jun 3, 2020
0e374ab
test commit
khaydarov Jun 4, 2020
7992995
Revert "test commit"
khaydarov Jun 4, 2020
cefe8da
Merge branch 'release/2.18' into pr/1035
khaydarov Jun 4, 2020
9bbf37d
last updates
khaydarov Jun 5, 2020
884baf2
comment
khaydarov Jun 9, 2020
f983a5a
requested changes
khaydarov Jun 9, 2020
d7d8be8
eslint fixes
khaydarov Jun 9, 2020
f07886d
last changes
khaydarov Jul 26, 2020
c82d359
Merge branch 'next' into pr/1035
khaydarov Jul 26, 2020
ea75bf2
small fix
khaydarov Jul 26, 2020
5772c04
fix defect with native selection
khaydarov Jul 26, 2020
96a1780
type magic
khaydarov Jul 26, 2020
22dd508
update
khaydarov Jul 26, 2020
a296077
updates
khaydarov Jul 26, 2020
8f74b37
eslint fixes
khaydarov Jul 26, 2020
4aaddfe
Check tools compatibility on read-only toggle
gohabereg Aug 22, 2020
1a61d3f
Merge branch 'next' of github.com:codex-team/editor.js into pr/1035
gohabereg Aug 22, 2020
a00090a
Update submodules
gohabereg Aug 22, 2020
99d074a
Use Math.floor instead of ~~
gohabereg Aug 23, 2020
014ea48
Merge branch 'next' into pr/1035
neSpecc Aug 26, 2020
f02e49c
upd demo page toggler
neSpecc Aug 26, 2020
93829a0
rm unused styles from example
neSpecc Aug 26, 2020
5921260
add description to generic type
neSpecc Aug 26, 2020
6ec8d06
Saver API: return promise.reject instead of undifined
neSpecc Aug 26, 2020
1af17f0
update
khaydarov Aug 26, 2020
e8efd87
update nodes
khaydarov Aug 26, 2020
edece25
lint fixes
khaydarov Aug 26, 2020
f0b5dc0
save changes
khaydarov Aug 27, 2020
189e7b6
Merge branch 'next' into pr/1035
khaydarov Aug 28, 2020
34a425f
Create editor.js.map
khaydarov Aug 28, 2020
7a3162f
updates
khaydarov Aug 28, 2020
748aa7d
save changes
khaydarov Aug 28, 2020
6977b33
Merge branch 'next' into pr/1035
khaydarov Sep 1, 2020
ef17dbf
Update editor.js.map
khaydarov Sep 1, 2020
a318dff
update
khaydarov Sep 1, 2020
b2865ad
new bundle
khaydarov Sep 1, 2020
15b2794
Update methods call prevention in read-only mode
gohabereg Sep 13, 2020
d04f1ae
Remove API restrictions for read only mode
gohabereg Sep 19, 2020
7f1ffcd
Update CBS event handlerr
gohabereg Sep 21, 2020
efef57f
Merge branch 'next' of github.com:codex-team/editor.js into pr/1035
gohabereg Sep 22, 2020
cd6d263
rm duplicated code
neSpecc Sep 29, 2020
899dd3f
Optimiza isAnyBlockSelected method
gohabereg Sep 29, 2020
59b2688
Update bundle
gohabereg Sep 29, 2020
24ab8f9
Update src/components/modules/blockSelection.ts
neSpecc Sep 29, 2020
d671342
Merge branch 'next' into pr/1035
neSpecc Sep 29, 2020
29945ae
pull next
neSpecc Sep 29, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/editor.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### 2.19

- `New` - Read-only mode 🥳 [#837](https://github.com/codex-team/editor.js/issues/837)
- `New` - RTL mode added [#670](https://github.com/codex-team/editor.js/issues/670)
- `Fix` — Fix problem with types usage [#1183](https://github.com/codex-team/editor.js/issues/1183)
- `Fix` - Fixed issue with Spam clicking the "Click to tune" button duplicates the icons on FireFox. [#1273](https://github.com/codex-team/editor.js/issues/1273)
Expand Down Expand Up @@ -40,7 +41,6 @@

> *Breaking changes* `blocks.getBlockByIndex` method now returns BlockAPI object. To access old value, use BlockAPI.holder property


### 2.17

- `Improvements` - Editor's [onchange callback](https://editorjs.io/configuration#editor-modifications-callback) now accepts an API as a parameter
Expand Down
25 changes: 25 additions & 0 deletions example/assets/demo.css
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,31 @@ body {
text-decoration: none;
}

.ce-example__statusbar {
position: fixed;
bottom: 10px;
right: 10px;
background: #fff;
border-radius: 8px;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
font-size: 12px;
padding: 8px 15px;
}

.ce-example__statusbar-button {
display: inline-flex;
margin-left: 10px;
background: #4A9DF8;
padding: 6px 12px;
box-shadow: 0 7px 8px -4px rgba(137, 207, 255, 0.77);
transition: all 150ms ease;
cursor: pointer;
border-radius: 31px;
color: #fff;
font-family: 'PT Mono', Menlo, Monaco, Consolas, Courier New, monospace;
text-align: center;
}

@media all and (max-width: 730px){
.ce-example__header,
.ce-example__content{
Expand Down
48 changes: 40 additions & 8 deletions example/example-dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@
<div class="ce-example__button" id="saveButton">
editor.save()
</div>
<div class="ce-example__statusbar">
Readonly:
<b id="readonly-state">
Off
</b>
<div class="ce-example__statusbar-button" id="toggleReadOnlyButton">
toggle
</div>
</div>
</div>
<div class="ce-example__output">
<pre class="ce-example__output-content" id="output"></pre>
Expand Down Expand Up @@ -74,16 +83,16 @@

<!-- Initialization -->
<script>
/**
* Saving button
*/
const saveButton = document.getElementById('saveButton');

/**
* To initialize the Editor, create a new instance with configuration object
* @see docs/installation.md for mode details
*/
var editor = new EditorJS({
/**
* Enable/Disable the read only mode
*/
readOnly: false,

/**
* Wrapper of Editor
*/
Expand Down Expand Up @@ -279,14 +288,37 @@
},
});

/**
* Saving button
*/
const saveButton = document.getElementById('saveButton');

/**
* Toggle read-only button
*/
const toggleReadOnlyButton = document.getElementById('toggleReadOnlyButton');
const readOnlyIndicator = document.getElementById('readonly-state');

/**
* Saving example
*/
saveButton.addEventListener('click', function () {
editor.save().then((savedData) => {
cPreview.show(savedData, document.getElementById("output"));
});
editor.save()
.then((savedData) => {
cPreview.show(savedData, document.getElementById("output"));
})
.catch((error) => {
console.error('Saving error', error);
});
});

/**
* Toggle read-only example
*/
toggleReadOnlyButton.addEventListener('click', async () => {
const readOnlyState = await editor.readOnly.toggle();

readOnlyIndicator.textContent = readOnlyState ? 'On' : 'Off';
});
</script>
</body>
Expand Down
2 changes: 1 addition & 1 deletion example/tools/checklist
Submodule checklist updated 3 files
+1 −1 dist/bundle.js
+1 −1 package.json
+55 −22 src/index.js
2 changes: 1 addition & 1 deletion example/tools/code
Submodule code updated 3 files
+1 −1 dist/bundle.js
+1 −1 package.json
+17 −1 src/index.js
2 changes: 1 addition & 1 deletion example/tools/delimiter
2 changes: 1 addition & 1 deletion example/tools/embed
Submodule embed updated 4 files
+1 −1 dist/bundle.js
+1 −1 package.json
+53 −37 src/index.js
+12 −220 yarn.lock
2 changes: 1 addition & 1 deletion example/tools/header
Submodule header updated 3 files
+2 −2 dist/bundle.js
+1 −1 package.json
+14 −2 src/index.js
2 changes: 1 addition & 1 deletion example/tools/image
Submodule image updated 4 files
+2 −2 dist/bundle.js
+1 −1 package.json
+13 −1 src/index.js
+4 −2 src/ui.js
2 changes: 1 addition & 1 deletion example/tools/link
Submodule link updated 3 files
+1 −1 dist/bundle.js
+1 −1 package.json
+76 −46 src/index.js
2 changes: 1 addition & 1 deletion example/tools/list
Submodule list updated from 497c04 to 439e5f
2 changes: 1 addition & 1 deletion example/tools/quote
Submodule quote updated 3 files
+1 −1 dist/bundle.js
+1 −1 package.json
+43 −29 src/index.js
2 changes: 1 addition & 1 deletion example/tools/raw
Submodule raw updated 3 files
+1 −1 dist/bundle.js
+1 −1 package.json
+39 −16 src/index.js
2 changes: 1 addition & 1 deletion example/tools/simple-image
2 changes: 1 addition & 1 deletion example/tools/table
2 changes: 1 addition & 1 deletion example/tools/warning
Submodule warning updated 3 files
+1 −1 dist/bundle.js
+1 −1 package.json
+44 −33 src/index.js
71 changes: 70 additions & 1 deletion src/components/__module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import { EditorModules } from '../types-internal/editor-modules';
import { EditorConfig } from '../../types';
import { ModuleConfig } from '../types-internal/module-config';

/**
* The type <T> of the Module generic.
* It describes the structure of nodes used in modules.
*/
export type ModuleNodes = object;

/**
* @abstract
* @class Module
Expand All @@ -11,7 +17,13 @@ import { ModuleConfig } from '../types-internal/module-config';
* @property {object} config - Editor user settings
* @property {EditorModules} Editor - List of Editor modules
*/
export default class Module {
export default class Module<T extends ModuleNodes = {}> {
/**
* Each module can provide some UI elements that will be stored in this property
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public nodes: T = {} as any;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without any I got the following

image


/**
* Editor modules list
*
Expand All @@ -26,6 +38,50 @@ export default class Module {
*/
protected config: EditorConfig;

/**
* This object provides methods to push into set of listeners that being dropped when read-only mode is enabled
*/
protected readOnlyMutableListeners = {
/**
* Assigns event listener on DOM element and pushes into special array that might be removed
*
* @param {EventTarget} element - DOM Element
* @param {string} eventType - Event name
* @param {Function} handler - Event handler
* @param {boolean|AddEventListenerOptions} options - Listening options
*/
on: (
neSpecc marked this conversation as resolved.
Show resolved Hide resolved
element: EventTarget,
eventType: string,
handler: (event: Event) => void,
options: boolean | AddEventListenerOptions = false
): void => {
neSpecc marked this conversation as resolved.
Show resolved Hide resolved
const { Listeners } = this.Editor;

this.mutableListenerIds.push(
Listeners.on(element, eventType, handler, options)
);
},

/**
* Clears all mutable listeners
*/
clearAll: (): void => {
khaydarov marked this conversation as resolved.
Show resolved Hide resolved
const { Listeners } = this.Editor;

for (const id of this.mutableListenerIds) {
Listeners.offById(id);
}

this.mutableListenerIds = [];
},
};

/**
* The set of listener identifiers which will be dropped in read-only mode
*/
private mutableListenerIds: string[] = [];

/**
* @class
* @param {EditorConfig} config - Editor's config
Expand All @@ -47,6 +103,19 @@ export default class Module {
this.Editor = Editor;
}

/**
* Remove memorized nodes
*/
public removeAllNodes(): void {
for (const key in this.nodes) {
const node = this.nodes[key];

if (node instanceof HTMLElement) {
node.remove();
khaydarov marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

/**
* Returns true if current direction is RTL (Right-To-Left)
*/
Expand Down
2 changes: 1 addition & 1 deletion src/components/block-tunes/block-tune-move-up.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export default class MoveUpTune implements BlockTune {
const currentBlock = this.api.blocks.getBlockByIndex(currentBlockIndex);
const previousBlock = this.api.blocks.getBlockByIndex(currentBlockIndex - 1);

if (!currentBlock || !previousBlock){
if (!currentBlock || !previousBlock) {
return;
}

Expand Down
4 changes: 3 additions & 1 deletion src/components/block/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import { BlockAPI as BlockAPIInterface } from '../../../types/api';
*
* @param {Block} block - Block to expose
*/
function BlockAPI(block: Block): void {
function BlockAPI(
block: Block
): void {
const blockAPI: BlockAPIInterface = {
/**
* Tool name
Expand Down
16 changes: 12 additions & 4 deletions src/components/block/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import { SavedData } from '../../../types/data-formats';
import $ from '../dom';
import * as _ from '../utils';
import ApiModule from '../modules/api';
import ApiModules from '../modules/api';
import BlockAPI from './api';
import { ToolType } from '../modules/tools';

Expand Down Expand Up @@ -49,7 +49,12 @@ interface BlockConstructorOptions {
/**
* Editor's API methods
*/
api: ApiModule;
api: ApiModules;

/**
* This flag indicates that the Block should be constructed in the read-only mode.
*/
readOnly: boolean;
}

/**
Expand Down Expand Up @@ -146,7 +151,7 @@ export default class Block {
/**
* Editor`s API module
*/
private readonly api: ApiModule;
private readonly api: ApiModules;

/**
* Focused input index
Expand Down Expand Up @@ -197,14 +202,16 @@ export default class Block {
* @param {BlockToolData} options.data - Tool's initial data
* @param {BlockToolConstructable} options.Tool — Tool's class
* @param {ToolSettings} options.settings - default tool's config
* @param {ApiModule} options.api - Editor API module for pass it to the Block Tunes
* @param {Module} options.api - Editor API module for pass it to the Block Tunes
* @param {boolean} options.readOnly - Read-Only flag
*/
constructor({
name,
data,
Tool,
settings,
api,
readOnly,
}: BlockConstructorOptions) {
this.name = name;
this.class = Tool;
Expand All @@ -220,6 +227,7 @@ export default class Block {
config: this.config,
api: this.api.getMethodsForTool(name, ToolType.Block),
block: this.blockAPI,
readOnly: readOnly,
});

this.holder = this.compose();
Expand Down
Loading