@textbus/xnote 0.0.10 → 0.1.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.
@@ -1,7 +1,8 @@
1
1
  import { jsxs, jsx, Fragment } from '@viewfly/core/jsx-runtime';
2
2
  import { withScopedCSS } from '@viewfly/scoped-css';
3
- import { Injectable, InjectFlags, Injector, inject, createSignal, onUnmounted, createRef, withAnnotation, onUpdated, onMounted, InjectionToken, getCurrentInstance, ReflectiveInjector, createDynamicRef, jsx as jsx$1, viewfly, Fragment as Fragment$1, watch } from '@viewfly/core';
4
- import { Subject, Selection, fromEvent, Subscription, Attribute, Keyboard, Commander, Controller, useContext, onBreak, onContentInsert, ContentType, merge, createVNode, Slot, Component, Registry, Query, QueryStateType, BehaviorSubject, onSlotApplyFormat, onSlotSetAttribute, onPaste, onFocus, onBlur, useDynamicShortcut, VTextNode, onFocusIn, onFocusOut, onDestroy, onGetRanges, Formatter, onParentSlotUpdated, Textbus, RootComponentRef, filter, map, distinctUntilChanged, sampleTime, debounceTime, throttleTime, delay, onContentInserted, onContentDeleted, switchMap, fromPromise, onCompositionStart } from '@textbus/core';
3
+ import { Injectable, InjectFlags, Injector, inject, createSignal, onUnmounted, getCurrentInstance, createRef, withAnnotation, onUpdated, onMounted, InjectionToken, ReflectiveInjector, createDynamicRef, jsx as jsx$1, viewfly, Fragment as Fragment$1, watch } from '@viewfly/core';
4
+ import { Subject, fromEvent, Selection, Subscription, Attribute, Keyboard, Commander, Controller, useContext, onBreak, onContentInsert, ContentType, merge, createVNode, Slot, Component, Registry, Query, QueryStateType, BehaviorSubject, onSlotApplyFormat, onSlotSetAttribute, onPaste, onFocus, onBlur, useDynamicShortcut, VTextNode, onFocusIn, onFocusOut, onDestroy, onGetRanges, Formatter, onParentSlotUpdated, Textbus, RootComponentRef, filter, map, distinctUntilChanged, sampleTime, debounceTime, throttleTime, delay, onContentInserted, onContentDeleted, switchMap, fromPromise, onCompositionStart } from '@textbus/core';
5
+ import { normalizeHex, hex2Hsl, hex2Rgb, hex2Hsv, hsl2Hex, hsl2Hsv, hsl2Rgb, rgb2Hsl, rgb2Hex, rgb2Hsv, hsv2Hex, hsv2Hsl, hsv2Rgb, any2Hsl, parseCss } from '@tanbo/color';
5
6
  import { VIEW_CONTAINER, isMac, DomAdapter, Input, SelectionBridge, BrowserModule, VIEW_DOCUMENT, CollaborateSelectionAwarenessDelegate, isMobileBrowser, CollaborateCursor, Parser } from '@textbus/platform-browser';
6
7
  import { createPortal, createApp, DomRenderer, HTMLRenderer, OutputTranslator } from '@viewfly/platform-browser';
7
8
  import { useProduce } from '@viewfly/hooks';
@@ -9,10 +10,9 @@ import highlightjs from 'highlight.js';
9
10
  import { v4 } from 'uuid';
10
11
  import Katex from 'katex';
11
12
  import { ViewflyAdapter, ViewflyVDomAdapter } from '@textbus/adapter-viewfly';
12
- import { any2Hsl, hsl2Rgb } from '@tanbo/color';
13
13
  import { MessageBus, CollaborateModule } from '@textbus/collaborate';
14
14
 
15
- var scopedId$n = "vf-d94b56";
15
+ var scopedId$o = "vf-d94b56";
16
16
 
17
17
  /******************************************************************************
18
18
  Copyright (c) Microsoft Corporation.
@@ -145,7 +145,7 @@ function Button(props) {
145
145
  subscription.unsubscribe();
146
146
  });
147
147
  }
148
- return withScopedCSS(scopedId$n, () => {
148
+ return withScopedCSS(scopedId$o, () => {
149
149
  return (jsxs("button", Object.assign({ type: "button" }, props, { class: [
150
150
  'btn',
151
151
  {
@@ -157,6 +157,346 @@ function Button(props) {
157
157
  });
158
158
  }
159
159
 
160
+ var scopedId$n = "vf-d552b9";
161
+
162
+ class Picker {
163
+ set hex(color) {
164
+ var _a;
165
+ const c = color ? normalizeHex(color) : null;
166
+ if (c) {
167
+ this.empty = false;
168
+ this._hex = c;
169
+ this._hsl = hex2Hsl(c);
170
+ this._rgb = hex2Rgb(c);
171
+ this._hsv = hex2Hsv(c);
172
+ this._rgba = Object.assign(Object.assign({}, this._rgb), { a: this.resetAlpha ? 1 : ((_a = this._rgba) === null || _a === void 0 ? void 0 : _a.a) || 1 });
173
+ }
174
+ else {
175
+ this.empty = true;
176
+ }
177
+ this.resetAlpha = true;
178
+ this.onChange();
179
+ }
180
+ get hex() {
181
+ return this.empty ? null : this._hex;
182
+ }
183
+ set hsl(color) {
184
+ var _a;
185
+ if (!color || typeof color.h !== 'number' || typeof color.s !== 'number' || typeof color.l !== 'number') {
186
+ this.empty = true;
187
+ }
188
+ else {
189
+ this.empty = false;
190
+ this._hsl = color;
191
+ this._hex = hsl2Hex(color);
192
+ this._hsv = hsl2Hsv(color);
193
+ this._rgb = hsl2Rgb(color);
194
+ this._rgba = Object.assign(Object.assign({}, this._rgb), { a: this.resetAlpha ? 1 : ((_a = this._rgba) === null || _a === void 0 ? void 0 : _a.a) || 1 });
195
+ }
196
+ this.resetAlpha = true;
197
+ this.onChange();
198
+ }
199
+ get hsl() {
200
+ return this.empty ? null : this._hsl;
201
+ }
202
+ set rgb(color) {
203
+ var _a;
204
+ if (!color || typeof color.r !== 'number' || typeof color.g !== 'number' || typeof color.b !== 'number') {
205
+ this.empty = true;
206
+ }
207
+ else {
208
+ this.empty = false;
209
+ this._rgb = color;
210
+ this._rgba = Object.assign(Object.assign({}, color), { a: this.resetAlpha ? 1 : ((_a = this._rgba) === null || _a === void 0 ? void 0 : _a.a) || 1 });
211
+ this._hsl = rgb2Hsl(color);
212
+ this._hex = rgb2Hex(color);
213
+ this._hsv = rgb2Hsv(color);
214
+ }
215
+ this.resetAlpha = true;
216
+ this.onChange();
217
+ }
218
+ get rgb() {
219
+ return this.empty ? null : this._rgb;
220
+ }
221
+ set rgba(color) {
222
+ if (!color ||
223
+ typeof color.r !== 'number' ||
224
+ typeof color.g !== 'number' ||
225
+ typeof color.b !== 'number' ||
226
+ typeof color.a !== 'number') {
227
+ this.empty = true;
228
+ }
229
+ else {
230
+ this.empty = false;
231
+ this._rgba = color;
232
+ this._hsl = rgb2Hsl(color);
233
+ this._hex = rgb2Hex(color);
234
+ this._hsv = rgb2Hsv(color);
235
+ }
236
+ this.onChange();
237
+ }
238
+ get rgba() {
239
+ return this.empty ? null : this._rgba;
240
+ }
241
+ set hsv(color) {
242
+ var _a;
243
+ if (!color || typeof color.h !== 'number' || typeof color.s !== 'number' || typeof color.v !== 'number') {
244
+ this.empty = true;
245
+ }
246
+ else {
247
+ this.empty = false;
248
+ this._hsv = color;
249
+ this._hex = hsv2Hex(color);
250
+ this._hsl = hsv2Hsl(color);
251
+ this._rgb = hsv2Rgb(color);
252
+ this._rgba = Object.assign(Object.assign({}, this._rgb), { a: this.resetAlpha ? 1 : ((_a = this._rgba) === null || _a === void 0 ? void 0 : _a.a) || 1 });
253
+ }
254
+ this.resetAlpha = true;
255
+ this.onChange();
256
+ }
257
+ get hsv() {
258
+ return this.empty ? null : this._hsv;
259
+ }
260
+ constructor(onChange, value) {
261
+ this.onChange = onChange;
262
+ this._hex = '';
263
+ this._hsl = null;
264
+ this._rgb = null;
265
+ this._hsv = null;
266
+ this._rgba = null;
267
+ this.empty = false;
268
+ this.resetAlpha = true;
269
+ this.hex = value || '#f00';
270
+ }
271
+ }
272
+ const recentColors = createSignal([]);
273
+ function ColorPicker(props) {
274
+ const instance = getCurrentInstance();
275
+ const picker = new Picker(() => {
276
+ instance.markAsDirtied();
277
+ }, props.value);
278
+ const mainColors = [
279
+ '#000', '#333', '#444', '#555', '#666', '#777', '#888',
280
+ '#999', '#aaa', '#bbb', '#ccc', '#ddd', '#eee', '#fff',
281
+ ];
282
+ const colors = [
283
+ '#fec6c2', '#fee5c3', '#fefcc3', '#baf6c4', '#c3ebfe', '#c3cbfe', '#e1caff',
284
+ '#fc8e88', '#fccc88', '#fcf888', '#76ec8a', '#88d8fc', '#97a4fb', '#c098f4',
285
+ '#ff6666', '#ffb151', '#fada3a', '#18c937', '#3aaafa', '#6373e2', '#a669f7',
286
+ '#f63030', '#f88933', '#deb12a', '#038e23', '#1276cc', '#3f52ce', '#8838ed',
287
+ '#c60000', '#d86912', '#b88811', '#086508', '#144c93', '#1b2eaa', '#6117bf',
288
+ ];
289
+ function addRecentColor() {
290
+ const color = picker.hex;
291
+ if (!color) {
292
+ return;
293
+ }
294
+ const colors = recentColors().filter(item => {
295
+ return item !== color;
296
+ });
297
+ colors.unshift(color);
298
+ if (colors.length >= 7) {
299
+ colors.length = 7;
300
+ }
301
+ recentColors.set(colors);
302
+ }
303
+ const paletteRef = createRef();
304
+ function bindPaletteEvent(ev) {
305
+ const update = (ev) => {
306
+ var _a;
307
+ const position = paletteRef.current.getBoundingClientRect();
308
+ const offsetX = ev.clientX - position.left;
309
+ const offsetY = ev.clientY - position.top;
310
+ let s = offsetX / 130 * 100;
311
+ let v = 100 - offsetY / 130 * 100;
312
+ s = Math.max(0, s);
313
+ s = Math.min(100, s);
314
+ v = Math.max(0, v);
315
+ v = Math.min(100, v);
316
+ picker.resetAlpha = false;
317
+ picker.hsv = {
318
+ h: picker.hsv.h,
319
+ s,
320
+ v
321
+ };
322
+ (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, picker);
323
+ };
324
+ update(ev);
325
+ const unMouseMove = fromEvent(document, 'mousemove').subscribe(ev => {
326
+ update(ev);
327
+ });
328
+ const unMouseUp = fromEvent(document, 'mouseup').subscribe(() => {
329
+ unMouseMove.unsubscribe();
330
+ unMouseUp.unsubscribe();
331
+ });
332
+ }
333
+ const hueBarRef = createRef();
334
+ function bindHueBarEvent(ev) {
335
+ const update = (ev) => {
336
+ var _a;
337
+ const position = hueBarRef.current.getBoundingClientRect();
338
+ let offsetY = ev.clientY - position.top;
339
+ offsetY = Math.max(0, offsetY);
340
+ offsetY = Math.min(100, offsetY);
341
+ const h = 360 / 100 * offsetY;
342
+ picker.resetAlpha = false;
343
+ picker.hsv = {
344
+ h,
345
+ s: picker.hsv.s,
346
+ v: picker.hsv.v
347
+ };
348
+ (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, picker);
349
+ };
350
+ update(ev);
351
+ const unMouseMove = fromEvent(document, 'mousemove').subscribe(ev => {
352
+ update(ev);
353
+ });
354
+ const unMouseUp = fromEvent(document, 'mouseup').subscribe(() => {
355
+ unMouseMove.unsubscribe();
356
+ unMouseUp.unsubscribe();
357
+ });
358
+ }
359
+ const alphaBarRef = createRef();
360
+ function bindAlphaEvent(ev) {
361
+ const update = (ev) => {
362
+ var _a;
363
+ const position = alphaBarRef.current.getBoundingClientRect();
364
+ let offsetX = ev.clientX - position.left;
365
+ offsetX = Math.max(0, offsetX);
366
+ offsetX = Math.min(position.width, offsetX);
367
+ picker.rgba = Object.assign(Object.assign({}, picker.rgba), { a: offsetX / position.width });
368
+ (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, picker);
369
+ };
370
+ update(ev);
371
+ const unMouseMove = fromEvent(document, 'mousemove').subscribe(ev => {
372
+ update(ev);
373
+ });
374
+ const unMouseUp = fromEvent(document, 'mouseup').subscribe(() => {
375
+ unMouseMove.unsubscribe();
376
+ unMouseUp.unsubscribe();
377
+ });
378
+ }
379
+ function bindInputsEvent(ev) {
380
+ var _a;
381
+ const updateByHSL = (h, s, l) => {
382
+ var _a;
383
+ picker.hex = hsl2Hex({ h, s, l });
384
+ (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, picker);
385
+ };
386
+ const updateByRGB = (r, g, b) => {
387
+ var _a;
388
+ picker.hex = rgb2Hex({ r, g, b });
389
+ (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, picker);
390
+ };
391
+ const el = ev.target;
392
+ const model = el.getAttribute('data-model');
393
+ if (el.type === 'number') {
394
+ const min = +el.min;
395
+ const max = +el.max;
396
+ el.value = Math.max(+el.value, min) + '';
397
+ el.value = Math.min(+el.value, max) + '';
398
+ }
399
+ const { h, s, l } = picker.hsl;
400
+ const { r, g, b } = picker.rgb;
401
+ switch (model) {
402
+ case 'H':
403
+ updateByHSL(+el.value, s, l);
404
+ break;
405
+ case 'S':
406
+ updateByHSL(h, +el.value, l);
407
+ break;
408
+ case 'L':
409
+ updateByHSL(h, s, +el.value);
410
+ break;
411
+ case 'R':
412
+ updateByRGB(+el.value, g, b);
413
+ break;
414
+ case 'G':
415
+ updateByRGB(r, +el.value, b);
416
+ break;
417
+ case 'B':
418
+ updateByRGB(r, g, +el.value);
419
+ break;
420
+ case 'HEX':
421
+ if (/^#(([0-9a-f]){3}){1,2}$/i.test(el.value)) {
422
+ picker.hex = el.value;
423
+ (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, picker);
424
+ }
425
+ break;
426
+ }
427
+ }
428
+ const isShowPalette = createSignal(false);
429
+ function selected() {
430
+ props.onSelected(picker);
431
+ addRecentColor();
432
+ isShowPalette.set(false);
433
+ }
434
+ function bindColorOptionsEvent(ev) {
435
+ const target = ev.target;
436
+ if (!target.hasAttribute('data-color')) {
437
+ return;
438
+ }
439
+ const c = target.getAttribute('data-color');
440
+ if (/^rgba/.test(c)) {
441
+ picker.rgba = parseCss(c);
442
+ }
443
+ else {
444
+ picker.hex = c;
445
+ }
446
+ props.onSelected(picker);
447
+ addRecentColor();
448
+ }
449
+ return withScopedCSS(scopedId$n, () => {
450
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
451
+ return (jsxs("div", { onMousedown: ev => {
452
+ ev.stopPropagation();
453
+ }, class: {
454
+ 'xnote-color-picker': true,
455
+ 'xnote-color-picker-show-palette': isShowPalette()
456
+ }, children: [jsxs("div", { class: "xnote-color-picker-preset", onClick: bindColorOptionsEvent, children: [jsx("div", { class: "xnote-color-picker-swatches", style: "height: 50px", children: mainColors.map(color => {
457
+ var _a, _b, _c;
458
+ const hsl = (any2Hsl(color) || {});
459
+ return (jsx("div", { "data-color": color, class: {
460
+ 'xnote-color-picker-current': hsl.l === ((_a = picker.hsl) === null || _a === void 0 ? void 0 : _a.l) && hsl.s === ((_b = picker.hsl) === null || _b === void 0 ? void 0 : _b.s) && hsl.h === ((_c = picker.hsl) === null || _c === void 0 ? void 0 : _c.h),
461
+ }, style: {
462
+ background: color
463
+ } }));
464
+ }) }), jsx("div", { class: "xnote-color-picker-swatches", style: "height: 118px;", children: colors.map(color => {
465
+ return (jsx("div", { "data-color": color, style: {
466
+ background: color
467
+ } }));
468
+ }) }), jsx("div", { class: "xnote-color-picker-recent-text", children: "\u6700\u8FD1\u989C\u8272" }), jsx("div", { class: "xnote-color-picker-swatches", style: "height: 25px;", children: Array.from({ length: 7 }).map((_, index) => {
469
+ const colors = recentColors();
470
+ const color = colors[index] || '';
471
+ return (jsx("div", { "data-color": color || 'unknown', style: {
472
+ background: color
473
+ } }));
474
+ }) }), jsxs("div", { class: "xnote-color-picker-flex", children: [jsx("div", { class: "xnote-color-picker-swatches", children: jsx("div", { "data-color": "" }) }), jsxs("button", { type: "button", class: "xnote-color-picker-to-palette", onClick: () => {
475
+ isShowPalette.set(true);
476
+ }, children: ["\u8C03\u8272\u76D8", jsx("svg", { style: "vertical-align: middle;fill: currentColor;overflow: hidden;", viewBox: "0 0 1024 1024", version: "1.1", xmlns: "http://www.w3.org/2000/svg", children: jsx("path", { transform: "rotate(180, 512, 512)", d: "M497.92 165.12L422.4 89.6 0 512l422.4 422.4 75.52-75.52L151.04 512z" }) })] })] })] }), jsxs("div", { class: "xnote-color-picker-menu", children: [jsx("div", { class: "xnote-color-picker-back-btn-wrap", children: jsxs("button", { type: "button", class: "xnote-color-picker-back-btn", onClick: () => {
477
+ isShowPalette.set(false);
478
+ }, children: [jsx("svg", { style: "vertical-align: middle;fill: currentColor;overflow: hidden;", viewBox: "0 0 1024 1024", version: "1.1", xmlns: "http://www.w3.org/2000/svg", children: jsx("path", { d: "M497.92 165.12L422.4 89.6 0 512l422.4 422.4 75.52-75.52L151.04 512z" }) }), "\u8FD4\u56DE"] }) }), jsxs("div", { class: "xnote-color-picker-viewer", children: [jsxs("div", { class: "xnote-color-picker-viewer-left", children: [jsx("div", { class: [
479
+ 'xnote-color-picker-palette',
480
+ {
481
+ 'xnote-color-picker-palette-empty': picker.empty
482
+ }
483
+ ], style: {
484
+ background: picker.empty ? '' : `linear-gradient(to right, #fff, hsl(${(_a = picker.hsv) === null || _a === void 0 ? void 0 : _a.h}, 100%, 50%))`
485
+ }, ref: paletteRef, onMousedown: bindPaletteEvent, children: jsx("div", { class: "xnote-color-picker-palette-point", style: {
486
+ left: `calc(${(_b = picker.hsv) === null || _b === void 0 ? void 0 : _b.s}% - 6px)`,
487
+ top: `calc(${100 - (((_c = picker.hsv) === null || _c === void 0 ? void 0 : _c.v) || 0)}% - 6px)`
488
+ } }) }), jsxs("div", { class: "xnote-color-picker-viewer-alpha", children: [jsx("div", { class: "xnote-color-picker-viewer-alpha-pointer", style: {
489
+ left: picker.empty ? '100%' : (((_d = picker.rgba) === null || _d === void 0 ? void 0 : _d.a) || 0) * 100 + '%',
490
+ } }), jsx("div", { class: "xnote-color-picker-viewer-alpha-bar", style: {
491
+ background: picker.empty ? '' : `linear-gradient(to right, transparent, ${picker.hex})`
492
+ }, onMousedown: bindAlphaEvent, ref: alphaBarRef })] })] }), jsxs("div", { class: "xnote-color-picker-viewer-right", children: [jsxs("div", { class: "xnote-color-picker-tools", children: [jsx("div", { class: "xnote-color-picker-value", children: jsx("div", { class: "xnote-color-picker-value-color", style: {
493
+ background: picker.empty ? '' : `rgba(${(_e = picker.rgba) === null || _e === void 0 ? void 0 : _e.r}, ${(_f = picker.rgba) === null || _f === void 0 ? void 0 : _f.g}, ${(_g = picker.rgba) === null || _g === void 0 ? void 0 : _g.b}, ${(_h = picker.rgba) === null || _h === void 0 ? void 0 : _h.a})`
494
+ } }) }), jsx("div", { class: "xnote-color-picker-hue-bar", ref: hueBarRef, onMousedown: bindHueBarEvent, children: jsx("div", { class: "xnote-color-picker-hue-pointer", style: {
495
+ top: `calc(${(((_j = picker.hsv) === null || _j === void 0 ? void 0 : _j.h) || 0) / 360 * 100}% - 4px)`
496
+ } }) })] }), jsx("div", { class: "xnote-color-picker-viewer-alpha-value", children: Number((_k = picker.rgba) === null || _k === void 0 ? void 0 : _k.a.toFixed(2)) })] })] }), jsxs("div", { class: "xnote-color-picker-inputs", onInput: bindInputsEvent, children: [jsxs("div", { class: "xnote-color-picker-hsl", children: [jsxs("div", { children: ["H ", jsx("input", { "data-model": "H", min: "0", max: "360", type: "number", value: (_l = picker.hsl) === null || _l === void 0 ? void 0 : _l.h })] }), jsxs("div", { children: ["S ", jsx("input", { "data-model": "S", min: "0", max: "100", type: "number", value: (_m = picker.hsl) === null || _m === void 0 ? void 0 : _m.s })] }), jsxs("div", { children: ["L ", jsx("input", { "data-model": "L", min: "0", max: "100", type: "number", value: (_o = picker.hsl) === null || _o === void 0 ? void 0 : _o.l })] })] }), jsxs("div", { class: "xnote-color-picker-rgb", children: [jsxs("div", { children: ["R ", jsx("input", { "data-model": "R", min: "0", max: "255", type: "number", value: (_p = picker.rgb) === null || _p === void 0 ? void 0 : _p.r })] }), jsxs("div", { children: ["G ", jsx("input", { "data-model": "G", min: "0", max: "255", type: "number", value: (_q = picker.rgb) === null || _q === void 0 ? void 0 : _q.g })] }), jsxs("div", { children: ["B ", jsx("input", { "data-model": "B", min: "0", max: "255", type: "number", value: (_r = picker.rgb) === null || _r === void 0 ? void 0 : _r.b })] })] }), jsx("div", { class: "xnote-color-picker-hex", children: jsxs("div", { children: ["HEX ", jsx("input", { "data-model": "HEX", type: "text", value: picker.hex })] }) })] }), jsx("div", { class: "xnote-color-picker-btn-wrap", children: jsx("button", { type: "button", class: "xnote-color-picker-btn", onClick: selected, children: "\u786E\u5B9A" }) })] })] }));
497
+ });
498
+ }
499
+
160
500
  var scopedId$m = "vf-ac7e8d";
161
501
 
162
502
  function ComponentToolbar(props) {
@@ -1834,11 +2174,18 @@ function findNonIntersectingRectangles(rectangles) {
1834
2174
  function getMaxRectangle(start, rectangles) {
1835
2175
  let merged = start;
1836
2176
  const remaining = [...rectangles];
2177
+ const unMerged = [];
1837
2178
  while (remaining.length > 0) {
1838
2179
  const current = remaining.shift();
1839
2180
  if (current.intersects(merged)) {
1840
2181
  merged = current.merge(merged);
1841
2182
  }
2183
+ else {
2184
+ unMerged.push(current);
2185
+ }
2186
+ }
2187
+ if (unMerged.length && merged !== start) {
2188
+ return getMaxRectangle(merged, unMerged);
1842
2189
  }
1843
2190
  return merged;
1844
2191
  }
@@ -2073,13 +2420,13 @@ class TableComponent extends Component {
2073
2420
  endIndex: i.length
2074
2421
  };
2075
2422
  });
2076
- this.selection.setSelectedRanges(slotRanges);
2077
2423
  this.tableSelection.set({
2078
2424
  startColumn: 0,
2079
2425
  endColumn: this.state.columnsConfig.length,
2080
2426
  startRow: startIndex,
2081
2427
  endRow: endIndex,
2082
2428
  });
2429
+ this.selection.setSelectedRanges(slotRanges);
2083
2430
  this.focus.next(true);
2084
2431
  if (slotRanges.length) {
2085
2432
  setTimeout(() => {
@@ -2108,13 +2455,13 @@ class TableComponent extends Component {
2108
2455
  endIndex: i.length
2109
2456
  };
2110
2457
  });
2111
- this.selection.setSelectedRanges(slotRanges);
2112
2458
  this.tableSelection.set({
2113
2459
  startColumn: startIndex,
2114
2460
  endColumn: endIndex,
2115
2461
  startRow: 0,
2116
2462
  endRow: this.state.rows.length,
2117
2463
  });
2464
+ this.selection.setSelectedRanges(slotRanges);
2118
2465
  this.focus.next(true);
2119
2466
  this.selection.restore();
2120
2467
  this.textbus.focus();
@@ -3146,7 +3493,7 @@ const backgroundColorFormatter = new Formatter('backgroundColor', {
3146
3493
  });
3147
3494
  const backgroundColorFormatLoader = {
3148
3495
  match(element) {
3149
- return !!element.style.backgroundColor;
3496
+ return element.tagName !== 'TD' && !!element.style.backgroundColor;
3150
3497
  },
3151
3498
  read(element) {
3152
3499
  return {
@@ -3959,6 +4306,36 @@ function CellAlignTool() {
3959
4306
  };
3960
4307
  }
3961
4308
 
4309
+ const cellBackgroundAttr = new Attribute('cellBackground', {
4310
+ render(node, formatValue) {
4311
+ const rgba = parseCss(formatValue);
4312
+ if (rgba) {
4313
+ const hsl = rgb2Hsl(rgba);
4314
+ if (hsl.l > 50) {
4315
+ hsl.l -= 10;
4316
+ }
4317
+ else {
4318
+ hsl.l += Math.max((50 - hsl.l) * 0.55, 10);
4319
+ }
4320
+ hsl.s *= 0.7;
4321
+ const newRgba = hsl2Rgb(hsl);
4322
+ node.styles.set('borderColor', `rgba(${newRgba.r}, ${newRgba.g}, ${newRgba.b}, ${rgba.a})`);
4323
+ }
4324
+ node.styles.set('backgroundColor', formatValue);
4325
+ }
4326
+ });
4327
+ const cellBackgroundAttrLoader = {
4328
+ match(element) {
4329
+ return element instanceof HTMLTableCellElement && !!element.style.backgroundColor;
4330
+ },
4331
+ read(element) {
4332
+ return {
4333
+ attribute: cellBackgroundAttr,
4334
+ value: element.style.backgroundColor
4335
+ };
4336
+ }
4337
+ };
4338
+
3962
4339
  function CellBackgroundTool() {
3963
4340
  const refreshService = inject(RefreshService);
3964
4341
  const selection = inject(Selection);
@@ -3966,16 +4343,24 @@ function CellBackgroundTool() {
3966
4343
  highlight: false,
3967
4344
  disabled: false,
3968
4345
  });
3969
- function split() {
3970
- // const commonAncestorComponent = selection.commonAncestorComponent
3971
- // if (commonAncestorComponent instanceof TableComponent) {
3972
- // const scopes = selection.getSelectedScopes()
3973
- // if (scopes.length) {
3974
- // const start = commonAncestorComponent.getCellBySlot(scopes.at(0)!.slot)
3975
- // const end = commonAncestorComponent.getCellBySlot(scopes.at(-1)!.slot)
3976
- // // Re
3977
- // }
3978
- // }
4346
+ function setColor(picker) {
4347
+ const commonAncestorComponent = selection.commonAncestorComponent;
4348
+ if (commonAncestorComponent instanceof TableComponent) {
4349
+ const slots = commonAncestorComponent.getSelectedNormalizedSlots();
4350
+ if (slots) {
4351
+ slots.map(i => {
4352
+ return i.cells.filter(t => t.visible).map(i => i.raw.slot);
4353
+ }).flat().forEach(slot => {
4354
+ const rgba = picker.rgba;
4355
+ if (rgba) {
4356
+ slot.setAttribute(cellBackgroundAttr, `rgba(${rgba.r}, ${rgba.g}, ${rgba.b}, ${rgba.a})`);
4357
+ }
4358
+ else {
4359
+ slot.removeAttribute(cellBackgroundAttr);
4360
+ }
4361
+ });
4362
+ }
4363
+ }
3979
4364
  }
3980
4365
  const sub = refreshService.onRefresh.subscribe(() => {
3981
4366
  const commonAncestorComponent = selection.commonAncestorComponent;
@@ -3988,7 +4373,7 @@ function CellBackgroundTool() {
3988
4373
  });
3989
4374
  return () => {
3990
4375
  const vm = viewModel();
3991
- return jsx(Button, { highlight: vm.highlight, disabled: vm.disabled, onClick: split, children: jsx("span", { class: "xnote-icon-palette" }) });
4376
+ return (jsx(Dropdown, { width: '177px', menu: jsx(ColorPicker, { onSelected: setColor }), trigger: 'hover', children: jsx(Button, { highlight: vm.highlight, disabled: vm.disabled, children: jsx("span", { class: "xnote-icon-palette" }) }) }));
3992
4377
  };
3993
4378
  }
3994
4379
 
@@ -4986,7 +5371,7 @@ const Toolbar = withAnnotation({
4986
5371
  opacity: p.opacity,
4987
5372
  display: editorService.hideInlineToolbar ? 'none' : '',
4988
5373
  transitionDuration: p.transitionDuration + 's'
4989
- }, children: [selection.commonAncestorComponent instanceof TableComponent && jsxs(Fragment$1, { children: [jsx(ToolbarItem, { children: jsx(MergeCellsTool, {}) }), jsx(ToolbarItem, { children: jsx(SplitCellsTool, {}) }), jsx(ToolbarItem, { children: jsx(CellAlignTool, {}) })] }, "table"), jsx(ToolbarItem, { children: jsx(BlockTool, {}) }), jsx(ToolbarItem, { children: jsx(AttrTool, {}) }), jsx(ToolbarItem, { children: jsx(BoldTool, {}) }), jsx(ToolbarItem, { children: jsx(ItalicTool, {}) }), jsx(ToolbarItem, { children: jsx(StrikeThroughTool, {}) }), jsx(ToolbarItem, { children: jsx(UnderlineTool, {}) }), jsx(ToolbarItem, { children: jsx(FontSizeTool, {}) }), jsx(ToolbarItem, { children: jsx(FontFamilyTool, {}) }), jsx(ToolbarItem, { children: jsx(LinkTool, { hideToolbar: hideToolbar }) }), jsx(ToolbarItem, { children: jsx(CodeTool, {}) }), jsx(ToolbarItem, { children: jsx(ColorTool, {}) })] }));
5374
+ }, children: [selection.commonAncestorComponent instanceof TableComponent && jsxs(Fragment$1, { children: [jsx(ToolbarItem, { children: jsx(MergeCellsTool, {}) }), jsx(ToolbarItem, { children: jsx(SplitCellsTool, {}) }), jsx(ToolbarItem, { children: jsx(CellBackgroundTool, {}) }), jsx(ToolbarItem, { children: jsx(CellAlignTool, {}) })] }, "table"), jsx(ToolbarItem, { children: jsx(BlockTool, {}) }), jsx(ToolbarItem, { children: jsx(AttrTool, {}) }), jsx(ToolbarItem, { children: jsx(BoldTool, {}) }), jsx(ToolbarItem, { children: jsx(ItalicTool, {}) }), jsx(ToolbarItem, { children: jsx(StrikeThroughTool, {}) }), jsx(ToolbarItem, { children: jsx(UnderlineTool, {}) }), jsx(ToolbarItem, { children: jsx(FontSizeTool, {}) }), jsx(ToolbarItem, { children: jsx(FontFamilyTool, {}) }), jsx(ToolbarItem, { children: jsx(LinkTool, { hideToolbar: hideToolbar }) }), jsx(ToolbarItem, { children: jsx(CodeTool, {}) }), jsx(ToolbarItem, { children: jsx(ColorTool, {}) })] }));
4990
5375
  });
4991
5376
  });
4992
5377
 
@@ -6204,24 +6589,25 @@ let TableSelectionAwarenessDelegate = class TableSelectionAwarenessDelegate exte
6204
6589
  return false;
6205
6590
  }
6206
6591
  const rect = data.data || commonAncestorComponent.getMaxRectangle(findFocusCell(commonAncestorComponent, startSlot), findFocusCell(commonAncestorComponent, endSlot));
6207
- const renderer = this.domAdapter;
6208
6592
  if (!rect) {
6209
6593
  return false;
6210
6594
  }
6211
- const normalizedSlots = commonAncestorComponent.getSelectedNormalizedSlotsByRectangle(rect);
6212
- const rects = normalizedSlots.map(row => {
6213
- return row.cells.filter(i => i.visible).map(i => {
6214
- const td = renderer.getNativeNodeBySlot(i.raw.slot);
6215
- return td.getBoundingClientRect();
6216
- });
6217
- }).flat();
6218
- const left = Math.min(...rects.map(i => i.left));
6219
- const top = Math.min(...rects.map(i => i.top));
6595
+ const dom = this.domAdapter.getNativeNodeByComponent(commonAncestorComponent);
6596
+ const content = dom.querySelector('.xnote-table-content');
6597
+ const trs = content.querySelectorAll('tr');
6598
+ const cols = content.querySelectorAll('col');
6599
+ const top = trs[rect.y1].getBoundingClientRect().top;
6600
+ const left = cols[rect.x1].getBoundingClientRect().left;
6601
+ let height = trs[rect.y2 - 1].getBoundingClientRect().bottom - top;
6602
+ if (height === 0) {
6603
+ height = trs[rect.y2 - 1].children.item(0).getBoundingClientRect().bottom - top;
6604
+ }
6605
+ const width = cols[rect.x2 - 1].getBoundingClientRect().right - left;
6220
6606
  return [{
6221
6607
  left,
6222
6608
  top,
6223
- width: Math.max(...rects.map(i => i.right)) - left,
6224
- height: Math.max(...rects.map(i => i.bottom)) - top
6609
+ width,
6610
+ height
6225
6611
  }];
6226
6612
  }
6227
6613
  };
@@ -6349,9 +6735,22 @@ class XNoteMessageBug extends MessageBus {
6349
6735
  get() {
6350
6736
  const selection = this.selection;
6351
6737
  const c = selection.commonAncestorComponent;
6352
- return Object.assign(Object.assign({}, this.userinfo), { selection: selection.getPaths(), data: (!selection.isCollapsed && c instanceof TableComponent) ? c.getSelectedRect() : null });
6738
+ const msg = Object.assign(Object.assign({}, this.userinfo), { selection: selection.getPaths() });
6739
+ if (!selection.isCollapsed && c instanceof TableComponent) {
6740
+ const selection = c.tableSelection();
6741
+ if (selection) {
6742
+ msg.data = {
6743
+ x1: selection.startColumn,
6744
+ x2: selection.endColumn,
6745
+ y1: selection.startRow,
6746
+ y2: selection.endRow,
6747
+ };
6748
+ }
6749
+ }
6750
+ return msg;
6353
6751
  }
6354
6752
  consume(message) {
6753
+ message = message.filter(i => i.message);
6355
6754
  this.messageChangeEvent.next([...message]);
6356
6755
  this.collaborateCursor.draw(message.filter(item => {
6357
6756
  return item.message.id !== this.userinfo.id;
@@ -6418,6 +6817,7 @@ class Editor extends Textbus {
6418
6817
  strikeThroughFormatLoader,
6419
6818
  underlineFormatLoader
6420
6819
  ], attributeLoaders: [
6820
+ cellBackgroundAttrLoader,
6421
6821
  cellAlignAttrLoader,
6422
6822
  headingAttrLoader,
6423
6823
  textAlignAttrLoader,
@@ -6505,6 +6905,7 @@ class Editor extends Textbus {
6505
6905
  strikeThroughFormatter,
6506
6906
  underlineFormatter
6507
6907
  ], attributes: [
6908
+ cellBackgroundAttr,
6508
6909
  cellAlignAttr,
6509
6910
  headingAttr,
6510
6911
  textAlignAttr,
@@ -6565,4 +6966,4 @@ class Editor extends Textbus {
6565
6966
  }
6566
6967
  }
6567
6968
 
6568
- export { AtComponent, AtComponentView, AttrTool, BlockTool, BlockquoteComponent, BlockquoteView, BoldTool, Button, CellAlignTool, CellBackgroundTool, CodeTool, ColorTool, ComponentToolbar, Divider, DragResize, Dropdown, DropdownContextService, DropdownMenuPortal, DropdownService, Editor, EditorService, FileUploader, FontFamilyTool, FontSizeTool, HighlightBoxComponent, HighlightBoxView, ImageComponent, ImageView, InsertTool, ItalicTool, KatexComponent, KatexComponentView, Keymap, LeftToolbar, LeftToolbarPlugin, LinkJump, LinkTool, ListComponent, ListComponentView, Matcher, MenuHeading, MenuItem, MergeCellsTool, Organization, OutputInjectionToken, ParagraphComponent, ParagraphView, Popup, RefreshService, RootComponent, RootView, SourceCodeComponent, SourceCodeView, SplitCellsTool, StrikeThroughTool, TableComponent, TableComponentView, TodolistComponent, TodolistView, Toolbar, ToolbarItem, ToolbarPlugin, UnderlineTool, VideoComponent, VideoView, XNoteMessageBug, atComponentLoader, backgroundColorFormatLoader, backgroundColorFormatter, blockquoteComponentLoader, boldFormatLoader, boldFormatter, cellAlignAttr, cellAlignAttrLoader, codeFormatLoader, codeFormatter, colorFormatLoader, colorFormatter, deltaToBlock, fontFamilyFormatLoader, fontFamilyFormatter, fontSizeFormatLoader, fontSizeFormatter, headingAttr, headingAttrLoader, highlightBoxComponentLoader, imageComponentLoader, isSupportFont, italicFormatLoader, italicFormatter, katexComponentLoader, languageList, linkFormatLoader, linkFormatter, listComponentLoader, paragraphComponentLoader, registerAtShortcut, registerBlockquoteShortcut, registerBoldShortcut, registerCodeShortcut, registerHeadingShortcut, registerItalicShortcut, registerListShortcut, registerStrikeThroughShortcut, registerTextAlignShortcut, registerTextIndentShortcut, registerUnderlineShortcut, rootComponentLoader, sourceCodeComponentLoader, sourceCodeThemes, strikeThroughFormatLoader, strikeThroughFormatter, tableComponentLoader, textAlignAttr, textAlignAttrLoader, textIndentAttr, textIndentAttrLoader, toBlockquote, toList, todolistComponentLoader, toggleBold, toggleCode, toggleItalic, toggleStrikeThrough, toggleUnderline, underlineFormatLoader, underlineFormatter, useActiveBlock, useBlockContent, useBlockTransform, useOutput, useReadonly, videoComponentLoader };
6969
+ export { AtComponent, AtComponentView, AttrTool, BlockTool, BlockquoteComponent, BlockquoteView, BoldTool, Button, CellAlignTool, CellBackgroundTool, CodeTool, ColorPicker, ColorTool, ComponentToolbar, Divider, DragResize, Dropdown, DropdownContextService, DropdownMenuPortal, DropdownService, Editor, EditorService, FileUploader, FontFamilyTool, FontSizeTool, HighlightBoxComponent, HighlightBoxView, ImageComponent, ImageView, InsertTool, ItalicTool, KatexComponent, KatexComponentView, Keymap, LeftToolbar, LeftToolbarPlugin, LinkJump, LinkTool, ListComponent, ListComponentView, Matcher, MenuHeading, MenuItem, MergeCellsTool, Organization, OutputInjectionToken, ParagraphComponent, ParagraphView, Picker, Popup, RefreshService, RootComponent, RootView, SourceCodeComponent, SourceCodeView, SplitCellsTool, StrikeThroughTool, TableComponent, TableComponentView, TodolistComponent, TodolistView, Toolbar, ToolbarItem, ToolbarPlugin, UnderlineTool, VideoComponent, VideoView, XNoteMessageBug, atComponentLoader, backgroundColorFormatLoader, backgroundColorFormatter, blockquoteComponentLoader, boldFormatLoader, boldFormatter, cellAlignAttr, cellAlignAttrLoader, cellBackgroundAttr, cellBackgroundAttrLoader, codeFormatLoader, codeFormatter, colorFormatLoader, colorFormatter, deltaToBlock, fontFamilyFormatLoader, fontFamilyFormatter, fontSizeFormatLoader, fontSizeFormatter, headingAttr, headingAttrLoader, highlightBoxComponentLoader, imageComponentLoader, isSupportFont, italicFormatLoader, italicFormatter, katexComponentLoader, languageList, linkFormatLoader, linkFormatter, listComponentLoader, paragraphComponentLoader, registerAtShortcut, registerBlockquoteShortcut, registerBoldShortcut, registerCodeShortcut, registerHeadingShortcut, registerItalicShortcut, registerListShortcut, registerStrikeThroughShortcut, registerTextAlignShortcut, registerTextIndentShortcut, registerUnderlineShortcut, rootComponentLoader, sourceCodeComponentLoader, sourceCodeThemes, strikeThroughFormatLoader, strikeThroughFormatter, tableComponentLoader, textAlignAttr, textAlignAttrLoader, textIndentAttr, textIndentAttrLoader, toBlockquote, toList, todolistComponentLoader, toggleBold, toggleCode, toggleItalic, toggleStrikeThrough, toggleUnderline, underlineFormatLoader, underlineFormatter, useActiveBlock, useBlockContent, useBlockTransform, useOutput, useReadonly, videoComponentLoader };