This repository has been archived by the owner on Apr 6, 2024. It is now read-only.
forked from johannschopplich/kirby-writer-marks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
130 lines (130 loc) · 3.26 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
(function() {
"use strict";
function writerNodes(Vue) {
const thirdParty = window.panel.plugins.thirdParty;
if (thirdParty.__nodesInitialized)
return;
const customNodes = thirdParty.nodes;
if (!customNodes)
return;
const original = Vue.component("k-writer");
Vue.component("k-writer", {
extends: original,
methods: {
createNodes() {
const originalNodes = original.options.methods.createNodes.call(this).filter(({ name }) => !Object.keys(customNodes).includes(name));
const nodes = Object.entries(customNodes).reduce((acc, [key, Constructor]) => {
acc[key] = new Constructor();
return acc;
}, {});
return [...originalNodes, ...this.filterExtensions(nodes, this.nodes)];
}
}
});
thirdParty.__nodesInitialized = true;
}
class Extension {
constructor(options = {}) {
this.options = __spreadValues(__spreadValues({}, this.defaults), options);
}
init() {
return null;
}
bindEditor(editor = null) {
this.editor = editor;
}
get name() {
return null;
}
get type() {
return "extension";
}
get defaults() {
return {};
}
plugins() {
return [];
}
inputRules() {
return [];
}
pasteRules() {
return [];
}
keys() {
return {};
}
}
class Node extends Extension {
constructor(options = {}) {
super(options);
}
get type() {
return "node";
}
get schema() {
return null;
}
commands() {
return {};
}
}
class Quote extends Node {
get button() {
return {
id: this.name,
icon: "quote",
label: window.panel.$t("field.blocks.quote.name"),
name: this.name
};
}
commands({ utils, type }) {
return {
quote: () => utils.setBlockType(type)
};
}
get name() {
return "quote";
}
get schema() {
return {
content: "inline*",
group: "block",
draggable: false,
parseDOM: [
{
tag: "blockquote"
}
],
toDOM: () => ["blockquote", 0]
};
}
}
window.panel.plugin("coralic/kirby-writer-nodes", {
use: [writerNodes],
thirdParty: {
nodes: __spreadProps(__spreadValues({}, window.panel.plugins.thirdParty.nodes || {}), {
quote: Quote
})
}
});
})();