@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.
package/bundles/index.js CHANGED
@@ -4,6 +4,7 @@ var jsxRuntime = require('@viewfly/core/jsx-runtime');
4
4
  var scopedCss = require('@viewfly/scoped-css');
5
5
  var core = require('@viewfly/core');
6
6
  var core$1 = require('@textbus/core');
7
+ var color = require('@tanbo/color');
7
8
  var platformBrowser = require('@textbus/platform-browser');
8
9
  var platformBrowser$1 = require('@viewfly/platform-browser');
9
10
  var hooks = require('@viewfly/hooks');
@@ -11,10 +12,9 @@ var highlightjs = require('highlight.js');
11
12
  var uuid = require('uuid');
12
13
  var Katex = require('katex');
13
14
  var adapterViewfly = require('@textbus/adapter-viewfly');
14
- var color = require('@tanbo/color');
15
15
  var collaborate = require('@textbus/collaborate');
16
16
 
17
- var scopedId$n = "vf-d94b56";
17
+ var scopedId$o = "vf-d94b56";
18
18
 
19
19
  /******************************************************************************
20
20
  Copyright (c) Microsoft Corporation.
@@ -147,7 +147,7 @@ function Button(props) {
147
147
  subscription.unsubscribe();
148
148
  });
149
149
  }
150
- return scopedCss.withScopedCSS(scopedId$n, () => {
150
+ return scopedCss.withScopedCSS(scopedId$o, () => {
151
151
  return (jsxRuntime.jsxs("button", Object.assign({ type: "button" }, props, { class: [
152
152
  'btn',
153
153
  {
@@ -159,6 +159,346 @@ function Button(props) {
159
159
  });
160
160
  }
161
161
 
162
+ var scopedId$n = "vf-d552b9";
163
+
164
+ class Picker {
165
+ set hex(color$1) {
166
+ var _a;
167
+ const c = color$1 ? color.normalizeHex(color$1) : null;
168
+ if (c) {
169
+ this.empty = false;
170
+ this._hex = c;
171
+ this._hsl = color.hex2Hsl(c);
172
+ this._rgb = color.hex2Rgb(c);
173
+ this._hsv = color.hex2Hsv(c);
174
+ this._rgba = Object.assign(Object.assign({}, this._rgb), { a: this.resetAlpha ? 1 : ((_a = this._rgba) === null || _a === void 0 ? void 0 : _a.a) || 1 });
175
+ }
176
+ else {
177
+ this.empty = true;
178
+ }
179
+ this.resetAlpha = true;
180
+ this.onChange();
181
+ }
182
+ get hex() {
183
+ return this.empty ? null : this._hex;
184
+ }
185
+ set hsl(color$1) {
186
+ var _a;
187
+ if (!color$1 || typeof color$1.h !== 'number' || typeof color$1.s !== 'number' || typeof color$1.l !== 'number') {
188
+ this.empty = true;
189
+ }
190
+ else {
191
+ this.empty = false;
192
+ this._hsl = color$1;
193
+ this._hex = color.hsl2Hex(color$1);
194
+ this._hsv = color.hsl2Hsv(color$1);
195
+ this._rgb = color.hsl2Rgb(color$1);
196
+ this._rgba = Object.assign(Object.assign({}, this._rgb), { a: this.resetAlpha ? 1 : ((_a = this._rgba) === null || _a === void 0 ? void 0 : _a.a) || 1 });
197
+ }
198
+ this.resetAlpha = true;
199
+ this.onChange();
200
+ }
201
+ get hsl() {
202
+ return this.empty ? null : this._hsl;
203
+ }
204
+ set rgb(color$1) {
205
+ var _a;
206
+ if (!color$1 || typeof color$1.r !== 'number' || typeof color$1.g !== 'number' || typeof color$1.b !== 'number') {
207
+ this.empty = true;
208
+ }
209
+ else {
210
+ this.empty = false;
211
+ this._rgb = color$1;
212
+ this._rgba = Object.assign(Object.assign({}, color$1), { a: this.resetAlpha ? 1 : ((_a = this._rgba) === null || _a === void 0 ? void 0 : _a.a) || 1 });
213
+ this._hsl = color.rgb2Hsl(color$1);
214
+ this._hex = color.rgb2Hex(color$1);
215
+ this._hsv = color.rgb2Hsv(color$1);
216
+ }
217
+ this.resetAlpha = true;
218
+ this.onChange();
219
+ }
220
+ get rgb() {
221
+ return this.empty ? null : this._rgb;
222
+ }
223
+ set rgba(color$1) {
224
+ if (!color$1 ||
225
+ typeof color$1.r !== 'number' ||
226
+ typeof color$1.g !== 'number' ||
227
+ typeof color$1.b !== 'number' ||
228
+ typeof color$1.a !== 'number') {
229
+ this.empty = true;
230
+ }
231
+ else {
232
+ this.empty = false;
233
+ this._rgba = color$1;
234
+ this._hsl = color.rgb2Hsl(color$1);
235
+ this._hex = color.rgb2Hex(color$1);
236
+ this._hsv = color.rgb2Hsv(color$1);
237
+ }
238
+ this.onChange();
239
+ }
240
+ get rgba() {
241
+ return this.empty ? null : this._rgba;
242
+ }
243
+ set hsv(color$1) {
244
+ var _a;
245
+ if (!color$1 || typeof color$1.h !== 'number' || typeof color$1.s !== 'number' || typeof color$1.v !== 'number') {
246
+ this.empty = true;
247
+ }
248
+ else {
249
+ this.empty = false;
250
+ this._hsv = color$1;
251
+ this._hex = color.hsv2Hex(color$1);
252
+ this._hsl = color.hsv2Hsl(color$1);
253
+ this._rgb = color.hsv2Rgb(color$1);
254
+ this._rgba = Object.assign(Object.assign({}, this._rgb), { a: this.resetAlpha ? 1 : ((_a = this._rgba) === null || _a === void 0 ? void 0 : _a.a) || 1 });
255
+ }
256
+ this.resetAlpha = true;
257
+ this.onChange();
258
+ }
259
+ get hsv() {
260
+ return this.empty ? null : this._hsv;
261
+ }
262
+ constructor(onChange, value) {
263
+ this.onChange = onChange;
264
+ this._hex = '';
265
+ this._hsl = null;
266
+ this._rgb = null;
267
+ this._hsv = null;
268
+ this._rgba = null;
269
+ this.empty = false;
270
+ this.resetAlpha = true;
271
+ this.hex = value || '#f00';
272
+ }
273
+ }
274
+ const recentColors = core.createSignal([]);
275
+ function ColorPicker(props) {
276
+ const instance = core.getCurrentInstance();
277
+ const picker = new Picker(() => {
278
+ instance.markAsDirtied();
279
+ }, props.value);
280
+ const mainColors = [
281
+ '#000', '#333', '#444', '#555', '#666', '#777', '#888',
282
+ '#999', '#aaa', '#bbb', '#ccc', '#ddd', '#eee', '#fff',
283
+ ];
284
+ const colors = [
285
+ '#fec6c2', '#fee5c3', '#fefcc3', '#baf6c4', '#c3ebfe', '#c3cbfe', '#e1caff',
286
+ '#fc8e88', '#fccc88', '#fcf888', '#76ec8a', '#88d8fc', '#97a4fb', '#c098f4',
287
+ '#ff6666', '#ffb151', '#fada3a', '#18c937', '#3aaafa', '#6373e2', '#a669f7',
288
+ '#f63030', '#f88933', '#deb12a', '#038e23', '#1276cc', '#3f52ce', '#8838ed',
289
+ '#c60000', '#d86912', '#b88811', '#086508', '#144c93', '#1b2eaa', '#6117bf',
290
+ ];
291
+ function addRecentColor() {
292
+ const color = picker.hex;
293
+ if (!color) {
294
+ return;
295
+ }
296
+ const colors = recentColors().filter(item => {
297
+ return item !== color;
298
+ });
299
+ colors.unshift(color);
300
+ if (colors.length >= 7) {
301
+ colors.length = 7;
302
+ }
303
+ recentColors.set(colors);
304
+ }
305
+ const paletteRef = core.createRef();
306
+ function bindPaletteEvent(ev) {
307
+ const update = (ev) => {
308
+ var _a;
309
+ const position = paletteRef.current.getBoundingClientRect();
310
+ const offsetX = ev.clientX - position.left;
311
+ const offsetY = ev.clientY - position.top;
312
+ let s = offsetX / 130 * 100;
313
+ let v = 100 - offsetY / 130 * 100;
314
+ s = Math.max(0, s);
315
+ s = Math.min(100, s);
316
+ v = Math.max(0, v);
317
+ v = Math.min(100, v);
318
+ picker.resetAlpha = false;
319
+ picker.hsv = {
320
+ h: picker.hsv.h,
321
+ s,
322
+ v
323
+ };
324
+ (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, picker);
325
+ };
326
+ update(ev);
327
+ const unMouseMove = core$1.fromEvent(document, 'mousemove').subscribe(ev => {
328
+ update(ev);
329
+ });
330
+ const unMouseUp = core$1.fromEvent(document, 'mouseup').subscribe(() => {
331
+ unMouseMove.unsubscribe();
332
+ unMouseUp.unsubscribe();
333
+ });
334
+ }
335
+ const hueBarRef = core.createRef();
336
+ function bindHueBarEvent(ev) {
337
+ const update = (ev) => {
338
+ var _a;
339
+ const position = hueBarRef.current.getBoundingClientRect();
340
+ let offsetY = ev.clientY - position.top;
341
+ offsetY = Math.max(0, offsetY);
342
+ offsetY = Math.min(100, offsetY);
343
+ const h = 360 / 100 * offsetY;
344
+ picker.resetAlpha = false;
345
+ picker.hsv = {
346
+ h,
347
+ s: picker.hsv.s,
348
+ v: picker.hsv.v
349
+ };
350
+ (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, picker);
351
+ };
352
+ update(ev);
353
+ const unMouseMove = core$1.fromEvent(document, 'mousemove').subscribe(ev => {
354
+ update(ev);
355
+ });
356
+ const unMouseUp = core$1.fromEvent(document, 'mouseup').subscribe(() => {
357
+ unMouseMove.unsubscribe();
358
+ unMouseUp.unsubscribe();
359
+ });
360
+ }
361
+ const alphaBarRef = core.createRef();
362
+ function bindAlphaEvent(ev) {
363
+ const update = (ev) => {
364
+ var _a;
365
+ const position = alphaBarRef.current.getBoundingClientRect();
366
+ let offsetX = ev.clientX - position.left;
367
+ offsetX = Math.max(0, offsetX);
368
+ offsetX = Math.min(position.width, offsetX);
369
+ picker.rgba = Object.assign(Object.assign({}, picker.rgba), { a: offsetX / position.width });
370
+ (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, picker);
371
+ };
372
+ update(ev);
373
+ const unMouseMove = core$1.fromEvent(document, 'mousemove').subscribe(ev => {
374
+ update(ev);
375
+ });
376
+ const unMouseUp = core$1.fromEvent(document, 'mouseup').subscribe(() => {
377
+ unMouseMove.unsubscribe();
378
+ unMouseUp.unsubscribe();
379
+ });
380
+ }
381
+ function bindInputsEvent(ev) {
382
+ var _a;
383
+ const updateByHSL = (h, s, l) => {
384
+ var _a;
385
+ picker.hex = color.hsl2Hex({ h, s, l });
386
+ (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, picker);
387
+ };
388
+ const updateByRGB = (r, g, b) => {
389
+ var _a;
390
+ picker.hex = color.rgb2Hex({ r, g, b });
391
+ (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, picker);
392
+ };
393
+ const el = ev.target;
394
+ const model = el.getAttribute('data-model');
395
+ if (el.type === 'number') {
396
+ const min = +el.min;
397
+ const max = +el.max;
398
+ el.value = Math.max(+el.value, min) + '';
399
+ el.value = Math.min(+el.value, max) + '';
400
+ }
401
+ const { h, s, l } = picker.hsl;
402
+ const { r, g, b } = picker.rgb;
403
+ switch (model) {
404
+ case 'H':
405
+ updateByHSL(+el.value, s, l);
406
+ break;
407
+ case 'S':
408
+ updateByHSL(h, +el.value, l);
409
+ break;
410
+ case 'L':
411
+ updateByHSL(h, s, +el.value);
412
+ break;
413
+ case 'R':
414
+ updateByRGB(+el.value, g, b);
415
+ break;
416
+ case 'G':
417
+ updateByRGB(r, +el.value, b);
418
+ break;
419
+ case 'B':
420
+ updateByRGB(r, g, +el.value);
421
+ break;
422
+ case 'HEX':
423
+ if (/^#(([0-9a-f]){3}){1,2}$/i.test(el.value)) {
424
+ picker.hex = el.value;
425
+ (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, picker);
426
+ }
427
+ break;
428
+ }
429
+ }
430
+ const isShowPalette = core.createSignal(false);
431
+ function selected() {
432
+ props.onSelected(picker);
433
+ addRecentColor();
434
+ isShowPalette.set(false);
435
+ }
436
+ function bindColorOptionsEvent(ev) {
437
+ const target = ev.target;
438
+ if (!target.hasAttribute('data-color')) {
439
+ return;
440
+ }
441
+ const c = target.getAttribute('data-color');
442
+ if (/^rgba/.test(c)) {
443
+ picker.rgba = color.parseCss(c);
444
+ }
445
+ else {
446
+ picker.hex = c;
447
+ }
448
+ props.onSelected(picker);
449
+ addRecentColor();
450
+ }
451
+ return scopedCss.withScopedCSS(scopedId$n, () => {
452
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
453
+ return (jsxRuntime.jsxs("div", { onMousedown: ev => {
454
+ ev.stopPropagation();
455
+ }, class: {
456
+ 'xnote-color-picker': true,
457
+ 'xnote-color-picker-show-palette': isShowPalette()
458
+ }, children: [jsxRuntime.jsxs("div", { class: "xnote-color-picker-preset", onClick: bindColorOptionsEvent, children: [jsxRuntime.jsx("div", { class: "xnote-color-picker-swatches", style: "height: 50px", children: mainColors.map(color$1 => {
459
+ var _a, _b, _c;
460
+ const hsl = (color.any2Hsl(color$1) || {});
461
+ return (jsxRuntime.jsx("div", { "data-color": color$1, class: {
462
+ '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),
463
+ }, style: {
464
+ background: color$1
465
+ } }));
466
+ }) }), jsxRuntime.jsx("div", { class: "xnote-color-picker-swatches", style: "height: 118px;", children: colors.map(color => {
467
+ return (jsxRuntime.jsx("div", { "data-color": color, style: {
468
+ background: color
469
+ } }));
470
+ }) }), jsxRuntime.jsx("div", { class: "xnote-color-picker-recent-text", children: "\u6700\u8FD1\u989C\u8272" }), jsxRuntime.jsx("div", { class: "xnote-color-picker-swatches", style: "height: 25px;", children: Array.from({ length: 7 }).map((_, index) => {
471
+ const colors = recentColors();
472
+ const color = colors[index] || '';
473
+ return (jsxRuntime.jsx("div", { "data-color": color || 'unknown', style: {
474
+ background: color
475
+ } }));
476
+ }) }), jsxRuntime.jsxs("div", { class: "xnote-color-picker-flex", children: [jsxRuntime.jsx("div", { class: "xnote-color-picker-swatches", children: jsxRuntime.jsx("div", { "data-color": "" }) }), jsxRuntime.jsxs("button", { type: "button", class: "xnote-color-picker-to-palette", onClick: () => {
477
+ isShowPalette.set(true);
478
+ }, children: ["\u8C03\u8272\u76D8", jsxRuntime.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: jsxRuntime.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" }) })] })] })] }), jsxRuntime.jsxs("div", { class: "xnote-color-picker-menu", children: [jsxRuntime.jsx("div", { class: "xnote-color-picker-back-btn-wrap", children: jsxRuntime.jsxs("button", { type: "button", class: "xnote-color-picker-back-btn", onClick: () => {
479
+ isShowPalette.set(false);
480
+ }, children: [jsxRuntime.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: jsxRuntime.jsx("path", { d: "M497.92 165.12L422.4 89.6 0 512l422.4 422.4 75.52-75.52L151.04 512z" }) }), "\u8FD4\u56DE"] }) }), jsxRuntime.jsxs("div", { class: "xnote-color-picker-viewer", children: [jsxRuntime.jsxs("div", { class: "xnote-color-picker-viewer-left", children: [jsxRuntime.jsx("div", { class: [
481
+ 'xnote-color-picker-palette',
482
+ {
483
+ 'xnote-color-picker-palette-empty': picker.empty
484
+ }
485
+ ], style: {
486
+ background: picker.empty ? '' : `linear-gradient(to right, #fff, hsl(${(_a = picker.hsv) === null || _a === void 0 ? void 0 : _a.h}, 100%, 50%))`
487
+ }, ref: paletteRef, onMousedown: bindPaletteEvent, children: jsxRuntime.jsx("div", { class: "xnote-color-picker-palette-point", style: {
488
+ left: `calc(${(_b = picker.hsv) === null || _b === void 0 ? void 0 : _b.s}% - 6px)`,
489
+ top: `calc(${100 - (((_c = picker.hsv) === null || _c === void 0 ? void 0 : _c.v) || 0)}% - 6px)`
490
+ } }) }), jsxRuntime.jsxs("div", { class: "xnote-color-picker-viewer-alpha", children: [jsxRuntime.jsx("div", { class: "xnote-color-picker-viewer-alpha-pointer", style: {
491
+ left: picker.empty ? '100%' : (((_d = picker.rgba) === null || _d === void 0 ? void 0 : _d.a) || 0) * 100 + '%',
492
+ } }), jsxRuntime.jsx("div", { class: "xnote-color-picker-viewer-alpha-bar", style: {
493
+ background: picker.empty ? '' : `linear-gradient(to right, transparent, ${picker.hex})`
494
+ }, onMousedown: bindAlphaEvent, ref: alphaBarRef })] })] }), jsxRuntime.jsxs("div", { class: "xnote-color-picker-viewer-right", children: [jsxRuntime.jsxs("div", { class: "xnote-color-picker-tools", children: [jsxRuntime.jsx("div", { class: "xnote-color-picker-value", children: jsxRuntime.jsx("div", { class: "xnote-color-picker-value-color", style: {
495
+ 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})`
496
+ } }) }), jsxRuntime.jsx("div", { class: "xnote-color-picker-hue-bar", ref: hueBarRef, onMousedown: bindHueBarEvent, children: jsxRuntime.jsx("div", { class: "xnote-color-picker-hue-pointer", style: {
497
+ top: `calc(${(((_j = picker.hsv) === null || _j === void 0 ? void 0 : _j.h) || 0) / 360 * 100}% - 4px)`
498
+ } }) })] }), jsxRuntime.jsx("div", { class: "xnote-color-picker-viewer-alpha-value", children: Number((_k = picker.rgba) === null || _k === void 0 ? void 0 : _k.a.toFixed(2)) })] })] }), jsxRuntime.jsxs("div", { class: "xnote-color-picker-inputs", onInput: bindInputsEvent, children: [jsxRuntime.jsxs("div", { class: "xnote-color-picker-hsl", children: [jsxRuntime.jsxs("div", { children: ["H ", jsxRuntime.jsx("input", { "data-model": "H", min: "0", max: "360", type: "number", value: (_l = picker.hsl) === null || _l === void 0 ? void 0 : _l.h })] }), jsxRuntime.jsxs("div", { children: ["S ", jsxRuntime.jsx("input", { "data-model": "S", min: "0", max: "100", type: "number", value: (_m = picker.hsl) === null || _m === void 0 ? void 0 : _m.s })] }), jsxRuntime.jsxs("div", { children: ["L ", jsxRuntime.jsx("input", { "data-model": "L", min: "0", max: "100", type: "number", value: (_o = picker.hsl) === null || _o === void 0 ? void 0 : _o.l })] })] }), jsxRuntime.jsxs("div", { class: "xnote-color-picker-rgb", children: [jsxRuntime.jsxs("div", { children: ["R ", jsxRuntime.jsx("input", { "data-model": "R", min: "0", max: "255", type: "number", value: (_p = picker.rgb) === null || _p === void 0 ? void 0 : _p.r })] }), jsxRuntime.jsxs("div", { children: ["G ", jsxRuntime.jsx("input", { "data-model": "G", min: "0", max: "255", type: "number", value: (_q = picker.rgb) === null || _q === void 0 ? void 0 : _q.g })] }), jsxRuntime.jsxs("div", { children: ["B ", jsxRuntime.jsx("input", { "data-model": "B", min: "0", max: "255", type: "number", value: (_r = picker.rgb) === null || _r === void 0 ? void 0 : _r.b })] })] }), jsxRuntime.jsx("div", { class: "xnote-color-picker-hex", children: jsxRuntime.jsxs("div", { children: ["HEX ", jsxRuntime.jsx("input", { "data-model": "HEX", type: "text", value: picker.hex })] }) })] }), jsxRuntime.jsx("div", { class: "xnote-color-picker-btn-wrap", children: jsxRuntime.jsx("button", { type: "button", class: "xnote-color-picker-btn", onClick: selected, children: "\u786E\u5B9A" }) })] })] }));
499
+ });
500
+ }
501
+
162
502
  var scopedId$m = "vf-ac7e8d";
163
503
 
164
504
  function ComponentToolbar(props) {
@@ -1836,11 +2176,18 @@ function findNonIntersectingRectangles(rectangles) {
1836
2176
  function getMaxRectangle(start, rectangles) {
1837
2177
  let merged = start;
1838
2178
  const remaining = [...rectangles];
2179
+ const unMerged = [];
1839
2180
  while (remaining.length > 0) {
1840
2181
  const current = remaining.shift();
1841
2182
  if (current.intersects(merged)) {
1842
2183
  merged = current.merge(merged);
1843
2184
  }
2185
+ else {
2186
+ unMerged.push(current);
2187
+ }
2188
+ }
2189
+ if (unMerged.length && merged !== start) {
2190
+ return getMaxRectangle(merged, unMerged);
1844
2191
  }
1845
2192
  return merged;
1846
2193
  }
@@ -2075,13 +2422,13 @@ class TableComponent extends core$1.Component {
2075
2422
  endIndex: i.length
2076
2423
  };
2077
2424
  });
2078
- this.selection.setSelectedRanges(slotRanges);
2079
2425
  this.tableSelection.set({
2080
2426
  startColumn: 0,
2081
2427
  endColumn: this.state.columnsConfig.length,
2082
2428
  startRow: startIndex,
2083
2429
  endRow: endIndex,
2084
2430
  });
2431
+ this.selection.setSelectedRanges(slotRanges);
2085
2432
  this.focus.next(true);
2086
2433
  if (slotRanges.length) {
2087
2434
  setTimeout(() => {
@@ -2110,13 +2457,13 @@ class TableComponent extends core$1.Component {
2110
2457
  endIndex: i.length
2111
2458
  };
2112
2459
  });
2113
- this.selection.setSelectedRanges(slotRanges);
2114
2460
  this.tableSelection.set({
2115
2461
  startColumn: startIndex,
2116
2462
  endColumn: endIndex,
2117
2463
  startRow: 0,
2118
2464
  endRow: this.state.rows.length,
2119
2465
  });
2466
+ this.selection.setSelectedRanges(slotRanges);
2120
2467
  this.focus.next(true);
2121
2468
  this.selection.restore();
2122
2469
  this.textbus.focus();
@@ -3148,7 +3495,7 @@ const backgroundColorFormatter = new core$1.Formatter('backgroundColor', {
3148
3495
  });
3149
3496
  const backgroundColorFormatLoader = {
3150
3497
  match(element) {
3151
- return !!element.style.backgroundColor;
3498
+ return element.tagName !== 'TD' && !!element.style.backgroundColor;
3152
3499
  },
3153
3500
  read(element) {
3154
3501
  return {
@@ -3961,6 +4308,36 @@ function CellAlignTool() {
3961
4308
  };
3962
4309
  }
3963
4310
 
4311
+ const cellBackgroundAttr = new core$1.Attribute('cellBackground', {
4312
+ render(node, formatValue) {
4313
+ const rgba = color.parseCss(formatValue);
4314
+ if (rgba) {
4315
+ const hsl = color.rgb2Hsl(rgba);
4316
+ if (hsl.l > 50) {
4317
+ hsl.l -= 10;
4318
+ }
4319
+ else {
4320
+ hsl.l += Math.max((50 - hsl.l) * 0.55, 10);
4321
+ }
4322
+ hsl.s *= 0.7;
4323
+ const newRgba = color.hsl2Rgb(hsl);
4324
+ node.styles.set('borderColor', `rgba(${newRgba.r}, ${newRgba.g}, ${newRgba.b}, ${rgba.a})`);
4325
+ }
4326
+ node.styles.set('backgroundColor', formatValue);
4327
+ }
4328
+ });
4329
+ const cellBackgroundAttrLoader = {
4330
+ match(element) {
4331
+ return element instanceof HTMLTableCellElement && !!element.style.backgroundColor;
4332
+ },
4333
+ read(element) {
4334
+ return {
4335
+ attribute: cellBackgroundAttr,
4336
+ value: element.style.backgroundColor
4337
+ };
4338
+ }
4339
+ };
4340
+
3964
4341
  function CellBackgroundTool() {
3965
4342
  const refreshService = core.inject(exports.RefreshService);
3966
4343
  const selection = core.inject(core$1.Selection);
@@ -3968,16 +4345,24 @@ function CellBackgroundTool() {
3968
4345
  highlight: false,
3969
4346
  disabled: false,
3970
4347
  });
3971
- function split() {
3972
- // const commonAncestorComponent = selection.commonAncestorComponent
3973
- // if (commonAncestorComponent instanceof TableComponent) {
3974
- // const scopes = selection.getSelectedScopes()
3975
- // if (scopes.length) {
3976
- // const start = commonAncestorComponent.getCellBySlot(scopes.at(0)!.slot)
3977
- // const end = commonAncestorComponent.getCellBySlot(scopes.at(-1)!.slot)
3978
- // // Re
3979
- // }
3980
- // }
4348
+ function setColor(picker) {
4349
+ const commonAncestorComponent = selection.commonAncestorComponent;
4350
+ if (commonAncestorComponent instanceof TableComponent) {
4351
+ const slots = commonAncestorComponent.getSelectedNormalizedSlots();
4352
+ if (slots) {
4353
+ slots.map(i => {
4354
+ return i.cells.filter(t => t.visible).map(i => i.raw.slot);
4355
+ }).flat().forEach(slot => {
4356
+ const rgba = picker.rgba;
4357
+ if (rgba) {
4358
+ slot.setAttribute(cellBackgroundAttr, `rgba(${rgba.r}, ${rgba.g}, ${rgba.b}, ${rgba.a})`);
4359
+ }
4360
+ else {
4361
+ slot.removeAttribute(cellBackgroundAttr);
4362
+ }
4363
+ });
4364
+ }
4365
+ }
3981
4366
  }
3982
4367
  const sub = refreshService.onRefresh.subscribe(() => {
3983
4368
  const commonAncestorComponent = selection.commonAncestorComponent;
@@ -3990,7 +4375,7 @@ function CellBackgroundTool() {
3990
4375
  });
3991
4376
  return () => {
3992
4377
  const vm = viewModel();
3993
- return jsxRuntime.jsx(Button, { highlight: vm.highlight, disabled: vm.disabled, onClick: split, children: jsxRuntime.jsx("span", { class: "xnote-icon-palette" }) });
4378
+ return (jsxRuntime.jsx(Dropdown, { width: '177px', menu: jsxRuntime.jsx(ColorPicker, { onSelected: setColor }), trigger: 'hover', children: jsxRuntime.jsx(Button, { highlight: vm.highlight, disabled: vm.disabled, children: jsxRuntime.jsx("span", { class: "xnote-icon-palette" }) }) }));
3994
4379
  };
3995
4380
  }
3996
4381
 
@@ -4988,7 +5373,7 @@ const Toolbar = core.withAnnotation({
4988
5373
  opacity: p.opacity,
4989
5374
  display: editorService.hideInlineToolbar ? 'none' : '',
4990
5375
  transitionDuration: p.transitionDuration + 's'
4991
- }, children: [selection.commonAncestorComponent instanceof TableComponent && jsxRuntime.jsxs(core.Fragment, { children: [jsxRuntime.jsx(ToolbarItem, { children: jsxRuntime.jsx(MergeCellsTool, {}) }), jsxRuntime.jsx(ToolbarItem, { children: jsxRuntime.jsx(SplitCellsTool, {}) }), jsxRuntime.jsx(ToolbarItem, { children: jsxRuntime.jsx(CellAlignTool, {}) })] }, "table"), jsxRuntime.jsx(ToolbarItem, { children: jsxRuntime.jsx(BlockTool, {}) }), jsxRuntime.jsx(ToolbarItem, { children: jsxRuntime.jsx(AttrTool, {}) }), jsxRuntime.jsx(ToolbarItem, { children: jsxRuntime.jsx(BoldTool, {}) }), jsxRuntime.jsx(ToolbarItem, { children: jsxRuntime.jsx(ItalicTool, {}) }), jsxRuntime.jsx(ToolbarItem, { children: jsxRuntime.jsx(StrikeThroughTool, {}) }), jsxRuntime.jsx(ToolbarItem, { children: jsxRuntime.jsx(UnderlineTool, {}) }), jsxRuntime.jsx(ToolbarItem, { children: jsxRuntime.jsx(FontSizeTool, {}) }), jsxRuntime.jsx(ToolbarItem, { children: jsxRuntime.jsx(FontFamilyTool, {}) }), jsxRuntime.jsx(ToolbarItem, { children: jsxRuntime.jsx(LinkTool, { hideToolbar: hideToolbar }) }), jsxRuntime.jsx(ToolbarItem, { children: jsxRuntime.jsx(CodeTool, {}) }), jsxRuntime.jsx(ToolbarItem, { children: jsxRuntime.jsx(ColorTool, {}) })] }));
5376
+ }, children: [selection.commonAncestorComponent instanceof TableComponent && jsxRuntime.jsxs(core.Fragment, { children: [jsxRuntime.jsx(ToolbarItem, { children: jsxRuntime.jsx(MergeCellsTool, {}) }), jsxRuntime.jsx(ToolbarItem, { children: jsxRuntime.jsx(SplitCellsTool, {}) }), jsxRuntime.jsx(ToolbarItem, { children: jsxRuntime.jsx(CellBackgroundTool, {}) }), jsxRuntime.jsx(ToolbarItem, { children: jsxRuntime.jsx(CellAlignTool, {}) })] }, "table"), jsxRuntime.jsx(ToolbarItem, { children: jsxRuntime.jsx(BlockTool, {}) }), jsxRuntime.jsx(ToolbarItem, { children: jsxRuntime.jsx(AttrTool, {}) }), jsxRuntime.jsx(ToolbarItem, { children: jsxRuntime.jsx(BoldTool, {}) }), jsxRuntime.jsx(ToolbarItem, { children: jsxRuntime.jsx(ItalicTool, {}) }), jsxRuntime.jsx(ToolbarItem, { children: jsxRuntime.jsx(StrikeThroughTool, {}) }), jsxRuntime.jsx(ToolbarItem, { children: jsxRuntime.jsx(UnderlineTool, {}) }), jsxRuntime.jsx(ToolbarItem, { children: jsxRuntime.jsx(FontSizeTool, {}) }), jsxRuntime.jsx(ToolbarItem, { children: jsxRuntime.jsx(FontFamilyTool, {}) }), jsxRuntime.jsx(ToolbarItem, { children: jsxRuntime.jsx(LinkTool, { hideToolbar: hideToolbar }) }), jsxRuntime.jsx(ToolbarItem, { children: jsxRuntime.jsx(CodeTool, {}) }), jsxRuntime.jsx(ToolbarItem, { children: jsxRuntime.jsx(ColorTool, {}) })] }));
4992
5377
  });
4993
5378
  });
4994
5379
 
@@ -6206,24 +6591,25 @@ let TableSelectionAwarenessDelegate = class TableSelectionAwarenessDelegate exte
6206
6591
  return false;
6207
6592
  }
6208
6593
  const rect = data.data || commonAncestorComponent.getMaxRectangle(findFocusCell(commonAncestorComponent, startSlot), findFocusCell(commonAncestorComponent, endSlot));
6209
- const renderer = this.domAdapter;
6210
6594
  if (!rect) {
6211
6595
  return false;
6212
6596
  }
6213
- const normalizedSlots = commonAncestorComponent.getSelectedNormalizedSlotsByRectangle(rect);
6214
- const rects = normalizedSlots.map(row => {
6215
- return row.cells.filter(i => i.visible).map(i => {
6216
- const td = renderer.getNativeNodeBySlot(i.raw.slot);
6217
- return td.getBoundingClientRect();
6218
- });
6219
- }).flat();
6220
- const left = Math.min(...rects.map(i => i.left));
6221
- const top = Math.min(...rects.map(i => i.top));
6597
+ const dom = this.domAdapter.getNativeNodeByComponent(commonAncestorComponent);
6598
+ const content = dom.querySelector('.xnote-table-content');
6599
+ const trs = content.querySelectorAll('tr');
6600
+ const cols = content.querySelectorAll('col');
6601
+ const top = trs[rect.y1].getBoundingClientRect().top;
6602
+ const left = cols[rect.x1].getBoundingClientRect().left;
6603
+ let height = trs[rect.y2 - 1].getBoundingClientRect().bottom - top;
6604
+ if (height === 0) {
6605
+ height = trs[rect.y2 - 1].children.item(0).getBoundingClientRect().bottom - top;
6606
+ }
6607
+ const width = cols[rect.x2 - 1].getBoundingClientRect().right - left;
6222
6608
  return [{
6223
6609
  left,
6224
6610
  top,
6225
- width: Math.max(...rects.map(i => i.right)) - left,
6226
- height: Math.max(...rects.map(i => i.bottom)) - top
6611
+ width,
6612
+ height
6227
6613
  }];
6228
6614
  }
6229
6615
  };
@@ -6351,9 +6737,22 @@ class XNoteMessageBug extends collaborate.MessageBus {
6351
6737
  get() {
6352
6738
  const selection = this.selection;
6353
6739
  const c = selection.commonAncestorComponent;
6354
- return Object.assign(Object.assign({}, this.userinfo), { selection: selection.getPaths(), data: (!selection.isCollapsed && c instanceof TableComponent) ? c.getSelectedRect() : null });
6740
+ const msg = Object.assign(Object.assign({}, this.userinfo), { selection: selection.getPaths() });
6741
+ if (!selection.isCollapsed && c instanceof TableComponent) {
6742
+ const selection = c.tableSelection();
6743
+ if (selection) {
6744
+ msg.data = {
6745
+ x1: selection.startColumn,
6746
+ x2: selection.endColumn,
6747
+ y1: selection.startRow,
6748
+ y2: selection.endRow,
6749
+ };
6750
+ }
6751
+ }
6752
+ return msg;
6355
6753
  }
6356
6754
  consume(message) {
6755
+ message = message.filter(i => i.message);
6357
6756
  this.messageChangeEvent.next([...message]);
6358
6757
  this.collaborateCursor.draw(message.filter(item => {
6359
6758
  return item.message.id !== this.userinfo.id;
@@ -6420,6 +6819,7 @@ class Editor extends core$1.Textbus {
6420
6819
  strikeThroughFormatLoader,
6421
6820
  underlineFormatLoader
6422
6821
  ], attributeLoaders: [
6822
+ cellBackgroundAttrLoader,
6423
6823
  cellAlignAttrLoader,
6424
6824
  headingAttrLoader,
6425
6825
  textAlignAttrLoader,
@@ -6507,6 +6907,7 @@ class Editor extends core$1.Textbus {
6507
6907
  strikeThroughFormatter,
6508
6908
  underlineFormatter
6509
6909
  ], attributes: [
6910
+ cellBackgroundAttr,
6510
6911
  cellAlignAttr,
6511
6912
  headingAttr,
6512
6913
  textAlignAttr,
@@ -6578,6 +6979,7 @@ exports.Button = Button;
6578
6979
  exports.CellAlignTool = CellAlignTool;
6579
6980
  exports.CellBackgroundTool = CellBackgroundTool;
6580
6981
  exports.CodeTool = CodeTool;
6982
+ exports.ColorPicker = ColorPicker;
6581
6983
  exports.ColorTool = ColorTool;
6582
6984
  exports.ComponentToolbar = ComponentToolbar;
6583
6985
  exports.Divider = Divider;
@@ -6611,6 +7013,7 @@ exports.Organization = Organization;
6611
7013
  exports.OutputInjectionToken = OutputInjectionToken;
6612
7014
  exports.ParagraphComponent = ParagraphComponent;
6613
7015
  exports.ParagraphView = ParagraphView;
7016
+ exports.Picker = Picker;
6614
7017
  exports.Popup = Popup;
6615
7018
  exports.RootComponent = RootComponent;
6616
7019
  exports.RootView = RootView;
@@ -6637,6 +7040,8 @@ exports.boldFormatLoader = boldFormatLoader;
6637
7040
  exports.boldFormatter = boldFormatter;
6638
7041
  exports.cellAlignAttr = cellAlignAttr;
6639
7042
  exports.cellAlignAttrLoader = cellAlignAttrLoader;
7043
+ exports.cellBackgroundAttr = cellBackgroundAttr;
7044
+ exports.cellBackgroundAttrLoader = cellBackgroundAttrLoader;
6640
7045
  exports.codeFormatLoader = codeFormatLoader;
6641
7046
  exports.codeFormatter = codeFormatter;
6642
7047
  exports.colorFormatLoader = colorFormatLoader;
@@ -1,4 +1,5 @@
1
1
  export * from './cell-align.attr';
2
+ export * from './cell-background.attr';
2
3
  export * from './heading.attr';
3
4
  export * from './text-align.attr';
4
5
  export * from './text-indent.attr';
@@ -0,0 +1,4 @@
1
+ import { Attribute } from '@textbus/core';
2
+ import { AttributeLoader } from '@textbus/platform-browser';
3
+ export declare const cellBackgroundAttr: Attribute<string>;
4
+ export declare const cellBackgroundAttrLoader: AttributeLoader<string>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@textbus/xnote",
3
- "version": "0.0.10",
3
+ "version": "0.1.0",
4
4
  "description": "A high-performance rich text editor that supports multiplayer online collaboration.",
5
5
  "main": "./bundles/index.js",
6
6
  "module": "./bundles/index.esm.js",
@@ -33,7 +33,7 @@
33
33
  "@textbus/platform-browser": "^4.2.0",
34
34
  "@viewfly/core": "^1.0.5",
35
35
  "@viewfly/hooks": "^1.0.5",
36
- "@viewfly/platform-browser": "^1.0.5",
36
+ "@viewfly/platform-browser": "^1.0.6",
37
37
  "@viewfly/scoped-css": "^1.0.5",
38
38
  "highlight.js": "^11.9.0",
39
39
  "katex": "^0.16.10",