@icure/form 1.0.0
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.
- package/.editorconfig +12 -0
- package/.idea/inspectionProfiles/Project_Default.xml +73 -0
- package/.idea/iqr-text-field.iml +9 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/.mocharc.json +5 -0
- package/app/demo-app.ts +191 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +14 -0
- package/lib/iqr-form/fields/datePicker.d.ts +8 -0
- package/lib/iqr-form/fields/datePicker.js +42 -0
- package/lib/iqr-form/fields/dateTimePicker.d.ts +8 -0
- package/lib/iqr-form/fields/dateTimePicker.js +42 -0
- package/lib/iqr-form/fields/measureField.d.ts +8 -0
- package/lib/iqr-form/fields/measureField.js +42 -0
- package/lib/iqr-form/fields/multipleChoice.d.ts +8 -0
- package/lib/iqr-form/fields/multipleChoice.js +42 -0
- package/lib/iqr-form/fields/numberField.d.ts +8 -0
- package/lib/iqr-form/fields/numberField.js +42 -0
- package/lib/iqr-form/fields/textfield.d.ts +1 -0
- package/lib/iqr-form/fields/textfield.js +86 -0
- package/lib/iqr-form/fields/timePicker.d.ts +8 -0
- package/lib/iqr-form/fields/timePicker.js +42 -0
- package/lib/iqr-form/index.d.ts +7 -0
- package/lib/iqr-form/index.js +83 -0
- package/lib/iqr-form/model/index.d.ts +78 -0
- package/lib/iqr-form/model/index.js +114 -0
- package/lib/iqr-form/renderer/cards.d.ts +2 -0
- package/lib/iqr-form/renderer/cards.js +43 -0
- package/lib/iqr-form/renderer/form.d.ts +2 -0
- package/lib/iqr-form/renderer/form.js +44 -0
- package/lib/iqr-form/renderer/index.d.ts +3 -0
- package/lib/iqr-form/renderer/index.js +2 -0
- package/lib/iqr-text-field/index.d.ts +2 -0
- package/lib/iqr-text-field/index.js +335 -0
- package/lib/iqr-text-field/plugin/caret-fix-plugin.d.ts +2 -0
- package/lib/iqr-text-field/plugin/caret-fix-plugin.js +23 -0
- package/lib/iqr-text-field/plugin/has-content-class-plugin.d.ts +2 -0
- package/lib/iqr-text-field/plugin/has-content-class-plugin.js +18 -0
- package/lib/iqr-text-field/plugin/mask-plugin.d.ts +2 -0
- package/lib/iqr-text-field/plugin/mask-plugin.js +143 -0
- package/lib/iqr-text-field/plugin/regexp-plugin.d.ts +2 -0
- package/lib/iqr-text-field/plugin/regexp-plugin.js +46 -0
- package/lib/iqr-text-field/prosemirror-commands.d.ts +4 -0
- package/lib/iqr-text-field/prosemirror-commands.js +52 -0
- package/lib/iqr-text-field/prosemirror-utils.d.ts +5 -0
- package/lib/iqr-text-field/prosemirror-utils.js +15 -0
- package/lib/iqr-text-field/schema/common-marks.d.ts +10 -0
- package/lib/iqr-text-field/schema/common-marks.js +90 -0
- package/lib/iqr-text-field/schema/date-time-schema.d.ts +7 -0
- package/lib/iqr-text-field/schema/date-time-schema.js +88 -0
- package/lib/iqr-text-field/schema/decimal-schema.d.ts +3 -0
- package/lib/iqr-text-field/schema/decimal-schema.js +27 -0
- package/lib/iqr-text-field/schema/index.d.ts +11 -0
- package/lib/iqr-text-field/schema/index.js +18 -0
- package/lib/iqr-text-field/schema/markdown-schema.d.ts +8 -0
- package/lib/iqr-text-field/schema/markdown-schema.js +139 -0
- package/lib/iqr-text-field/schema/measure-schema.d.ts +3 -0
- package/lib/iqr-text-field/schema/measure-schema.js +35 -0
- package/lib/iqr-text-field/schema/token-schema.d.ts +6 -0
- package/lib/iqr-text-field/schema/token-schema.js +36 -0
- package/lib/iqr-text-field/schema/utils.d.ts +11 -0
- package/lib/iqr-text-field/schema/utils.js +11 -0
- package/lib/iqr-text-field/selection-companion.d.ts +11 -0
- package/lib/iqr-text-field/selection-companion.js +52 -0
- package/lib/iqr-text-field/suggestion-palette.d.ts +33 -0
- package/lib/iqr-text-field/suggestion-palette.js +139 -0
- package/package.json +60 -0
- package/test/form.yaml +96 -0
- package/test/simple/test.spec.ts +303 -0
- package/webpack.config.js +41 -0
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
12
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
13
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
14
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
15
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
16
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
17
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
21
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
22
|
+
};
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
// Import the LitElement base class and html helper function
|
|
25
|
+
const lit_element_1 = require("lit-element");
|
|
26
|
+
const prosemirror_state_1 = require("prosemirror-state");
|
|
27
|
+
const prosemirror_view_1 = require("prosemirror-view");
|
|
28
|
+
const prosemirror_history_1 = require("prosemirror-history");
|
|
29
|
+
const prosemirror_keymap_1 = require("prosemirror-keymap");
|
|
30
|
+
const prosemirror_commands_1 = require("prosemirror-commands");
|
|
31
|
+
const prosemirror_schema_list_1 = require("prosemirror-schema-list");
|
|
32
|
+
const schema_1 = require("./schema");
|
|
33
|
+
const markdown_it_1 = __importDefault(require("markdown-it"));
|
|
34
|
+
const prosemirror_markdown_1 = require("prosemirror-markdown");
|
|
35
|
+
const prosemirror_commands_2 = require("./prosemirror-commands");
|
|
36
|
+
const selection_companion_1 = require("./selection-companion");
|
|
37
|
+
const suggestion_palette_1 = require("./suggestion-palette");
|
|
38
|
+
const caret_fix_plugin_1 = require("./plugin/caret-fix-plugin");
|
|
39
|
+
const prosemirror_utils_1 = require("./prosemirror-utils");
|
|
40
|
+
// @ts-ignore
|
|
41
|
+
const style_scss_1 = __importDefault(require("./styles/style.scss"));
|
|
42
|
+
// @ts-ignore
|
|
43
|
+
const kendo_scss_1 = __importDefault(require("./styles/kendo.scss"));
|
|
44
|
+
const mask_plugin_1 = require("./plugin/mask-plugin");
|
|
45
|
+
const has_content_class_plugin_1 = require("./plugin/has-content-class-plugin");
|
|
46
|
+
const regexp_plugin_1 = require("./plugin/regexp-plugin");
|
|
47
|
+
// Extend the LitElement base class
|
|
48
|
+
class IqrTextField extends lit_element_1.LitElement {
|
|
49
|
+
constructor() {
|
|
50
|
+
super();
|
|
51
|
+
this.suggestionStopWords = new Set();
|
|
52
|
+
this.linksProvider = () => Promise.resolve(undefined);
|
|
53
|
+
this.suggestionProvider = () => [];
|
|
54
|
+
this.codeColorProvider = () => 'XI';
|
|
55
|
+
this.linkColorProvider = () => 'cat1';
|
|
56
|
+
this.codeContentProvider = (codes) => codes.map(c => c.code).join(',');
|
|
57
|
+
this.schema = 'styled-text-with-codes';
|
|
58
|
+
this.label = '';
|
|
59
|
+
this.labelPosition = 'float';
|
|
60
|
+
this.placeholder = '';
|
|
61
|
+
this.value = '';
|
|
62
|
+
this.displayOwnerMenu = false;
|
|
63
|
+
this.suggestions = false;
|
|
64
|
+
this.links = false;
|
|
65
|
+
this.textRegex = '';
|
|
66
|
+
this.windowListeners = [];
|
|
67
|
+
this.mouseCount = 0;
|
|
68
|
+
}
|
|
69
|
+
connectedCallback() {
|
|
70
|
+
super.connectedCallback();
|
|
71
|
+
const cmu = this.mouseUp.bind(this);
|
|
72
|
+
const cmd = this.mouseDown.bind(this);
|
|
73
|
+
this.windowListeners.push(['mouseup', cmu], ['mousedown', cmd]);
|
|
74
|
+
window.addEventListener('mouseup', cmu);
|
|
75
|
+
window.addEventListener('mousedown', cmd);
|
|
76
|
+
}
|
|
77
|
+
disconnectedCallback() {
|
|
78
|
+
super.disconnectedCallback();
|
|
79
|
+
this.windowListeners.forEach(wl => window.removeEventListener(wl[0], wl[1]));
|
|
80
|
+
}
|
|
81
|
+
static get styles() {
|
|
82
|
+
return [style_scss_1.default, kendo_scss_1.default];
|
|
83
|
+
}
|
|
84
|
+
render() {
|
|
85
|
+
return lit_element_1.html `
|
|
86
|
+
<div id="root" class="iqr-text-field" data-placeholder=${this.placeholder}>
|
|
87
|
+
<label class="iqr-label ${this.labelPosition}"><span>${this.label}</span></label>
|
|
88
|
+
<div class="iqr-input">
|
|
89
|
+
<div id="editor"></div>
|
|
90
|
+
<div id="extra" class=${'extra' + (this.displayOwnerMenu ? ' forced' : '')}>
|
|
91
|
+
<div class="info">
|
|
92
|
+
~${this.owner}
|
|
93
|
+
</div>
|
|
94
|
+
<div class="buttons-container">
|
|
95
|
+
<div class="menu-container">
|
|
96
|
+
<button data-content="${this.owner}" @click="${this.toggleOwnerMenu}" class="btn menu-trigger author">
|
|
97
|
+
<svg width="10" height="10" viewBox="0 0 10 10" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
98
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M10 5C10 7.76142 7.76142 10 5 10C2.23858 10 0 7.76142 0 5C0 2.23858 2.23858 0 5 0C7.76142 0 10 2.23858 10 5ZM7 3C7 4.10457 6.10457 5 5 5C3.89543 5 3 4.10457 3 3C3 1.89543 3.89543 1 5 1C6.10457 1 7 1.89543 7 3ZM5.00001 9C6.53071 9 7.8606 8.1402 8.53306 6.8772C7.62844 6.33518 6.37946 6 5.00001 6C3.62055 6 2.37158 6.33517 1.46695 6.87719C2.13941 8.14019 3.4693 9 5.00001 9Z"/>
|
|
99
|
+
</svg>
|
|
100
|
+
</button>
|
|
101
|
+
${this.displayOwnerMenu ? lit_element_1.html `
|
|
102
|
+
<div id="menu" class="menu">
|
|
103
|
+
<div class="input-container">
|
|
104
|
+
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
105
|
+
<path d="M12.9167 11.6667H12.2583L12.025 11.4417C12.8417 10.4917 13.3333 9.25833 13.3333 7.91667C13.3333 4.925 10.9083 2.5 7.91667 2.5C4.925 2.5 2.5 4.925 2.5 7.91667C2.5 10.9083 4.925 13.3333 7.91667 13.3333C9.25833 13.3333 10.4917 12.8417 11.4417 12.025L11.6667 12.2583V12.9167L15.8333 17.075L17.075 15.8333L12.9167 11.6667ZM7.91667 11.6667C5.84167 11.6667 4.16667 9.99167 4.16667 7.91667C4.16667 5.84167 5.84167 4.16667 7.91667 4.16667C9.99167 4.16667 11.6667 5.84167 11.6667 7.91667C11.6667 9.99167 9.99167 11.6667 7.91667 11.6667Z" fill="#809AB4"/>
|
|
106
|
+
</svg>
|
|
107
|
+
<input>
|
|
108
|
+
</div>
|
|
109
|
+
<button class="item">
|
|
110
|
+
Jean René
|
|
111
|
+
</button>
|
|
112
|
+
<button class="item">
|
|
113
|
+
Jean José
|
|
114
|
+
</button>
|
|
115
|
+
<button class="item">
|
|
116
|
+
Marie-Josée Perrec
|
|
117
|
+
</button>
|
|
118
|
+
</div>
|
|
119
|
+
` : ''}
|
|
120
|
+
</div>
|
|
121
|
+
<div class="menu-container">
|
|
122
|
+
<button data-content="01/02/20" class="btn date">
|
|
123
|
+
<svg width="10" height="10" viewBox="0 0 10 10" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
124
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M2 0C0.895431 0 0 0.89543 0 2V8C0 9.10457 0.89543 10 2 10H8C9.10457 10 10 9.10457 10 8V2C10 0.895431 9.10457 0 8 0H2ZM1 3V8C1 8.55229 1.44772 9 2 9H8C8.55229 9 9 8.55229 9 8V3H1ZM8 8H5V5H8V8Z"/>
|
|
125
|
+
</svg>
|
|
126
|
+
</button>
|
|
127
|
+
</div>
|
|
128
|
+
<div class="menu-container">
|
|
129
|
+
<button data-content="1.0" class="btn version">
|
|
130
|
+
<svg width="10" height="10" viewBox="0 0 10 10" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
131
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M5 10C7.76141 10 10 7.76142 10 5C10 2.23858 7.76141 0 5 0C2.23859 0 0 2.23858 0 5C0 7.76142 2.23859 10 5 10ZM3.5 3.33172C3.03394 3.16698 2.70001 2.72249 2.70001 2.2C2.70001 1.53726 3.23727 1 3.90002 1C4.56274 1 5.10001 1.53726 5.10001 2.2C5.10001 2.72249 4.76608 3.16698 4.30002 3.33172V5.04041C4.73386 4.59767 5.31354 4.29838 5.96133 4.22028C6.12021 3.74364 6.56998 3.4 7.10001 3.4C7.76276 3.4 8.30002 3.93726 8.30002 4.6C8.30002 5.26274 7.76276 5.8 7.10001 5.8C6.58722 5.8 6.14957 5.47836 5.97775 5.02583C5.13132 5.16293 4.46295 5.8313 4.32584 6.67775C4.77838 6.84955 5.10001 7.28722 5.10001 7.8C5.10001 8.46274 4.56274 9 3.90002 9C3.23727 9 2.70001 8.46274 2.70001 7.8C2.70001 7.27751 3.03394 6.83302 3.5 6.66828V3.33172ZM3.5 7.8C3.5 7.58001 3.67758 7.4015 3.89722 7.4H3.9028C4.12241 7.4015 4.29999 7.58001 4.29999 7.8C4.29999 8.0209 4.12091 8.2 3.89999 8.2C3.67908 8.2 3.5 8.0209 3.5 7.8ZM6.70001 4.59555V4.60446C6.70239 4.82333 6.88055 5.00001 7.09998 5.00001C7.32089 5.00001 7.5 4.82092 7.5 4.60001C7.5 4.37909 7.32089 4.2 7.09998 4.2C6.88055 4.2 6.70239 4.37669 6.70001 4.59555ZM3.89999 2.6C4.12091 2.6 4.29999 2.42091 4.29999 2.2C4.29999 1.97909 4.12091 1.8 3.89999 1.8C3.67908 1.8 3.5 1.97909 3.5 2.2C3.5 2.42091 3.67908 2.6 3.89999 2.6Z"/>
|
|
132
|
+
</svg>
|
|
133
|
+
</button>
|
|
134
|
+
</div>
|
|
135
|
+
<div class="menu-container">
|
|
136
|
+
<button data-content="fr" class="btn language">
|
|
137
|
+
<svg width="10" height="10" viewBox="0 0 10 10" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
138
|
+
<path d="M5 0C2.2379 0 0 2.2379 0 5C0 7.7621 2.2379 10 5 10C7.7621 10 10 7.7621 10 5C10 2.2379 7.7621 0 5 0ZM9.03226 5C9.03226 5.45363 8.95363 5.89113 8.81452 6.29839H8.40524C8.31855 6.29839 8.23589 6.26411 8.1754 6.20161L7.53024 5.54435C7.43952 5.45161 7.43952 5.3004 7.53226 5.20766L7.78427 4.95565V4.78024C7.78427 4.71976 7.76008 4.66129 7.71774 4.61895L7.52823 4.42944C7.48589 4.3871 7.42742 4.3629 7.36694 4.3629H7.04435C6.91935 4.3629 6.81653 4.26008 6.81653 4.13508C6.81653 4.0746 6.84073 4.01613 6.88306 3.97379L7.07258 3.78427C7.11492 3.74194 7.17339 3.71774 7.23387 3.71774H7.87903C8.00403 3.71774 8.10685 3.61492 8.10685 3.48992V3.3004C8.10685 3.1754 8.00403 3.07258 7.87903 3.07258H7.13911C6.96169 3.07258 6.81653 3.21774 6.81653 3.39516V3.48589C6.81653 3.625 6.72782 3.74798 6.59677 3.79234L5.95968 4.00403C5.89315 4.02621 5.84879 4.08669 5.84879 4.15726V4.20161C5.84879 4.29032 5.77621 4.3629 5.6875 4.3629H5.36492C5.27621 4.3629 5.20363 4.29032 5.20363 4.20161C5.20363 4.1129 5.13105 4.04032 5.04234 4.04032H4.97984C4.91935 4.04032 4.8629 4.0746 4.83468 4.12903L4.64516 4.50605C4.59073 4.61492 4.47984 4.68347 4.35685 4.68347H3.91129C3.73387 4.68347 3.58871 4.53831 3.58871 4.36089V3.85081C3.58871 3.76613 3.62298 3.68347 3.68347 3.62298L4.08871 3.21774C4.18145 3.125 4.23387 2.99798 4.23387 2.86492C4.23387 2.79637 4.27823 2.73387 4.34476 2.71169L5.15121 2.44355C5.18548 2.43145 5.21573 2.41331 5.23992 2.38911L5.78024 1.84879C5.82258 1.80645 5.84677 1.74798 5.84677 1.6875C5.84677 1.5625 5.74395 1.45968 5.61895 1.45968H5.20161L4.87903 1.78226V1.94355C4.87903 2.03226 4.80645 2.10484 4.71774 2.10484H4.39516C4.30645 2.10484 4.23387 2.03226 4.23387 1.94355V1.54032C4.23387 1.48992 4.25806 1.44153 4.29839 1.41129L4.88105 0.97379C4.91935 0.971774 4.95766 0.967742 4.99597 0.967742C7.22379 0.967742 9.03226 2.77621 9.03226 5ZM2.62298 2.84476C2.62298 2.78427 2.64718 2.72581 2.68952 2.68347L3.20161 2.17137C3.24395 2.12903 3.30242 2.10484 3.3629 2.10484C3.4879 2.10484 3.59073 2.20766 3.59073 2.33266V2.65524C3.59073 2.71573 3.56653 2.77419 3.52419 2.81653L3.33468 3.00605C3.29234 3.04839 3.23387 3.07258 3.17339 3.07258H2.85081C2.72581 3.07258 2.62298 2.96976 2.62298 2.84476ZM5.20363 9.02218V8.87903C5.20363 8.70161 5.05847 8.55645 4.88105 8.55645H4.47379C4.25605 8.55645 3.93548 8.4496 3.76008 8.31855L3.3125 7.98185C3.08065 7.80847 2.94556 7.53629 2.94556 7.24798V6.76613C2.94556 6.44355 3.11492 6.14516 3.39113 5.97984L4.25605 5.46169C4.39919 5.37702 4.5625 5.33065 4.72782 5.33065H5.35685C5.57661 5.33065 5.78831 5.40927 5.95363 5.5504L6.8246 6.29839H7.19355C7.36492 6.29839 7.52823 6.36694 7.64919 6.4879L7.99798 6.83669C8.06653 6.90524 8.16129 6.94355 8.25806 6.94355H8.52823C7.875 8.13105 6.6371 8.9496 5.20363 9.02218Z"/>
|
|
139
|
+
</svg>
|
|
140
|
+
</button>
|
|
141
|
+
</div>
|
|
142
|
+
</div>
|
|
143
|
+
</div>
|
|
144
|
+
</div>
|
|
145
|
+
</div>
|
|
146
|
+
`;
|
|
147
|
+
}
|
|
148
|
+
toggleOwnerMenu() {
|
|
149
|
+
this.displayOwnerMenu = !this.displayOwnerMenu;
|
|
150
|
+
}
|
|
151
|
+
mouseDown() {
|
|
152
|
+
this.mouseCount++;
|
|
153
|
+
console.log(this.mouseCount);
|
|
154
|
+
}
|
|
155
|
+
mouseUp() {
|
|
156
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
157
|
+
this.mouseCount = 0;
|
|
158
|
+
if (!((_c = (_b = (_a = this.view) === null || _a === void 0 ? void 0 : _a.dom) === null || _b === void 0 ? void 0 : _b.classList) === null || _c === void 0 ? void 0 : _c.contains('ProseMirror-focused'))) {
|
|
159
|
+
(_g = (_f = (_e = (_d = this.view) === null || _d === void 0 ? void 0 : _d.dom) === null || _e === void 0 ? void 0 : _e.parentElement) === null || _f === void 0 ? void 0 : _f.querySelectorAll('.companion')) === null || _g === void 0 ? void 0 : _g.forEach(x => {
|
|
160
|
+
x.style.display = 'none';
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
firstUpdated() {
|
|
165
|
+
var _a;
|
|
166
|
+
const schema = this.proseMirrorSchema = schema_1.createSchema(this.schema, (t, c, isC) => isC ? this.codeColorProvider(t, c) : this.linkColorProvider(t, c), this.codeContentProvider);
|
|
167
|
+
const tokenizer = markdown_it_1.default("commonmark", { html: false });
|
|
168
|
+
this.parser = this.schema === 'date' ? {
|
|
169
|
+
parse: (value) => schema.node("paragraph", {}, [
|
|
170
|
+
schema.node("date", {}, value ? [schema.text(value)] : []),
|
|
171
|
+
])
|
|
172
|
+
} : this.schema === 'date-time' ? {
|
|
173
|
+
parse: (value) => {
|
|
174
|
+
const date = value ? value.split(' ')[0] : '';
|
|
175
|
+
const time = value ? value.split(' ')[1] : '';
|
|
176
|
+
return schema.node("paragraph", {}, [
|
|
177
|
+
schema.node("date", {}, date && date.length ? [schema.text(date)] : [schema.text(' ')]),
|
|
178
|
+
schema.node("time", {}, time && time.length ? [schema.text(time)] : [schema.text(' ')]),
|
|
179
|
+
]);
|
|
180
|
+
}
|
|
181
|
+
} : this.schema === 'text-document' ? new prosemirror_markdown_1.MarkdownParser(schema, markdown_it_1.default("commonmark", { html: false }), {
|
|
182
|
+
blockquote: { block: "blockquote" },
|
|
183
|
+
paragraph: { block: "paragraph" },
|
|
184
|
+
list_item: { block: "list_item" },
|
|
185
|
+
bullet_list: { block: "bullet_list" },
|
|
186
|
+
ordered_list: { block: "ordered_list", getAttrs: tok => ({ order: +(tok.attrGet("start") || 1) }) },
|
|
187
|
+
heading: { block: "heading", getAttrs: tok => ({ level: +tok.tag.slice(1) }) },
|
|
188
|
+
hr: { node: "horizontal_rule" },
|
|
189
|
+
image: { node: "image", getAttrs: tok => {
|
|
190
|
+
var _a;
|
|
191
|
+
return ({
|
|
192
|
+
src: tok.attrGet("src"),
|
|
193
|
+
title: tok.attrGet("title") || null,
|
|
194
|
+
alt: ((_a = (tok.children || [])[0]) === null || _a === void 0 ? void 0 : _a.content) || null
|
|
195
|
+
});
|
|
196
|
+
} },
|
|
197
|
+
hardbreak: { node: "hard_break" },
|
|
198
|
+
em: prosemirror_utils_1.hasMark(schema.spec.marks, 'em') ? { mark: "em" } : { ignore: true },
|
|
199
|
+
strong: prosemirror_utils_1.hasMark(schema.spec.marks, 'strong') ? { mark: "strong" } : { ignore: true },
|
|
200
|
+
link: prosemirror_utils_1.hasMark(schema.spec.marks, 'link') ? { mark: "link", getAttrs: tok => ({
|
|
201
|
+
href: tok.attrGet("href"),
|
|
202
|
+
title: tok.attrGet("title") || null
|
|
203
|
+
}) } : { ignore: true }
|
|
204
|
+
}) : new prosemirror_markdown_1.MarkdownParser(schema, { parse: (src, env) => {
|
|
205
|
+
return tokenizer.parse(src, env).filter(t => !t.type.startsWith('paragraph_'));
|
|
206
|
+
} }, {
|
|
207
|
+
em: prosemirror_utils_1.hasMark(schema.spec.marks, 'em') ? { mark: "em" } : { ignore: true },
|
|
208
|
+
strong: prosemirror_utils_1.hasMark(schema.spec.marks, 'strong') ? { mark: "strong" } : { ignore: true },
|
|
209
|
+
link: prosemirror_utils_1.hasMark(schema.spec.marks, 'link') ? { mark: "link", getAttrs: tok => ({
|
|
210
|
+
href: tok.attrGet("href"),
|
|
211
|
+
title: tok.attrGet("title") || null
|
|
212
|
+
}) } : { ignore: true }
|
|
213
|
+
});
|
|
214
|
+
const cmp = this;
|
|
215
|
+
this.container = ((_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.getElementById('editor')) || undefined;
|
|
216
|
+
let br = schema.nodes.hard_break;
|
|
217
|
+
const hardBreak = prosemirror_commands_1.chainCommands(prosemirror_commands_1.exitCode, (state, dispatch) => {
|
|
218
|
+
dispatch && dispatch(state.tr.replaceSelectionWith(br.create()).scrollIntoView());
|
|
219
|
+
return true;
|
|
220
|
+
});
|
|
221
|
+
const replaceRangeWithSuggestion = (from, to, sug) => __awaiter(this, void 0, void 0, function* () {
|
|
222
|
+
const link = yield this.linksProvider(sug);
|
|
223
|
+
return link && cmp.view.state.tr.replaceWith(from, to, this.proseMirrorSchema.text(sug.text, [this.proseMirrorSchema.mark('link', link)])) || undefined;
|
|
224
|
+
});
|
|
225
|
+
if (this.container) {
|
|
226
|
+
let headingsKeymap = prosemirror_keymap_1.keymap([1, 2, 3, 4, 5, 6].reduce((acc, idx) => {
|
|
227
|
+
return Object.assign(acc, { [`Mod-ctrl-${idx}`]: prosemirror_commands_1.setBlockType(this.proseMirrorSchema.nodes.heading, { level: '' + idx }) });
|
|
228
|
+
}, {}));
|
|
229
|
+
const parsedDoc = this.parser.parse(this.value);
|
|
230
|
+
this.view = new prosemirror_view_1.EditorView(this.container, {
|
|
231
|
+
state: prosemirror_state_1.EditorState.create({
|
|
232
|
+
doc: parsedDoc,
|
|
233
|
+
schema: this.proseMirrorSchema,
|
|
234
|
+
plugins: [
|
|
235
|
+
caret_fix_plugin_1.caretFixPlugin(),
|
|
236
|
+
prosemirror_history_1.history(),
|
|
237
|
+
this.links ?
|
|
238
|
+
new prosemirror_state_1.Plugin({
|
|
239
|
+
view(editorView) { return new selection_companion_1.SelectionCompanion(editorView, () => cmp.mouseCount > 0); }
|
|
240
|
+
}) : null,
|
|
241
|
+
this.suggestions ?
|
|
242
|
+
new prosemirror_state_1.Plugin({
|
|
243
|
+
view(editorView) { return (cmp.suggestionPalette = new suggestion_palette_1.SuggestionPalette(editorView, (terms) => cmp.suggestionProvider(terms), () => cmp.suggestionStopWords)); }
|
|
244
|
+
}) : null,
|
|
245
|
+
this.suggestions ?
|
|
246
|
+
prosemirror_keymap_1.keymap({
|
|
247
|
+
"Tab": (state, dispatch) => { return cmp.suggestionPalette && cmp.suggestionPalette.focusOrInsert(this.view, replaceRangeWithSuggestion) || false; },
|
|
248
|
+
"ArrowUp": (state, dispatch) => { return cmp.suggestionPalette && cmp.suggestionPalette.arrowUp() || false; },
|
|
249
|
+
"ArrowDown": (state, dispatch) => { return cmp.suggestionPalette && cmp.suggestionPalette.arrowDown() || false; },
|
|
250
|
+
"Enter": (state, dispatch) => { return cmp.suggestionPalette && cmp.suggestionPalette.insert(this.view, replaceRangeWithSuggestion) || false; },
|
|
251
|
+
}) : null,
|
|
252
|
+
prosemirror_keymap_1.keymap({ "Mod-z": prosemirror_history_1.undo, "Mod-Shift-z": prosemirror_history_1.redo }),
|
|
253
|
+
prosemirror_keymap_1.keymap(Object.assign({}, schema.marks.strong ? { "Mod-b": prosemirror_commands_1.toggleMark(schema.marks.strong) } : {}, schema.marks.em ? { "Mod-i": prosemirror_commands_1.toggleMark(schema.marks.em) } : {}, schema.nodes.paragraph ? { "Alt-ArrowUp": prosemirror_commands_1.joinUp } : {}, schema.nodes.paragraph ? { "Alt-ArrowDown": prosemirror_commands_1.joinDown } : {}, schema.nodes.paragraph ? { "Alt-Enter": hardBreak } : {}, schema.nodes.paragraph ? { "Shift-Enter": hardBreak } : {}, schema.nodes.ordered_list ? { "Shift-ctrl-1": prosemirror_schema_list_1.wrapInList(schema.nodes.ordered_list) } : {}, schema.nodes.bullet_list ? { "Shift-ctrl-*": prosemirror_schema_list_1.wrapInList(schema.nodes.bullet_list) } : {}, schema.nodes.blockquote ? { "Shift-ctrl-w": prosemirror_commands_2.wrapInIfNeeded(schema.nodes.blockquote) } : {}, schema.nodes.blockquote ? { "Shift-ctrl-u": prosemirror_commands_2.unwrapFrom(schema.nodes.blockquote) } : {}, schema.nodes.paragraph ? { "Mod-ctrl-0": prosemirror_commands_1.setBlockType(schema.nodes.paragraph) } : {}, schema.nodes.paragraph ? { "Shift-ctrl-0": prosemirror_commands_1.setBlockType(schema.nodes.paragraph) } : {}, schema.nodes.list_item ? { "Enter": prosemirror_schema_list_1.splitListItem(schema.nodes.list_item) } : {}, schema.nodes.ordered_list || schema.nodes.bullet_list ? { "Mod-(": prosemirror_schema_list_1.liftListItem(schema.nodes.list_item) } : {}, schema.nodes.ordered_list || schema.nodes.bullet_list ? { "Mod-[": prosemirror_schema_list_1.liftListItem(schema.nodes.list_item) } : {}, schema.nodes.ordered_list || schema.nodes.bullet_list ? { "Mod-)": prosemirror_schema_list_1.sinkListItem(schema.nodes.list_item) } : {}, schema.nodes.ordered_list || schema.nodes.bullet_list ? { "Mod-]": prosemirror_schema_list_1.sinkListItem(schema.nodes.list_item) } : {})),
|
|
254
|
+
schema.nodes.heading ? headingsKeymap : null,
|
|
255
|
+
mask_plugin_1.maskPlugin(),
|
|
256
|
+
regexp_plugin_1.regexpPlugin(),
|
|
257
|
+
has_content_class_plugin_1.hasContentClassPlugin(this.shadowRoot),
|
|
258
|
+
prosemirror_keymap_1.keymap(prosemirror_commands_1.baseKeymap)
|
|
259
|
+
].filter(x => !!x).map(x => x)
|
|
260
|
+
}),
|
|
261
|
+
dispatchTransaction: (tr) => {
|
|
262
|
+
this.view && this.view.updateState(this.view.state.apply(tr));
|
|
263
|
+
//current state as json in text area
|
|
264
|
+
//this.view && console.log(JSON.stringify(this.view.state.doc.toJSON(), null, 2));
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
__decorate([
|
|
271
|
+
lit_element_1.property(),
|
|
272
|
+
__metadata("design:type", Set)
|
|
273
|
+
], IqrTextField.prototype, "suggestionStopWords", void 0);
|
|
274
|
+
__decorate([
|
|
275
|
+
lit_element_1.property(),
|
|
276
|
+
__metadata("design:type", Function)
|
|
277
|
+
], IqrTextField.prototype, "linksProvider", void 0);
|
|
278
|
+
__decorate([
|
|
279
|
+
lit_element_1.property(),
|
|
280
|
+
__metadata("design:type", Function)
|
|
281
|
+
], IqrTextField.prototype, "suggestionProvider", void 0);
|
|
282
|
+
__decorate([
|
|
283
|
+
lit_element_1.property(),
|
|
284
|
+
__metadata("design:type", Function)
|
|
285
|
+
], IqrTextField.prototype, "codeColorProvider", void 0);
|
|
286
|
+
__decorate([
|
|
287
|
+
lit_element_1.property(),
|
|
288
|
+
__metadata("design:type", Function)
|
|
289
|
+
], IqrTextField.prototype, "linkColorProvider", void 0);
|
|
290
|
+
__decorate([
|
|
291
|
+
lit_element_1.property(),
|
|
292
|
+
__metadata("design:type", Function)
|
|
293
|
+
], IqrTextField.prototype, "codeContentProvider", void 0);
|
|
294
|
+
__decorate([
|
|
295
|
+
lit_element_1.property(),
|
|
296
|
+
__metadata("design:type", String)
|
|
297
|
+
], IqrTextField.prototype, "schema", void 0);
|
|
298
|
+
__decorate([
|
|
299
|
+
lit_element_1.property(),
|
|
300
|
+
__metadata("design:type", String)
|
|
301
|
+
], IqrTextField.prototype, "label", void 0);
|
|
302
|
+
__decorate([
|
|
303
|
+
lit_element_1.property(),
|
|
304
|
+
__metadata("design:type", String)
|
|
305
|
+
], IqrTextField.prototype, "labelPosition", void 0);
|
|
306
|
+
__decorate([
|
|
307
|
+
lit_element_1.property(),
|
|
308
|
+
__metadata("design:type", String)
|
|
309
|
+
], IqrTextField.prototype, "placeholder", void 0);
|
|
310
|
+
__decorate([
|
|
311
|
+
lit_element_1.property(),
|
|
312
|
+
__metadata("design:type", String)
|
|
313
|
+
], IqrTextField.prototype, "value", void 0);
|
|
314
|
+
__decorate([
|
|
315
|
+
lit_element_1.property(),
|
|
316
|
+
__metadata("design:type", String)
|
|
317
|
+
], IqrTextField.prototype, "owner", void 0);
|
|
318
|
+
__decorate([
|
|
319
|
+
lit_element_1.property(),
|
|
320
|
+
__metadata("design:type", Boolean)
|
|
321
|
+
], IqrTextField.prototype, "displayOwnerMenu", void 0);
|
|
322
|
+
__decorate([
|
|
323
|
+
lit_element_1.property(),
|
|
324
|
+
__metadata("design:type", Boolean)
|
|
325
|
+
], IqrTextField.prototype, "suggestions", void 0);
|
|
326
|
+
__decorate([
|
|
327
|
+
lit_element_1.property(),
|
|
328
|
+
__metadata("design:type", Boolean)
|
|
329
|
+
], IqrTextField.prototype, "links", void 0);
|
|
330
|
+
__decorate([
|
|
331
|
+
lit_element_1.property(),
|
|
332
|
+
__metadata("design:type", String)
|
|
333
|
+
], IqrTextField.prototype, "textRegex", void 0);
|
|
334
|
+
// Register the new element with the browser.
|
|
335
|
+
customElements.define('iqr-text-field', IqrTextField);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.caretFixPlugin = void 0;
|
|
4
|
+
const prosemirror_state_1 = require("prosemirror-state");
|
|
5
|
+
exports.caretFixPlugin = () => {
|
|
6
|
+
let focusing = false;
|
|
7
|
+
return new prosemirror_state_1.Plugin({
|
|
8
|
+
props: {
|
|
9
|
+
handleDOMEvents: {
|
|
10
|
+
focus: view => {
|
|
11
|
+
if (focusing) {
|
|
12
|
+
focusing = false;
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
focusing = true;
|
|
16
|
+
setTimeout(() => { view.dom.blur(); view.dom.focus(); }, 0);
|
|
17
|
+
}
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hasContentClassPlugin = void 0;
|
|
4
|
+
const prosemirror_state_1 = require("prosemirror-state");
|
|
5
|
+
exports.hasContentClassPlugin = (root) => {
|
|
6
|
+
return new prosemirror_state_1.Plugin({
|
|
7
|
+
view: (v) => {
|
|
8
|
+
var _a, _b;
|
|
9
|
+
v.state.doc.textContent && v.state.doc.textContent.length && ((_b = (_a = root === null || root === void 0 ? void 0 : root.getElementById('root')) === null || _a === void 0 ? void 0 : _a.classList) === null || _b === void 0 ? void 0 : _b.add('has-content'));
|
|
10
|
+
return {
|
|
11
|
+
update: (v, s) => {
|
|
12
|
+
var _a, _b, _c, _d;
|
|
13
|
+
v.state.doc.textContent && v.state.doc.textContent.length ? (_b = (_a = root === null || root === void 0 ? void 0 : root.getElementById('root')) === null || _a === void 0 ? void 0 : _a.classList) === null || _b === void 0 ? void 0 : _b.add('has-content') : (_d = (_c = root.getElementById('root')) === null || _c === void 0 ? void 0 : _c.classList) === null || _d === void 0 ? void 0 : _d.remove('has-content');
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
};
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.maskPlugin = void 0;
|
|
4
|
+
const prosemirror_state_1 = require("prosemirror-state");
|
|
5
|
+
const prosemirror_view_1 = require("prosemirror-view");
|
|
6
|
+
exports.maskPlugin = () => {
|
|
7
|
+
const maskText = ($pos, text, mask, tr, setSelection = true) => {
|
|
8
|
+
const textFromBeginning = $pos.parent.textBetween(0, $pos.parentOffset) + text;
|
|
9
|
+
const trailingText = $pos.parent.textBetween($pos.parentOffset, $pos.parent.content.size);
|
|
10
|
+
let t = textFromBeginning;
|
|
11
|
+
let skip = 0;
|
|
12
|
+
let completed = false;
|
|
13
|
+
if (t.length === 0) {
|
|
14
|
+
t += trailingText.substring(text.length + skip);
|
|
15
|
+
completed = true;
|
|
16
|
+
}
|
|
17
|
+
for (let i = 0; i < mask.length && i < t.length; i++) {
|
|
18
|
+
if (mask[i] === '.' && t[i].normalize("NFD").replace(/[\u0300-\u036f]/g, "").match(/\w|-/) ||
|
|
19
|
+
mask[i] === '-' && t[i].match(/\d/)) {
|
|
20
|
+
//skip
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
if (mask[i] === t[i]) {
|
|
24
|
+
//skip
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
t = t.substring(0, i) + mask[i] + t.substring(i);
|
|
28
|
+
if (!completed)
|
|
29
|
+
skip++;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (t.length === i + 1 && !completed) {
|
|
33
|
+
t += trailingText.substring(text.length + skip);
|
|
34
|
+
completed = true;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const tail = t.length > mask.length ? t.substring(mask.length) : '';
|
|
38
|
+
t = t.substring(0, mask.length);
|
|
39
|
+
let trail = t.length < mask.length ? mask.substring(t.length) : '';
|
|
40
|
+
if (t === textFromBeginning && trail === trailingText) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
const currentSel = tr.selection;
|
|
44
|
+
tr = tr.insertText(t + trail, $pos.pos - $pos.parentOffset, $pos.pos - $pos.parentOffset + $pos.parent.content.size);
|
|
45
|
+
if (setSelection) {
|
|
46
|
+
tr = tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc, Math.min($pos.pos + text.length + skip, tr.doc.content.size - 1)));
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
tr = tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc, Math.min(currentSel.$anchor.pos, tr.doc.content.size - 1), Math.min(currentSel.$head.pos, tr.doc.content.size - 1)));
|
|
50
|
+
}
|
|
51
|
+
tr.setMeta("tailText", tail);
|
|
52
|
+
return tr;
|
|
53
|
+
};
|
|
54
|
+
function applyDocMasks(state) {
|
|
55
|
+
let tr = undefined;
|
|
56
|
+
let posMark = 0;
|
|
57
|
+
//Scan nodes and add mask when needed
|
|
58
|
+
while ((tr || state).doc && posMark < (tr || state).doc.content.size) {
|
|
59
|
+
const $pos = (tr || state).doc.resolve(posMark);
|
|
60
|
+
const node = $pos.node($pos.depth) || undefined;
|
|
61
|
+
const mask = node === null || node === void 0 ? void 0 : node.type.spec.mask;
|
|
62
|
+
if (mask) {
|
|
63
|
+
tr = tr || state.tr;
|
|
64
|
+
tr = maskText(tr.doc.resolve(posMark), '', mask, tr, false) || tr;
|
|
65
|
+
const $newPos = tr.doc.resolve(posMark);
|
|
66
|
+
const newNode = $newPos.node($newPos.depth);
|
|
67
|
+
if (newNode) {
|
|
68
|
+
posMark += newNode.content.size + 1;
|
|
69
|
+
}
|
|
70
|
+
else
|
|
71
|
+
posMark++;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
posMark++;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return tr;
|
|
78
|
+
}
|
|
79
|
+
return new prosemirror_state_1.Plugin({
|
|
80
|
+
view: (v) => {
|
|
81
|
+
let tr = applyDocMasks(v.state);
|
|
82
|
+
if (tr)
|
|
83
|
+
v.updateState(v.state.apply(tr));
|
|
84
|
+
return {};
|
|
85
|
+
},
|
|
86
|
+
props: {
|
|
87
|
+
decorations(state) {
|
|
88
|
+
let $pos = state.doc.resolve(Math.min(state.selection.$from.pos, state.doc.content.size));
|
|
89
|
+
let node = $pos.parent;
|
|
90
|
+
let start = $pos.pos - $pos.parentOffset;
|
|
91
|
+
if (node.type.spec.mask) {
|
|
92
|
+
if (node.type.spec.mask.length === $pos.parentOffset && node.type.spec.mask.length === node.content.size) {
|
|
93
|
+
//Move to the next one
|
|
94
|
+
while ($pos.pos < state.doc.content.size - 1) {
|
|
95
|
+
$pos = state.doc.resolve($pos.pos + 1);
|
|
96
|
+
node = $pos.parent;
|
|
97
|
+
if (node && node.type.spec.mask) {
|
|
98
|
+
start = $pos.pos - $pos.parentOffset;
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return prosemirror_view_1.DecorationSet.create(state.doc, [
|
|
104
|
+
prosemirror_view_1.Decoration.node(start - 1, start - 1 + node.nodeSize, { class: "focused" })
|
|
105
|
+
]);
|
|
106
|
+
}
|
|
107
|
+
return undefined;
|
|
108
|
+
},
|
|
109
|
+
handleTextInput: (view, from, to, text) => {
|
|
110
|
+
if (view.composing)
|
|
111
|
+
return false;
|
|
112
|
+
const state = view.state;
|
|
113
|
+
const $from = state.doc.resolve(from);
|
|
114
|
+
const mask = $from.parent.type.spec.mask;
|
|
115
|
+
const regexp = $from.parent.type.spec.regexp;
|
|
116
|
+
if (!mask)
|
|
117
|
+
return false;
|
|
118
|
+
const tr = maskText($from, regexp && regexp.length ? text.split('').filter(x => x.match(new RegExp(regexp))).join('') : text, mask, state.tr);
|
|
119
|
+
if (tr) {
|
|
120
|
+
const tail = tr.getMeta('tailText');
|
|
121
|
+
if (tail === null || tail === void 0 ? void 0 : tail.length) {
|
|
122
|
+
const nextPos = tr.selection.$to.pos < tr.doc.content.size ? tr.doc.resolve(tr.selection.$to.pos + 1) : undefined;
|
|
123
|
+
if (nextPos) {
|
|
124
|
+
const nextNode = nextPos.node(nextPos.depth);
|
|
125
|
+
if (nextNode && nextNode.type.spec.mask && nextNode.type.spec.mask.length) {
|
|
126
|
+
maskText(nextPos, tail, nextNode.type.spec.mask, tr);
|
|
127
|
+
}
|
|
128
|
+
else if (nextNode && (nextNode.type.isText || nextNode.type.isTextblock)) {
|
|
129
|
+
tr.insertText(tail, nextPos.pos, nextPos.pos);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
view.dispatch(tr);
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
appendTransaction: (transactions, oldState, newState) => {
|
|
140
|
+
return applyDocMasks(newState);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.regexpPlugin = void 0;
|
|
4
|
+
const prosemirror_state_1 = require("prosemirror-state");
|
|
5
|
+
exports.regexpPlugin = () => {
|
|
6
|
+
return new prosemirror_state_1.Plugin({
|
|
7
|
+
props: {
|
|
8
|
+
handleTextInput: (view, from, to, text) => {
|
|
9
|
+
if (view.composing)
|
|
10
|
+
return false;
|
|
11
|
+
const state = view.state;
|
|
12
|
+
const $from = state.doc.resolve(from);
|
|
13
|
+
const mask = $from.parent.type.spec.mask;
|
|
14
|
+
const regexp = $from.parent.type.spec.regexp;
|
|
15
|
+
if (mask || !regexp)
|
|
16
|
+
return false; // Will be handled by mask plugin
|
|
17
|
+
const allowedCharacters = text.split('').filter(x => x.match(new RegExp(regexp))).join('');
|
|
18
|
+
if (allowedCharacters === text)
|
|
19
|
+
return false;
|
|
20
|
+
let tr = state.tr;
|
|
21
|
+
if (allowedCharacters.length) {
|
|
22
|
+
tr = tr.insertText(allowedCharacters, from, to);
|
|
23
|
+
tr = tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc, Math.min(to + allowedCharacters.length, tr.doc.content.size - 1)));
|
|
24
|
+
}
|
|
25
|
+
if (text.startsWith(allowedCharacters)) {
|
|
26
|
+
const tail = text.substring(allowedCharacters.length);
|
|
27
|
+
if (tail === null || tail === void 0 ? void 0 : tail.length) {
|
|
28
|
+
let posMark = tr.selection.$to.pos + 1;
|
|
29
|
+
while (posMark < tr.doc.content.size) {
|
|
30
|
+
const nextPos = tr.doc.resolve(posMark);
|
|
31
|
+
const nextNode = nextPos.node(nextPos.depth);
|
|
32
|
+
if (nextNode && (nextNode.type.isText || nextNode.type.isTextblock)) {
|
|
33
|
+
tr = tr.insertText(tail, nextPos.pos, nextPos.pos);
|
|
34
|
+
tr = tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc, Math.min(nextPos.pos + tail.length, tr.doc.content.size - 1)));
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
posMark++;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
view.dispatch(tr);
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { NodeType } from "prosemirror-model";
|
|
2
|
+
import { EditorState, Transaction } from "prosemirror-state";
|
|
3
|
+
export declare function wrapInIfNeeded(nodeType: NodeType, attrs?: any): (state: EditorState, dispatch?: ((tr: Transaction) => void) | undefined) => boolean;
|
|
4
|
+
export declare function unwrapFrom(nodeType: NodeType): (state: EditorState, dispatch?: ((tr: Transaction) => void) | undefined) => boolean;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unwrapFrom = exports.wrapInIfNeeded = void 0;
|
|
4
|
+
const prosemirror_transform_1 = require("prosemirror-transform");
|
|
5
|
+
const prosemirror_model_1 = require("prosemirror-model");
|
|
6
|
+
const prosemirror_state_1 = require("prosemirror-state");
|
|
7
|
+
// :: (NodeType, ?Object) → (state: EditorState, dispatch: ?(tr: Transaction)) → bool
|
|
8
|
+
// Wrap the selection in a node of the given type with the given
|
|
9
|
+
// attributes.
|
|
10
|
+
function wrapInIfNeeded(nodeType, attrs) {
|
|
11
|
+
return function (state, dispatch) {
|
|
12
|
+
var _a, _b;
|
|
13
|
+
const { $from, $to, to } = state.selection;
|
|
14
|
+
const range = $from.blockRange($to);
|
|
15
|
+
if (!range) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
let same = range.$from.sharedDepth(to);
|
|
19
|
+
if (same) {
|
|
20
|
+
const pos = $from.before(same);
|
|
21
|
+
if (((_b = (_a = prosemirror_state_1.NodeSelection.create(state.doc, pos).$from) === null || _a === void 0 ? void 0 : _a.node()) === null || _b === void 0 ? void 0 : _b.type) === nodeType) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const wrapping = range && prosemirror_transform_1.findWrapping(range, nodeType, attrs);
|
|
26
|
+
if (!wrapping)
|
|
27
|
+
return false;
|
|
28
|
+
if (dispatch)
|
|
29
|
+
dispatch(state.tr.wrap(range, wrapping).scrollIntoView());
|
|
30
|
+
return true;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
exports.wrapInIfNeeded = wrapInIfNeeded;
|
|
34
|
+
// :: (NodeType, ?Object) → (state: EditorState, dispatch: ?(tr: Transaction)) → bool
|
|
35
|
+
// Wrap the selection in a node of the given type with the given
|
|
36
|
+
// attributes.
|
|
37
|
+
function unwrapFrom(nodeType) {
|
|
38
|
+
return function (state, dispatch) {
|
|
39
|
+
const { $from, $to } = state.selection;
|
|
40
|
+
const range = $from.blockRange($to);
|
|
41
|
+
const depth = range && prosemirror_transform_1.liftTarget(range);
|
|
42
|
+
if (depth === null || depth === undefined) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
let gapStart = $from.before(depth + 1), gapEnd = $to.after(depth + 1);
|
|
46
|
+
const frag = prosemirror_model_1.Fragment.from($from.node());
|
|
47
|
+
if (dispatch)
|
|
48
|
+
dispatch(state.tr.replaceRange(gapStart, gapEnd, new prosemirror_model_1.Slice(frag, 0, 0)).scrollIntoView());
|
|
49
|
+
return true;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
exports.unwrapFrom = unwrapFrom;
|