@folijs/react 0.1.0 → 0.3.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/src/editor.tsx CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  createEditor,
3
3
  type Editor,
4
+ type EditorDocument,
4
5
  type EditorState,
5
- type FoliDocument,
6
6
  type Plugin,
7
7
  } from "@folijs/core";
8
8
  import {
@@ -25,15 +25,20 @@ export const useIsomorphicLayoutEffect =
25
25
  typeof document === "undefined" ? useEffect : useLayoutEffect;
26
26
 
27
27
  export interface UseFoliEditorOptions {
28
- /** Read once, when the editor is created. To load another document, `editor.setDocument()`. */
29
- initialContent?: FoliDocument | undefined;
28
+ /**
29
+ * Read once, when the editor is created: a document of any version (0.1.0 and 0.2.0 documents
30
+ * are validated and migrated to schema v3, `parseDocument`). Default: an empty document. To
31
+ * load another document, `editor.setDocument()`.
32
+ */
33
+ initialContent?: EditorDocument | undefined;
30
34
  /** Read once, when the editor is created. */
31
35
  plugins?: readonly Plugin[] | undefined;
32
36
  }
33
37
 
34
38
  /**
35
- * A headless `Editor` (state, commands, history) owned by the calling component: created on the
36
- * first render and kept for its lifetime. Later changes to `options` are ignored.
39
+ * A headless `Editor` (state, commands, history) of a schema v3 document, owned by the calling
40
+ * component: created on the first render and kept for its lifetime. Later changes to `options`
41
+ * are ignored. Throws FoliDocumentError when `initialContent` is not a valid document.
37
42
  */
38
43
  export function useFoliEditor(options: UseFoliEditorOptions = {}): Editor {
39
44
  const [editor] = useState(() => {
package/styles.css CHANGED
@@ -10,15 +10,13 @@
10
10
  --foli-border-color: #e2e2df;
11
11
  --foli-text-color: #1d1d1b;
12
12
  --foli-selection-color: rgb(35 103 220 / 0.22);
13
- --foli-font-family: Georgia, "Times New Roman", serif;
14
- --foli-font-size: 11pt;
15
- --foli-line-height: 1.5;
16
13
  --foli-page-gap: 24px;
17
14
  --foli-toolbar-background: #ffffff;
18
15
  --foli-toolbar-color: #1d1d1b;
19
16
  --foli-toolbar-pressed: #dfe8f8;
20
17
  --foli-toolbar-hover: #f0f0ee;
21
18
  --foli-focus-ring: #2367dc;
19
+ --foli-error-color: #b3261e;
22
20
  }
23
21
 
24
22
  .foli-canvas {
@@ -32,9 +30,6 @@
32
30
  background: var(--foli-page-background);
33
31
  box-shadow: var(--foli-page-shadow);
34
32
  color: var(--foli-text-color);
35
- font-family: var(--foli-font-family);
36
- font-size: var(--foli-font-size);
37
- line-height: var(--foli-line-height);
38
33
  }
39
34
 
40
35
  .foli-page + .foli-page {
@@ -49,6 +44,12 @@
49
44
  background: var(--foli-selection-color);
50
45
  }
51
46
 
47
+ /* A node-selected block (an opaque block, a table): the view adds the class. */
48
+ .foli-content .foli-selected-node {
49
+ outline: 2px solid var(--foli-focus-ring);
50
+ outline-offset: 2px;
51
+ }
52
+
52
53
  /* Toolbar (FoliToolbar). */
53
54
  .foli-toolbar {
54
55
  display: flex;
@@ -108,12 +109,147 @@
108
109
  text-decoration: line-through;
109
110
  }
110
111
 
112
+ /* Text color and highlight menu buttons: the letter over the current color. */
113
+ .foli-toolbar-menu {
114
+ position: relative;
115
+ display: inline-flex;
116
+ }
117
+
118
+ .foli-toolbar-textColor,
119
+ .foli-toolbar-highlight {
120
+ display: inline-flex;
121
+ flex-direction: column;
122
+ align-items: center;
123
+ justify-content: center;
124
+ gap: 2px;
125
+ }
126
+
127
+ .foli-toolbar-swatch {
128
+ width: 16px;
129
+ height: 4px;
130
+ border-radius: 1px;
131
+ box-shadow: inset 0 0 0 1px var(--foli-border-color);
132
+ }
133
+
134
+ .foli-menu {
135
+ position: absolute;
136
+ top: 100%;
137
+ left: 0;
138
+ z-index: 10;
139
+ display: flex;
140
+ flex-direction: column;
141
+ min-width: 10em;
142
+ margin-top: 2px;
143
+ padding: 4px;
144
+ border: 1px solid var(--foli-border-color);
145
+ border-radius: 4px;
146
+ background: var(--foli-toolbar-background);
147
+ box-shadow: 0 2px 8px rgb(0 0 0 / 0.15);
148
+ }
149
+
150
+ .foli-menu-item {
151
+ display: flex;
152
+ align-items: center;
153
+ gap: 8px;
154
+ height: 28px;
155
+ padding: 0 8px;
156
+ border: 0;
157
+ border-radius: 3px;
158
+ background: none;
159
+ color: inherit;
160
+ font: inherit;
161
+ text-align: start;
162
+ cursor: pointer;
163
+ }
164
+
165
+ .foli-menu-item:hover,
166
+ .foli-menu-item:focus-visible {
167
+ background: var(--foli-toolbar-hover);
168
+ }
169
+
170
+ .foli-menu-item:focus-visible {
171
+ outline: 2px solid var(--foli-focus-ring);
172
+ outline-offset: -2px;
173
+ }
174
+
175
+ .foli-menu-swatch {
176
+ width: 16px;
177
+ height: 16px;
178
+ border-radius: 3px;
179
+ box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.2);
180
+ }
181
+
182
+ /* The checked color: a ring around its swatch (an outline also shows in forced colors). */
183
+ .foli-menu-item[aria-checked="true"] .foli-menu-swatch {
184
+ outline: 2px solid var(--foli-focus-ring);
185
+ outline-offset: 1px;
186
+ }
187
+
188
+ /* Link dialog (FoliToolbar): under the toolbar. */
189
+ .foli-link-dialog {
190
+ padding: 8px;
191
+ border-bottom: 1px solid var(--foli-border-color);
192
+ background: var(--foli-toolbar-background);
193
+ color: var(--foli-toolbar-color);
194
+ font:
195
+ 14px / 1.4 system-ui,
196
+ sans-serif;
197
+ }
198
+
199
+ .foli-link-dialog form {
200
+ display: flex;
201
+ flex-wrap: wrap;
202
+ align-items: center;
203
+ gap: 8px;
204
+ }
205
+
206
+ .foli-link-dialog input {
207
+ flex: 1 1 16em;
208
+ min-width: 0;
209
+ height: 32px;
210
+ padding: 0 8px;
211
+ border: 1px solid var(--foli-border-color);
212
+ border-radius: 4px;
213
+ font: inherit;
214
+ }
215
+
216
+ .foli-link-dialog input[aria-invalid="true"] {
217
+ border-color: var(--foli-error-color);
218
+ }
219
+
220
+ .foli-link-dialog button {
221
+ height: 32px;
222
+ padding: 0 12px;
223
+ border: 1px solid var(--foli-border-color);
224
+ border-radius: 4px;
225
+ background: none;
226
+ color: inherit;
227
+ font: inherit;
228
+ cursor: pointer;
229
+ }
230
+
231
+ .foli-link-dialog :focus-visible {
232
+ outline: 2px solid var(--foli-focus-ring);
233
+ outline-offset: 1px;
234
+ }
235
+
236
+ .foli-link-error {
237
+ flex-basis: 100%;
238
+ margin: 0;
239
+ color: var(--foli-error-color);
240
+ }
241
+
111
242
  /* Forced colors (Windows High Contrast) drop backgrounds: mark pressed buttons another way. */
112
243
  @media (forced-colors: active) {
113
244
  .foli-toolbar-button[aria-pressed="true"] {
114
245
  outline: 2px solid Highlight;
115
246
  outline-offset: -2px;
116
247
  }
248
+ /* Swatches show their color (the names say it too). */
249
+ .foli-toolbar-swatch,
250
+ .foli-menu-swatch {
251
+ forced-color-adjust: none;
252
+ }
117
253
  }
118
254
 
119
255
  .foli-toolbar-separator {
@@ -136,7 +272,8 @@
136
272
  .foli-page {
137
273
  box-shadow: none;
138
274
  }
139
- .foli-toolbar {
275
+ .foli-toolbar,
276
+ .foli-link-dialog {
140
277
  display: none;
141
278
  }
142
279
  }