Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .changeset/quick-shrimps-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lblod/ember-rdfa-editor': minor
---

Add option to configure editor as non-editable
8 changes: 8 additions & 0 deletions addon/components/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface RdfaEditorArgs {
};
defaultAttrGenerators?: DefaultAttrGenPuginOptions;
keyMapOptions?: KeymapOptions;
editable?: boolean;
}

/**
Expand Down Expand Up @@ -70,6 +71,10 @@ export default class RdfaEditor extends Component<RdfaEditorArgs> {
return this.args.baseIRI || window.document.baseURI;
}

get editable() {
return this.args.editable;
}

/**
* Handle init of rawEditor
*
Expand Down Expand Up @@ -111,6 +116,9 @@ export default class RdfaEditor extends Component<RdfaEditorArgs> {
nodeViews: this.args.nodeViews,
defaultAttrGenerators: this.args.defaultAttrGenerators,
keyMapOptions: this.args.keyMapOptions,
editable: () => {
return !(this.editable === false);
Copy link
Contributor

Choose a reason for hiding this comment

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

you can do !!this.editable I think

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not in this case I think, as we do not want to trigger it when editable is undefined or null, this is why we strictly compare it to false.

},
});
window.__PM = this.prosemirror;
window.__PC = new SayController(this.prosemirror);
Expand Down
3 changes: 3 additions & 0 deletions addon/components/ember-node/embedded-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ export default class EmbeddedEditor extends Component<Args> {
this.contentWrapper,
{
decorations: () => this.args.contentDecorations,
editable: () => {
return this.outerView.editable;
},
state: EditorState.create({
doc: this.node,
plugins: [keymap(this.keymap), ...this.plugins],
Expand Down
12 changes: 12 additions & 0 deletions addon/core/say-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ export default class SayController {
return this.mainEditorView.domParser;
}

get editable() {
return this.mainEditorView.editable;
}

setEditable(editable: boolean) {
this.mainEditorView.setProps({
editable: () => {
return editable;
},
});
}

clone() {
return new SayController(this.editor);
}
Expand Down
3 changes: 3 additions & 0 deletions addon/core/say-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ interface SayEditorArgs {
controller: SayController,
) => Record<string, NodeViewConstructor>;
defaultAttrGenerators?: DefaultAttrGenPuginOptions;
editable?: SayView['props']['editable'];
}

export default class SayEditor {
Expand Down Expand Up @@ -87,6 +88,7 @@ export default class SayEditor {
},
defaultAttrGenerators = [],
keyMapOptions,
editable,
}: SayEditorArgs & { keyMapOptions?: KeymapOptions }) {
this.logger = createLogger(this.constructor.name);
this.owner = owner;
Expand Down Expand Up @@ -148,6 +150,7 @@ export default class SayEditor {
state,
attributes: { class: 'say-editor__inner say-content' },
nodeViews: nodeViews(new SayController(this)),
editable,
dispatchTransaction: (tr) => {
const newState = this.mainView.state.apply(tr);
this.mainView.updateState(newState);
Expand Down
Binary file modified e2e/__screenshots__/list.spec.ts/ordered-list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified e2e/__screenshots__/list.spec.ts/unordered-list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions tests/dummy/app/controllers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import { headingWithConfig } from '@lblod/ember-rdfa-editor/plugins/heading/node

export default class IndexController extends Controller {
@tracked rdfaEditor?: SayController;
@tracked editable = true;
@service declare intl: IntlService;
schema = new Schema({
nodes: {
Expand Down Expand Up @@ -126,6 +127,10 @@ export default class IndexController extends Controller {
};
}

toggleEditable = () => {
this.editable = !this.editable;
};

@tracked plugins: PluginConfig = [
listTrackingPlugin(),
firefoxCursorFix(),
Expand Down
2 changes: 2 additions & 0 deletions tests/dummy/app/templates/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<DummyContainer>
<:header>
<DebugTools @controller={{this.rdfaEditor}} />
<button type='button' {{on 'click' this.toggleEditable}}>Toggle editable</button>
</:header>
<:content>
<EditorContainer
Expand All @@ -27,6 +28,7 @@
@schema={{this.schema}}
@nodeViews={{this.nodeViews}}
@rdfaEditorInit={{this.rdfaEditorInit}}
@editable={{this.editable}}
/>
{{#if this.rdfaEditor}}
<Plugins::Table::TableTooltip @controller={{this.rdfaEditor}} />
Expand Down