@plitzi/sdk-style 0.36.2 → 0.37.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.
Files changed (47) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/dist/StyleMap/StyleMap.d.ts +5 -21
  3. package/dist/StyleMap/helpers/isValueValid.d.ts +1 -0
  4. package/dist/StyleMap/helpers/isValueValid.mjs +3 -3
  5. package/dist/StyleMap/helpers/utils.d.ts +2 -2
  6. package/dist/StyleMap/helpers/utils.mjs +43 -28
  7. package/dist/StyleMap/methods/addSelector.d.ts +2 -7
  8. package/dist/StyleMap/methods/addSelector.mjs +4 -4
  9. package/dist/StyleMap/methods/updateSelector.d.ts +2 -5
  10. package/dist/StyleMap/methods/updateSelector.mjs +2 -2
  11. package/dist/StyleReducer.d.ts +3 -11
  12. package/dist/components/Selector/Selector.mjs +149 -125
  13. package/dist/components/Selector/SelectorHelper.d.ts +25 -0
  14. package/dist/components/Selector/SelectorHelper.mjs +43 -2
  15. package/dist/components/StyleInspector/Inspector.d.ts +2 -1
  16. package/dist/components/StyleInspector/Inspector.mjs +92 -87
  17. package/dist/components/StyleInspector/StyleInspector.mjs +240 -169
  18. package/dist/components/StyleInspector/StyleInspectorContext.d.ts +1 -0
  19. package/dist/components/StyleInspector/StyleInspectorProvider.d.ts +2 -1
  20. package/dist/components/StyleInspector/StyleInspectorProvider.mjs +37 -31
  21. package/dist/components/StyleInspector/categories/Others/Others.mjs +58 -48
  22. package/dist/components/StyleInspector/categories/Others/OthersScrollbar.d.ts +9 -0
  23. package/dist/components/StyleInspector/categories/Others/OthersScrollbar.mjs +36 -0
  24. package/dist/components/StyleInspector/categories/Typography/Typography.mjs +29 -45
  25. package/dist/components/StyleInspector/categories/Typography/TypographyFigures.d.ts +13 -0
  26. package/dist/components/StyleInspector/categories/Typography/TypographyFigures.mjs +61 -0
  27. package/dist/components/StyleInspector/components/AncestorRules/AncestorRuleChip.d.ts +10 -0
  28. package/dist/components/StyleInspector/components/AncestorRules/AncestorRuleChip.mjs +39 -0
  29. package/dist/components/StyleInspector/components/AncestorRules/AncestorRules.d.ts +14 -0
  30. package/dist/components/StyleInspector/components/AncestorRules/AncestorRules.mjs +36 -0
  31. package/dist/components/StyleInspector/components/AncestorRules/index.d.ts +3 -0
  32. package/dist/components/StyleInspector/components/AncestorRules/index.mjs +5 -0
  33. package/dist/components/StyleInspector/helpers.d.ts +36 -0
  34. package/dist/components/StyleInspector/helpers.mjs +54 -0
  35. package/dist/components/StyleInspector/hooks/useStyleInherit.d.ts +2 -1
  36. package/dist/components/StyleInspector/hooks/useStyleInherit.mjs +7 -5
  37. package/dist/components/StyleManager/ManagerSelector.d.ts +3 -2
  38. package/dist/components/StyleManager/ManagerSelector.mjs +114 -86
  39. package/dist/components/StyleManager/StyleManager.mjs +1 -0
  40. package/dist/components/StyleManager/StyleSelectorTag.d.ts +4 -1
  41. package/dist/components/StyleManager/StyleSelectorTag.mjs +36 -22
  42. package/dist/helpers/calculateInheriting.d.ts +1 -0
  43. package/dist/helpers/calculateInheriting.mjs +38 -28
  44. package/dist/helpers/processSelector.mjs +44 -21
  45. package/dist/helpers/processSelectorAttributes.d.ts +14 -6
  46. package/dist/helpers/processSelectorAttributes.mjs +38 -22
  47. package/package.json +16 -4
@@ -1,106 +1,110 @@
1
- import { selectorFormatter as e } from "./SelectorHelper.mjs";
2
- import t from "./SelectorItem/index.mjs";
3
- import n from "./SelectorSuggestions/index.mjs";
4
- import r from "../StyleManager/index.mjs";
5
- import { memo as i, useCallback as a, useMemo as o, useRef as s, useState as c } from "react";
6
- import { get as l, omit as u, pick as d } from "@plitzi/plitzi-ui/helpers";
7
- import { jsx as f, jsxs as p } from "react/jsx-runtime";
8
- import m from "@plitzi/plitzi-ui/Button";
9
- import h, { useFloating as g } from "@plitzi/plitzi-ui/ContainerFloating";
10
- import _ from "clsx";
11
- import { usePopup as v } from "@plitzi/plitzi-ui/Popup";
12
- var y = i(({ className: i = "", value: y = "", selectors: b, selector: x, componentType: S, disabled: C = !1, onChange: w, onSelectorSelected: T, onAdd: E, onRemove: D }) => {
13
- let O = s(null), [k, A] = c(""), [j, M, , N, P] = g({ disabled: C }), { existsPopup: F, addPopup: I } = v("floating"), L = o(() => Object.values(b ?? {}).find((e) => e.type === "element" && e.componentType === S), [S, b]), R = o(() => Object.values(d(b ?? {}, y.split(" "))).map((e) => d(e, ["name", "type"])), [b, y]), z = o(() => Object.values(u(b ?? {}, y.split(" "))), [b, y]), B = a((e) => {
14
- M(e.target.value.length > 0), A(e.target.value);
15
- }, [M]), V = a(() => {
16
- O.current?.focus(), M(k.length > 0);
1
+ import { inStylesheetOrder as e, overriddenProperties as t, overrideNote as n, selectorFormatter as r } from "./SelectorHelper.mjs";
2
+ import i from "./SelectorItem/index.mjs";
3
+ import a from "./SelectorSuggestions/index.mjs";
4
+ import o from "../StyleManager/index.mjs";
5
+ import { memo as s, useCallback as c, useMemo as l, useRef as u, useState as d } from "react";
6
+ import { get as f, omit as p, pick as m } from "@plitzi/plitzi-ui/helpers";
7
+ import { jsx as h, jsxs as g } from "react/jsx-runtime";
8
+ import _ from "@plitzi/plitzi-ui/Button";
9
+ import v, { useFloating as y } from "@plitzi/plitzi-ui/ContainerFloating";
10
+ import b from "clsx";
11
+ import { usePopup as x } from "@plitzi/plitzi-ui/Popup";
12
+ //#region src/components/Selector/Selector.tsx
13
+ var S = "Classes apply left to right, in the order the stylesheet lists them: where two set the same property, the one further right wins.", C = s(({ className: s = "", value: C = "", selectors: w, selector: T, componentType: E, disabled: D = !1, onChange: O, onSelectorSelected: k, onAdd: A, onRemove: j }) => {
14
+ let M = u(null), [N, P] = d(""), [F, I, , L, R] = y({ disabled: D }), { existsPopup: z, addPopup: B } = x("floating"), V = l(() => Object.values(w ?? {}).find((e) => e.type === "element" && e.componentType === E), [E, w]), H = l(() => Object.values(m(w ?? {}, C.split(" "))).map((e) => m(e, ["name", "type"])), [w, C]), U = l(() => e(H.map((e, t) => ({
15
+ ...e,
16
+ position: t
17
+ })), Object.keys(w ?? {})), [H, w]), W = l(() => t(U.map(({ name: e }) => e), w ?? {}), [U, w]), G = l(() => n(T?.name.replace(/:.*/, ""), W), [T, W]), K = l(() => Object.values(p(w ?? {}, C.split(" "))), [w, C]), q = c((e) => {
18
+ I(e.target.value.length > 0), P(e.target.value);
19
+ }, [I]), J = c(() => {
20
+ M.current?.focus(), I(N.length > 0);
17
21
  }, [
18
- O,
19
- k,
20
- M
21
- ]), H = a((e) => T?.(e), [T]), U = a((e) => (t, n = !0) => {
22
- let r = [...R.filter((t, n) => n !== e), t].filter((e) => !!e.name).reduce((e, t) => `${e} ${t.name}`, "").trim();
23
- E?.(t, !1), w?.(r), n && T?.(t);
22
+ M,
23
+ N,
24
+ I
25
+ ]), Y = c((e) => k?.(e), [k]), X = c((e) => (t, n = !0) => {
26
+ let r = [...H.filter((t, n) => n !== e), t].filter((e) => !!e.name).reduce((e, t) => `${e} ${t.name}`, "").trim();
27
+ A?.(t, !1), O?.(r), n && k?.(t);
24
28
  }, [
25
- R,
26
- E,
27
- w,
28
- T
29
- ]), W = a((e) => (t, n) => {
29
+ H,
30
+ A,
31
+ O,
32
+ k
33
+ ]), Z = c((e) => (t, n) => {
30
34
  switch (t) {
31
35
  case "remove":
32
36
  case "delete": {
33
- let n = R.filter((t, n) => n !== e), r = n.reduce((e, t) => `${e} ${t.name}`, "").trim();
34
- x && R[e].name === x.name && T?.(l(n, "0")), w?.(r), t === "delete" && D?.(R[e]);
37
+ let n = H.filter((t, n) => n !== e), r = n.reduce((e, t) => `${e} ${t.name}`, "").trim();
38
+ T && H[e].name === T.name && k?.(f(n, "0")), O?.(r), t === "delete" && j?.(H[e]);
35
39
  break;
36
40
  }
37
41
  case "duplicate": {
38
42
  if (!n) break;
39
- let t = [...R, n].filter((e) => !!e.name).reduce((e, t) => `${e} ${t.name}`, "").trim();
40
- E?.(n, !0, l(R, `${e}`)), w?.(t);
43
+ let t = [...H, n].filter((e) => !!e.name).reduce((e, t) => `${e} ${t.name}`, "").trim();
44
+ A?.(n, !0, f(H, `${e}`)), O?.(t);
41
45
  break;
42
46
  }
43
47
  }
44
48
  }, [
45
- R,
46
- x,
47
- w,
49
+ H,
48
50
  T,
49
- E,
50
- D
51
- ]), G = a((t) => {
52
- switch (t.key) {
51
+ O,
52
+ k,
53
+ A,
54
+ j
55
+ ]), Q = c((e) => {
56
+ switch (e.key) {
53
57
  case "Enter": {
54
- let { value: n } = t.target;
55
- if (n !== "" && !R.find((e) => e.name === n)) {
56
- A("");
57
- let r = {
58
- name: e(n),
58
+ let { value: t } = e.target;
59
+ if (t !== "" && !H.find((e) => e.name === t)) {
60
+ P("");
61
+ let n = {
62
+ name: r(t),
59
63
  type: "class"
60
- }, i = [...R, r].filter((e) => !!e.name).reduce((e, t) => `${e} ${t.name}`, "").trim();
61
- E?.(r, !1), w?.(i), M(!1), t.target.blur(), T?.(r);
64
+ }, i = [...H, n].filter((e) => !!e.name).reduce((e, t) => `${e} ${t.name}`, "").trim();
65
+ A?.(n, !1), O?.(i), I(!1), e.target.blur(), k?.(n);
62
66
  }
63
67
  setTimeout(() => {
64
- O.current?.focus();
68
+ M.current?.focus();
65
69
  }, 0);
66
70
  break;
67
71
  }
68
72
  case "ArrowUp":
69
- M(!1);
73
+ I(!1);
70
74
  break;
71
75
  case "ArrowDown":
72
- M(!0);
76
+ I(!0);
73
77
  break;
74
- case "Escape": t.stopPropagation(), A(""), t.target.blur();
78
+ case "Escape": e.stopPropagation(), P(""), e.target.blur();
75
79
  }
76
80
  }, [
77
- R,
78
- E,
79
- w,
80
- T,
81
- M
82
- ]), K = a((e) => {
83
- setTimeout(() => A(""), 0), M(!1);
84
- let t = [...R, e].reduce((e, t) => `${e} ${t.name}`, "").trim();
85
- w?.(t), T?.(e);
81
+ H,
82
+ A,
83
+ O,
84
+ k,
85
+ I
86
+ ]), $ = c((e) => {
87
+ setTimeout(() => P(""), 0), I(!1);
88
+ let t = [...H, e].reduce((e, t) => `${e} ${t.name}`, "").trim();
89
+ O?.(t), k?.(e);
86
90
  }, [
87
- R,
88
- w,
89
- T,
90
- M
91
- ]), q = a((e) => {
92
- setTimeout(() => A(""), 0), M(!1);
93
- let t = [...R, e].reduce((e, t) => `${e} ${t.name}`, "").trim();
94
- w?.(t), E?.(e, !1), T?.(e);
91
+ H,
92
+ O,
93
+ k,
94
+ I
95
+ ]), ee = c((e) => {
96
+ setTimeout(() => P(""), 0), I(!1);
97
+ let t = [...H, e].reduce((e, t) => `${e} ${t.name}`, "").trim();
98
+ O?.(t), A?.(e, !1), k?.(e);
95
99
  }, [
96
- R,
97
- w,
98
- E,
99
- T,
100
- M
101
- ]), J = a((e) => {
102
- e.preventDefault(), e.stopPropagation(), F("styleManager") || I("styleManager", /* @__PURE__ */ f(r, {}), {
103
- icon: /* @__PURE__ */ f("i", { className: "fas fa-swatchbook text-base" }),
100
+ H,
101
+ O,
102
+ A,
103
+ k,
104
+ I
105
+ ]), te = c((e) => {
106
+ e.preventDefault(), e.stopPropagation(), z("styleManager") || B("styleManager", /* @__PURE__ */ h(o, {}), {
107
+ icon: /* @__PURE__ */ h("i", { className: "fas fa-swatchbook text-base" }),
104
108
  title: "Style Manager",
105
109
  resizeHandles: ["se"],
106
110
  allowLeftSide: !0,
@@ -108,60 +112,80 @@ var y = i(({ className: i = "", value: y = "", selectors: b, selector: x, compon
108
112
  placement: "floating",
109
113
  width: 600
110
114
  });
111
- }, [I, F]), Y = o(() => ({ width: P?.width }), [P]), X = L ? [L, ...R] : R;
112
- return /* @__PURE__ */ p(h, {
113
- ref: N,
114
- className: "w-full",
115
- open: j,
116
- children: [/* @__PURE__ */ f(h.Trigger, {
115
+ }, [B, z]), ne = l(() => ({ width: R?.width }), [R]);
116
+ return /* @__PURE__ */ g("div", {
117
+ className: "flex w-full min-w-0 flex-col gap-1",
118
+ children: [/* @__PURE__ */ g(v, {
119
+ ref: L,
117
120
  className: "w-full",
118
- children: /* @__PURE__ */ p("div", {
119
- className: _("bg-grayviolet-200 relative flex flex-wrap gap-1 rounded-sm p-1 dark:bg-zinc-800", i, {
120
- "pointer-events-none cursor-not-allowed bg-gray-100 dark:bg-zinc-900": C,
121
- "cursor-pointer": !C
122
- }),
123
- onClick: V,
124
- onKeyDown: G,
125
- children: [
126
- /* @__PURE__ */ f(m, {
127
- intent: "secondary",
128
- size: "custom",
129
- onClick: J,
130
- className: "h-7 w-7 rounded-sm bg-white dark:bg-zinc-700 dark:text-zinc-200",
131
- title: "Style Manager",
132
- children: /* @__PURE__ */ f(m.Icon, { icon: "fas fa-swatchbook" })
121
+ open: F,
122
+ children: [/* @__PURE__ */ h(v.Trigger, {
123
+ className: "w-full",
124
+ children: /* @__PURE__ */ g("div", {
125
+ className: b("bg-grayviolet-200 relative flex flex-wrap gap-1 rounded-sm p-1 dark:bg-zinc-800", s, {
126
+ "pointer-events-none cursor-not-allowed bg-gray-100 dark:bg-zinc-900": D,
127
+ "cursor-pointer": !D
133
128
  }),
134
- X.map((e, n) => /* @__PURE__ */ f(t, {
135
- selector: e.name,
136
- type: e.type,
137
- editable: e.type !== "element",
138
- active: e.name === x?.name.replace(/:.*/, ""),
139
- onAction: W(L ? n - 1 : n),
140
- onClick: H,
141
- onChange: U(L ? n - 1 : n)
142
- }, `${n}_${e.name}`)),
143
- /* @__PURE__ */ f("input", {
144
- ref: O,
145
- className: "flex min-h-0 w-0 border-none bg-transparent px-1 py-0 text-xs text-inherit outline-hidden focus:min-w-[50px] focus:grow focus:ring-transparent",
146
- autoComplete: "off",
147
- autoCorrect: "off",
148
- autoCapitalize: "off",
149
- spellCheck: "false",
150
- value: k,
151
- onChange: B
152
- })
153
- ]
154
- })
155
- }), /* @__PURE__ */ f(h.Content, {
156
- style: Y,
157
- children: /* @__PURE__ */ f(n, {
158
- selector: k,
159
- selectors: z,
160
- onSelect: K,
161
- onCreate: q
162
- })
129
+ onClick: J,
130
+ onKeyDown: Q,
131
+ children: [
132
+ /* @__PURE__ */ h(_, {
133
+ intent: "secondary",
134
+ size: "custom",
135
+ onClick: te,
136
+ className: "h-7 w-7 rounded-sm bg-white dark:bg-zinc-700 dark:text-zinc-200",
137
+ title: "Style Manager",
138
+ children: /* @__PURE__ */ h(_.Icon, { icon: "fas fa-swatchbook" })
139
+ }),
140
+ V && /* @__PURE__ */ h(i, {
141
+ selector: V.name,
142
+ type: V.type,
143
+ editable: !1,
144
+ active: V.name === T?.name.replace(/:.*/, ""),
145
+ onClick: Y
146
+ }),
147
+ U.map(({ position: e, ...t }) => /* @__PURE__ */ h(i, {
148
+ selector: t.name,
149
+ type: t.type,
150
+ editable: t.type !== "element",
151
+ active: t.name === T?.name.replace(/:.*/, ""),
152
+ onAction: Z(e),
153
+ onClick: Y,
154
+ onChange: X(e)
155
+ }, `${e}_${t.name}`)),
156
+ /* @__PURE__ */ h("input", {
157
+ ref: M,
158
+ className: "flex min-h-0 w-0 border-none bg-transparent px-1 py-0 text-xs text-inherit outline-hidden focus:min-w-[50px] focus:grow focus:ring-transparent",
159
+ autoComplete: "off",
160
+ autoCorrect: "off",
161
+ autoCapitalize: "off",
162
+ spellCheck: "false",
163
+ value: N,
164
+ onChange: q
165
+ })
166
+ ]
167
+ })
168
+ }), /* @__PURE__ */ h(v.Content, {
169
+ style: ne,
170
+ children: /* @__PURE__ */ h(a, {
171
+ selector: N,
172
+ selectors: K,
173
+ onSelect: $,
174
+ onCreate: ee
175
+ })
176
+ })]
177
+ }), U.length > 1 && /* @__PURE__ */ g("div", {
178
+ className: "flex min-w-0 items-center gap-1.5 px-1 text-[11px] text-gray-500 dark:text-zinc-400",
179
+ title: G ?? S,
180
+ children: [/* @__PURE__ */ h("i", {
181
+ className: "fas fa-circle-info shrink-0",
182
+ title: S
183
+ }), /* @__PURE__ */ h("span", {
184
+ className: "truncate",
185
+ children: G ?? "Left to right: the class further right wins where they overlap"
186
+ })]
163
187
  })]
164
188
  });
165
189
  });
166
190
  //#endregion
167
- export { y as default };
191
+ export { C as default };
@@ -1 +1,26 @@
1
+ import { StyleItem } from '@plitzi/sdk-shared';
1
2
  export declare const selectorFormatter: (selector: string) => string;
3
+ /**
4
+ * The classes of one element in the order the stylesheet lists them, which is the order they win in: where two set the
5
+ * same property, the later one applies. The order they are written on the element decides nothing, so it is not the
6
+ * order they are shown in. A class the stylesheet does not hold keeps its place after the rest.
7
+ */
8
+ export declare const inStylesheetOrder: <T extends {
9
+ name: string;
10
+ }>(tags: T[], stylesheet: string[]) => T[];
11
+ export type Overridden = {
12
+ by: string;
13
+ properties: string[];
14
+ };
15
+ /**
16
+ * For each class of an element, what a class after it in the stylesheet sets again — the rules it loses wherever both
17
+ * apply. `ordered` is the element's classes in stylesheet order; a class nothing overrides is left out.
18
+ */
19
+ export declare const overriddenProperties: (ordered: string[], selectors: Record<string, StyleItem>) => Record<string, Overridden[]>;
20
+ /**
21
+ * A list of properties as a person reads it: the four sides of one box property as that property, so a lost padding
22
+ * reads `padding` rather than four lines of it. What is left of a side set that is not whole stays as written.
23
+ */
24
+ export declare const summarizeProperties: (properties: string[]) => string[];
25
+ /** What the class being edited loses to the classes after it, as one line — or nothing, when it loses nothing. */
26
+ export declare const overrideNote: (name: string | undefined, overridden: Record<string, Overridden[]>) => string | undefined;
@@ -1,4 +1,45 @@
1
1
  //#region src/components/Selector/SelectorHelper.ts
2
- var e = (e) => (e.match(/^[0-9]/) && (e = `_${e}`), e.replace(" ", "-").replace(/[^a-zA-Z0-9_-]+/, ""));
2
+ var e = (e) => (e.match(/^[0-9]/) && (e = `_${e}`), e.replace(" ", "-").replace(/[^a-zA-Z0-9_-]+/, "")), t = (e, t) => {
3
+ let n = (e) => {
4
+ let n = t.indexOf(e);
5
+ return n === -1 ? t.length : n;
6
+ };
7
+ return [...e].sort((e, t) => n(e.name) - n(t.name));
8
+ }, n = (e) => {
9
+ let t = e?.attributes.base;
10
+ return t ? [...Object.keys(t.default ?? {}), ...Object.entries(t.states ?? {}).flatMap(([e, t]) => Object.keys(t).map((t) => `${e}: ${t}`))] : [];
11
+ }, r = (e, t) => {
12
+ let r = {};
13
+ return e.forEach((i, a) => {
14
+ let o = new Set(n(t[i])), s = e.slice(a + 1).flatMap((e) => {
15
+ let r = n(t[e]).filter((e) => o.has(e));
16
+ return r.length > 0 ? [{
17
+ by: e,
18
+ properties: r
19
+ }] : [];
20
+ });
21
+ s.length > 0 && (r[i] = s);
22
+ }), r;
23
+ }, i = [
24
+ "top",
25
+ "right",
26
+ "bottom",
27
+ "left"
28
+ ], a = (e) => {
29
+ let t = new Set(e), n = [];
30
+ for (let r of e) {
31
+ if (!t.has(r)) continue;
32
+ let e = /^(.*?)-(top|right|bottom|left)(-[a-z]+)?$/.exec(r), a = e?.at(3) ?? "", o = e ? i.map((t) => `${e[1]}-${t}${a}`) : [];
33
+ if (e && o.every((e) => t.has(e))) {
34
+ o.forEach((e) => t.delete(e)), n.push(`${e[1]}${a}`);
35
+ continue;
36
+ }
37
+ t.delete(r), n.push(r);
38
+ }
39
+ return n;
40
+ }, o = (e, t) => {
41
+ let n = e ? t[e] : void 0;
42
+ if (n) return n.map(({ by: e, properties: t }) => `${a(t).join(", ")} overridden by ${e}`).join(" · ");
43
+ };
3
44
  //#endregion
4
- export { e as selectorFormatter };
45
+ export { t as inStylesheetOrder, r as overriddenProperties, o as overrideNote, e as selectorFormatter, a as summarizeProperties };
@@ -6,10 +6,11 @@ export type InspectorProps = {
6
6
  selector?: StyleItem;
7
7
  styleState?: StyleState;
8
8
  styleVariant?: string;
9
+ styleAncestor?: string;
9
10
  styleSelector?: string;
10
11
  element?: Element;
11
12
  displayMode: DisplayMode;
12
13
  mode?: 'element' | 'manager';
13
14
  };
14
- declare const Inspector: ({ selectors, componentType, componentSubType, selector, styleState, styleVariant, styleSelector, element, displayMode, mode }: InspectorProps) => import("react").JSX.Element;
15
+ declare const Inspector: ({ selectors, componentType, componentSubType, selector, styleState, styleVariant, styleAncestor, styleSelector, element, displayMode, mode }: InspectorProps) => import("react").JSX.Element;
15
16
  export default Inspector;