mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-31 20:22:27 +08:00
refactor(admonitions): convention for constants
This commit is contained in:
parent
2f3106d8cd
commit
2c6df42d51
@ -1,14 +1,14 @@
|
|||||||
import Plugin from "@ckeditor/ckeditor5-core/src/plugin";
|
import Plugin from "@ckeditor/ckeditor5-core/src/plugin";
|
||||||
import Autoformat from "@ckeditor/ckeditor5-autoformat/src/autoformat";
|
import Autoformat from "@ckeditor/ckeditor5-autoformat/src/autoformat";
|
||||||
import blockAutoformatEditing from "@ckeditor/ckeditor5-autoformat/src/blockautoformatediting";
|
import blockAutoformatEditing from "@ckeditor/ckeditor5-autoformat/src/blockautoformatediting";
|
||||||
import { AdmonitionType, admonitionTypes } from "./admonitioncommand";
|
import { AdmonitionType, ADMONITION_TYPES } from "./admonitioncommand";
|
||||||
|
|
||||||
function tryParseAdmonitionType(match: RegExpMatchArray) {
|
function tryParseAdmonitionType(match: RegExpMatchArray) {
|
||||||
if (match.length !== 2) {
|
if (match.length !== 2) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((admonitionTypes as readonly string[]).includes(match[1])) {
|
if ((ADMONITION_TYPES as readonly string[]).includes(match[1])) {
|
||||||
return match[1] as AdmonitionType;
|
return match[1] as AdmonitionType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,9 +17,9 @@ import type { DocumentFragment, Element, Position, Range, Schema, Writer } from
|
|||||||
* @extends module:core/command~Command
|
* @extends module:core/command~Command
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export const admonitionTypes = [ "note", "tip", "important", "caution", "warning" ] as const;
|
export const ADMONITION_TYPES = [ "note", "tip", "important", "caution", "warning" ] as const;
|
||||||
export const defaultAdmonitionType = admonitionTypes[0];
|
export const DEFAULT_ADMONITION_TYPE = ADMONITION_TYPES[0];
|
||||||
export type AdmonitionType = typeof admonitionTypes[number];
|
export type AdmonitionType = typeof ADMONITION_TYPES[number];
|
||||||
|
|
||||||
interface ExecuteOpts {
|
interface ExecuteOpts {
|
||||||
/**
|
/**
|
||||||
|
@ -11,8 +11,7 @@ import { Plugin } from 'ckeditor5/src/core.js';
|
|||||||
import { Enter, type ViewDocumentEnterEvent } from 'ckeditor5/src/enter.js';
|
import { Enter, type ViewDocumentEnterEvent } from 'ckeditor5/src/enter.js';
|
||||||
import { Delete, type ViewDocumentDeleteEvent } from 'ckeditor5/src/typing.js';
|
import { Delete, type ViewDocumentDeleteEvent } from 'ckeditor5/src/typing.js';
|
||||||
|
|
||||||
import AdmonitionCommand, { AdmonitionType, admonitionTypes, defaultAdmonitionType } from './admonitioncommand.js';
|
import AdmonitionCommand, { AdmonitionType, ADMONITION_TYPES, DEFAULT_ADMONITION_TYPE } from './admonitioncommand.js';
|
||||||
import { ADMONITION_TYPES } from './admonitionui.js';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The block quote editing.
|
* The block quote editing.
|
||||||
@ -56,9 +55,9 @@ export default class AdmonitionEditing extends Plugin {
|
|||||||
classes: "admonition",
|
classes: "admonition",
|
||||||
},
|
},
|
||||||
model: (viewElement, { writer }) => {
|
model: (viewElement, { writer }) => {
|
||||||
let type: AdmonitionType = defaultAdmonitionType;
|
let type: AdmonitionType = DEFAULT_ADMONITION_TYPE;
|
||||||
for (const className of viewElement.getClassNames()) {
|
for (const className of viewElement.getClassNames()) {
|
||||||
if (className !== "admonition" && (admonitionTypes as readonly string[]).includes(className)) {
|
if (className !== "admonition" && (ADMONITION_TYPES as readonly string[]).includes(className)) {
|
||||||
type = className as AdmonitionType;
|
type = className as AdmonitionType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user