@fastkit/vui 0.7.61 → 0.7.64

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/dist/tool/index.js +1 -0
  2. package/dist/tool/vite-plugin.d.ts.map +1 -1
  3. package/dist/vui.cjs.js +437 -228
  4. package/dist/vui.cjs.prod.js +437 -228
  5. package/dist/vui.css +166 -12
  6. package/dist/vui.d.ts +101 -54
  7. package/dist/vui.min.css +1 -1
  8. package/dist/vui.min.css.map +1 -1
  9. package/dist/vui.mjs +431 -225
  10. package/package.json +7 -6
  11. package/src/components/VButton/VButtonGroup.scss +4 -0
  12. package/src/components/VButton/VButtonGroup.tsx +12 -1
  13. package/src/components/VWysiwygEditor/VWysiwygEditor.scss +4 -0
  14. package/src/components/VWysiwygEditor/VWysiwygEditor.tsx +19 -9
  15. package/src/components/VWysiwygEditor/extensions/.DS_Store +0 -0
  16. package/src/components/VWysiwygEditor/extensions/color.ts +72 -0
  17. package/src/components/VWysiwygEditor/extensions/index.ts +1 -0
  18. package/src/components/VWysiwygEditor/extensions/linter/.DS_Store +0 -0
  19. package/src/components/VWysiwygEditor/extensions/linter/Linter.scss +80 -15
  20. package/src/components/VWysiwygEditor/extensions/linter/Linter.tsx +210 -0
  21. package/src/components/VWysiwygEditor/extensions/linter/LinterPlugin.ts +29 -11
  22. package/src/components/VWysiwygEditor/extensions/linter/index.ts +3 -3
  23. package/src/components/VWysiwygEditor/extensions/linter/plugins/BadWords.tsx +50 -0
  24. package/src/components/VWysiwygEditor/extensions/linter/plugins/HeadingLevel.ts +9 -3
  25. package/src/components/VWysiwygEditor/extensions/linter/plugins/Punctuation.ts +9 -3
  26. package/src/components/VWysiwygEditor/extensions/linter/plugins/index.ts +3 -3
  27. package/src/components/VWysiwygEditor/extensions/linter/utils.ts +28 -0
  28. package/src/components/VWysiwygEditor/schemes.ts +87 -5
  29. package/src/components/VWysiwygEditor/tools/color.scss +140 -0
  30. package/src/components/VWysiwygEditor/tools/color.tsx +90 -0
  31. package/src/components/VWysiwygEditor/tools/index.ts +1 -1
  32. package/src/service.tsx +5 -0
  33. package/src/tool/vite-plugin.ts +1 -0
  34. package/src/components/VWysiwygEditor/extensions/linter/Linter.ts +0 -262
  35. package/src/components/VWysiwygEditor/extensions/linter/plugins/BadWords.ts +0 -34
  36. package/src/components/VWysiwygEditor/tools/text-color.ts +0 -14
@@ -1,262 +0,0 @@
1
- import './Linter.scss';
2
-
3
- import { Extension } from '@tiptap/core';
4
- import { Decoration, DecorationSet } from 'prosemirror-view';
5
- import { Plugin, PluginKey, TextSelection } from 'prosemirror-state';
6
- import { Node as ProsemirrorNode } from 'prosemirror-model';
7
- import { LinterPlugin, LinterResult as Issue } from './LinterPlugin';
8
- import { debounce } from '@fastkit/helpers';
9
- import { EditorView } from 'prosemirror-view';
10
-
11
- const PROBLEM_CLASS_NAME = 'v-linter__problem';
12
- const ISSUE_ICON_CLASS_NAME = 'v-linter__issue-icon';
13
- const ISSUE_MENU_CLASS_NAME = 'v-linter__issue-menu';
14
-
15
- interface IssueElement extends HTMLDivElement {
16
- issue?: Issue;
17
- }
18
-
19
- function renderIcon(view: EditorView<any>, issue: Issue) {
20
- const { level = 'warning' } = issue;
21
- const icon: IssueElement = document.createElement('div');
22
-
23
- icon.className = `${ISSUE_ICON_CLASS_NAME} ${level}-scope`;
24
- icon.title = issue.message;
25
- icon.issue = issue;
26
-
27
- return icon;
28
- }
29
-
30
- function renderMenu(view: EditorView<any>, issue: Issue) {
31
- const menuWrapper = document.createElement('div');
32
- menuWrapper.className = 'v-linter__issue-menu-wrapper';
33
- const menu: IssueElement = document.createElement('div');
34
-
35
- menu.className = `${ISSUE_MENU_CLASS_NAME} elevation-3`;
36
- menu.innerText = issue.message;
37
-
38
- const { fix, fixMessage } = issue;
39
-
40
- if (fix && fixMessage) {
41
- const $fix = document.createElement('button');
42
- $fix.type = 'button';
43
- $fix.innerHTML = fixMessage;
44
- $fix.addEventListener('click', () => {
45
- fix(view, issue);
46
- });
47
- $fix.className = `v-linter__issue-menu__fix`;
48
- menu.appendChild($fix);
49
- }
50
-
51
- menu.issue = issue;
52
-
53
- menuWrapper.appendChild(menu);
54
- return menuWrapper;
55
- }
56
-
57
- function getIssueElement(
58
- source: HTMLElement | EventTarget | null,
59
- className: string,
60
- ): IssueElement | undefined {
61
- if (!source || !(source instanceof HTMLElement)) {
62
- return;
63
- }
64
- if (source.classList.contains(className)) {
65
- return source as IssueElement;
66
- }
67
- const el = source.closest(`.${className}`);
68
- if (el) {
69
- return el as IssueElement;
70
- }
71
- }
72
-
73
- function getIconElement(
74
- source: HTMLElement | EventTarget | null,
75
- ): IssueElement | undefined {
76
- return getIssueElement(source, ISSUE_ICON_CLASS_NAME);
77
- }
78
-
79
- function getMenuElement(
80
- source: HTMLElement | EventTarget | null,
81
- ): IssueElement | undefined {
82
- return getIssueElement(source, ISSUE_MENU_CLASS_NAME);
83
- }
84
-
85
- function getProblemElement(
86
- source: HTMLElement | EventTarget | null,
87
- ): IssueElement | undefined {
88
- return getIssueElement(source, PROBLEM_CLASS_NAME);
89
- }
90
-
91
- function runAllLinterPlugins(
92
- doc: ProsemirrorNode,
93
- plugins: Array<typeof LinterPlugin>,
94
- ) {
95
- const decorations: [any?] = [];
96
-
97
- const results = plugins
98
- .map((RegisteredLinterPlugin) => {
99
- return new RegisteredLinterPlugin(doc).scan().getResults();
100
- })
101
- .flat();
102
-
103
- results.forEach((issue) => {
104
- const { level = 'warning' } = issue;
105
- decorations.push(
106
- Decoration.inline(issue.from, issue.to, {
107
- class: `${PROBLEM_CLASS_NAME} ${level}-scope`,
108
- 'data-issue': JSON.stringify(issue),
109
- title: issue.message,
110
- }),
111
- Decoration.widget(issue.from, (view) => renderIcon(view, issue)),
112
- Decoration.widget(issue.from, (view) => renderMenu(view, issue)),
113
- );
114
- });
115
-
116
- return DecorationSet.create(doc, decorations);
117
- }
118
-
119
- export interface LinterOptions {
120
- plugins: Array<typeof LinterPlugin>;
121
- }
122
-
123
- function updateMenusPosition(editorElement: Element) {
124
- const { left, right } = editorElement.getBoundingClientRect();
125
- const menus = Array.from(
126
- editorElement.querySelectorAll(`.${ISSUE_MENU_CLASS_NAME}`),
127
- );
128
- menus.forEach((menu) => {
129
- const { left: menuLeft, right: menuRight } = menu.getBoundingClientRect();
130
- const overflow = menuRight - right;
131
- let offset = 0;
132
- if (overflow > 0) {
133
- offset = -overflow;
134
-
135
- if (menuLeft + offset < left) {
136
- offset = 0;
137
- }
138
- }
139
- (menu as HTMLElement).style.transform = `translateX(${offset}px)`;
140
- });
141
- }
142
-
143
- const debouncedUpdateMenusPosition = debounce(updateMenusPosition, 250);
144
-
145
- export const Linter = Extension.create<LinterOptions>({
146
- name: 'linter',
147
-
148
- addOptions() {
149
- return {
150
- plugins: [],
151
- };
152
- },
153
-
154
- onCreate() {
155
- const { dom } = this.editor.view;
156
- debouncedUpdateMenusPosition(dom);
157
- },
158
-
159
- onUpdate() {
160
- const { dom } = this.editor.view;
161
- debouncedUpdateMenusPosition(dom);
162
- },
163
-
164
- addProseMirrorPlugins() {
165
- const { plugins } = this.options;
166
-
167
- return [
168
- new Plugin({
169
- key: new PluginKey('linter'),
170
- state: {
171
- init(_, { doc }) {
172
- return runAllLinterPlugins(doc, plugins);
173
- },
174
- apply(transaction, oldState) {
175
- return transaction.docChanged
176
- ? runAllLinterPlugins(transaction.doc, plugins)
177
- : oldState;
178
- },
179
- },
180
- props: {
181
- decorations(state) {
182
- return this.getState(state);
183
- },
184
- handleClick(view, _, event) {
185
- const activeMenus = Array.from(
186
- view.dom.querySelectorAll(`.${ISSUE_MENU_CLASS_NAME}--active`),
187
- );
188
-
189
- activeMenus.forEach((menu) =>
190
- menu.classList.remove(`${ISSUE_MENU_CLASS_NAME}--active`),
191
- );
192
-
193
- const problem = getProblemElement(event.target);
194
-
195
- const issueString = problem && problem.dataset['issue'];
196
-
197
- const issue = issueString && JSON.parse(issueString);
198
- if (issue) {
199
- const menuWrapper = problem.previousElementSibling;
200
- const menu =
201
- menuWrapper &&
202
- menuWrapper.querySelector(`.${ISSUE_MENU_CLASS_NAME}`);
203
- menu && menu.classList.add(`${ISSUE_MENU_CLASS_NAME}--active`);
204
-
205
- const { from, to } = issue;
206
- view.dispatch(
207
- view.state.tr
208
- .setSelection(TextSelection.create(view.state.doc, from, to))
209
- .scrollIntoView(),
210
- );
211
-
212
- return true;
213
- }
214
-
215
- const menu = getMenuElement(event.target);
216
-
217
- if (menu) {
218
- menu.classList.add(`${ISSUE_MENU_CLASS_NAME}--active`);
219
- }
220
-
221
- const target = getIconElement(event.target);
222
-
223
- if (target && target.issue) {
224
- const menuWrapper = target.nextElementSibling;
225
- const menu =
226
- menuWrapper &&
227
- menuWrapper.querySelector(`.${ISSUE_MENU_CLASS_NAME}`);
228
- menu && menu.classList.add(`${ISSUE_MENU_CLASS_NAME}--active`);
229
-
230
- const { from, to } = target.issue;
231
-
232
- view.dispatch(
233
- view.state.tr
234
- .setSelection(TextSelection.create(view.state.doc, from, to))
235
- .scrollIntoView(),
236
- );
237
-
238
- return true;
239
- }
240
-
241
- return false;
242
- },
243
- handleDoubleClick(view, _, event) {
244
- const target = getIconElement(event.target);
245
-
246
- if (target && target.issue) {
247
- const prob = target.issue;
248
-
249
- if (prob.fix) {
250
- prob.fix(view, prob);
251
- view.focus();
252
- return true;
253
- }
254
- }
255
-
256
- return false;
257
- },
258
- },
259
- }),
260
- ];
261
- },
262
- });
@@ -1,34 +0,0 @@
1
- import { LinterPlugin } from '../LinterPlugin';
2
-
3
- export function BadWords(words: string[]): typeof LinterPlugin {
4
- const regex = new RegExp(`\\b(${words.join('|')})\\b`);
5
-
6
- return class BadWords extends LinterPlugin {
7
- scan() {
8
- this.doc.descendants((node: any, position: number) => {
9
- if (!node.isText) {
10
- return;
11
- }
12
-
13
- const matches = regex.exec(node.text);
14
-
15
- if (matches) {
16
- const fixValue = matches[0] + '!!!!!';
17
-
18
- this.record({
19
- level: 'warning',
20
- message: `Try not to say '${matches[0]}'`,
21
- from: position + matches.index,
22
- to: position + matches.index + matches[0].length,
23
- fix: () => {
24
- console.log('hoge');
25
- },
26
- fixMessage: `「${fixValue}」に修正する。`,
27
- });
28
- }
29
- });
30
-
31
- return this;
32
- }
33
- };
34
- }
@@ -1,14 +0,0 @@
1
- import { WysiwygEditorToolFactory, WysiwygEditorTool } from '../schemes';
2
-
3
- export const WysiwygTextColorTool: WysiwygEditorToolFactory = (vui) => {
4
- const tool: WysiwygEditorTool = {
5
- key: 'textColor',
6
- icon: vui.icon('editorTextColor'),
7
- // icon: (gen) => vui.icon('editorTextColor'),
8
- onClick: (ctx) => {
9
- ctx.vui.alert('ok');
10
- },
11
- floating: true,
12
- };
13
- return tool;
14
- };