Skip to content

Commit 29dcb2f

Browse files
committed
Plumbing for enrichments
1 parent ca2781b commit 29dcb2f

File tree

12 files changed

+1496
-53
lines changed

12 files changed

+1496
-53
lines changed

indigo_app/js/compat-imports.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* These are imports from local libraries that must be compiled using browserify and then injected
3+
* into the window global for Indigo to use them.
4+
*
5+
* This provides a bridge between Indigo's lack of any support for require() or 'import', and require-js and
6+
* ES6-style imports.
7+
*/
8+
9+
import * as enrichments from './enrichments/popups';
10+
window.enrichments = enrichments;

indigo_app/js/enrichments/popups.ts

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { IEnrichment, IEnrichmentProvider } from '@laws-africa/indigo-akn/src/enrichments/popups';
2+
import { Instance as Tippy } from 'tippy.js';
3+
4+
class LinterEnrichment implements IEnrichment {
5+
public issue: any;
6+
public target: object;
7+
8+
constructor (issue: any, target: any) {
9+
this.issue = issue;
10+
this.target = target;
11+
}
12+
}
13+
14+
export class PopupIssuesProvider implements IEnrichmentProvider {
15+
private issues: any;
16+
17+
constructor (issues: any) {
18+
this.issues = issues;
19+
}
20+
21+
getEnrichments(): IEnrichment[] {
22+
return [new LinterEnrichment({
23+
message: 'hi',
24+
}, {
25+
anchor_id: 'sec_1_2__p_1',
26+
selectors: [{
27+
type: 'TextPositionSelector',
28+
start: 0,
29+
end: 4,
30+
}]
31+
})];
32+
33+
// convert issues into enrichments
34+
return this.issues.map((issue: any) => {
35+
return new LinterEnrichment(issue, {
36+
anchor_id: 'sec_1_2__p_1',
37+
selectors: [{
38+
type: 'TextPositionSelector',
39+
start: 0,
40+
end: 4,
41+
}]
42+
});
43+
});
44+
}
45+
46+
getPopupContent(enrichment: IEnrichment, mark: Element): Element {
47+
const issue = enrichment as LinterEnrichment;
48+
const div = window.document.createElement('div');
49+
div.innerText = issue.issue.message;
50+
return div;
51+
}
52+
53+
markCreated(enrichment: IEnrichment, mark: Element): void {
54+
mark.classList.add('enrichment--warning');
55+
}
56+
57+
markDestroyed(enrichment: IEnrichment, mark: Element): void {
58+
}
59+
60+
popupCreated(popup: Tippy): void {
61+
}
62+
}

indigo_app/js/indigo.js

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as vueComponents from './components';
22
import '@laws-africa/web-components/dist/components/la-akoma-ntoso';
33
import '@laws-africa/web-components/dist/components/la-gutter';
44
import '@laws-africa/web-components/dist/components/la-gutter-item';
5+
import './compat-imports';
56

67
import Vue from 'vue';
78

indigo_app/static/javascript/indigo-app.js

+25-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

indigo_app/static/javascript/indigo/views/document.js

+9
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,15 @@
196196
editorView: this.bodyEditorView,
197197
});
198198

199+
// TODO: imported from indigo akn
200+
const akn = this.el.querySelector('.document-workspace-content la-akoma-ntoso');
201+
this.popupManager = new window.indigoAkn.PopupEnrichmentManager(akn);
202+
this.listenTo(this.bodyEditorView.sourceEditor, 'rendered', () => {
203+
this.popupManager.render();
204+
});
205+
// TODO: created locally in TS
206+
this.popupManager.addProvider(new window.enrichments.PopupIssuesProvider(this.document.issues));
207+
199208
// pretend we've fetched it, this sets up additional handlers
200209
this.document.trigger('sync');
201210

indigo_app/static/lib/external-imports.js

+1,147-42
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.enrichment {
2+
&.enrichment--popup {
3+
background-color: transparent;
4+
5+
&.enrichment--warning {
6+
border-bottom: 3px double purple;
7+
}
8+
}
9+
}

indigo_app/static/stylesheets/app.scss

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ $fa-font-path: '../lib/fontawesome-5.2/webfonts';
2727
@import 'attachments';
2828
@import 'badges';
2929
@import 'documents';
30+
@import 'enrichments';
3031
@import 'diffs';
3132
@import 'forms';
3233
@import 'gutter';

0 commit comments

Comments
 (0)