@parallelworks/tandem-web 0.157.1 → 0.158.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.
@@ -1,16 +1,17 @@
1
1
  import { api as e, unwrap as t } from "../api/client.js";
2
2
  import { externalUrl as n } from "../lib/externalUrl.js";
3
- import { Button as r, ErrorText as i, Input as a } from "@parallelworks/ui";
4
- import { useParams as o } from "@tanstack/react-router";
5
- import { useEffect as s, useState as c } from "react";
6
- import { useErrorMessage as l } from "@parallelworks/problem/react";
7
- import { useTranslations as u } from "use-intl";
8
- import { jsx as d, jsxs as f } from "react/jsx-runtime";
9
- import { useMutation as p } from "@tanstack/react-query";
10
- import { GlobeIcon as m } from "@parallelworks/ui/icons";
11
- import { Node as h, NodeViewWrapper as g, ReactNodeViewRenderer as _, mergeAttributes as v } from "@tiptap/react";
3
+ import { FigmaCard as r, isFigma as i } from "./Figma.js";
4
+ import { Button as a, ErrorText as o, Input as s } from "@parallelworks/ui";
5
+ import { useParams as c } from "@tanstack/react-router";
6
+ import { useEffect as l, useState as u } from "react";
7
+ import { useErrorMessage as d } from "@parallelworks/problem/react";
8
+ import { useTranslations as f } from "use-intl";
9
+ import { jsx as p, jsxs as m } from "react/jsx-runtime";
10
+ import { useMutation as h } from "@tanstack/react-query";
11
+ import { GlobeIcon as g } from "@parallelworks/ui/icons";
12
+ import { Node as _, NodeViewWrapper as v, ReactNodeViewRenderer as y, mergeAttributes as b } from "@tiptap/react";
12
13
  // src/components/LinkCard.tsx
13
- var y = /^<(https?:\/\/[^\s<>]+)>[ \t]*(?:\n|$)/, b = h.create({
14
+ var x = /^<(https?:\/\/[^\s<>]+)>[ \t]*(?:\n|$)/, S = /^(https:\/\/(?:www\.)?figma\.com\/(?:file|design|proto|board|slides)\/[^\s<>]+)[ \t]*(?:\n|$)/, C = _.create({
14
15
  name: "linkCard",
15
16
  group: "block",
16
17
  atom: !0,
@@ -26,21 +27,21 @@ var y = /^<(https?:\/\/[^\s<>]+)>[ \t]*(?:\n|$)/, b = h.create({
26
27
  parseHTML: () => [{ tag: "div[data-link-card]" }],
27
28
  renderHTML: ({ node: e, HTMLAttributes: t }) => [
28
29
  "div",
29
- v(t, { "data-link-card": "" }),
30
+ b(t, { "data-link-card": "" }),
30
31
  [
31
32
  "a",
32
33
  { href: e.attrs.url },
33
34
  e.attrs.title || e.attrs.url
34
35
  ]
35
36
  ],
36
- addNodeView: () => _(S, { stopEvent: ({ event: e }) => e.target instanceof Element && !!e.target.closest("[data-card-ui]") }),
37
+ addNodeView: () => y(T, { stopEvent: ({ event: e }) => e.target instanceof Element && !!e.target.closest("[data-card-ui]") }),
37
38
  markdownTokenName: "linkCard",
38
39
  markdownTokenizer: {
39
40
  name: "linkCard",
40
41
  level: "block",
41
- start: (e) => e.search(/^<https?:\/\//m),
42
+ start: (e) => e.search(/^(?:<https?:\/\/|https:\/\/(?:www\.)?figma\.com\/)/m),
42
43
  tokenize: (e) => {
43
- let t = y.exec(e);
44
+ let t = x.exec(e) ?? S.exec(e);
44
45
  return t ? {
45
46
  type: "linkCard",
46
47
  raw: t[0],
@@ -51,7 +52,7 @@ var y = /^<(https?:\/\/[^\s<>]+)>[ \t]*(?:\n|$)/, b = h.create({
51
52
  parseMarkdown: (e, t) => t.createNode("linkCard", { url: e.text ?? "" }),
52
53
  renderMarkdown: (e) => `<${String(e.attrs?.url ?? "")}>`
53
54
  });
54
- function x(e) {
55
+ function w(e) {
55
56
  let { $from: t } = e.state.selection, n = t.parent, r = "";
56
57
  if (n.type.name === "paragraph" && n.childCount === 1) {
57
58
  let e = n.firstChild, t = e?.marks.find((e) => e.type.name === "link");
@@ -69,96 +70,102 @@ function x(e) {
69
70
  }, i).run();
70
71
  } else e.chain().focus().insertContent(i).run();
71
72
  }
72
- function S({ node: h, updateAttributes: _, editor: v }) {
73
- let y = u("linkCard"), b = l(), { workspace: x = "" } = o({ strict: !1 }), S = String(h.attrs.url ?? ""), C = String(h.attrs.title ?? ""), [w, T] = c(""), E = p({
73
+ function T({ node: _, updateAttributes: y, editor: b }) {
74
+ let x = f("linkCard"), S = d(), { workspace: C = "" } = c({ strict: !1 }), w = String(_.attrs.url ?? ""), T = String(_.attrs.title ?? ""), [E, D] = u(""), O = h({
74
75
  mutationFn: async (n) => t(await e.POST("/api/v1/workspaces/{workspace}/link-previews", {
75
- params: { path: { workspace: x } },
76
+ params: { path: { workspace: C } },
76
77
  body: { url: n }
77
78
  })),
78
- onSuccess: (e) => _({
79
+ onSuccess: (e) => y({
79
80
  url: e.url,
80
81
  title: e.title,
81
82
  description: e.description ?? "",
82
83
  siteName: e.siteName ?? "",
83
84
  icon: e.icon ?? ""
84
85
  })
85
- }), D = !!S && !C && v.isEditable && !!x, { mutate: O, isIdle: k } = E;
86
- if (s(() => {
87
- D && k && O(S);
86
+ }), k = !!w && !T && b.isEditable && !!C && !i(w), { mutate: A, isIdle: j } = O;
87
+ if (l(() => {
88
+ k && j && A(w);
88
89
  }, [
89
- D,
90
90
  k,
91
- O,
92
- S
93
- ]), !S) return /* @__PURE__ */ d(g, {
91
+ j,
92
+ A,
93
+ w
94
+ ]), !w) return /* @__PURE__ */ p(v, {
94
95
  className: "link-card link-card-empty",
95
96
  contentEditable: !1,
96
- children: /* @__PURE__ */ f("form", {
97
+ children: /* @__PURE__ */ m("form", {
97
98
  "data-card-ui": !0,
98
99
  className: "flex flex-wrap items-center gap-2",
99
100
  onSubmit: (e) => {
100
- e.preventDefault(), w.trim() && E.mutate(w.trim());
101
+ e.preventDefault(), E.trim() && O.mutate(E.trim());
101
102
  },
102
103
  children: [
103
- /* @__PURE__ */ d(a, {
104
- value: w,
105
- onChange: (e) => T(e.target.value),
104
+ /* @__PURE__ */ p(s, {
105
+ value: E,
106
+ onChange: (e) => D(e.target.value),
106
107
  placeholder: "https://",
107
- "aria-label": y("address"),
108
+ "aria-label": x("address"),
108
109
  className: "min-w-0 flex-1",
109
- disabled: !v.isEditable
110
+ disabled: !b.isEditable
110
111
  }),
111
- /* @__PURE__ */ d(r, {
112
+ /* @__PURE__ */ p(a, {
112
113
  type: "submit",
113
114
  size: "sm",
114
115
  variant: "primary",
115
- loading: E.isPending,
116
- children: y("make")
116
+ loading: O.isPending,
117
+ children: x("make")
117
118
  }),
118
- E.error && /* @__PURE__ */ d(i, {
119
+ O.error && /* @__PURE__ */ p(o, {
119
120
  className: "w-full",
120
- children: b(E.error)
121
+ children: S(O.error)
121
122
  })
122
123
  ]
123
124
  })
124
125
  });
125
- let A = n(S), j = (() => {
126
+ if (i(w)) return /* @__PURE__ */ p(v, {
127
+ className: "link-card",
128
+ contentEditable: !1,
129
+ "data-drag-handle": !0,
130
+ children: /* @__PURE__ */ p(r, { url: w })
131
+ });
132
+ let M = n(w), N = (() => {
126
133
  try {
127
- return new URL(S).host;
134
+ return new URL(w).host;
128
135
  } catch {
129
- return S;
136
+ return w;
130
137
  }
131
- })(), M = String(h.attrs.icon ?? "");
132
- return /* @__PURE__ */ d(g, {
138
+ })(), P = String(_.attrs.icon ?? "");
139
+ return /* @__PURE__ */ p(v, {
133
140
  className: "link-card",
134
141
  contentEditable: !1,
135
142
  "data-drag-handle": !0,
136
- children: /* @__PURE__ */ d("a", {
137
- href: A,
143
+ children: /* @__PURE__ */ p("a", {
144
+ href: M,
138
145
  target: "_blank",
139
146
  rel: "noreferrer noopener",
140
147
  className: "link-card-link",
141
148
  "data-card-ui": !0,
142
- children: /* @__PURE__ */ f("span", {
149
+ children: /* @__PURE__ */ m("span", {
143
150
  className: "min-w-0 flex-1",
144
151
  children: [
145
- /* @__PURE__ */ d("span", {
152
+ /* @__PURE__ */ p("span", {
146
153
  className: "link-card-title",
147
- children: C || (E.isPending ? y("reading") : j)
154
+ children: T || (O.isPending ? x("reading") : N)
148
155
  }),
149
- h.attrs.description && /* @__PURE__ */ d("span", {
156
+ _.attrs.description && /* @__PURE__ */ p("span", {
150
157
  className: "link-card-description",
151
- children: String(h.attrs.description)
158
+ children: String(_.attrs.description)
152
159
  }),
153
- /* @__PURE__ */ f("span", {
160
+ /* @__PURE__ */ m("span", {
154
161
  className: "link-card-site",
155
- children: [M.startsWith("data:image/") ? /* @__PURE__ */ d("img", {
156
- src: M,
162
+ children: [P.startsWith("data:image/") ? /* @__PURE__ */ p("img", {
163
+ src: P,
157
164
  alt: "",
158
165
  className: "size-4 shrink-0 rounded-sm"
159
- }) : /* @__PURE__ */ d(m, { className: "size-4 shrink-0" }), /* @__PURE__ */ d("span", {
166
+ }) : /* @__PURE__ */ p(g, { className: "size-4 shrink-0" }), /* @__PURE__ */ p("span", {
160
167
  className: "truncate",
161
- children: h.attrs.siteName || j
168
+ children: _.attrs.siteName || N
162
169
  })]
163
170
  })
164
171
  ]
@@ -166,4 +173,4 @@ function S({ node: h, updateAttributes: _, editor: v }) {
166
173
  })
167
174
  });
168
175
  }
169
- export { b as LinkCard, x as insertLinkCard };
176
+ export { C as LinkCard, w as insertLinkCard };
@@ -50,6 +50,7 @@ var w = {
50
50
  mathBlock: "∑",
51
51
  mathInline: "√",
52
52
  linkCard: "↗",
53
+ figma: "◈",
53
54
  toggle: "▸",
54
55
  divider: "—",
55
56
  columns2: "▥",
@@ -93,6 +94,7 @@ var w = {
93
94
  mathBlock: (e) => e.insertContent({ type: "mathBlock" }),
94
95
  mathInline: (e) => e.insertContent({ type: "mathInline" }),
95
96
  linkCard: (e) => e,
97
+ figma: (e) => e.insertContent({ type: "figmaEmbed" }),
96
98
  toggle: (e) => e.setDetails(),
97
99
  divider: (e) => e.setHorizontalRule(),
98
100
  columns2: (e) => s(e, 2),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parallelworks/tandem-web",
3
- "version": "0.157.1",
3
+ "version": "0.158.0",
4
4
  "description": "Tandem's pages, for a host app to render in its own",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",