vue-editor-layout-headless 0.0.0-stage → 4.6.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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2020-present Jimmy Chen
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,64 @@
1
- # Temporary Holding Version
1
+ # vue-editor-layout-headless
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![Apache-2.0 licensed][badge-license]][url-license]
4
+ [![NPM version][badge-npm-version]][url-npm]
5
+ [![NPM downloads][badge-npm-downloads]][url-npm]
6
+ [![NPM Unpacked Size (with version)][badge-npm-unpacked-size]][url-npm]
7
+
8
+ A headless editor layout: the regions and panels of an editor held as data, resolved for the mode, tool, selection and window size, with the reader's sizes and open regions kept apart from it.
9
+
10
+ Design notes live in [the specs](https://github.com/Esposter/Esposter/tree/main/openspec/specs).
11
+
12
+ ## Table of Contents
13
+
14
+ - 🚀 [Getting Started](#getting-started)
15
+ - 🧩 [Key Exports](#key-exports)
16
+ - ⚖️ [License](#license)
17
+
18
+ ---
19
+
20
+ ## <a name="getting-started">🚀 Getting Started</a>
21
+
22
+ ```bash
23
+ pnpm i vue-editor-layout-headless
24
+ ```
25
+
26
+ Its peers are `vue`, `@vueuse/core` and `zod`, which the app already ships.
27
+
28
+ ## <a name="key-exports">🧩 Key Exports</a>
29
+
30
+ | Export | Kind | Purpose |
31
+ | --------------------------------------------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
32
+ | `checkLayout` | function | The gaps in a layout for an editor: a selection kind with no content, an unregistered content key, a duplicate id, a panel in an unknown region |
33
+ | `Condition` | interface | A panel's condition: lists of modes, tools and selection kinds, where a missing or empty list matches any value |
34
+ | `Context` | interface | What the reader is doing: the mode, the tool, the selection kind (`""` when nothing is selected) and the selection count |
35
+ | `EditorLayout` | interface | What `useEditorLayout` answers: the reader's state, the resolved layout and the functions that change the reader's state |
36
+ | `Finding` | interface | One thing a layout check reports, with the id, selection kind or content key it names |
37
+ | `FindingKind` | enum | What a layout check found: a duplicate id, a missing content, an unknown region or an unregistered content key |
38
+ | `getDefaultReaderState` | function | The reader state of a reader who has changed nothing |
39
+ | `Layout` | interface | An editor's layout as plain data: its canvas, its regions and its panels |
40
+ | `Panel` | interface | A panel in one region, shown under its condition, with the content each selection kind shows |
41
+ | `parseReaderState` | function | Reads a stored value back as a reader state for a layout, or answers the default state when the value is not one |
42
+ | `Region` | interface | A strip at one edge of the window, with its presentation for each size class, its size limits and how it opens |
43
+ | `RegionEdge` | enum | The edge of the window a region sits at: top, bottom, start or end |
44
+ | `RegionOpening` | enum | Whether a region opens with its content or on demand |
45
+ | `RegionPresentation` | enum | How a region is drawn for a size class: docked, overlay, sheet or hidden |
46
+ | `ReaderState` | interface | What a reader has changed: each region's size, which on-demand regions are open and each tabbed region's active panel |
47
+ | `resizeRegion` | function | A reader state with a region sized to the size asked for, held between its limits |
48
+ | `resolveLayout` | function | Resolves a layout for a context, a size class and a reader state into the canvas and the regions to draw |
49
+ | `ResolvedLayout`, `ResolvedRegion`, `ResolvedPanel` | interface | What resolving answers: the canvas and the regions, each with its edge, presentation, size, size limits, open state and panels |
50
+ | `setActivePanel` | function | A reader state with a tabbed region's active panel set |
51
+ | `SizeClass` | enum | The window's size class, compact, medium or expanded, which the caller derives |
52
+ | `toggleRegion` | function | A reader state with a region's open state turned over |
53
+ | `useEditorLayout` | function | An editor's layout resolved for its reactive context and size class, with the reader's state kept beside it |
54
+
55
+ ## <a name="license">⚖️ License</a>
56
+
57
+ Licensed under [Apache-2.0][url-license].
58
+
59
+ [badge-license]: https://img.shields.io/github/license/Esposter/Esposter.svg?color=blue
60
+ [url-license]: https://github.com/Esposter/Esposter/blob/main/LICENSE
61
+ [badge-npm-version]: https://img.shields.io/npm/v/vue-editor-layout-headless/latest?color=brightgreen
62
+ [url-npm]: https://www.npmjs.com/package/vue-editor-layout-headless/v/latest
63
+ [badge-npm-unpacked-size]: https://img.shields.io/npm/unpacked-size/vue-editor-layout-headless/latest?label=npm
64
+ [badge-npm-downloads]: https://img.shields.io/npm/dm/vue-editor-layout-headless.svg
@@ -0,0 +1,134 @@
1
+ import { ComputedRef, MaybeRefOrGetter } from "vue";
2
+ import { z } from "zod";
3
+ export interface Context {
4
+ mode: string;
5
+ selectionCount: number;
6
+ selectionKind: string;
7
+ tool: string;
8
+ }
9
+ export interface ReaderState {
10
+ regionActivePanelIdMap: Record<string, string>;
11
+ regionOpenMap: Record<string, boolean>;
12
+ regionSizeMap: Record<string, number>;
13
+ }
14
+ export declare const readerStateSchema: z.ZodObject<{
15
+ regionActivePanelIdMap: z.ZodRecord<z.ZodString, z.ZodString>;
16
+ regionOpenMap: z.ZodRecord<z.ZodString, z.ZodBoolean>;
17
+ regionSizeMap: z.ZodRecord<z.ZodString, z.ZodNumber>;
18
+ }>;
19
+ export declare enum RegionEdge {
20
+ Bottom = "bottom",
21
+ End = "end",
22
+ Start = "start",
23
+ Top = "top"
24
+ }
25
+ export declare enum RegionPresentation {
26
+ Docked = "docked",
27
+ Hidden = "hidden",
28
+ Overlay = "overlay",
29
+ Sheet = "sheet"
30
+ }
31
+ export interface ResolvedPanel {
32
+ contentKey: string;
33
+ id: string;
34
+ }
35
+ export interface ResolvedRegion {
36
+ activePanelId: string;
37
+ edge: RegionEdge;
38
+ id: string;
39
+ isOpen: boolean;
40
+ maximumSize: number;
41
+ minimumSize: number;
42
+ panels: ResolvedPanel[];
43
+ presentation: RegionPresentation;
44
+ size: number;
45
+ }
46
+ export interface ResolvedLayout {
47
+ canvasId: string;
48
+ regions: ResolvedRegion[];
49
+ }
50
+ export interface EditorLayout {
51
+ readerState: ComputedRef<ReaderState>;
52
+ resizeRegion: (regionId: string, size: number) => void;
53
+ resolvedLayout: ComputedRef<ResolvedLayout>;
54
+ setActivePanel: (regionId: string, panelId: string) => void;
55
+ toggleRegion: (regionId: string) => void;
56
+ }
57
+ export interface Condition {
58
+ modes?: string[];
59
+ selectionKinds?: string[];
60
+ tools?: string[];
61
+ }
62
+ export interface Panel {
63
+ condition: Condition;
64
+ id: string;
65
+ regionId: string;
66
+ selectionKindContentKeyMap: Record<string, string>;
67
+ wildcardContentKey: string;
68
+ }
69
+ export declare enum RegionOpening {
70
+ OnDemand = "onDemand",
71
+ WithContent = "withContent"
72
+ }
73
+ export declare enum SizeClass {
74
+ Compact = "compact",
75
+ Expanded = "expanded",
76
+ Medium = "medium"
77
+ }
78
+ export interface Region {
79
+ defaultSize: number;
80
+ edge: RegionEdge;
81
+ id: string;
82
+ maximumSize: number;
83
+ minimumSize: number;
84
+ opening: RegionOpening;
85
+ sizeClassEdgeMap: Partial<Record<SizeClass, RegionEdge>>;
86
+ sizeClassPresentationMap: Record<SizeClass, RegionPresentation>;
87
+ }
88
+ export interface Layout {
89
+ canvasId: string;
90
+ panels: Panel[];
91
+ regions: Region[];
92
+ }
93
+ export declare const useEditorLayout: (layout: MaybeRefOrGetter<Layout>, context: MaybeRefOrGetter<Context>, sizeClass: MaybeRefOrGetter<SizeClass>, initialReaderState: ReaderState) => EditorLayout;
94
+ export declare enum FindingKind {
95
+ DuplicateId = "duplicateId",
96
+ MissingContent = "missingContent",
97
+ UnknownRegion = "unknownRegion",
98
+ UnregisteredContentKey = "unregisteredContentKey"
99
+ }
100
+ export interface Finding {
101
+ kind: FindingKind;
102
+ subject: string;
103
+ }
104
+ export interface RegionPlacement {
105
+ edge: RegionEdge;
106
+ isOpen: boolean;
107
+ presentation: RegionPresentation;
108
+ }
109
+ export declare const checkIsConditionMet: (condition: Condition, context: Context) => boolean;
110
+ export declare const checkIsListMatch: (list: string[] | undefined, value: string) => boolean;
111
+ export declare const checkIsRegionOpen: (region: Region, presentation: RegionPresentation, readerState: ReaderState) => boolean;
112
+ export declare const checkLayout: (layout: Layout, selectionKinds: string[], registeredContentKeys: string[]) => Finding[];
113
+ export declare const clampRegionSize: (region: Region, size: number) => number;
114
+ export declare const MAX_LAYOUT_ID_LENGTH = 64;
115
+ export declare const MAX_LAYOUT_REGION_COUNT = 32;
116
+ export declare const fitReaderState: (layout: Layout, readerState: ReaderState) => ReaderState;
117
+ export declare const fitRegionMap: <TValue>(layout: Layout, storedMap: Record<string, TValue>, fitValue: (region: Region, storedValue: TValue) => TValue | undefined) => Record<string, TValue>;
118
+ export declare const getActivePanelId: (region: Region, panels: ResolvedPanel[], readerState: ReaderState) => string;
119
+ export declare const getDefaultReaderState: () => ReaderState;
120
+ export declare const getDuplicateIdFindings: (ids: string[]) => Finding[];
121
+ export declare const getMissingContentFindings: (layout: Layout, selectionKinds: string[]) => Finding[];
122
+ export declare const getPanelContentKey: (panel: Panel, selectionKind: string) => string;
123
+ export declare const getRegionEdge: (region: Region, sizeClass: SizeClass) => RegionEdge;
124
+ export declare const getRegionSize: (region: Region, readerState: ReaderState) => number;
125
+ export declare const getUnknownRegionFindings: ({ panels, regions }: Layout) => Finding[];
126
+ export declare const getUnregisteredContentKeyFindings: (layout: Layout, registeredContentKeys: string[]) => Finding[];
127
+ export declare const parseReaderState: (layout: Layout, value: unknown) => ReaderState;
128
+ export declare const presentRegion: (region: Region, sizeClass: SizeClass, readerState: ReaderState) => RegionPlacement;
129
+ export declare const resizeRegion: (region: Region, readerState: ReaderState, size: number) => ReaderState;
130
+ export declare const resolveLayout: (layout: Layout, context: Context, sizeClass: SizeClass, readerState: ReaderState) => ResolvedLayout;
131
+ export declare const resolvePanels: (panels: Panel[], region: Region, context: Context) => ResolvedPanel[];
132
+ export declare const resolveRegion: (region: Region, panels: ResolvedPanel[], sizeClass: SizeClass, readerState: ReaderState) => ResolvedRegion;
133
+ export declare const setActivePanel: (readerState: ReaderState, regionId: string, panelId: string) => ReaderState;
134
+ export declare const toggleRegion: (readerState: ReaderState, regionId: string, isCurrentlyOpen: boolean) => ReaderState;
package/dist/index.js ADDED
@@ -0,0 +1,256 @@
1
+ import { clamp } from "@vueuse/core";
2
+ import { createRecordSchema, takeOne } from "@esposter/shared";
3
+ import { computed, shallowRef, toValue } from "vue";
4
+ import { z } from "zod";
5
+ // src/services/clampRegionSize.ts
6
+ const clampRegionSize = (region, size) => clamp(size, region.minimumSize, region.maximumSize);
7
+ // src/services/resizeRegion.ts
8
+ const resizeRegion = (region, readerState, size) => {
9
+ const clampedSize = clampRegionSize(region, size);
10
+ return {
11
+ ...readerState,
12
+ regionSizeMap: {
13
+ ...readerState.regionSizeMap,
14
+ [region.id]: clampedSize
15
+ }
16
+ };
17
+ };
18
+ // src/services/checkIsListMatch.ts
19
+ const checkIsListMatch = (list, value) => !list?.length || list.includes(value);
20
+ // src/services/checkIsConditionMet.ts
21
+ const checkIsConditionMet = (condition, context) => {
22
+ const isModeMatch = checkIsListMatch(condition.modes, context.mode);
23
+ const isToolMatch = checkIsListMatch(condition.tools, context.tool);
24
+ const isSelectionKindMatch = checkIsListMatch(condition.selectionKinds, context.selectionKind);
25
+ return isModeMatch && isToolMatch && isSelectionKindMatch;
26
+ };
27
+ // src/services/getPanelContentKey.ts
28
+ const getPanelContentKey = (panel, selectionKind) => {
29
+ return (Object.hasOwn(panel.selectionKindContentKeyMap, selectionKind) ? panel.selectionKindContentKeyMap[selectionKind] : "") || panel.wildcardContentKey;
30
+ };
31
+ // src/services/resolvePanels.ts
32
+ const resolvePanels = (panels, region, context) => panels.flatMap((panel) => {
33
+ if (panel.regionId !== region.id || !checkIsConditionMet(panel.condition, context)) return [];
34
+ const contentKey = getPanelContentKey(panel, context.selectionKind);
35
+ return contentKey ? [{
36
+ contentKey,
37
+ id: panel.id
38
+ }] : [];
39
+ });
40
+ // src/services/getActivePanelId.ts
41
+ const getActivePanelId = (region, panels, readerState) => {
42
+ const storedPanelId = readerState.regionActivePanelIdMap[region.id];
43
+ const storedPanel = panels.find((panel) => panel.id === storedPanelId);
44
+ return storedPanel ? storedPanel.id : takeOne(panels, 0).id;
45
+ };
46
+ // src/services/getRegionSize.ts
47
+ const getRegionSize = (region, readerState) => {
48
+ const storedSize = readerState.regionSizeMap[region.id];
49
+ return clampRegionSize(region, storedSize ?? region.defaultSize);
50
+ };
51
+ // src/models/RegionOpening.ts
52
+ let RegionOpening = /* @__PURE__ */ function(RegionOpening) {
53
+ RegionOpening["OnDemand"] = "onDemand";
54
+ RegionOpening["WithContent"] = "withContent";
55
+ return RegionOpening;
56
+ }({});
57
+ // src/models/RegionPresentation.ts
58
+ let RegionPresentation = /* @__PURE__ */ function(RegionPresentation) {
59
+ RegionPresentation["Docked"] = "docked";
60
+ RegionPresentation["Hidden"] = "hidden";
61
+ RegionPresentation["Overlay"] = "overlay";
62
+ RegionPresentation["Sheet"] = "sheet";
63
+ return RegionPresentation;
64
+ }({});
65
+ // src/services/checkIsRegionOpen.ts
66
+ const checkIsRegionOpen = (region, presentation, readerState) => {
67
+ if (presentation === "hidden") return false;
68
+ const storedIsOpen = readerState.regionOpenMap[region.id];
69
+ if (presentation === "sheet") return storedIsOpen ?? false;
70
+ if (region.opening === "withContent") return true;
71
+ return storedIsOpen ?? presentation === "docked";
72
+ };
73
+ // src/services/getRegionEdge.ts
74
+ const getRegionEdge = (region, sizeClass) => region.sizeClassEdgeMap[sizeClass] ?? region.edge;
75
+ // src/services/presentRegion.ts
76
+ const presentRegion = (region, sizeClass, readerState) => {
77
+ const edge = getRegionEdge(region, sizeClass);
78
+ const presentation = region.sizeClassPresentationMap[sizeClass];
79
+ return {
80
+ edge,
81
+ isOpen: checkIsRegionOpen(region, presentation, readerState),
82
+ presentation
83
+ };
84
+ };
85
+ // src/services/resolveRegion.ts
86
+ const resolveRegion = (region, panels, sizeClass, readerState) => {
87
+ const placement = presentRegion(region, sizeClass, readerState);
88
+ const activePanelId = getActivePanelId(region, panels, readerState);
89
+ const size = getRegionSize(region, readerState);
90
+ return {
91
+ activePanelId,
92
+ edge: placement.edge,
93
+ id: region.id,
94
+ isOpen: placement.isOpen,
95
+ maximumSize: region.maximumSize,
96
+ minimumSize: region.minimumSize,
97
+ panels,
98
+ presentation: placement.presentation,
99
+ size
100
+ };
101
+ };
102
+ // src/services/resolveLayout.ts
103
+ const resolveLayout = (layout, context, sizeClass, readerState) => {
104
+ const regions = [];
105
+ for (const region of layout.regions) {
106
+ const panels = resolvePanels(layout.panels, region, context);
107
+ if (panels.length > 0) regions.push(resolveRegion(region, panels, sizeClass, readerState));
108
+ }
109
+ return {
110
+ canvasId: layout.canvasId,
111
+ regions
112
+ };
113
+ };
114
+ // src/services/setActivePanel.ts
115
+ const setActivePanel = (readerState, regionId, panelId) => ({
116
+ ...readerState,
117
+ regionActivePanelIdMap: {
118
+ ...readerState.regionActivePanelIdMap,
119
+ [regionId]: panelId
120
+ }
121
+ });
122
+ // src/services/toggleRegion.ts
123
+ const toggleRegion = (readerState, regionId, isCurrentlyOpen) => ({
124
+ ...readerState,
125
+ regionOpenMap: {
126
+ ...readerState.regionOpenMap,
127
+ [regionId]: !isCurrentlyOpen
128
+ }
129
+ });
130
+ // src/composables/useEditorLayout.ts
131
+ const useEditorLayout = (layout, context, sizeClass, initialReaderState) => {
132
+ const readerStateRef = shallowRef(initialReaderState);
133
+ const readerState = computed(() => readerStateRef.value);
134
+ const resolvedLayout = computed(() => resolveLayout(toValue(layout), toValue(context), toValue(sizeClass), readerStateRef.value));
135
+ const resizeRegion$1 = (regionId, size) => {
136
+ const region = toValue(layout).regions.find((candidate) => candidate.id === regionId);
137
+ if (region) readerStateRef.value = resizeRegion(region, readerStateRef.value, size);
138
+ };
139
+ const toggleRegion$1 = (regionId) => {
140
+ const resolvedRegion = resolvedLayout.value.regions.find((candidate) => candidate.id === regionId);
141
+ if (resolvedRegion) readerStateRef.value = toggleRegion(readerStateRef.value, regionId, resolvedRegion.isOpen);
142
+ };
143
+ const setActivePanel$1 = (regionId, panelId) => {
144
+ readerStateRef.value = setActivePanel(readerStateRef.value, regionId, panelId);
145
+ };
146
+ return {
147
+ readerState,
148
+ resizeRegion: resizeRegion$1,
149
+ resolvedLayout,
150
+ setActivePanel: setActivePanel$1,
151
+ toggleRegion: toggleRegion$1
152
+ };
153
+ };
154
+ // src/models/FindingKind.ts
155
+ let FindingKind = /* @__PURE__ */ function(FindingKind) {
156
+ FindingKind["DuplicateId"] = "duplicateId";
157
+ FindingKind["MissingContent"] = "missingContent";
158
+ FindingKind["UnknownRegion"] = "unknownRegion";
159
+ FindingKind["UnregisteredContentKey"] = "unregisteredContentKey";
160
+ return FindingKind;
161
+ }({});
162
+ // src/services/constants.ts
163
+ const MAX_LAYOUT_ID_LENGTH = 64;
164
+ const MAX_LAYOUT_REGION_COUNT = 32;
165
+ // src/models/ReaderState.ts
166
+ const layoutIdSchema = z.string().max(64);
167
+ const readerStateSchema = z.object({
168
+ regionActivePanelIdMap: createRecordSchema(layoutIdSchema, layoutIdSchema, 32),
169
+ regionOpenMap: createRecordSchema(layoutIdSchema, z.boolean(), 32),
170
+ regionSizeMap: createRecordSchema(layoutIdSchema, z.number().nonnegative(), 32)
171
+ });
172
+ // src/models/RegionEdge.ts
173
+ let RegionEdge = /* @__PURE__ */ function(RegionEdge) {
174
+ RegionEdge["Bottom"] = "bottom";
175
+ RegionEdge["End"] = "end";
176
+ RegionEdge["Start"] = "start";
177
+ RegionEdge["Top"] = "top";
178
+ return RegionEdge;
179
+ }({});
180
+ // src/models/SizeClass.ts
181
+ let SizeClass = /* @__PURE__ */ function(SizeClass) {
182
+ SizeClass["Compact"] = "compact";
183
+ SizeClass["Expanded"] = "expanded";
184
+ SizeClass["Medium"] = "medium";
185
+ return SizeClass;
186
+ }({});
187
+ // src/services/getDuplicateIdFindings.ts
188
+ const getDuplicateIdFindings = (ids) => {
189
+ const duplicateIds = new Set(ids.filter((id, index) => ids.indexOf(id) !== index));
190
+ return Array.from(duplicateIds, (id) => ({
191
+ kind: "duplicateId",
192
+ subject: id
193
+ }));
194
+ };
195
+ // src/services/getMissingContentFindings.ts
196
+ const getMissingContentFindings = (layout, selectionKinds) => {
197
+ return selectionKinds.filter((selectionKind) => !layout.panels.some((panel) => checkIsListMatch(panel.condition.selectionKinds, selectionKind) && Boolean(getPanelContentKey(panel, selectionKind)))).map((selectionKind) => ({
198
+ kind: "missingContent",
199
+ subject: selectionKind
200
+ }));
201
+ };
202
+ // src/services/getUnknownRegionFindings.ts
203
+ const getUnknownRegionFindings = ({ panels, regions }) => {
204
+ const regionIds = new Set(regions.map(({ id }) => id));
205
+ return panels.filter((panel) => !regionIds.has(panel.regionId)).map((panel) => ({
206
+ kind: "unknownRegion",
207
+ subject: panel.id
208
+ }));
209
+ };
210
+ // src/services/getUnregisteredContentKeyFindings.ts
211
+ const getUnregisteredContentKeyFindings = (layout, registeredContentKeys) => {
212
+ const contentKeys = layout.panels.flatMap((panel) => [panel.wildcardContentKey, ...Object.values(panel.selectionKindContentKeyMap)]);
213
+ const unregisteredContentKeys = new Set(contentKeys.filter((contentKey) => Boolean(contentKey) && !registeredContentKeys.includes(contentKey)));
214
+ return Array.from(unregisteredContentKeys, (contentKey) => ({
215
+ kind: "unregisteredContentKey",
216
+ subject: contentKey
217
+ }));
218
+ };
219
+ // src/services/checkLayout.ts
220
+ const checkLayout = (layout, selectionKinds, registeredContentKeys) => {
221
+ const regionIds = layout.regions.map(({ id }) => id);
222
+ const panelIds = layout.panels.map(({ id }) => id);
223
+ return [
224
+ ...getMissingContentFindings(layout, selectionKinds),
225
+ ...getUnregisteredContentKeyFindings(layout, registeredContentKeys),
226
+ ...getDuplicateIdFindings(regionIds),
227
+ ...getDuplicateIdFindings(panelIds),
228
+ ...getUnknownRegionFindings(layout)
229
+ ];
230
+ };
231
+ // src/services/fitRegionMap.ts
232
+ const fitRegionMap = (layout, storedMap, fitValue) => Object.fromEntries(layout.regions.flatMap((region) => {
233
+ const storedValue = storedMap[region.id];
234
+ const fittedValue = storedValue === void 0 ? void 0 : fitValue(region, storedValue);
235
+ return fittedValue === void 0 ? [] : [[region.id, fittedValue]];
236
+ }));
237
+ // src/services/fitReaderState.ts
238
+ const fitReaderState = (layout, readerState) => {
239
+ return {
240
+ regionActivePanelIdMap: fitRegionMap(layout, readerState.regionActivePanelIdMap, (region, panelId) => layout.panels.some((panel) => panel.id === panelId && panel.regionId === region.id) ? panelId : void 0),
241
+ regionOpenMap: fitRegionMap(layout, readerState.regionOpenMap, (_region, isOpen) => isOpen),
242
+ regionSizeMap: fitRegionMap(layout, readerState.regionSizeMap, clampRegionSize)
243
+ };
244
+ };
245
+ // src/services/getDefaultReaderState.ts
246
+ const getDefaultReaderState = () => ({
247
+ regionActivePanelIdMap: {},
248
+ regionOpenMap: {},
249
+ regionSizeMap: {}
250
+ });
251
+ // src/services/parseReaderState.ts
252
+ const parseReaderState = (layout, value) => {
253
+ const parseResult = readerStateSchema.safeParse(value);
254
+ return parseResult.success ? fitReaderState(layout, parseResult.data) : getDefaultReaderState();
255
+ };
256
+ export { FindingKind, MAX_LAYOUT_ID_LENGTH, MAX_LAYOUT_REGION_COUNT, RegionEdge, RegionOpening, RegionPresentation, SizeClass, checkIsConditionMet, checkIsListMatch, checkIsRegionOpen, checkLayout, clampRegionSize, fitReaderState, fitRegionMap, getActivePanelId, getDefaultReaderState, getDuplicateIdFindings, getMissingContentFindings, getPanelContentKey, getRegionEdge, getRegionSize, getUnknownRegionFindings, getUnregisteredContentKeyFindings, parseReaderState, presentRegion, readerStateSchema, resizeRegion, resolveLayout, resolvePanels, resolveRegion, setActivePanel, toggleRegion, useEditorLayout };
package/package.json CHANGED
@@ -1,6 +1,58 @@
1
1
  {
2
2
  "name": "vue-editor-layout-headless",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "4.6.0",
4
+ "description": "A headless editor layout: the regions and panels of an editor held as data, resolved for the mode, tool, selection and window size, with the reader's sizes and open regions kept apart from it.",
5
+ "keywords": [
6
+ "editor",
7
+ "headless",
8
+ "layout",
9
+ "typescript",
10
+ "vue"
11
+ ],
12
+ "homepage": "https://github.com/Esposter/Esposter/blob/main/packages/vue-editor-layout-headless#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/Esposter/Esposter/issues"
15
+ },
16
+ "license": "Apache-2.0",
17
+ "author": "Jimmy Chen",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/Esposter/Esposter.git"
21
+ },
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "type": "module",
26
+ "sideEffects": false,
27
+ "types": "dist/index.d.ts",
28
+ "imports": {
29
+ "#src/*": "./src/*.ts"
30
+ },
31
+ "exports": {
32
+ ".": "./dist/index.js",
33
+ "./package.json": "./package.json"
34
+ },
35
+ "publishConfig": {
36
+ "access": "public"
37
+ },
38
+ "scripts": {
39
+ "build": "tsdown",
40
+ "lint": "eslint .",
41
+ "lint:fix": "eslint --fix .",
42
+ "test": "vitest",
43
+ "typecheck": "tsrs --fast"
44
+ },
45
+ "dependencies": {
46
+ "@esposter/shared": "4.6.0"
47
+ },
48
+ "devDependencies": {
49
+ "@esposter/configuration": "4.6.0",
50
+ "tsdown": "^0.23.7"
51
+ },
52
+ "peerDependencies": {
53
+ "@vueuse/core": "^15.0.0",
54
+ "vue": "^3.5.45",
55
+ "zod": "^4.6.7"
56
+ },
57
+ "gitHead": "0ceea3ffbe12ca69413ea5db2d3cfad197a63cba"
58
+ }