alinea 0.5.11 → 0.5.12

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.
@@ -12151,11 +12151,11 @@ var PasteRule = class {
12151
12151
  this.handler = config.handler;
12152
12152
  }
12153
12153
  };
12154
- var pasteRuleMatcherHandler = (text, find) => {
12154
+ var pasteRuleMatcherHandler = (text, find, event) => {
12155
12155
  if (isRegExp(find)) {
12156
12156
  return [...text.matchAll(find)];
12157
12157
  }
12158
- const matches2 = find(text);
12158
+ const matches2 = find(text, event);
12159
12159
  if (!matches2) {
12160
12160
  return [];
12161
12161
  }
@@ -12187,7 +12187,7 @@ function run(config) {
12187
12187
  const resolvedFrom = Math.max(from, pos);
12188
12188
  const resolvedTo = Math.min(to, pos + node.content.size);
12189
12189
  const textToMatch = node.textBetween(resolvedFrom - pos, resolvedTo - pos, void 0, "\uFFFC");
12190
- const matches2 = pasteRuleMatcherHandler(textToMatch, rule.find);
12190
+ const matches2 = pasteRuleMatcherHandler(textToMatch, rule.find, pasteEvent);
12191
12191
  matches2.forEach((match) => {
12192
12192
  if (match.index === void 0) {
12193
12193
  return;
@@ -12913,9 +12913,23 @@ var forEach = (items, fn) => (props) => {
12913
12913
  var insertContent = (value, options) => ({ tr, commands: commands2 }) => {
12914
12914
  return commands2.insertContentAt({ from: tr.selection.from, to: tr.selection.to }, value, options);
12915
12915
  };
12916
+ var removeWhitespaces = (node) => {
12917
+ const children = node.childNodes;
12918
+ for (let i = children.length - 1; i >= 0; i -= 1) {
12919
+ const child = children[i];
12920
+ if (child.nodeType === 3 && child.nodeValue && !/\S/.test(child.nodeValue)) {
12921
+ node.removeChild(child);
12922
+ } else if (child.nodeType === 1) {
12923
+ removeWhitespaces(child);
12924
+ }
12925
+ }
12926
+ return node;
12927
+ };
12916
12928
  function elementFromString(value) {
12917
12929
  const wrappedValue = `<body>${value}</body>`;
12918
- return new window.DOMParser().parseFromString(wrappedValue, "text/html").body;
12930
+ const html = new window.DOMParser().parseFromString(wrappedValue, "text/html").body;
12931
+ removeWhitespaces(html);
12932
+ return removeWhitespaces(html);
12919
12933
  }
12920
12934
  function createNodeFromContent(content, schema, options) {
12921
12935
  options = {
@@ -13355,6 +13369,9 @@ function getMarksBetween(from, to, doc3) {
13355
13369
  });
13356
13370
  } else {
13357
13371
  doc3.nodesBetween(from, to, (node, pos) => {
13372
+ if (!node || node.nodeSize === void 0) {
13373
+ return;
13374
+ }
13358
13375
  marks.push(...node.marks.map((mark) => ({
13359
13376
  from: pos,
13360
13377
  to: pos + node.nodeSize,
@@ -2,7 +2,7 @@
2
2
  var package_default = {
3
3
  bin: "./dist/cli.js",
4
4
  name: "alinea",
5
- version: "0.5.11",
5
+ version: "0.5.12",
6
6
  license: "MIT",
7
7
  type: "module",
8
8
  scripts: {
@@ -3,7 +3,7 @@ import {
3
3
  Plugin,
4
4
  PluginKey,
5
5
  posToDOMRect
6
- } from "./chunk-MDIOFKJQ.js";
6
+ } from "./chunk-533F6JLE.js";
7
7
 
8
8
  // node_modules/@popperjs/core/lib/enums.js
9
9
  var top = "top";
package/dist/cli/Serve.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  package_default
3
- } from "../chunks/chunk-UUSWXVEM.js";
3
+ } from "../chunks/chunk-ADJ4N76W.js";
4
4
  import "../chunks/chunk-U5RRZUYZ.js";
5
5
 
6
6
  // src/cli/Serve.ts
package/dist/cli/bin.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  package_default
3
- } from "../chunks/chunk-UUSWXVEM.js";
3
+ } from "../chunks/chunk-ADJ4N76W.js";
4
4
  import "../chunks/chunk-U5RRZUYZ.js";
5
5
 
6
6
  // node_modules/mri/lib/index.mjs
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  package_default
3
- } from "../../chunks/chunk-UUSWXVEM.js";
3
+ } from "../../chunks/chunk-ADJ4N76W.js";
4
4
  import {
5
5
  __commonJS,
6
6
  __toESM
@@ -3,7 +3,7 @@ import {
3
3
  } from "../../chunks/chunk-IKINPSS5.js";
4
4
  import {
5
5
  package_default
6
- } from "../../chunks/chunk-UUSWXVEM.js";
6
+ } from "../../chunks/chunk-ADJ4N76W.js";
7
7
  import "../../chunks/chunk-U5RRZUYZ.js";
8
8
 
9
9
  // src/cloud/server/CloudAuthServer.ts
package/dist/core/Type.js CHANGED
@@ -113,12 +113,29 @@ var TypeInstance = class {
113
113
  this.sections.push(section({ definition: current }));
114
114
  current = {};
115
115
  };
116
+ const seen = /* @__PURE__ */ new Map();
117
+ function validateField(key, field) {
118
+ const ref = Field.ref(field);
119
+ if (!seen.has(ref))
120
+ return seen.set(ref, key);
121
+ const fieldLabel = Field.label(field);
122
+ throw new Error(
123
+ `Duplicate field "${fieldLabel}" in type "${label}", found under key "${key}" and "${seen.get(
124
+ ref
125
+ )}"
126
+ See: https://alinea.sh/docs/configuration/schema/type#fields-must-be-unique`
127
+ );
128
+ }
116
129
  for (const [key, value] of entries(definition)) {
117
130
  if (Field.isField(value)) {
118
131
  current[key] = value;
132
+ validateField(key, value);
119
133
  } else if (Section.isSection(value)) {
120
134
  addCurrent();
121
135
  this.sections.push(value);
136
+ for (const [key2, field] of entries(Section.fields(value))) {
137
+ validateField(key2, field);
138
+ }
122
139
  }
123
140
  }
124
141
  addCurrent();
@@ -120,19 +120,19 @@ var ListShape = class {
120
120
  parent.set(key, this.toY(this.create()));
121
121
  }
122
122
  watch(parent, key) {
123
- const record = parent.has(key) ? parent.get(key) : parent.set(key, new YMap());
123
+ const map = parent.get(key);
124
124
  return (fun) => {
125
125
  function w(events, transaction) {
126
126
  for (const event of events) {
127
- if (event.target === record)
127
+ if (event.target === map)
128
128
  fun();
129
129
  if (event instanceof YMapEvent && event.keysChanged.has("index"))
130
130
  fun();
131
131
  }
132
132
  }
133
- record.observeDeep(w);
133
+ map.observeDeep(w);
134
134
  return () => {
135
- record.unobserveDeep(w);
135
+ map.unobserveDeep(w);
136
136
  };
137
137
  };
138
138
  }
@@ -48,7 +48,9 @@ var RecordShape = class _RecordShape {
48
48
  return void map.set(key, this.toY(value));
49
49
  const self = value ?? {};
50
50
  for (const key2 of keys(this.properties)) {
51
- this.properties[key2].applyY(self[key2], current, key2);
51
+ this.properties[key2].init(current, key2);
52
+ if (key2 in self)
53
+ this.properties[key2].applyY(self[key2], current, key2);
52
54
  }
53
55
  }
54
56
  init(parent, key) {
@@ -28,14 +28,14 @@ export declare class RichTextShape<Blocks> implements Shape<TextDoc<Blocks>, Ric
28
28
  values: Record<string, RecordShape>;
29
29
  constructor(label: Label, shapes?: Record<string, RecordShape<object>> | undefined, initialValue?: TextDoc<Blocks> | undefined, searchable?: boolean | undefined);
30
30
  create(): TextDoc<Blocks>;
31
- toXml(rows: TextDoc<Blocks>): (Y.XmlElement<{
31
+ toXml(rows: TextDoc<Blocks>): (Y.XmlText | Y.XmlElement<{
32
32
  [key: string]: string;
33
- }> | Y.XmlText)[];
33
+ }>)[];
34
34
  toY(value: TextDoc<Blocks>): Y.Map<unknown>;
35
35
  fromY(value: Y.Map<any>): TextDoc<Blocks>;
36
36
  applyY(value: TextDoc<Blocks>, parent: Y.Map<any>, key: string): void;
37
37
  init(parent: Y.Map<any>, key: string): void;
38
- watch(parent: Y.Map<any>, key: string): () => () => void;
38
+ watch(parent: Y.Map<any>, key: string): (fun: () => void) => () => void;
39
39
  mutator(parent: Y.Map<any>, key: string): {
40
40
  map: any;
41
41
  fragment: any;
@@ -239,15 +239,19 @@ var RichTextShape = class {
239
239
  parent.set(key, this.toY(this.create()));
240
240
  }
241
241
  watch(parent, key) {
242
- return () => () => {
242
+ const map = parent.get(key);
243
+ return (fun) => {
244
+ const listener = (events, tx) => {
245
+ if (tx.origin === "self")
246
+ return;
247
+ fun();
248
+ };
249
+ map.observeDeep(listener);
250
+ return () => map.unobserveDeep(listener);
243
251
  };
244
252
  }
245
253
  mutator(parent, key) {
246
- let map = parent.get(key);
247
- if (!map) {
248
- parent.set(key, this.toY([]));
249
- map = parent.get(key);
250
- }
254
+ const map = parent.get(key);
251
255
  return {
252
256
  map,
253
257
  fragment: map.get("$text"),
@@ -5,8 +5,7 @@ import {
5
5
  atom
6
6
  } from "../../chunks/chunk-OBOPLPUQ.js";
7
7
  import {
8
- Doc,
9
- YMap
8
+ Doc
10
9
  } from "../../chunks/chunk-OYP4EJOA.js";
11
10
  import "../../chunks/chunk-O6EXLFU2.js";
12
11
  import "../../chunks/chunk-U5RRZUYZ.js";
@@ -87,7 +86,7 @@ var FormAtoms = class {
87
86
  g(revision);
88
87
  const current = shape.fromY(this.container.get(key));
89
88
  const next = tracker ? tracker(this.getter(g)) : current;
90
- if (next !== current)
89
+ if (tracker && next !== current)
91
90
  shape.applyY(next, this.container, key);
92
91
  return next;
93
92
  });
@@ -146,10 +145,6 @@ function FormRow({
146
145
  const rowForm = useMemo(() => {
147
146
  const key = form.keyOf(field);
148
147
  const inner = form.container.get(key);
149
- if (rowId) {
150
- if (!inner.has(rowId))
151
- inner.set(rowId, new YMap());
152
- }
153
148
  const row = rowId ? inner.get(rowId) : inner;
154
149
  return new FormAtoms(type, row, {
155
150
  readOnly,
@@ -7,8 +7,11 @@ import "../../chunks/chunk-U5RRZUYZ.js";
7
7
  function yAtom(yType, get) {
8
8
  const revision = atom(0);
9
9
  revision.onMount = (setAtom) => {
10
- const onChange = () => setAtom((x) => x + 1);
11
- onChange();
10
+ const onChange = (events, tx) => {
11
+ if (tx.origin === "self")
12
+ return;
13
+ setAtom((x) => x + 1);
14
+ };
12
15
  yType.observeDeep(onChange);
13
16
  return () => yType.unobserveDeep(onChange);
14
17
  };
@@ -37,9 +37,9 @@ function MissingView({ field }) {
37
37
  }
38
38
  function InputField({ field }) {
39
39
  const View = field[Field.Data].view;
40
+ const options = useFieldOptions(field);
40
41
  if (!View)
41
42
  return /* @__PURE__ */ jsx(MissingView, { field });
42
- const options = useFieldOptions(field);
43
43
  if (options.hidden)
44
44
  return null;
45
45
  return /* @__PURE__ */ jsx(ErrorBoundary, { children: /* @__PURE__ */ jsx(View, { field }) });
@@ -14,6 +14,10 @@ var InputLabel_module_default = {
14
14
  "root": "alinea-InputLabel",
15
15
  "root-inner": "alinea-InputLabel-inner",
16
16
  "rootInner": "alinea-InputLabel-inner",
17
+ "is-readOnly": "alinea-InputLabel-is-readOnly",
18
+ "isReadOnly": "alinea-InputLabel-is-readOnly",
19
+ "root-inner-content": "alinea-InputLabel-inner-content",
20
+ "rootInnerContent": "alinea-InputLabel-inner-content",
17
21
  "root-header": "alinea-InputLabel-header",
18
22
  "rootHeader": "alinea-InputLabel-header",
19
23
  "header": "alinea-InputLabel-header",
@@ -42,7 +46,7 @@ var LabelHeader = memo(function LabelHeader2({
42
46
  }) {
43
47
  return /* @__PURE__ */ jsx("header", { className: styles.header(size, { focused }), children: /* @__PURE__ */ jsxs(HStack, { center: true, wrap: true, gap: `${px(4)} ${px(8)}`, children: [
44
48
  /* @__PURE__ */ jsx(HStack, { center: true, gap: 8, className: styles.header.title(), children: /* @__PURE__ */ jsx("span", { children: renderLabel(label) }) }),
45
- readOnly && /* @__PURE__ */ jsx(Icon, { title: "Read-only", icon: IcOutlineLock }),
49
+ readOnly && /* @__PURE__ */ jsx(Icon, { title: "Read-only", icon: IcOutlineLock, style: { opacity: 0.6 } }),
46
50
  shared && /* @__PURE__ */ jsx(Chip, { icon: PhGlobe, children: "Shared" }),
47
51
  optional && /* @__PURE__ */ jsx(Chip, { children: "Optional" }),
48
52
  help && /* @__PURE__ */ jsx("div", { className: styles.header.help(), children: renderLabel(help) })
@@ -93,7 +97,7 @@ var InputLabel = forwardRef(
93
97
  readOnly
94
98
  }
95
99
  ),
96
- children
100
+ /* @__PURE__ */ jsx("div", { className: styles.root.inner.content(), children })
97
101
  ] })
98
102
  }
99
103
  );
package/dist/index.css CHANGED
@@ -1247,6 +1247,12 @@ button {
1247
1247
  .alinea-InputLabel-inner {
1248
1248
  padding: 0.375rem 0.375rem 0.5rem 0.375rem;
1249
1249
  }
1250
+ .alinea-InputLabel.alinea-InputLabel-is-readOnly .alinea-InputLabel-inner-content {
1251
+ opacity: 0.75;
1252
+ }
1253
+ .alinea-InputLabel.alinea-InputLabel-is-readOnly .alinea-InputLabel.alinea-InputLabel-is-readOnly .alinea-InputLabel-inner-content {
1254
+ opacity: 1;
1255
+ }
1250
1256
  .alinea-InputLabel-header {
1251
1257
  padding-top: 0;
1252
1258
  }
@@ -2471,8 +2477,7 @@ html[data-theme=dark] .alinea-Viewport {
2471
2477
  border-radius: var(--alinea-border-radius);
2472
2478
  line-height: 1.5;
2473
2479
  font-family: "JetBrains Mono", monospace;
2474
- white-space: pre;
2475
- overflow-x: auto !important;
2480
+ white-space: pre !important;
2476
2481
  font-size: 0.8125rem;
2477
2482
  background: var(--alinea-fields);
2478
2483
  box-shadow: var(--alinea-fields-shadow);
@@ -2515,7 +2520,6 @@ html[data-theme=dark] .alinea-Viewport {
2515
2520
  line-height: 1.5;
2516
2521
  font-family: "JetBrains Mono", monospace;
2517
2522
  white-space: pre;
2518
- overflow-x: auto !important;
2519
2523
  font-size: 0.8125rem;
2520
2524
  border-radius: var(--alinea-border-radius);
2521
2525
  background: var(--alinea-fields);
@@ -3143,7 +3147,6 @@ h3.alinea-RichTextKit-heading:not(:last-child) {
3143
3147
  color: inherit;
3144
3148
  font: inherit;
3145
3149
  width: 100%;
3146
- resize: none;
3147
3150
  padding: 0.5625rem 0.875rem;
3148
3151
  border-radius: var(--alinea-border-radius);
3149
3152
  line-height: 1.5;
@@ -3999,4 +4002,23 @@ h3.alinea-RichTextKit-heading:not(:last-child) {
3999
4002
  font-size: 0.8em;
4000
4003
  }
4001
4004
 
4005
+ /* src/ui/util/TextareaAutosize.module.scss */
4006
+ .alinea-TextareaAutosize {
4007
+ display: grid;
4008
+ width: 100%;
4009
+ }
4010
+ .alinea-TextareaAutosize-textarea {
4011
+ grid-area: 1/1/2/2;
4012
+ overflow-x: auto;
4013
+ resize: none;
4014
+ white-space: pre-wrap;
4015
+ }
4016
+ .alinea-TextareaAutosize-shadow {
4017
+ content: attr(data-value) " ";
4018
+ grid-area: 1/1/2/2;
4019
+ overflow-x: auto;
4020
+ visibility: hidden;
4021
+ white-space: pre-wrap;
4022
+ }
4023
+
4002
4024
  /* css-entry:css-entry */
@@ -104,6 +104,7 @@ function ListInputRow({
104
104
  rootRef,
105
105
  isDragging,
106
106
  isDragOverlay,
107
+ readOnly,
107
108
  onCreate,
108
109
  firstRow,
109
110
  ...rest
@@ -119,7 +120,7 @@ function ListInputRow({
119
120
  ref: rootRef,
120
121
  ...rest,
121
122
  children: [
122
- !isDragOverlay && /* @__PURE__ */ jsx(
123
+ !readOnly && !isDragOverlay && /* @__PURE__ */ jsx(
123
124
  ListInsertRow,
124
125
  {
125
126
  open: showInsert,
@@ -148,7 +149,7 @@ function ListInputRow({
148
149
  }
149
150
  ) }),
150
151
  /* @__PURE__ */ jsx(Sink.Title, { children: /* @__PURE__ */ jsx(TextLabel, { label: Type.label(type) }) }),
151
- /* @__PURE__ */ jsxs(Sink.Options, { children: [
152
+ !readOnly && /* @__PURE__ */ jsxs(Sink.Options, { children: [
152
153
  /* @__PURE__ */ jsx(
153
154
  IconButton,
154
155
  {
@@ -171,8 +172,13 @@ function ListInputRow({
171
172
  }
172
173
  );
173
174
  }
174
- function ListCreateRow({ schema, inline, onCreate }) {
175
- return /* @__PURE__ */ jsx("div", { className: styles.create({ inline }), children: /* @__PURE__ */ jsx(Create.Root, { children: entries(schema).map(([key, type]) => {
175
+ function ListCreateRow({
176
+ schema,
177
+ readOnly,
178
+ inline,
179
+ onCreate
180
+ }) {
181
+ return /* @__PURE__ */ jsx("div", { className: styles.create({ inline }), children: /* @__PURE__ */ jsx(Create.Root, { disabled: readOnly, children: entries(schema).map(([key, type]) => {
176
182
  return /* @__PURE__ */ jsx(
177
183
  Create.Button,
178
184
  {
@@ -238,6 +244,7 @@ function ListInput({ field }) {
238
244
  {
239
245
  row,
240
246
  schema,
247
+ readOnly,
241
248
  onMove: (direction) => {
242
249
  if (readOnly)
243
250
  return;
@@ -264,6 +271,7 @@ function ListInput({ field }) {
264
271
  ListCreateRow,
265
272
  {
266
273
  schema,
274
+ readOnly,
267
275
  onCreate: (type) => {
268
276
  if (readOnly)
269
277
  return;