Skip to content

Commit

Permalink
0.5.16
Browse files Browse the repository at this point in the history
  • Loading branch information
humyfred committed Dec 20, 2021
1 parent e6fc6b8 commit 8d6bde0
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 65 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [0.5.16](https://github.com/Tencent/cherry-markdown/compare/v0.5.15...v0.5.16) (2021-12-20)


### Bug Fixes

* **custom-syntax:** revert get config from customSyntax & fix type error ([e6fc6b8](https://github.com/Tencent/cherry-markdown/commit/e6fc6b8330437c77bf9023579292c88968208b10))

### [0.5.15](https://github.com/Tencent/cherry-markdown/compare/v0.5.14...v0.5.15) (2021-12-12)


Expand Down
2 changes: 1 addition & 1 deletion dist/cherry-markdown.core.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/cherry-markdown.engine.core.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/cherry-markdown.esm.js

Large diffs are not rendered by default.

185 changes: 126 additions & 59 deletions dist/cherry-markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -19322,8 +19322,6 @@
return Editor;
}();

var getPrototypeOf$5 = getPrototypeOf$1;

var $findIndex = arrayIteration.findIndex;


Expand Down Expand Up @@ -21003,6 +21001,14 @@
return NestedError;
}( /*#__PURE__*/_wrapNativeSuper(Error));

/**
* @typedef {import('~types/cherry').CherryOptions} CherryOptions
* @typedef {import('~types/cherry').CherryEngineOptions} CherryEngineOptions
* @typedef {import('~types/cherry').CustomSyntaxRegConfig} CustomSyntaxRegConfig
* @typedef { (SyntaxBase | ParagraphBase) & { Cherry$$CUSTOM: true } } CustomSyntax
* @typedef { (typeof SyntaxBase | typeof ParagraphBase) & { Cherry$$CUSTOM: true } } CustomSyntaxClass
*/

var WARN_DUPLICATED = -1;
var WARN_NOT_A_VALID_HOOK = -2;
/**
Expand All @@ -21023,12 +21029,63 @@
Logger.warn(concat$2(_context3 = "Hook [".concat(objClass.toString(), "] ")).call(_context3, isNaN(index) ? '' : "at index [".concat(index, "] "), "is not a valid hook, and will not take effect."));
}
}
/**
* 是否一个合法的 HookClass
* @param {any} HookClass
* @returns { HookClass is (typeof SyntaxBase | typeof ParagraphBase) }
*/


function isHookValid(HookClass) {
return getPrototypeOf$5(HookClass) === SyntaxBase || getPrototypeOf$5(HookClass) === ParagraphBase;
return isProtoOfSyntaxBase(HookClass) || isProtoOfParagraphBase(HookClass);
}
/** @typedef {import('~types/cherry').CherryOptions} CherryOptions */
/**
* 传入的类是否 SyntaxBase 的子类
* @param {any} value
* @returns { value is typeof SyntaxBase }
*/


function isProtoOfSyntaxBase(value) {
return Object.prototype.isPrototypeOf.call(SyntaxBase, value);
}
/**
* 传入的类是否 ParagraphBase 的子类
* @param {any} value
* @returns { value is typeof ParagraphBase }
*/


function isProtoOfParagraphBase(value) {
return Object.prototype.isPrototypeOf.call(ParagraphBase, value);
}
/**
* 是否一个配置型的自定义语法
* @param {any} value
* @returns { value is CustomSyntaxRegConfig }
*/


function isCustomSyntaxConfig(value) {
var syntaxClass =
/** @type {any} */

/** @type {CustomSyntaxRegConfig} */
value === null || value === void 0 ? void 0 : value.syntaxClass;
return isProtoOfSyntaxBase(syntaxClass) || isProtoOfParagraphBase(syntaxClass);
}
/**
* 是否一个已注册的自定义语法hook类
* @param {any} value
* @returns { value is CustomSyntaxClass }
*/


function isRegisteredCustomSyntaxClass(value) {
return isHookValid(value) &&
/** @type {CustomSyntaxClass} */
(value === null || value === void 0 ? void 0 : value.Cherry$$CUSTOM) === true;
}
/**
* 语法注册中心
*/
Expand All @@ -21043,7 +21100,18 @@
function HookCenter(hooksConfig, editorConfig) {
_classCallCheck(this, HookCenter);

this.hookList = {};
/**
* @property
* @type {Record<import('./SyntaxBase').HookType, SyntaxBase[]>} hookList hook 名称 -> hook 类型的映射
*/
this.hookList =
/** @type {any} */
{};
/**
* @property
* @type {Record<string, { type: import('./SyntaxBase').HookType }>} hookNameList hook 名称 -> hook 类型的映射
*/

this.hookNameList = {};
$expectTarget(hooksConfig, Array);
this.registerInternalHooks(hooksConfig, editorConfig);
Expand Down Expand Up @@ -21075,37 +21143,40 @@
}
/**
* 注册第三方的语法hook
* @param {CherryOptions['engine']['customSyntax']} customHooks 用户传入的配置
* @param {CherryEngineOptions['customSyntax']} customHooks 用户传入的配置
* @param {Partial<CherryOptions>} editorConfig 编辑器配置
*/

}, {
key: "registerCustomHooks",
value: function registerCustomHooks(customHooks, editorConfig) {
var _context4,
_this2 = this;
var _this2 = this;

if (!customHooks || !keys$3(customHooks)) {
if (!customHooks) {
return;
}

forEach$2(_context4 = keys$3(customHooks)).call(_context4, function (CustomHook) {
var paramType = _typeof(customHooks[CustomHook]);
var hookNames = keys$3(customHooks);

forEach$2(hookNames).call(hookNames, function (hookName) {
/** @type {number} */
var result;
/** @type {typeof SyntaxBase} */

var HookClass;
var customHookConfig = {};

if (paramType === 'function') {
HookClass = customHooks[CustomHook];
} else if (paramType === 'object') {
HookClass = customHooks[CustomHook].syntaxClass;
customHookConfig.force = !!customHooks[CustomHook].force;

if (customHooks[CustomHook].before) {
customHookConfig.before = customHooks[CustomHook].before;
} else if (customHooks[CustomHook].after) {
customHookConfig.after = customHooks[CustomHook].after;
var hookClassOrConfig = customHooks[hookName];

if (isProtoOfSyntaxBase(hookClassOrConfig)) {
HookClass = hookClassOrConfig;
} else if (isCustomSyntaxConfig(hookClassOrConfig)) {
HookClass = hookClassOrConfig.syntaxClass;
customHookConfig.force = Boolean(hookClassOrConfig.force);

if (hookClassOrConfig.before) {
customHookConfig.before = hookClassOrConfig.before;
} else if (hookClassOrConfig.after) {
customHookConfig.after = hookClassOrConfig.after;
}
} else {
return;
Expand Down Expand Up @@ -21142,7 +21213,7 @@
*
* @param {((...args: any[]) => any) | typeof SyntaxBase} HookClass
* @param {Partial<CherryOptions>} editorConfig
* @param {Record<string, any>} [customHookConfig]
* @param {Omit<CustomSyntaxRegConfig, 'syntaxClass'>} [customHookConfig]
* @returns
*/

Expand All @@ -21152,17 +21223,18 @@
// filter Configs Here
var externals = editorConfig.externals,
engine = editorConfig.engine;
var syntax = engine.syntax,
customSyntax = engine.customSyntax;
var syntax = engine.syntax;
/** @type {SyntaxBase | CustomSyntax} */

var instance;
/** @type {string} */

var hookName; // 首先校验Hook是否合法

if (!isHookValid(HookClass)) {
// 可能是一个function hook
if (typeof HookClass === 'function') {
var funcHook =
/** @type {((...args: any[]) => any)}*/
HookClass;
var funcHook = HookClass;
instance = funcHook(editorConfig);

if (!instance || !isHookValid(instance.constructor)) {
Expand All @@ -21174,44 +21246,41 @@
return WARN_NOT_A_VALID_HOOK;
}
} else {
hookName =
/** @type {typeof SyntaxBase}*/
HookClass.HOOK_NAME;
var config = syntax[hookName] ? syntax[hookName] : customSyntax[hookName] ? customSyntax[hookName] : {};
instance = new
/** @type {typeof SyntaxBase}*/
HookClass({
hookName = HookClass.HOOK_NAME; // TODO: 需要考虑自定义 hook 配置的传入方式

var config = (syntax === null || syntax === void 0 ? void 0 : syntax[hookName]) || {};
instance = new HookClass({
externals: externals,
config: config,
globalConfig: engine.global
});
} // Skip Internal Hook
} // TODO: 待校验是否需要跳过禁用的自定义 hook
// Skip Disabled Internal Hooks


if (syntax[hookName] === false &&
/** @type {any}*/
HookClass.Cherry$$CUSTOM !== true) {
if (syntax[hookName] === false && !isRegisteredCustomSyntaxClass(HookClass)) {
return;
}
} // 下面处理的都是 CustomSyntax


var hookType = instance.getType();

if (this.hookNameList[hookName]) {
var _context5;
var _context4;

if (!
/** @type {any}*/
HookClass.Cherry$$CUSTOM) {
// 内置 hook 重名
if (!isRegisteredCustomSyntaxClass(HookClass)) {
return WARN_DUPLICATED;
}
} // 自定义 hook 重名且没有开启覆盖的选项


if (!customHookConfig.force) {
return WARN_DUPLICATED;
} // 强制覆盖以前的Hook,所以需要移除


var duplicateHookType = this.hookNameList[hookName].type;
this.hookList[duplicateHookType] = filter$2(_context5 = this.hookList[duplicateHookType]).call(_context5, function (hook) {
this.hookList[duplicateHookType] = filter$2(_context4 = this.hookList[duplicateHookType]).call(_context4, function (hook) {
return hook.getName() !== hookName;
});
}
Expand All @@ -21221,9 +21290,7 @@
};
this.hookList[hookType] = this.hookList[hookType] || []; // 内置Hook直接push到结尾

if (
/** @type {any}*/
HookClass.Cherry$$CUSTOM !== true) {
if (!isRegisteredCustomSyntaxClass(HookClass)) {
this.hookList[hookType].push(instance);
return;
} // 插入自定义Hook
Expand All @@ -21232,33 +21299,33 @@
var insertIndex = -1;

if (customHookConfig.before) {
var _context6;
var _context5;

insertIndex = findIndex$2(_context6 = this.hookList[hookType]).call(_context6, function (hook) {
insertIndex = findIndex$2(_context5 = this.hookList[hookType]).call(_context5, function (hook) {
return hook.getName() === customHookConfig.before;
});

if (insertIndex === -1) {
var _context7;
var _context6;

Logger.warn(concat$2(_context7 = "Cannot find hook named [".concat(customHookConfig.before, "],\n custom hook [")).call(_context7, hookName, "] will append to the end of the hooks."));
Logger.warn(concat$2(_context6 = "Cannot find hook named [".concat(customHookConfig.before, "],\n custom hook [")).call(_context6, hookName, "] will append to the end of the hooks."));
}
} else if (customHookConfig.after) {
var _context8, _context9;
var _context7, _context8;

insertIndex = findIndex$2(_context8 = this.hookList[hookType]).call(_context8, function (hook) {
insertIndex = findIndex$2(_context7 = this.hookList[hookType]).call(_context7, function (hook) {
return hook.getName() === customHookConfig.after;
});
insertIndex === -1 ? Logger.warn(concat$2(_context9 = "Cannot find hook named [".concat(customHookConfig.after, "],\n custom hook [")).call(_context9, hookName, "] will append to the end of the hooks.")) : insertIndex += 1; // 统一处理往前插入的逻辑,所以要插入某Hook之后,索引需要加一
insertIndex === -1 ? Logger.warn(concat$2(_context8 = "Cannot find hook named [".concat(customHookConfig.after, "],\n custom hook [")).call(_context8, hookName, "] will append to the end of the hooks.")) : insertIndex += 1; // 统一处理往前插入的逻辑,所以要插入某Hook之后,索引需要加一
} // 无需插入或目标索引为数组结尾


if (insertIndex < 0 || insertIndex >= this.hookList[hookType].length) {
this.hookList[hookType].push(instance);
} else {
var _context10;
var _context9;

splice$3(_context10 = this.hookList[hookType]).call(_context10, insertIndex, 0, instance);
splice$3(_context9 = this.hookList[hookType]).call(_context9, insertIndex, 0, instance);
} // console.log(this.hookList[hookType]);

}
Expand Down Expand Up @@ -82026,7 +82093,7 @@
});
}

var VERSION = "0.5.15-1e24f127";
var VERSION = "0.5.16-e6fc6b83";
var CherryStatic = /*#__PURE__*/function () {
function CherryStatic() {
_classCallCheck(this, CherryStatic);
Expand Down
2 changes: 1 addition & 1 deletion dist/cherry-markdown.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/cherry-markdown.min.js

Large diffs are not rendered by default.

Binary file modified dist/fonts/ch-icon.eot
Binary file not shown.
Binary file modified dist/fonts/ch-icon.ttf
Binary file not shown.
Binary file modified dist/fonts/ch-icon.woff
Binary file not shown.
Binary file modified dist/fonts/ch-icon.woff2
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cherry-markdown",
"license": "Apache-2.0",
"version": "0.5.15",
"version": "0.5.16",
"description": "a new markdown editor",
"repository": {
"type": "git",
Expand Down

0 comments on commit 8d6bde0

Please sign in to comment.