kritzel-stencil 0.1.81 → 0.1.82
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/dist/cjs/index.cjs.js +1 -1
- package/dist/cjs/kritzel-active-users_42.cjs.entry.js +2 -2
- package/dist/cjs/{workspace.migrations-BVBITEM5.js → workspace.migrations-4HATwIMK.js} +37 -49
- package/dist/collection/classes/objects/shape.class.js +14 -20
- package/dist/collection/classes/objects/text.class.js +23 -29
- package/dist/collection/constants/version.js +1 -1
- package/dist/components/index.js +1 -1
- package/dist/components/kritzel-controls.js +1 -1
- package/dist/components/kritzel-editor.js +1 -1
- package/dist/components/kritzel-engine.js +1 -1
- package/dist/components/kritzel-settings.js +1 -1
- package/dist/components/kritzel-tool-config.js +1 -1
- package/dist/components/{p-D8jD4OI9.js → p-BPQOTise.js} +1 -1
- package/dist/components/{p-DXhiNQyH.js → p-C35iuSnC.js} +1 -1
- package/dist/components/{p-CwQOwQm0.js → p-CgtykATT.js} +2 -2
- package/dist/components/{p-Dxr5oLKF.js → p-DK_d3fKa.js} +1 -1
- package/dist/components/{p--7j0gU6F.js → p-DsfD4pGR.js} +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/kritzel-active-users_42.entry.js +2 -2
- package/dist/esm/{workspace.migrations-BVtbsm5p.js → workspace.migrations-Be65cOkQ.js} +37 -49
- package/dist/stencil/index.esm.js +1 -1
- package/dist/stencil/p-Be65cOkQ.js +1 -0
- package/dist/stencil/{p-56122555.entry.js → p-f318b7d5.entry.js} +2 -2
- package/dist/stencil/stencil.esm.js +1 -1
- package/dist/types/classes/objects/shape.class.d.ts +0 -1
- package/dist/types/classes/objects/text.class.d.ts +0 -1
- package/dist/types/constants/version.d.ts +1 -1
- package/package.json +1 -1
- package/dist/stencil/p-BVtbsm5p.js +0 -1
package/dist/cjs/index.cjs.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var index = require('./index-CFnj_FXt.js');
|
|
4
|
-
var workspace_migrations = require('./workspace.migrations-
|
|
4
|
+
var workspace_migrations = require('./workspace.migrations-4HATwIMK.js');
|
|
5
5
|
var Y = require('yjs');
|
|
6
6
|
require('y-websocket');
|
|
7
7
|
require('y-indexeddb');
|
|
@@ -28708,7 +28708,7 @@ const KritzelPortal = class {
|
|
|
28708
28708
|
* This file is auto-generated by the version bump scripts.
|
|
28709
28709
|
* Do not modify manually.
|
|
28710
28710
|
*/
|
|
28711
|
-
const KRITZEL_VERSION = '0.1.
|
|
28711
|
+
const KRITZEL_VERSION = '0.1.82';
|
|
28712
28712
|
|
|
28713
28713
|
const kritzelSettingsCss = () => `:host{display:contents}kritzel-dialog{--kritzel-dialog-body-padding:0;--kritzel-dialog-width-large:800px;--kritzel-dialog-height-large:500px}.footer-button{padding:8px 16px;border-radius:6px;cursor:pointer;font-size:14px}.cancel-button{border:1px solid #ebebeb;background:#fff;color:inherit}.cancel-button:hover{background:#f5f5f5}.settings-content{padding:0}.settings-content h3{margin:0 0 16px 0;font-size:18px;font-weight:600;color:var(--kritzel-settings-content-heading-color, #333333)}.settings-content p{margin:0;font-size:14px;color:var(--kritzel-settings-content-text-color, #666666);line-height:1.5}.settings-group{display:flex;flex-direction:column;gap:24px}.settings-item{display:flex;flex-direction:column;gap:8px}.settings-row{display:flex;align-items:center;justify-content:space-between;gap:16px}.settings-label{font-size:14px;font-weight:600;color:var(--kritzel-settings-label-color, #333333);margin:0 0 4px 0}.settings-description{font-size:12px;color:var(--kritzel-settings-description-color, #888888);margin:0;line-height:1.4}.shortcuts-list{display:flex;flex-direction:column;gap:24px}.shortcuts-category{display:flex;flex-direction:column;gap:8px}.shortcuts-category-title{font-size:14px;font-weight:600;color:var(--kritzel-settings-label-color, #333333);margin:0 0 4px 0}.shortcuts-group{display:flex;flex-direction:column;gap:4px}.shortcut-item{display:flex;justify-content:space-between;align-items:center;padding:6px 8px;border-radius:4px;background:var(--kritzel-settings-shortcut-item-bg, rgba(0, 0, 0, 0.02))}.shortcut-label{font-size:14px;color:var(--kritzel-settings-content-text-color, #666666)}.shortcut-key{font-family:monospace;font-size:12px;padding:2px 8px;border-radius:4px;background:var(--kritzel-settings-shortcut-key-bg, #f0f0f0);color:var(--kritzel-settings-shortcut-key-color, #333333);border:1px solid var(--kritzel-settings-shortcut-key-border, #ddd)}`;
|
|
28714
28714
|
|
|
@@ -15250,12 +15250,6 @@ class KritzelText extends KritzelBaseObject {
|
|
|
15250
15250
|
isEditing = false;
|
|
15251
15251
|
editor = null;
|
|
15252
15252
|
content = null;
|
|
15253
|
-
get _editor() {
|
|
15254
|
-
if (!this._editor) {
|
|
15255
|
-
throw new Error('KritzelShape: editor is not initialized');
|
|
15256
|
-
}
|
|
15257
|
-
return this._editor;
|
|
15258
|
-
}
|
|
15259
15253
|
_schema = new Schema({
|
|
15260
15254
|
nodes: addListNodes(schema.spec.nodes, 'paragraph block*', 'block'),
|
|
15261
15255
|
marks: schema.spec.marks,
|
|
@@ -15267,10 +15261,10 @@ class KritzelText extends KritzelBaseObject {
|
|
|
15267
15261
|
* @returns `true` if the editor is empty or contains only whitespace, `false` otherwise.
|
|
15268
15262
|
*/
|
|
15269
15263
|
get isEmpty() {
|
|
15270
|
-
if (!this.
|
|
15264
|
+
if (!this.editor) {
|
|
15271
15265
|
return true;
|
|
15272
15266
|
}
|
|
15273
|
-
const doc = this.
|
|
15267
|
+
const doc = this.editor.state.doc;
|
|
15274
15268
|
if (doc.content.size === 0) {
|
|
15275
15269
|
return true;
|
|
15276
15270
|
}
|
|
@@ -15374,7 +15368,7 @@ class KritzelText extends KritzelBaseObject {
|
|
|
15374
15368
|
element.style.fontFamily = this.fontFamily;
|
|
15375
15369
|
element.style.fontSize = `${this.fontSize}pt`;
|
|
15376
15370
|
element.style.color = KritzelColorHelper.resolveThemeColor(this.fontColor);
|
|
15377
|
-
if (this.isMounted && this.elementRef === element && this.
|
|
15371
|
+
if (this.isMounted && this.elementRef === element && this.editor.dom.parentElement === element) {
|
|
15378
15372
|
if (!this._core.store.state.isScaling && !this._core.store.state.isPanning) {
|
|
15379
15373
|
requestAnimationFrame(() => this.adjustSizeOnInput());
|
|
15380
15374
|
}
|
|
@@ -15384,7 +15378,7 @@ class KritzelText extends KritzelBaseObject {
|
|
|
15384
15378
|
this.elementRef.style.whiteSpace = 'pre-wrap';
|
|
15385
15379
|
this.elementRef.style.wordWrap = 'break-word';
|
|
15386
15380
|
this.elementRef.innerHTML = '';
|
|
15387
|
-
this.elementRef.appendChild(this.
|
|
15381
|
+
this.elementRef.appendChild(this.editor.dom);
|
|
15388
15382
|
this.isMounted = true;
|
|
15389
15383
|
requestAnimationFrame(() => this.adjustSizeOnInput());
|
|
15390
15384
|
}
|
|
@@ -15402,8 +15396,8 @@ class KritzelText extends KritzelBaseObject {
|
|
|
15402
15396
|
}),
|
|
15403
15397
|
editable: () => false,
|
|
15404
15398
|
dispatchTransaction: transaction => {
|
|
15405
|
-
const newState = this.
|
|
15406
|
-
this.
|
|
15399
|
+
const newState = this.editor.state.apply(transaction);
|
|
15400
|
+
this.editor.updateState(newState);
|
|
15407
15401
|
if (transaction.docChanged) {
|
|
15408
15402
|
this.content = newState.doc.toJSON();
|
|
15409
15403
|
this.adjustSizeOnInput();
|
|
@@ -15421,11 +15415,11 @@ class KritzelText extends KritzelBaseObject {
|
|
|
15421
15415
|
*/
|
|
15422
15416
|
setContent(content) {
|
|
15423
15417
|
this.content = content;
|
|
15424
|
-
if (this.
|
|
15425
|
-
const newDoc = this.
|
|
15426
|
-
const tr = this.
|
|
15418
|
+
if (this.editor && content) {
|
|
15419
|
+
const newDoc = this.editor.state.schema.nodeFromJSON(content);
|
|
15420
|
+
const tr = this.editor.state.tr.replaceWith(0, this.editor.state.doc.content.size, newDoc.content);
|
|
15427
15421
|
tr.setMeta('fromRemote', true);
|
|
15428
|
-
this.
|
|
15422
|
+
this.editor.dispatch(tr);
|
|
15429
15423
|
}
|
|
15430
15424
|
}
|
|
15431
15425
|
/**
|
|
@@ -15490,13 +15484,13 @@ class KritzelText extends KritzelBaseObject {
|
|
|
15490
15484
|
* @param coords.y - Y coordinate for cursor placement.
|
|
15491
15485
|
*/
|
|
15492
15486
|
focus(coords) {
|
|
15493
|
-
if (this.
|
|
15494
|
-
const doc = this.
|
|
15487
|
+
if (this.editor) {
|
|
15488
|
+
const doc = this.editor.state.doc;
|
|
15495
15489
|
if (coords.x && coords.y && !this.isEmpty) {
|
|
15496
|
-
const pos = this.
|
|
15490
|
+
const pos = this.editor.posAtCoords({ left: coords.x, top: coords.y });
|
|
15497
15491
|
if (pos) {
|
|
15498
|
-
this.
|
|
15499
|
-
this.
|
|
15492
|
+
this.editor.dispatch(this.editor.state.tr.setSelection(TextSelection.create(doc, pos.pos)));
|
|
15493
|
+
this.editor.focus();
|
|
15500
15494
|
if (KritzelDevicesHelper.isIOS()) {
|
|
15501
15495
|
this.scrollIntoViewOnIOS();
|
|
15502
15496
|
}
|
|
@@ -15504,8 +15498,8 @@ class KritzelText extends KritzelBaseObject {
|
|
|
15504
15498
|
}
|
|
15505
15499
|
}
|
|
15506
15500
|
const end = Math.max(1, doc.content.size - 1);
|
|
15507
|
-
this.
|
|
15508
|
-
this.
|
|
15501
|
+
this.editor.dispatch(this.editor.state.tr.setSelection(TextSelection.create(doc, end)));
|
|
15502
|
+
this.editor.focus();
|
|
15509
15503
|
if (KritzelDevicesHelper.isIOS()) {
|
|
15510
15504
|
this.scrollIntoViewOnIOS();
|
|
15511
15505
|
}
|
|
@@ -15517,8 +15511,8 @@ class KritzelText extends KritzelBaseObject {
|
|
|
15517
15511
|
*/
|
|
15518
15512
|
scrollIntoViewOnIOS() {
|
|
15519
15513
|
setTimeout(() => {
|
|
15520
|
-
if (this.
|
|
15521
|
-
this.
|
|
15514
|
+
if (this.editor && this.editor.dom) {
|
|
15515
|
+
this.editor.dom.scrollIntoView({
|
|
15522
15516
|
behavior: 'smooth',
|
|
15523
15517
|
block: 'center',
|
|
15524
15518
|
inline: 'nearest',
|
|
@@ -15536,7 +15530,7 @@ class KritzelText extends KritzelBaseObject {
|
|
|
15536
15530
|
KritzelKeyboardHelper.disableInteractiveWidget();
|
|
15537
15531
|
this.uneditedObject = this.clone();
|
|
15538
15532
|
this._core.store.setState('activeTool', KritzelToolRegistry.getTool('text'));
|
|
15539
|
-
this.
|
|
15533
|
+
this.editor.setProps({ editable: () => true });
|
|
15540
15534
|
this.isEditing = true;
|
|
15541
15535
|
this._core.rerender();
|
|
15542
15536
|
this.adjustSizeOnInput();
|
|
@@ -15552,9 +15546,9 @@ class KritzelText extends KritzelBaseObject {
|
|
|
15552
15546
|
*/
|
|
15553
15547
|
save() {
|
|
15554
15548
|
requestAnimationFrame(() => this.adjustSizeOnInput());
|
|
15555
|
-
this.content = this.
|
|
15556
|
-
this.
|
|
15557
|
-
this.
|
|
15549
|
+
this.content = this.editor.state.doc.toJSON();
|
|
15550
|
+
this.editor.setProps({ editable: () => false });
|
|
15551
|
+
this.editor.dom.blur();
|
|
15558
15552
|
this.isEditing = false;
|
|
15559
15553
|
this._core.store.objects.consolidateTemporaryItems();
|
|
15560
15554
|
this._core.store.objects.update(this);
|
|
@@ -17645,12 +17639,6 @@ class KritzelShape extends KritzelBaseObject {
|
|
|
17645
17639
|
get viewBox() {
|
|
17646
17640
|
return `${this.x} ${this.y} ${this.width} ${this.height}`;
|
|
17647
17641
|
}
|
|
17648
|
-
get _editor() {
|
|
17649
|
-
if (!this.editor) {
|
|
17650
|
-
throw new Error('KritzelShape: editor is not initialized');
|
|
17651
|
-
}
|
|
17652
|
-
return this.editor;
|
|
17653
|
-
}
|
|
17654
17642
|
/**
|
|
17655
17643
|
* Creates a new KritzelShape instance with optional configuration.
|
|
17656
17644
|
* This constructor initializes the shape with default values that can be
|
|
@@ -17758,7 +17746,7 @@ class KritzelShape extends KritzelBaseObject {
|
|
|
17758
17746
|
if (element === null || this.isInViewport() === false) {
|
|
17759
17747
|
return;
|
|
17760
17748
|
}
|
|
17761
|
-
if (this.isMounted && this.elementRef === element && this.
|
|
17749
|
+
if (this.isMounted && this.elementRef === element && this.editor.dom.parentElement === element) {
|
|
17762
17750
|
return;
|
|
17763
17751
|
}
|
|
17764
17752
|
this.elementRef = element;
|
|
@@ -17774,7 +17762,7 @@ class KritzelShape extends KritzelBaseObject {
|
|
|
17774
17762
|
* @returns void
|
|
17775
17763
|
*/
|
|
17776
17764
|
mountTextEditor(element) {
|
|
17777
|
-
if (element === null
|
|
17765
|
+
if (element === null) {
|
|
17778
17766
|
return;
|
|
17779
17767
|
}
|
|
17780
17768
|
element.style.fontFamily = this.fontFamily;
|
|
@@ -17805,8 +17793,8 @@ class KritzelShape extends KritzelBaseObject {
|
|
|
17805
17793
|
}),
|
|
17806
17794
|
editable: () => false,
|
|
17807
17795
|
dispatchTransaction: transaction => {
|
|
17808
|
-
const newState = this.
|
|
17809
|
-
this.
|
|
17796
|
+
const newState = this.editor.state.apply(transaction);
|
|
17797
|
+
this.editor.updateState(newState);
|
|
17810
17798
|
if (transaction.docChanged) {
|
|
17811
17799
|
this.content = newState.doc.toJSON();
|
|
17812
17800
|
if (!transaction.getMeta('fromRemote')) {
|
|
@@ -17868,12 +17856,12 @@ class KritzelShape extends KritzelBaseObject {
|
|
|
17868
17856
|
* @returns void
|
|
17869
17857
|
*/
|
|
17870
17858
|
focus(coords) {
|
|
17871
|
-
const doc = this.
|
|
17859
|
+
const doc = this.editor.state.doc;
|
|
17872
17860
|
if (coords?.x && coords?.y) {
|
|
17873
|
-
const pos = this.
|
|
17861
|
+
const pos = this.editor.posAtCoords({ left: coords.x, top: coords.y });
|
|
17874
17862
|
if (pos) {
|
|
17875
|
-
this.
|
|
17876
|
-
this.
|
|
17863
|
+
this.editor.dispatch(this.editor.state.tr.setSelection(TextSelection.create(doc, pos.pos)));
|
|
17864
|
+
this.editor.focus();
|
|
17877
17865
|
if (KritzelDevicesHelper.isIOS()) {
|
|
17878
17866
|
this.scrollIntoViewOnIOS();
|
|
17879
17867
|
}
|
|
@@ -17881,8 +17869,8 @@ class KritzelShape extends KritzelBaseObject {
|
|
|
17881
17869
|
}
|
|
17882
17870
|
}
|
|
17883
17871
|
const end = Math.max(1, doc.content.size - 1);
|
|
17884
|
-
this.
|
|
17885
|
-
this.
|
|
17872
|
+
this.editor.dispatch(this.editor.state.tr.setSelection(TextSelection.create(doc, end)));
|
|
17873
|
+
this.editor.focus();
|
|
17886
17874
|
if (KritzelDevicesHelper.isIOS()) {
|
|
17887
17875
|
this.scrollIntoViewOnIOS();
|
|
17888
17876
|
}
|
|
@@ -17920,7 +17908,7 @@ class KritzelShape extends KritzelBaseObject {
|
|
|
17920
17908
|
KritzelKeyboardHelper.disableInteractiveWidget();
|
|
17921
17909
|
this.uneditedObject = this.clone();
|
|
17922
17910
|
this._core.store.setState('activeTool', KritzelToolRegistry.getTool('shape'));
|
|
17923
|
-
this.
|
|
17911
|
+
this.editor.setProps({ editable: () => true });
|
|
17924
17912
|
this.isEditing = true;
|
|
17925
17913
|
this._core.rerender();
|
|
17926
17914
|
if (event?.clientX && event?.clientY) {
|
|
@@ -17937,9 +17925,9 @@ class KritzelShape extends KritzelBaseObject {
|
|
|
17937
17925
|
* @returns void
|
|
17938
17926
|
*/
|
|
17939
17927
|
save() {
|
|
17940
|
-
this.content = this.
|
|
17941
|
-
this.
|
|
17942
|
-
this.
|
|
17928
|
+
this.content = this.editor.state.doc.toJSON();
|
|
17929
|
+
this.editor.setProps({ editable: () => false });
|
|
17930
|
+
this.editor.dom.blur();
|
|
17943
17931
|
this.isEditing = false;
|
|
17944
17932
|
this._core.store.objects.consolidateTemporaryItems();
|
|
17945
17933
|
this._core.store.objects.update(this);
|
|
@@ -44,12 +44,6 @@ export class KritzelShape extends KritzelBaseObject {
|
|
|
44
44
|
get viewBox() {
|
|
45
45
|
return `${this.x} ${this.y} ${this.width} ${this.height}`;
|
|
46
46
|
}
|
|
47
|
-
get _editor() {
|
|
48
|
-
if (!this.editor) {
|
|
49
|
-
throw new Error('KritzelShape: editor is not initialized');
|
|
50
|
-
}
|
|
51
|
-
return this.editor;
|
|
52
|
-
}
|
|
53
47
|
/**
|
|
54
48
|
* Creates a new KritzelShape instance with optional configuration.
|
|
55
49
|
* This constructor initializes the shape with default values that can be
|
|
@@ -157,7 +151,7 @@ export class KritzelShape extends KritzelBaseObject {
|
|
|
157
151
|
if (element === null || this.isInViewport() === false) {
|
|
158
152
|
return;
|
|
159
153
|
}
|
|
160
|
-
if (this.isMounted && this.elementRef === element && this.
|
|
154
|
+
if (this.isMounted && this.elementRef === element && this.editor.dom.parentElement === element) {
|
|
161
155
|
return;
|
|
162
156
|
}
|
|
163
157
|
this.elementRef = element;
|
|
@@ -173,7 +167,7 @@ export class KritzelShape extends KritzelBaseObject {
|
|
|
173
167
|
* @returns void
|
|
174
168
|
*/
|
|
175
169
|
mountTextEditor(element) {
|
|
176
|
-
if (element === null
|
|
170
|
+
if (element === null) {
|
|
177
171
|
return;
|
|
178
172
|
}
|
|
179
173
|
element.style.fontFamily = this.fontFamily;
|
|
@@ -204,8 +198,8 @@ export class KritzelShape extends KritzelBaseObject {
|
|
|
204
198
|
}),
|
|
205
199
|
editable: () => false,
|
|
206
200
|
dispatchTransaction: transaction => {
|
|
207
|
-
const newState = this.
|
|
208
|
-
this.
|
|
201
|
+
const newState = this.editor.state.apply(transaction);
|
|
202
|
+
this.editor.updateState(newState);
|
|
209
203
|
if (transaction.docChanged) {
|
|
210
204
|
this.content = newState.doc.toJSON();
|
|
211
205
|
if (!transaction.getMeta('fromRemote')) {
|
|
@@ -267,12 +261,12 @@ export class KritzelShape extends KritzelBaseObject {
|
|
|
267
261
|
* @returns void
|
|
268
262
|
*/
|
|
269
263
|
focus(coords) {
|
|
270
|
-
const doc = this.
|
|
264
|
+
const doc = this.editor.state.doc;
|
|
271
265
|
if (coords?.x && coords?.y) {
|
|
272
|
-
const pos = this.
|
|
266
|
+
const pos = this.editor.posAtCoords({ left: coords.x, top: coords.y });
|
|
273
267
|
if (pos) {
|
|
274
|
-
this.
|
|
275
|
-
this.
|
|
268
|
+
this.editor.dispatch(this.editor.state.tr.setSelection(TextSelection.create(doc, pos.pos)));
|
|
269
|
+
this.editor.focus();
|
|
276
270
|
if (KritzelDevicesHelper.isIOS()) {
|
|
277
271
|
this.scrollIntoViewOnIOS();
|
|
278
272
|
}
|
|
@@ -280,8 +274,8 @@ export class KritzelShape extends KritzelBaseObject {
|
|
|
280
274
|
}
|
|
281
275
|
}
|
|
282
276
|
const end = Math.max(1, doc.content.size - 1);
|
|
283
|
-
this.
|
|
284
|
-
this.
|
|
277
|
+
this.editor.dispatch(this.editor.state.tr.setSelection(TextSelection.create(doc, end)));
|
|
278
|
+
this.editor.focus();
|
|
285
279
|
if (KritzelDevicesHelper.isIOS()) {
|
|
286
280
|
this.scrollIntoViewOnIOS();
|
|
287
281
|
}
|
|
@@ -319,7 +313,7 @@ export class KritzelShape extends KritzelBaseObject {
|
|
|
319
313
|
KritzelKeyboardHelper.disableInteractiveWidget();
|
|
320
314
|
this.uneditedObject = this.clone();
|
|
321
315
|
this._core.store.setState('activeTool', KritzelToolRegistry.getTool('shape'));
|
|
322
|
-
this.
|
|
316
|
+
this.editor.setProps({ editable: () => true });
|
|
323
317
|
this.isEditing = true;
|
|
324
318
|
this._core.rerender();
|
|
325
319
|
if (event?.clientX && event?.clientY) {
|
|
@@ -336,9 +330,9 @@ export class KritzelShape extends KritzelBaseObject {
|
|
|
336
330
|
* @returns void
|
|
337
331
|
*/
|
|
338
332
|
save() {
|
|
339
|
-
this.content = this.
|
|
340
|
-
this.
|
|
341
|
-
this.
|
|
333
|
+
this.content = this.editor.state.doc.toJSON();
|
|
334
|
+
this.editor.setProps({ editable: () => false });
|
|
335
|
+
this.editor.dom.blur();
|
|
342
336
|
this.isEditing = false;
|
|
343
337
|
this._core.store.objects.consolidateTemporaryItems();
|
|
344
338
|
this._core.store.objects.update(this);
|
|
@@ -28,12 +28,6 @@ export class KritzelText extends KritzelBaseObject {
|
|
|
28
28
|
isEditing = false;
|
|
29
29
|
editor = null;
|
|
30
30
|
content = null;
|
|
31
|
-
get _editor() {
|
|
32
|
-
if (!this._editor) {
|
|
33
|
-
throw new Error('KritzelShape: editor is not initialized');
|
|
34
|
-
}
|
|
35
|
-
return this._editor;
|
|
36
|
-
}
|
|
37
31
|
_schema = new Schema({
|
|
38
32
|
nodes: addListNodes(schema.spec.nodes, 'paragraph block*', 'block'),
|
|
39
33
|
marks: schema.spec.marks,
|
|
@@ -45,10 +39,10 @@ export class KritzelText extends KritzelBaseObject {
|
|
|
45
39
|
* @returns `true` if the editor is empty or contains only whitespace, `false` otherwise.
|
|
46
40
|
*/
|
|
47
41
|
get isEmpty() {
|
|
48
|
-
if (!this.
|
|
42
|
+
if (!this.editor) {
|
|
49
43
|
return true;
|
|
50
44
|
}
|
|
51
|
-
const doc = this.
|
|
45
|
+
const doc = this.editor.state.doc;
|
|
52
46
|
if (doc.content.size === 0) {
|
|
53
47
|
return true;
|
|
54
48
|
}
|
|
@@ -152,7 +146,7 @@ export class KritzelText extends KritzelBaseObject {
|
|
|
152
146
|
element.style.fontFamily = this.fontFamily;
|
|
153
147
|
element.style.fontSize = `${this.fontSize}pt`;
|
|
154
148
|
element.style.color = KritzelColorHelper.resolveThemeColor(this.fontColor);
|
|
155
|
-
if (this.isMounted && this.elementRef === element && this.
|
|
149
|
+
if (this.isMounted && this.elementRef === element && this.editor.dom.parentElement === element) {
|
|
156
150
|
if (!this._core.store.state.isScaling && !this._core.store.state.isPanning) {
|
|
157
151
|
requestAnimationFrame(() => this.adjustSizeOnInput());
|
|
158
152
|
}
|
|
@@ -162,7 +156,7 @@ export class KritzelText extends KritzelBaseObject {
|
|
|
162
156
|
this.elementRef.style.whiteSpace = 'pre-wrap';
|
|
163
157
|
this.elementRef.style.wordWrap = 'break-word';
|
|
164
158
|
this.elementRef.innerHTML = '';
|
|
165
|
-
this.elementRef.appendChild(this.
|
|
159
|
+
this.elementRef.appendChild(this.editor.dom);
|
|
166
160
|
this.isMounted = true;
|
|
167
161
|
requestAnimationFrame(() => this.adjustSizeOnInput());
|
|
168
162
|
}
|
|
@@ -180,8 +174,8 @@ export class KritzelText extends KritzelBaseObject {
|
|
|
180
174
|
}),
|
|
181
175
|
editable: () => false,
|
|
182
176
|
dispatchTransaction: transaction => {
|
|
183
|
-
const newState = this.
|
|
184
|
-
this.
|
|
177
|
+
const newState = this.editor.state.apply(transaction);
|
|
178
|
+
this.editor.updateState(newState);
|
|
185
179
|
if (transaction.docChanged) {
|
|
186
180
|
this.content = newState.doc.toJSON();
|
|
187
181
|
this.adjustSizeOnInput();
|
|
@@ -199,11 +193,11 @@ export class KritzelText extends KritzelBaseObject {
|
|
|
199
193
|
*/
|
|
200
194
|
setContent(content) {
|
|
201
195
|
this.content = content;
|
|
202
|
-
if (this.
|
|
203
|
-
const newDoc = this.
|
|
204
|
-
const tr = this.
|
|
196
|
+
if (this.editor && content) {
|
|
197
|
+
const newDoc = this.editor.state.schema.nodeFromJSON(content);
|
|
198
|
+
const tr = this.editor.state.tr.replaceWith(0, this.editor.state.doc.content.size, newDoc.content);
|
|
205
199
|
tr.setMeta('fromRemote', true);
|
|
206
|
-
this.
|
|
200
|
+
this.editor.dispatch(tr);
|
|
207
201
|
}
|
|
208
202
|
}
|
|
209
203
|
/**
|
|
@@ -268,13 +262,13 @@ export class KritzelText extends KritzelBaseObject {
|
|
|
268
262
|
* @param coords.y - Y coordinate for cursor placement.
|
|
269
263
|
*/
|
|
270
264
|
focus(coords) {
|
|
271
|
-
if (this.
|
|
272
|
-
const doc = this.
|
|
265
|
+
if (this.editor) {
|
|
266
|
+
const doc = this.editor.state.doc;
|
|
273
267
|
if (coords.x && coords.y && !this.isEmpty) {
|
|
274
|
-
const pos = this.
|
|
268
|
+
const pos = this.editor.posAtCoords({ left: coords.x, top: coords.y });
|
|
275
269
|
if (pos) {
|
|
276
|
-
this.
|
|
277
|
-
this.
|
|
270
|
+
this.editor.dispatch(this.editor.state.tr.setSelection(TextSelection.create(doc, pos.pos)));
|
|
271
|
+
this.editor.focus();
|
|
278
272
|
if (KritzelDevicesHelper.isIOS()) {
|
|
279
273
|
this.scrollIntoViewOnIOS();
|
|
280
274
|
}
|
|
@@ -282,8 +276,8 @@ export class KritzelText extends KritzelBaseObject {
|
|
|
282
276
|
}
|
|
283
277
|
}
|
|
284
278
|
const end = Math.max(1, doc.content.size - 1);
|
|
285
|
-
this.
|
|
286
|
-
this.
|
|
279
|
+
this.editor.dispatch(this.editor.state.tr.setSelection(TextSelection.create(doc, end)));
|
|
280
|
+
this.editor.focus();
|
|
287
281
|
if (KritzelDevicesHelper.isIOS()) {
|
|
288
282
|
this.scrollIntoViewOnIOS();
|
|
289
283
|
}
|
|
@@ -295,8 +289,8 @@ export class KritzelText extends KritzelBaseObject {
|
|
|
295
289
|
*/
|
|
296
290
|
scrollIntoViewOnIOS() {
|
|
297
291
|
setTimeout(() => {
|
|
298
|
-
if (this.
|
|
299
|
-
this.
|
|
292
|
+
if (this.editor && this.editor.dom) {
|
|
293
|
+
this.editor.dom.scrollIntoView({
|
|
300
294
|
behavior: 'smooth',
|
|
301
295
|
block: 'center',
|
|
302
296
|
inline: 'nearest',
|
|
@@ -314,7 +308,7 @@ export class KritzelText extends KritzelBaseObject {
|
|
|
314
308
|
KritzelKeyboardHelper.disableInteractiveWidget();
|
|
315
309
|
this.uneditedObject = this.clone();
|
|
316
310
|
this._core.store.setState('activeTool', KritzelToolRegistry.getTool('text'));
|
|
317
|
-
this.
|
|
311
|
+
this.editor.setProps({ editable: () => true });
|
|
318
312
|
this.isEditing = true;
|
|
319
313
|
this._core.rerender();
|
|
320
314
|
this.adjustSizeOnInput();
|
|
@@ -330,9 +324,9 @@ export class KritzelText extends KritzelBaseObject {
|
|
|
330
324
|
*/
|
|
331
325
|
save() {
|
|
332
326
|
requestAnimationFrame(() => this.adjustSizeOnInput());
|
|
333
|
-
this.content = this.
|
|
334
|
-
this.
|
|
335
|
-
this.
|
|
327
|
+
this.content = this.editor.state.doc.toJSON();
|
|
328
|
+
this.editor.setProps({ editable: () => false });
|
|
329
|
+
this.editor.dom.blur();
|
|
336
330
|
this.isEditing = false;
|
|
337
331
|
this._core.store.objects.consolidateTemporaryItems();
|
|
338
332
|
this._core.store.objects.update(this);
|
package/dist/components/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{g as getAssetPath,r as render,s as setAssetPath,a as setNonce,b as setPlatformOptions}from"./p-BWj1eE2b.js";export{d as KritzelBrushTool,b as KritzelGroup,a as KritzelImage,e as KritzelLineTool,h as KritzelSelectionTool,c as KritzelShape,g as KritzelShapeTool,K as KritzelText,f as KritzelTextTool,S as ShapeType}from"./p-
|
|
1
|
+
export{g as getAssetPath,r as render,s as setAssetPath,a as setNonce,b as setPlatformOptions}from"./p-BWj1eE2b.js";export{d as KritzelBrushTool,b as KritzelGroup,a as KritzelImage,e as KritzelLineTool,h as KritzelSelectionTool,c as KritzelShape,g as KritzelShapeTool,K as KritzelText,f as KritzelTextTool,S as ShapeType}from"./p-BPQOTise.js";export{a as KritzelLine,K as KritzelPath}from"./p-DQK_4lkI.js";export{A as APP_STATE_MIGRATIONS,I as IndexedDBSyncProvider,d as KritzelAlignment,c as KritzelAnchorManager,b as KritzelCursorHelper,K as KritzelEraserTool,a as KritzelImageTool,W as WORKSPACE_MIGRATIONS,r as runMigrations}from"./p-CgtykATT.js";import*as t from"yjs";import{WebsocketProvider as i}from"y-websocket";export{D as DEFAULT_BRUSH_CONFIG,b as DEFAULT_LINE_TOOL_CONFIG,a as DEFAULT_TEXT_CONFIG,H as HocuspocusSyncProvider,KritzelEditor,defineCustomElement as defineCustomElementKritzelEditor}from"./kritzel-editor.js";export{K as KritzelWorkspace,W as WORKSPACE_EXPORT_VERSION}from"./p-DhMlShij.js";export{K as KritzelThemeManager,d as darkTheme,l as lightTheme}from"./p-CjazGGq3.js";export{C as CURRENT_APP_STATE_SCHEMA_VERSION,a as CURRENT_WORKSPACE_SCHEMA_VERSION}from"./p-CW-VyJgK.js";export{KritzelActiveUsers,defineCustomElement as defineCustomElementKritzelActiveUsers}from"./kritzel-active-users.js";export{KritzelAvatar,defineCustomElement as defineCustomElementKritzelAvatar}from"./kritzel-avatar.js";export{KritzelAwarenessCursors,defineCustomElement as defineCustomElementKritzelAwarenessCursors}from"./kritzel-awareness-cursors.js";export{KritzelBackToContent,defineCustomElement as defineCustomElementKritzelBackToContent}from"./kritzel-back-to-content.js";export{KritzelBrushStyle,defineCustomElement as defineCustomElementKritzelBrushStyle}from"./kritzel-brush-style.js";export{KritzelButton,defineCustomElement as defineCustomElementKritzelButton}from"./kritzel-button.js";export{KritzelColor,defineCustomElement as defineCustomElementKritzelColor}from"./kritzel-color.js";export{KritzelColorPalette,defineCustomElement as defineCustomElementKritzelColorPalette}from"./kritzel-color-palette.js";export{KritzelContextMenu,defineCustomElement as defineCustomElementKritzelContextMenu}from"./kritzel-context-menu.js";export{KritzelControls,defineCustomElement as defineCustomElementKritzelControls}from"./kritzel-controls.js";export{KritzelCurrentUser,defineCustomElement as defineCustomElementKritzelCurrentUser}from"./kritzel-current-user.js";export{KritzelCurrentUserDialog,defineCustomElement as defineCustomElementKritzelCurrentUserDialog}from"./kritzel-current-user-dialog.js";export{KritzelCursorTrail,defineCustomElement as defineCustomElementKritzelCursorTrail}from"./kritzel-cursor-trail.js";export{KritzelDialog,defineCustomElement as defineCustomElementKritzelDialog}from"./kritzel-dialog.js";export{KritzelDropdown,defineCustomElement as defineCustomElementKritzelDropdown}from"./kritzel-dropdown.js";export{KritzelEngine,defineCustomElement as defineCustomElementKritzelEngine}from"./kritzel-engine.js";export{KritzelExport,defineCustomElement as defineCustomElementKritzelExport}from"./kritzel-export.js";export{KritzelFont,defineCustomElement as defineCustomElementKritzelFont}from"./kritzel-font.js";export{KritzelFontFamily,defineCustomElement as defineCustomElementKritzelFontFamily}from"./kritzel-font-family.js";export{KritzelFontSize,defineCustomElement as defineCustomElementKritzelFontSize}from"./kritzel-font-size.js";export{KritzelIcon,defineCustomElement as defineCustomElementKritzelIcon}from"./kritzel-icon.js";export{KritzelInput,defineCustomElement as defineCustomElementKritzelInput}from"./kritzel-input.js";export{KritzelLineEndings,defineCustomElement as defineCustomElementKritzelLineEndings}from"./kritzel-line-endings.js";export{KritzelLoginDialog,defineCustomElement as defineCustomElementKritzelLoginDialog}from"./kritzel-login-dialog.js";export{KritzelMasterDetail,defineCustomElement as defineCustomElementKritzelMasterDetail}from"./kritzel-master-detail.js";export{KritzelMenu,defineCustomElement as defineCustomElementKritzelMenu}from"./kritzel-menu.js";export{KritzelMenuItem,defineCustomElement as defineCustomElementKritzelMenuItem}from"./kritzel-menu-item.js";export{KritzelMoreMenu,defineCustomElement as defineCustomElementKritzelMoreMenu}from"./kritzel-more-menu.js";export{KritzelNumericInput,defineCustomElement as defineCustomElementKritzelNumericInput}from"./kritzel-numeric-input.js";export{KritzelOpacitySlider,defineCustomElement as defineCustomElementKritzelOpacitySlider}from"./kritzel-opacity-slider.js";export{KritzelPillTabs,defineCustomElement as defineCustomElementKritzelPillTabs}from"./kritzel-pill-tabs.js";export{KritzelPortal,defineCustomElement as defineCustomElementKritzelPortal}from"./kritzel-portal.js";export{KritzelSettings,defineCustomElement as defineCustomElementKritzelSettings}from"./kritzel-settings.js";export{KritzelShapeFill,defineCustomElement as defineCustomElementKritzelShapeFill}from"./kritzel-shape-fill.js";export{KritzelShareDialog,defineCustomElement as defineCustomElementKritzelShareDialog}from"./kritzel-share-dialog.js";export{KritzelSlideToggle,defineCustomElement as defineCustomElementKritzelSlideToggle}from"./kritzel-slide-toggle.js";export{KritzelSplitButton,defineCustomElement as defineCustomElementKritzelSplitButton}from"./kritzel-split-button.js";export{KritzelStrokeSize,defineCustomElement as defineCustomElementKritzelStrokeSize}from"./kritzel-stroke-size.js";export{KritzelToolConfig,defineCustomElement as defineCustomElementKritzelToolConfig}from"./kritzel-tool-config.js";export{KritzelTooltip,defineCustomElement as defineCustomElementKritzelTooltip}from"./kritzel-tooltip.js";export{KritzelUtilityPanel,defineCustomElement as defineCustomElementKritzelUtilityPanel}from"./kritzel-utility-panel.js";export{KritzelWorkspaceManager,defineCustomElement as defineCustomElementKritzelWorkspaceManager}from"./kritzel-workspace-manager.js";const o=Math.floor,n=127,m=Number.MAX_SAFE_INTEGER;class u{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const z=()=>new u,E=e=>{const t=new Uint8Array((e=>{let t=e.cpos;for(let r=0;r<e.bufs.length;r++)t+=e.bufs[r].length;return t})(e));let r=0;for(let s=0;s<e.bufs.length;s++){const i=e.bufs[s];t.set(i,r),r+=i.length}return t.set(new Uint8Array(e.cbuf.buffer,0,e.cpos),r),t},p=(e,t)=>{const r=e.cbuf.length;e.cpos===r&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(2*r),e.cpos=0),e.cbuf[e.cpos++]=t},k=(e,t)=>{for(;t>n;)p(e,128|n&t),t=o(t/128);p(e,n&t)},x=(e,t)=>{k(e,t.byteLength),((e,t)=>{const r=e.cbuf.length,s=e.cpos,i=((e,t)=>e<t?e:t)(r-s,t.length),o=t.length-i;e.cbuf.set(t.subarray(0,i),s),e.cpos+=i,o>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(((e,t)=>e>t?e:t)(2*r,o)),e.cbuf.set(t.subarray(i)),e.cpos=o)})(e,t)},j=e=>Error(e),T=j("Unexpected end of array"),y=j("Integer out of Range");class w{constructor(e){this.arr=e,this.pos=0}}const P=e=>((e,t)=>{const r=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,r})(e,M(e)),M=e=>{let t=0,r=1;const s=e.arr.length;for(;e.pos<s;){const s=e.arr[e.pos++];if(t+=(s&n)*r,r*=128,s<128)return t;if(t>m)throw y}throw T};class U{type="local";doc;channel;_synced=!1;constructor(e,t,r){this.doc=t,this.channel=new BroadcastChannel(e),this.channel.onmessage=e=>{this.handleMessage(e.data)},this.doc.on("update",this.handleDocUpdate),this.broadcastSync(),setTimeout((()=>{this._synced=!0}),100),r?.quiet||console.info("BroadcastChannel Provider initialized: "+e)}handleDocUpdate=(e,t)=>{if(t!==this){const t=z();k(t,0),x(t,e),this.channel.postMessage(E(t))}};handleMessage(e){const r=(e=>new w(e))(new Uint8Array(e));switch(M(r)){case 0:const e=P(r);t.applyUpdate(this.doc,e,this);break;case 1:this.broadcastSync();break;case 2:const s=P(r),i=t.encodeStateAsUpdate(this.doc,s);if(i.length>0){const e=z();k(e,0),x(e,i),this.channel.postMessage(E(e))}}}broadcastSync(){const e=z();k(e,2),x(e,t.encodeStateVector(this.doc)),this.channel.postMessage(E(e))}async connect(){if(!this._synced)return new Promise((e=>{const t=()=>{this._synced?e():setTimeout(t,50)};t()}))}disconnect(){}async reconnect(){return this.disconnect(),this.connect()}destroy(){this.doc.off("update",this.handleDocUpdate),this.channel.close()}}class _{type="network";provider;isConnected=!1;_quiet=!1;get awareness(){return this.provider.awareness}constructor(e,t,r){const s=r?.url||"ws://localhost:1234",o=r?.roomName||e;this.provider=new i(s,o,t,{params:r?.params,protocols:r?.protocols,WebSocketPolyfill:r?.WebSocketPolyfill,awareness:r?.awareness,maxBackoffTime:r?.maxBackoffTime,disableBc:!0}),this._quiet=r?.quiet??!1,this.setupEventListeners(),this._quiet||console.info(`WebSocket Provider initialized: ${s}/${o}`)}static with(e){return{create:(t,r,s)=>{const i=s?{...e,...s}:e;return new _(t,r,i)}}}setupEventListeners(){this.provider.on("status",(({status:e})=>{"connected"===e?(this.isConnected=!0,this._quiet||console.info("WebSocket connected")):"disconnected"===e&&(this.isConnected=!1,this._quiet||console.info("WebSocket disconnected"))})),this.provider.on("sync",(e=>{e&&!this._quiet&&console.info("WebSocket synced")}))}async connect(){if(!this.isConnected)return new Promise(((e,t)=>{const r=setTimeout((()=>{t(Error("WebSocket connection timeout"))}),1e4),s=({status:t})=>{"connected"===t&&(clearTimeout(r),this.provider.off("status",s),this.isConnected=!0,e())};this.provider.on("status",s),this.provider.wsconnected&&(clearTimeout(r),this.provider.off("status",s),this.isConnected=!0,e())}))}disconnect(){this.provider&&this.provider.disconnect(),this.isConnected=!1}async reconnect(){return this.disconnect(),this.connect()}destroy(){this.provider&&this.provider.destroy(),this.isConnected=!1}}export{U as BroadcastSyncProvider,_ as WebSocketSyncProvider}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{K as o,d as s}from"./p-
|
|
1
|
+
import{K as o,d as s}from"./p-C35iuSnC.js";const p=o,r=s;export{p as KritzelControls,r as defineCustomElement}
|