@formicoidea/labre-core 0.55.0 → 0.57.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.
@@ -45,9 +45,15 @@ import { property, query, state } from 'lit/decorators.js';
45
45
  import { guard } from 'lit/directives/guard.js';
46
46
  import { styleMap } from 'lit/directives/style-map.js';
47
47
  import debounce from 'lodash-es/debounce.js';
48
+ import { fluidPreviewSize } from './preview-size.js';
48
49
  const DEFAULT_PREVIEW_CONTAINER_WIDTH = 280;
49
50
  const DEFAULT_PREVIEW_CONTAINER_HEIGHT = 166;
50
51
  const styles = css `
52
+ frame-preview[data-fluid] {
53
+ display: block;
54
+ width: 100%;
55
+ }
56
+
51
57
  .frame-preview-container {
52
58
  display: block;
53
59
  width: 100%;
@@ -89,9 +95,15 @@ let FramePreview = (() => {
89
95
  let _std_decorators;
90
96
  let _std_initializers = [];
91
97
  let _std_extraInitializers = [];
98
+ let __containerWidth_decorators;
99
+ let __containerWidth_initializers = [];
100
+ let __containerWidth_extraInitializers = [];
92
101
  let _fillScreen_decorators;
93
102
  let _fillScreen_initializers = [];
94
103
  let _fillScreen_extraInitializers = [];
104
+ let _fluid_decorators;
105
+ let _fluid_initializers = [];
106
+ let _fluid_extraInitializers = [];
95
107
  let _frame_decorators;
96
108
  let _frame_initializers = [];
97
109
  let _frame_extraInitializers = [];
@@ -111,14 +123,18 @@ let FramePreview = (() => {
111
123
  static {
112
124
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
113
125
  _std_decorators = [property({ attribute: false })];
126
+ __containerWidth_decorators = [state()];
114
127
  _fillScreen_decorators = [state()];
128
+ _fluid_decorators = [property({ attribute: false })];
115
129
  _frame_decorators = [property({ attribute: false })];
116
130
  _frameViewportWH_decorators = [state()];
117
131
  _previewEditor_decorators = [query('editor-host')];
118
132
  _surfaceHeight_decorators = [property({ attribute: false })];
119
133
  _surfaceWidth_decorators = [property({ attribute: false })];
120
134
  __esDecorate(this, null, _std_decorators, { kind: "accessor", name: "std", static: false, private: false, access: { has: obj => "std" in obj, get: obj => obj.std, set: (obj, value) => { obj.std = value; } }, metadata: _metadata }, _std_initializers, _std_extraInitializers);
135
+ __esDecorate(this, null, __containerWidth_decorators, { kind: "accessor", name: "_containerWidth", static: false, private: false, access: { has: obj => "_containerWidth" in obj, get: obj => obj._containerWidth, set: (obj, value) => { obj._containerWidth = value; } }, metadata: _metadata }, __containerWidth_initializers, __containerWidth_extraInitializers);
121
136
  __esDecorate(this, null, _fillScreen_decorators, { kind: "accessor", name: "fillScreen", static: false, private: false, access: { has: obj => "fillScreen" in obj, get: obj => obj.fillScreen, set: (obj, value) => { obj.fillScreen = value; } }, metadata: _metadata }, _fillScreen_initializers, _fillScreen_extraInitializers);
137
+ __esDecorate(this, null, _fluid_decorators, { kind: "accessor", name: "fluid", static: false, private: false, access: { has: obj => "fluid" in obj, get: obj => obj.fluid, set: (obj, value) => { obj.fluid = value; } }, metadata: _metadata }, _fluid_initializers, _fluid_extraInitializers);
122
138
  __esDecorate(this, null, _frame_decorators, { kind: "accessor", name: "frame", static: false, private: false, access: { has: obj => "frame" in obj, get: obj => obj.frame, set: (obj, value) => { obj.frame = value; } }, metadata: _metadata }, _frame_initializers, _frame_extraInitializers);
123
139
  __esDecorate(this, null, _frameViewportWH_decorators, { kind: "accessor", name: "frameViewportWH", static: false, private: false, access: { has: obj => "frameViewportWH" in obj, get: obj => obj.frameViewportWH, set: (obj, value) => { obj.frameViewportWH = value; } }, metadata: _metadata }, _frameViewportWH_initializers, _frameViewportWH_extraInitializers);
124
140
  __esDecorate(this, null, _previewEditor_decorators, { kind: "accessor", name: "previewEditor", static: false, private: false, access: { has: obj => "previewEditor" in obj, get: obj => obj.previewEditor, set: (obj, value) => { obj.previewEditor = value; } }, metadata: _metadata }, _previewEditor_initializers, _previewEditor_extraInitializers);
@@ -157,9 +173,13 @@ let FramePreview = (() => {
157
173
  payload.view.model.flavour !== 'affine:page') {
158
174
  return;
159
175
  }
176
+ // Every size, not only the first: a fluid preview follows its
177
+ // panel's width, and the mini editor's viewport settles on the new
178
+ // size (debounced) after the box has changed — fitting then is what
179
+ // keeps the frame filling it. The subject completes with the
180
+ // viewport, which ends the subscription.
160
181
  const viewport = std.get(GfxControllerIdentifier).viewport;
161
- const subscription = viewport.sizeUpdated.subscribe(() => {
162
- subscription.unsubscribe();
182
+ viewport.sizeUpdated.subscribe(() => {
163
183
  refreshViewport();
164
184
  });
165
185
  });
@@ -219,14 +239,50 @@ let FramePreview = (() => {
219
239
  this._initPreviewDoc();
220
240
  this._updateFrameViewportWH();
221
241
  this._setFrameDisposables(this.frame);
242
+ this._observeWidth();
222
243
  }
223
244
  disconnectedCallback() {
224
245
  super.disconnectedCallback();
225
246
  this._clearFrameDisposables();
247
+ this._resizeObserver?.disconnect();
248
+ this._resizeObserver = null;
249
+ }
250
+ /** A fluid preview follows its own width: the panel's, as it is resized. */
251
+ _observeWidth() {
252
+ this._resizeObserver?.disconnect();
253
+ this._resizeObserver = null;
254
+ if (!this.fluid || typeof ResizeObserver === 'undefined')
255
+ return;
256
+ this._resizeObserver = new ResizeObserver(([entry]) => {
257
+ if (!entry)
258
+ return;
259
+ const width = Math.floor(entry.contentRect.width);
260
+ if (width !== this._containerWidth)
261
+ this._containerWidth = width;
262
+ });
263
+ this._resizeObserver.observe(this);
264
+ }
265
+ willUpdate(changed) {
266
+ if (changed.has('fluid')) {
267
+ this.toggleAttribute('data-fluid', this.fluid);
268
+ if (this.isConnected)
269
+ this._observeWidth();
270
+ }
271
+ // The box was only read at connect and on a frame's own update, so a host
272
+ // that resized it after mounting kept the old scale.
273
+ if (changed.has('fluid') ||
274
+ changed.has('_containerWidth') ||
275
+ changed.has('surfaceWidth') ||
276
+ changed.has('surfaceHeight') ||
277
+ changed.has('fillScreen')) {
278
+ this._updateFrameViewportWH();
279
+ }
226
280
  }
227
281
  render() {
228
282
  const { frame } = this;
229
- const noContent = !frame || !frame.xywh;
283
+ // A fluid preview builds its mini editor once it knows its width, never
284
+ // at the default box first.
285
+ const noContent = !frame || !frame.xywh || (this.fluid && this._containerWidth === 0);
230
286
  return html `<div class="frame-preview-container">
231
287
  ${noContent ? nothing : this._renderSurfaceContent()}
232
288
  </div>`;
@@ -242,9 +298,21 @@ let FramePreview = (() => {
242
298
  #std_accessor_storage;
243
299
  get std() { return this.#std_accessor_storage; }
244
300
  set std(value) { this.#std_accessor_storage = value; }
301
+ #_containerWidth_accessor_storage;
302
+ /** The width a fluid preview measured on itself; `0` until laid out. */
303
+ get _containerWidth() { return this.#_containerWidth_accessor_storage; }
304
+ set _containerWidth(value) { this.#_containerWidth_accessor_storage = value; }
245
305
  #fillScreen_accessor_storage;
246
306
  get fillScreen() { return this.#fillScreen_accessor_storage; }
247
307
  set fillScreen(value) { this.#fillScreen_accessor_storage = value; }
308
+ #fluid_accessor_storage;
309
+ /**
310
+ * Take the container's width and the frame's proportions (recette 1,
311
+ * P0-1.2): the box grows and shrinks with the panel, never taller than
312
+ * wide, and `surfaceWidth` / `surfaceHeight` are computed, not read.
313
+ */
314
+ get fluid() { return this.#fluid_accessor_storage; }
315
+ set fluid(value) { this.#fluid_accessor_storage = value; }
248
316
  #frame_accessor_storage;
249
317
  get frame() { return this.#frame_accessor_storage; }
250
318
  set frame(value) { this.#frame_accessor_storage = value; }
@@ -278,8 +346,14 @@ let FramePreview = (() => {
278
346
  this._frameDisposables = null;
279
347
  this._previewDoc = null;
280
348
  this._runtimePreviewExt = [];
349
+ this._resizeObserver = null;
281
350
  this._updateFrameViewportWH = () => {
282
351
  const [, , w, h] = deserializeXYWH(this.frame.xywh);
352
+ if (this.fluid) {
353
+ const box = fluidPreviewSize(this._containerWidth, w, h);
354
+ this.surfaceWidth = box.width;
355
+ this.surfaceHeight = box.height;
356
+ }
283
357
  let scale = 1;
284
358
  if (this.fillScreen) {
285
359
  scale = Math.max(this.surfaceWidth / w, this.surfaceHeight / h);
@@ -293,8 +367,10 @@ let FramePreview = (() => {
293
367
  };
294
368
  };
295
369
  this.#std_accessor_storage = __runInitializers(this, _std_initializers, void 0);
296
- this.#fillScreen_accessor_storage = (__runInitializers(this, _std_extraInitializers), __runInitializers(this, _fillScreen_initializers, false));
297
- this.#frame_accessor_storage = (__runInitializers(this, _fillScreen_extraInitializers), __runInitializers(this, _frame_initializers, void 0));
370
+ this.#_containerWidth_accessor_storage = (__runInitializers(this, _std_extraInitializers), __runInitializers(this, __containerWidth_initializers, 0));
371
+ this.#fillScreen_accessor_storage = (__runInitializers(this, __containerWidth_extraInitializers), __runInitializers(this, _fillScreen_initializers, false));
372
+ this.#fluid_accessor_storage = (__runInitializers(this, _fillScreen_extraInitializers), __runInitializers(this, _fluid_initializers, false));
373
+ this.#frame_accessor_storage = (__runInitializers(this, _fluid_extraInitializers), __runInitializers(this, _frame_initializers, void 0));
298
374
  this.#frameViewportWH_accessor_storage = (__runInitializers(this, _frame_extraInitializers), __runInitializers(this, _frameViewportWH_initializers, {
299
375
  width: 0,
300
376
  height: 0,
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The box of a fluid frame preview (recette 1, P0-1.2): the container's width,
3
+ * the frame's proportions, never taller than it is wide. A frame without an
4
+ * area gets a square box; a container not laid out yet gets no box at all.
5
+ */
6
+ export declare function fluidPreviewSize(containerWidth: number, frameWidth: number, frameHeight: number): {
7
+ width: number;
8
+ height: number;
9
+ };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * A portrait frame previewed at the panel's full width would be taller than
3
+ * the sidebar is wide many times over and push every other card off screen:
4
+ * past a square, the box stops growing and the frame is contained in it.
5
+ */
6
+ const MAX_HEIGHT_PER_WIDTH = 1;
7
+ /**
8
+ * The box of a fluid frame preview (recette 1, P0-1.2): the container's width,
9
+ * the frame's proportions, never taller than it is wide. A frame without an
10
+ * area gets a square box; a container not laid out yet gets no box at all.
11
+ */
12
+ export function fluidPreviewSize(containerWidth, frameWidth, frameHeight) {
13
+ const width = Math.max(0, Math.floor(containerWidth));
14
+ if (width === 0)
15
+ return { width: 0, height: 0 };
16
+ const ratio = frameWidth > 0 && frameHeight > 0
17
+ ? Math.min(frameHeight / frameWidth, MAX_HEIGHT_PER_WIDTH)
18
+ : MAX_HEIGHT_PER_WIDTH;
19
+ return { width, height: Math.round(width * ratio) };
20
+ }
@@ -1,14 +1,12 @@
1
1
  import { AFFINE_FRAME_PANEL_BODY, FramePanelBody, } from './body/frame-panel-body.js';
2
2
  import { AFFINE_FRAME_CARD, FrameCard } from './card/frame-card.js';
3
3
  import { AFFINE_FRAME_CARD_TITLE, FrameCardTitle, } from './card/frame-card-title.js';
4
- import { AFFINE_FRAME_TITLE_EDITOR, FrameCardTitleEditor, } from './card/frame-card-title-editor.js';
5
4
  import { AFFINE_FRAME_PREVIEW, FramePreview } from './card/frame-preview.js';
6
5
  import { AFFINE_FRAME_PANEL, FramePanel } from './frame-panel.js';
7
6
  import { AFFINE_FRAME_PANEL_HEADER, FramePanelHeader, } from './header/frame-panel-header.js';
8
7
  import { AFFINE_FRAMES_SETTING_MENU, FramesSettingMenu, } from './header/frames-setting-menu.js';
9
8
  export function effects() {
10
9
  customElements.define(AFFINE_FRAME_PANEL, FramePanel);
11
- customElements.define(AFFINE_FRAME_TITLE_EDITOR, FrameCardTitleEditor);
12
10
  customElements.define(AFFINE_FRAME_CARD, FrameCard);
13
11
  customElements.define(AFFINE_FRAME_CARD_TITLE, FrameCardTitle);
14
12
  customElements.define(AFFINE_FRAME_PANEL_BODY, FramePanelBody);
@@ -68,6 +68,8 @@ const styles = css `
68
68
 
69
69
  overflow: auto;
70
70
  overflow-x: hidden;
71
+ /* A scrollbar appearing must not narrow the fluid cards it scrolls. */
72
+ scrollbar-gutter: stable;
71
73
  scrollbar-width: thin; /* For Firefox */
72
74
  scrollbar-color: transparent transparent; /* For Firefox */
73
75
  }
@@ -2,11 +2,23 @@ import isMatch from 'lodash.ismatch';
2
2
  export function runQuery(query, block) {
3
3
  const blockViewType = getBlockViewType(query, block);
4
4
  block.blockViewType = blockViewType;
5
- if (blockViewType !== 'hidden') {
5
+ if (blockViewType !== 'hidden' && canHideBlocks(query)) {
6
6
  const queryMode = query.mode;
7
7
  setAncestorsToDisplayIfHidden(queryMode, block);
8
8
  }
9
9
  }
10
+ /**
11
+ * A loose query hides a block only through a `viewType: 'hidden'` entry, so
12
+ * without one no ancestor can be hidden and the walk below is a no-op. The
13
+ * walk costs one O(n) `getParent` per ancestor, which made opening a store
14
+ * with the default query quadratic in the block count (#507, guard
15
+ * `__tests__/query.unit.spec.ts`).
16
+ */
17
+ function canHideBlocks(query) {
18
+ if (query.mode !== 'loose')
19
+ return true;
20
+ return query.match.some(entry => entry.viewType === 'hidden');
21
+ }
10
22
  function getBlockViewType(query, block) {
11
23
  const flavour = block.model.flavour;
12
24
  const id = block.model.id;
@@ -54,8 +54,9 @@ import { type BlockStdScope, type CommandFile } from './_pkgs/std/index.js';
54
54
  */
55
55
  export { type AnyCommandDescriptor, type CommandFile, type CommandInvocation, type CommandOwner, type CommandSurface, getCommandIcon, getCommandsForSurface, getRegisteredCommands, runCommand, runCommandAsync, } from './_pkgs/std/index.js';
56
56
  export { armArtefact } from './_pkgs/affine-widget-edgeless-toolbar/index.js';
57
- export { type SelectionPaneNode, selectionPaneTree, } from './_pkgs/affine-block-surface/index.js';
57
+ export { type SelectionPaneNode, selectionPaneCommands, selectionPaneTree, } from './_pkgs/affine-block-surface/index.js';
58
58
  export { frameCommands, type ReorderFramesParams, reorderFramesParams, } from './_pkgs/affine-block-frame/index.js';
59
+ export { createPanelReorderDrag, type PanelDragPoint, type PanelReorderDrag, type PanelReorderDragOptions, panelReorderGap, } from './_pkgs/affine-shared/utils/index.js';
59
60
  export { formatPropertyValue, isPropertyValueEmpty, } from './_pkgs/affine-fragment-doc-title/index.js';
60
61
  export type { PropertiesPanelRequest, PropertiesPanelService, TitleBandNotShownPage, TitleBandProperty, TitleBandService, TitleBandSheetState, } from './_pkgs/affine-shared/services/index.js';
61
62
  export { ThreadMarksExtension } from './_pkgs/affine-shared/services/index.js';
@@ -89,9 +90,12 @@ export declare function fitToModel(std: BlockStdScope, id: string, padding?: [nu
89
90
  * thumbnail renders one through `ExportManager` instead.
90
91
  *
91
92
  * Returns the element ready to be appended; `width` and `height` are the
92
- * preview box in CSS pixels (the panel's card is 280 × 166), `fillScreen`
93
- * covers the box instead of containing the frame. One mini editor per
94
- * preview: mount only the cards on screen. The element is defined by the
93
+ * preview box in CSS pixels, `fillScreen` covers the box instead of
94
+ * containing the frame. `fluid` (0.57) replaces the fixed box: the preview
95
+ * takes its container's width and the frame's proportions, never taller than
96
+ * wide, and follows the container as it is resized — the library's own panel
97
+ * cards draw it that way (recette 1, P0-1.2); `width` and `height` are then
98
+ * ignored. One mini editor per preview: mount only the cards on screen. The element is defined by the
95
99
  * frame panel's view extension, so it renders nothing in an assembly where the
96
100
  * `frame` flag is off (ADR 0009) — the same assembly where there is no frame
97
101
  * to preview.
@@ -100,6 +104,7 @@ export declare function createFramePreview(std: BlockStdScope, frame: FrameBlock
100
104
  width?: number;
101
105
  height?: number;
102
106
  fillScreen?: boolean;
107
+ fluid?: boolean;
103
108
  }): FramePreview;
104
109
  /**
105
110
  * One entry of the current view's own actions — what a host draws in the
@@ -57,8 +57,18 @@ import { frameworkDescriptor } from './frameworks.js';
57
57
  */
58
58
  export { getCommandIcon, getCommandsForSurface, getRegisteredCommands, runCommand, runCommandAsync, } from './_pkgs/std/index.js';
59
59
  export { armArtefact } from './_pkgs/affine-widget-edgeless-toolbar/index.js';
60
- export { selectionPaneTree, } from './_pkgs/affine-block-surface/index.js';
60
+ export { selectionPaneCommands, selectionPaneTree, } from './_pkgs/affine-block-surface/index.js';
61
61
  export { frameCommands, reorderFramesParams, } from './_pkgs/affine-block-frame/index.js';
62
+ /*
63
+ * The side panels' one drag-to-reorder gesture (ADR 0034 §6), the one the
64
+ * library's frame panel and selection pane run: a host's slide list hands it
65
+ * its rows, its drop rule and its write (`canvas.frame.reorder`), and gets the
66
+ * threshold, the read-only refusal, the cursor mask, Escape and
67
+ * `pointercancel` as cancels and the swallowed click. A factory, not a class:
68
+ * the controller it returns is the host's, disposed with its panel. DOM types
69
+ * only, so a React panel types it without Lit (recette 1, P0-1.3).
70
+ */
71
+ export { createPanelReorderDrag, panelReorderGap, } from './_pkgs/affine-shared/utils/index.js';
62
72
  /*
63
73
  * The properties panel (ADR 0035 §9b and §11). The editor asks the host to
64
74
  * show it through `PropertiesPanelExtension` and feeds the title band through
@@ -124,9 +134,12 @@ export function fitToModel(std, id, padding = [0, 0, 0, 0]) {
124
134
  * thumbnail renders one through `ExportManager` instead.
125
135
  *
126
136
  * Returns the element ready to be appended; `width` and `height` are the
127
- * preview box in CSS pixels (the panel's card is 280 × 166), `fillScreen`
128
- * covers the box instead of containing the frame. One mini editor per
129
- * preview: mount only the cards on screen. The element is defined by the
137
+ * preview box in CSS pixels, `fillScreen` covers the box instead of
138
+ * containing the frame. `fluid` (0.57) replaces the fixed box: the preview
139
+ * takes its container's width and the frame's proportions, never taller than
140
+ * wide, and follows the container as it is resized — the library's own panel
141
+ * cards draw it that way (recette 1, P0-1.2); `width` and `height` are then
142
+ * ignored. One mini editor per preview: mount only the cards on screen. The element is defined by the
130
143
  * frame panel's view extension, so it renders nothing in an assembly where the
131
144
  * `frame` flag is off (ADR 0009) — the same assembly where there is no frame
132
145
  * to preview.
@@ -141,6 +154,8 @@ export function createFramePreview(std, frame, options = {}) {
141
154
  preview.surfaceHeight = options.height;
142
155
  if (options.fillScreen !== undefined)
143
156
  preview.fillScreen = options.fillScreen;
157
+ if (options.fluid !== undefined)
158
+ preview.fluid = options.fluid;
144
159
  return preview;
145
160
  }
146
161
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@formicoidea/labre-core",
3
3
  "description": "Labre editor — the full BlockSuite-derived editor as one package.",
4
- "version": "0.55.0",
4
+ "version": "0.57.0",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "author": "lajola",
@@ -904,7 +904,8 @@
904
904
  }
905
905
  },
906
906
  "files": [
907
- "dist"
907
+ "dist",
908
+ "architecture"
908
909
  ],
909
910
  "dependencies": {
910
911
  "@atlaskit/pragmatic-drag-and-drop": "^2.0.0",
@@ -1,25 +0,0 @@
1
- import type { FrameBlockModel } from '../../affine-model/index.js';
2
- import type { RichText } from '../../affine-rich-text/index.js';
3
- import { ShadowlessElement } from '../../std/index.js';
4
- export declare const AFFINE_FRAME_TITLE_EDITOR = "affine-frame-card-title-editor";
5
- declare const FrameCardTitleEditor_base: typeof ShadowlessElement & import("../../global/utils/types.js").Constructor<import("../../global/lit/with-disposable.js").DisposableClass>;
6
- export declare class FrameCardTitleEditor extends FrameCardTitleEditor_base {
7
- static styles: import("lit").CSSResult;
8
- private readonly _isComposing;
9
- get inlineEditor(): import("../../affine-shared/types/index.js").AffineInlineEditor | null;
10
- private _unmount;
11
- firstUpdated(): void;
12
- getUpdateComplete(): Promise<boolean>;
13
- render(): import("lit-html").TemplateResult<1>;
14
- accessor frameModel: FrameBlockModel;
15
- accessor left: number;
16
- accessor maxWidth: number;
17
- accessor richText: RichText;
18
- accessor titleContentElement: HTMLElement;
19
- }
20
- declare global {
21
- interface HTMLElementTagNameMap {
22
- [AFFINE_FRAME_TITLE_EDITOR]: FrameCardTitleEditor;
23
- }
24
- }
25
- export {};
@@ -1,181 +0,0 @@
1
- var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
2
- function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
3
- var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
4
- var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
5
- var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
6
- var _, done = false;
7
- for (var i = decorators.length - 1; i >= 0; i--) {
8
- var context = {};
9
- for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
10
- for (var p in contextIn.access) context.access[p] = contextIn.access[p];
11
- context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
12
- var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
13
- if (kind === "accessor") {
14
- if (result === void 0) continue;
15
- if (result === null || typeof result !== "object") throw new TypeError("Object expected");
16
- if (_ = accept(result.get)) descriptor.get = _;
17
- if (_ = accept(result.set)) descriptor.set = _;
18
- if (_ = accept(result.init)) initializers.unshift(_);
19
- }
20
- else if (_ = accept(result)) {
21
- if (kind === "field") initializers.unshift(_);
22
- else descriptor[key] = _;
23
- }
24
- }
25
- if (target) Object.defineProperty(target, contextIn.name, descriptor);
26
- done = true;
27
- };
28
- var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
29
- var useValue = arguments.length > 2;
30
- for (var i = 0; i < initializers.length; i++) {
31
- value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
32
- }
33
- return useValue ? value : void 0;
34
- };
35
- import { WithDisposable } from '../../global/lit/index.js';
36
- import { ShadowlessElement } from '../../std/index.js';
37
- import { css, html } from 'lit';
38
- import { property, query } from 'lit/decorators.js';
39
- import { styleMap } from 'lit/directives/style-map.js';
40
- const styles = css `
41
- frame-card-title-editor rich-text .nowrap-lines::-webkit-scrollbar {
42
- display: none;
43
- }
44
- `;
45
- export const AFFINE_FRAME_TITLE_EDITOR = 'affine-frame-card-title-editor';
46
- let FrameCardTitleEditor = (() => {
47
- let _classSuper = WithDisposable(ShadowlessElement);
48
- let _frameModel_decorators;
49
- let _frameModel_initializers = [];
50
- let _frameModel_extraInitializers = [];
51
- let _left_decorators;
52
- let _left_initializers = [];
53
- let _left_extraInitializers = [];
54
- let _maxWidth_decorators;
55
- let _maxWidth_initializers = [];
56
- let _maxWidth_extraInitializers = [];
57
- let _richText_decorators;
58
- let _richText_initializers = [];
59
- let _richText_extraInitializers = [];
60
- let _titleContentElement_decorators;
61
- let _titleContentElement_initializers = [];
62
- let _titleContentElement_extraInitializers = [];
63
- return class FrameCardTitleEditor extends _classSuper {
64
- static {
65
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
66
- _frameModel_decorators = [property({ attribute: false })];
67
- _left_decorators = [property({ attribute: false })];
68
- _maxWidth_decorators = [property({ attribute: false })];
69
- _richText_decorators = [query('rich-text')];
70
- _titleContentElement_decorators = [property({ attribute: false })];
71
- __esDecorate(this, null, _frameModel_decorators, { kind: "accessor", name: "frameModel", static: false, private: false, access: { has: obj => "frameModel" in obj, get: obj => obj.frameModel, set: (obj, value) => { obj.frameModel = value; } }, metadata: _metadata }, _frameModel_initializers, _frameModel_extraInitializers);
72
- __esDecorate(this, null, _left_decorators, { kind: "accessor", name: "left", static: false, private: false, access: { has: obj => "left" in obj, get: obj => obj.left, set: (obj, value) => { obj.left = value; } }, metadata: _metadata }, _left_initializers, _left_extraInitializers);
73
- __esDecorate(this, null, _maxWidth_decorators, { kind: "accessor", name: "maxWidth", static: false, private: false, access: { has: obj => "maxWidth" in obj, get: obj => obj.maxWidth, set: (obj, value) => { obj.maxWidth = value; } }, metadata: _metadata }, _maxWidth_initializers, _maxWidth_extraInitializers);
74
- __esDecorate(this, null, _richText_decorators, { kind: "accessor", name: "richText", static: false, private: false, access: { has: obj => "richText" in obj, get: obj => obj.richText, set: (obj, value) => { obj.richText = value; } }, metadata: _metadata }, _richText_initializers, _richText_extraInitializers);
75
- __esDecorate(this, null, _titleContentElement_decorators, { kind: "accessor", name: "titleContentElement", static: false, private: false, access: { has: obj => "titleContentElement" in obj, get: obj => obj.titleContentElement, set: (obj, value) => { obj.titleContentElement = value; } }, metadata: _metadata }, _titleContentElement_initializers, _titleContentElement_extraInitializers);
76
- if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
77
- }
78
- static { this.styles = styles; }
79
- get inlineEditor() {
80
- return this.richText.inlineEditor;
81
- }
82
- _unmount() {
83
- // dispose in advance to avoid execute `this.remove()` twice
84
- this.disposables.dispose();
85
- this.remove();
86
- this.titleContentElement.style.display = 'block';
87
- }
88
- firstUpdated() {
89
- this.updateComplete
90
- .then(() => {
91
- if (this.inlineEditor === null)
92
- return;
93
- this.titleContentElement.style.display = 'none';
94
- this.inlineEditor.selectAll();
95
- this.inlineEditor.slots.renderComplete.subscribe(() => {
96
- this.requestUpdate();
97
- });
98
- const inlineEditorContainer = this.inlineEditor.rootElement;
99
- if (!inlineEditorContainer)
100
- return;
101
- this.disposables.addFromEvent(inlineEditorContainer, 'blur', () => {
102
- this._unmount();
103
- });
104
- this.disposables.addFromEvent(inlineEditorContainer, 'click', e => {
105
- e.stopPropagation();
106
- });
107
- this.disposables.addFromEvent(inlineEditorContainer, 'dblclick', e => {
108
- e.stopPropagation();
109
- });
110
- this.disposables.addFromEvent(inlineEditorContainer, 'keydown', e => {
111
- e.stopPropagation();
112
- if (e.key === 'Enter' && !this._isComposing) {
113
- this._unmount();
114
- }
115
- });
116
- })
117
- .catch(console.error);
118
- }
119
- async getUpdateComplete() {
120
- const result = await super.getUpdateComplete();
121
- await this.richText?.updateComplete;
122
- return result;
123
- }
124
- render() {
125
- const inlineEditorStyle = styleMap({
126
- transformOrigin: 'top left',
127
- borderRadius: '4px',
128
- maxWidth: `${this.maxWidth}px`,
129
- maxHeight: '20px',
130
- width: 'fit-content',
131
- height: '20px',
132
- fontSize: 'var(--affine-font-sm)',
133
- lineHeight: '20px',
134
- position: 'absolute',
135
- left: `${this.left}px`,
136
- top: '0px',
137
- minWidth: '8px',
138
- background: 'var(--affine-background-primary-color)',
139
- border: '1px solid var(--affine-primary-color)',
140
- color: 'var(--affine-text-primary-color)',
141
- boxShadow: '0px 0px 0px 2px color-mix(in srgb, var(--affine-primary-color) 30%, transparent)',
142
- zIndex: '1',
143
- display: 'block',
144
- });
145
- return html `<rich-text
146
- .yText=${this.frameModel.props.title.yText}
147
- .enableFormat=${false}
148
- .enableAutoScrollHorizontally=${true}
149
- .enableUndoRedo=${false}
150
- .wrapText=${false}
151
- style=${inlineEditorStyle}
152
- ></rich-text>`;
153
- }
154
- #frameModel_accessor_storage;
155
- get frameModel() { return this.#frameModel_accessor_storage; }
156
- set frameModel(value) { this.#frameModel_accessor_storage = value; }
157
- #left_accessor_storage;
158
- get left() { return this.#left_accessor_storage; }
159
- set left(value) { this.#left_accessor_storage = value; }
160
- #maxWidth_accessor_storage;
161
- get maxWidth() { return this.#maxWidth_accessor_storage; }
162
- set maxWidth(value) { this.#maxWidth_accessor_storage = value; }
163
- #richText_accessor_storage;
164
- get richText() { return this.#richText_accessor_storage; }
165
- set richText(value) { this.#richText_accessor_storage = value; }
166
- #titleContentElement_accessor_storage;
167
- get titleContentElement() { return this.#titleContentElement_accessor_storage; }
168
- set titleContentElement(value) { this.#titleContentElement_accessor_storage = value; }
169
- constructor() {
170
- super(...arguments);
171
- this._isComposing = false;
172
- this.#frameModel_accessor_storage = __runInitializers(this, _frameModel_initializers, void 0);
173
- this.#left_accessor_storage = (__runInitializers(this, _frameModel_extraInitializers), __runInitializers(this, _left_initializers, void 0));
174
- this.#maxWidth_accessor_storage = (__runInitializers(this, _left_extraInitializers), __runInitializers(this, _maxWidth_initializers, void 0));
175
- this.#richText_accessor_storage = (__runInitializers(this, _maxWidth_extraInitializers), __runInitializers(this, _richText_initializers, void 0));
176
- this.#titleContentElement_accessor_storage = (__runInitializers(this, _richText_extraInitializers), __runInitializers(this, _titleContentElement_initializers, void 0));
177
- __runInitializers(this, _titleContentElement_extraInitializers);
178
- }
179
- };
180
- })();
181
- export { FrameCardTitleEditor };