Skip to content

Commit

Permalink
Convert citation into a keyed plugin (#522)
Browse files Browse the repository at this point in the history
* Convert citation into a keyed plugin

* linting

* linting 2

---------

Co-authored-by: Arne Bertrand <[email protected]>
  • Loading branch information
lagartoverde and abeforgit authored Dec 18, 2024
1 parent 3188ea3 commit 2332962
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/popular-countries-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lblod/ember-rdfa-editor-lblod-plugins': patch
---

Convert citation into a keyed plugin
9 changes: 5 additions & 4 deletions addon/components/citation-plugin/citation-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import {
} from '@lblod/ember-rdfa-editor-lblod-plugins/utils/option';
import {
CitationDecoration,
CitationPlugin,
CitationPluginEmberComponentConfig,
CitationPluginState,
} from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/citation-plugin';
import {
DecorationSet,
PluginKey,
SayController,
Transaction,
} from '@lblod/ember-rdfa-editor';
Expand All @@ -32,10 +33,10 @@ import {
} from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/citation-plugin/utils/legal-documents';
import { cleanCaches } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/citation-plugin/utils/cache';
import { SearchIcon } from '@appuniversum/ember-appuniversum/components/icons/search';
import { citationPluginKey } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/citation-plugin';

interface Args {
controller: SayController;
plugin: CitationPlugin;
config: CitationPluginEmberComponentConfig;
}

Expand Down Expand Up @@ -76,8 +77,8 @@ export default class CitationCardComponent extends Component<Args> {
return !this.controller.inEmbeddedView && this.activeDecoration;
}

get plugin() {
return this.args.plugin;
get plugin(): PluginKey<CitationPluginState> {
return citationPluginKey;
}

get config() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ export default class LegalDocumentDetailComponent extends Component<Args> {
});
this.totalCount = results.totalCount;

console.log({ result: results.articles });

return results.articles;
} catch (e) {
console.warn(e); // eslint-ignore-line no-console
Expand Down
8 changes: 7 additions & 1 deletion addon/plugins/citation-plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ProsePlugin,
ResolvedPos,
Schema,
PluginKey,
} from '@lblod/ember-rdfa-editor';
import processMatch, {
RegexpMatchArrayWithIndices,
Expand Down Expand Up @@ -112,7 +113,7 @@ export interface CitationDecoration extends Decoration {
spec: CitationDecorationSpec;
}

interface CitationPluginState {
export interface CitationPluginState {
highlights: DecorationSet;
activeRanges: [number, number][];
}
Expand Down Expand Up @@ -153,8 +154,13 @@ export type CitationPluginEmberComponentConfig = CitationPluginConfig & {
defaultDecisionsGovernmentName?: string;
};

export const citationPluginKey: PluginKey<CitationPluginState> = new PluginKey(
'say-citation-plugin',
);

export function citationPlugin(config: CitationPluginConfig): CitationPlugin {
const citation: CitationPlugin = new ProsePlugin({
key: citationPluginKey,
state: {
init(stateConfig: EditorStateConfig, state: EditorState) {
return calculateCitationPluginState(state, config);
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion tests/dummy/app/templates/besluit-sample.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@
/>
<CitationPlugin::CitationCard
@controller={{this.controller}}
@plugin={{this.citationPlugin}}
@config={{this.config.citation}}
/>
<ImportSnippetPlugin::Card @controller={{this.controller}} />
Expand Down

0 comments on commit 2332962

Please sign in to comment.