@synchra24/app-ui 0.2.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/CHANGELOG.md +6 -0
- package/README.md +10 -2
- package/custom-elements.json +42 -0
- package/dist/auto.js +265 -22
- package/dist/index.d.ts +28 -0
- package/dist/index.js +265 -22
- package/dist/react.d.ts +2 -0
- package/dist/synchra-app-ui.js +12 -12
- package/docs/AI-AGENT.md +8 -0
- package/docs/API.md +66 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -9,3 +9,9 @@
|
|
|
9
9
|
- Документация, TypeScript/React-типы и примеры Storybook для всех новых сценариев.
|
|
10
10
|
|
|
11
11
|
Нативные действия требуют обновлённого хоста Synchra24. В автономном проекте передавайте список сотрудников и адаптер загрузки; локальные File не сохраняются автоматически. API существующих компонентов сохранён.
|
|
12
|
+
|
|
13
|
+
## 0.3.0
|
|
14
|
+
|
|
15
|
+
- `s24-sheet`: schema v1 for native content sheets with a web dialog fallback.
|
|
16
|
+
- Native form controls, sections, text, dividers, draft reset and fixed safe-area actions.
|
|
17
|
+
- Typed `show/close`, cancellation, validation and Storybook examples. Native host capability `nativeSheet:1` is required.
|
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
Synchra24 и самостоятельных веб-приложений. Общий API, отдельные оформление и
|
|
5
5
|
поведение для веб-кабинета и мобильного приложения. Светлая и тёмная темы,
|
|
6
6
|
система островов, формы, поиск, вкладки, состояния и нативный редактор текста.
|
|
7
|
-
Всего
|
|
7
|
+
Всего 35 компонентов, включая Screen, Well, Space, CircleButton, выбор даты/времени и Slider.
|
|
8
8
|
|
|
9
9
|
[Открыть Storybook](https://synchra24.github.io/app-ui/) · [Исходники на GitHub](https://github.com/synchra24/app-ui)
|
|
10
10
|
|
|
@@ -60,7 +60,7 @@ npm install @synchra24/app-ui
|
|
|
60
60
|
|
|
61
61
|
[Пакет на npm](https://www.npmjs.com/package/@synchra24/app-ui).
|
|
62
62
|
Для установки подготовленного архива вместо реестра:
|
|
63
|
-
`npm install ./synchra24-app-ui-0.
|
|
63
|
+
`npm install ./synchra24-app-ui-0.3.0.tgz`.
|
|
64
64
|
|
|
65
65
|
Без SDK можно передать тему и платформу явно:
|
|
66
66
|
|
|
@@ -120,3 +120,11 @@ Mobile selects use the app selection sheet when `nativeSelect: 1` is available:
|
|
|
120
120
|
примеры находятся в «Виджеты / Сотрудники и вложения» и «Навигация / Вкладки».
|
|
121
121
|
|
|
122
122
|
Дополнительно доступны `s24-info` (нативная информационная шторка / веб-диалог), `s24-progress` и `s24-text-editor` (штатный мобильный редактор / веб-панель форматирования). Контракты, ограничения нативного хоста и примеры приведены в [API](docs/API.md). Новые сценарии можно проверить в локальном Storybook, разделы «Информация и прогресс», «Формы / TextEditor» и «Виджеты».
|
|
123
|
+
|
|
124
|
+
### Нативная шторка содержимого
|
|
125
|
+
|
|
126
|
+
С версии 0.3.0 используйте `s24-sheet.show(definition)` для фильтров и компактных форм.
|
|
127
|
+
Мобильное приложение с `nativeSheet:1` рисует содержимое штатными нативными компонентами;
|
|
128
|
+
веб и старые хосты используют диалог. Контракт, ограничения и пример описаны в
|
|
129
|
+
[API: s24-sheet](docs/API.md#s24-sheet--нативная-шторка-содержимого-030), примеры —
|
|
130
|
+
Storybook → «Обратная связь / Нативная шторка». Произвольный HTML в нативные компоненты не преобразуется.
|
package/custom-elements.json
CHANGED
|
@@ -2244,6 +2244,48 @@
|
|
|
2244
2244
|
"name": "s24-error"
|
|
2245
2245
|
}
|
|
2246
2246
|
]
|
|
2247
|
+
},
|
|
2248
|
+
{
|
|
2249
|
+
"kind": "class",
|
|
2250
|
+
"name": "Sheet",
|
|
2251
|
+
"tagName": "s24-sheet",
|
|
2252
|
+
"customElement": true,
|
|
2253
|
+
"description": "Структурированная шторка: настоящие нативные компоненты в мобильном приложении; стандартный диалог в вебе и старых версиях.",
|
|
2254
|
+
"members": [
|
|
2255
|
+
{
|
|
2256
|
+
"kind": "method",
|
|
2257
|
+
"name": "show",
|
|
2258
|
+
"description": "show(definition: SheetDefinition): Promise<SheetResult>; version:1, content, actions и resetValues."
|
|
2259
|
+
},
|
|
2260
|
+
{
|
|
2261
|
+
"kind": "method",
|
|
2262
|
+
"name": "close",
|
|
2263
|
+
"description": "Закрывает без применения изменений."
|
|
2264
|
+
}
|
|
2265
|
+
],
|
|
2266
|
+
"events": [
|
|
2267
|
+
{
|
|
2268
|
+
"name": "s24-submit",
|
|
2269
|
+
"type": {
|
|
2270
|
+
"text": "CustomEvent<SheetResult>"
|
|
2271
|
+
},
|
|
2272
|
+
"description": "Применение значений."
|
|
2273
|
+
},
|
|
2274
|
+
{
|
|
2275
|
+
"name": "s24-close",
|
|
2276
|
+
"type": {
|
|
2277
|
+
"text": "CustomEvent<SheetResult>"
|
|
2278
|
+
},
|
|
2279
|
+
"description": "Закрытие или отмена."
|
|
2280
|
+
},
|
|
2281
|
+
{
|
|
2282
|
+
"name": "s24-error",
|
|
2283
|
+
"type": {
|
|
2284
|
+
"text": "CustomEvent<{message:string}>"
|
|
2285
|
+
},
|
|
2286
|
+
"description": "Ошибка моста."
|
|
2287
|
+
}
|
|
2288
|
+
]
|
|
2247
2289
|
}
|
|
2248
2290
|
]
|
|
2249
2291
|
}
|
package/dist/auto.js
CHANGED
|
@@ -853,6 +853,248 @@ var segmentedStyles = `
|
|
|
853
853
|
:host(s24-tab[data-segment-mobile]) .tab-count{display:inline;font-size:inherit;line-height:inherit;font-weight:inherit;flex:initial;width:auto;height:auto;background:transparent;border:0;border-radius:0;padding:0;margin-left:4px;color:inherit}
|
|
854
854
|
`;
|
|
855
855
|
|
|
856
|
+
// src/sheet-schema.js
|
|
857
|
+
var object = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
858
|
+
var text = (value, max = 500) => typeof value === "string" && value.length <= max;
|
|
859
|
+
var optionalText = (value, max = 500) => value === void 0 || text(value, max);
|
|
860
|
+
var optionalBoolean = (value) => value === void 0 || typeof value === "boolean";
|
|
861
|
+
var namePattern = /^[A-Za-z][A-Za-z0-9_.-]{0,63}$/;
|
|
862
|
+
function parseSheetDefinition(value) {
|
|
863
|
+
if (!object(value) || value.version !== 1 || !text(value.title) || !value.title.trim() || !optionalText(value.description, 2e3))
|
|
864
|
+
return null;
|
|
865
|
+
try {
|
|
866
|
+
if (JSON.stringify(value).length > 131072)
|
|
867
|
+
return null;
|
|
868
|
+
} catch {
|
|
869
|
+
return null;
|
|
870
|
+
}
|
|
871
|
+
const names = /* @__PURE__ */ new Set();
|
|
872
|
+
let count = 0;
|
|
873
|
+
const nodes = (items, depth) => {
|
|
874
|
+
if (!Array.isArray(items) || depth > 4)
|
|
875
|
+
return false;
|
|
876
|
+
return items.every((node) => {
|
|
877
|
+
if (!object(node) || ++count > 100)
|
|
878
|
+
return false;
|
|
879
|
+
if (node.type === "divider")
|
|
880
|
+
return true;
|
|
881
|
+
if (node.type === "text")
|
|
882
|
+
return text(node.text, 8e3) && (node.tone === void 0 || ["default", "secondary"].includes(node.tone));
|
|
883
|
+
if (node.type === "section")
|
|
884
|
+
return text(node.title) && optionalText(node.description, 2e3) && nodes(node.children, depth + 1);
|
|
885
|
+
if (!["input", "select", "toggle"].includes(node.type) || !text(node.name, 64) || !namePattern.test(node.name) || names.has(node.name) || !text(node.label) || !optionalText(node.description, 2e3) || !optionalText(node.placeholder) || !optionalBoolean(node.required) || !optionalBoolean(node.disabled))
|
|
886
|
+
return false;
|
|
887
|
+
names.add(node.name);
|
|
888
|
+
if (node.type === "toggle")
|
|
889
|
+
return optionalBoolean(node.value);
|
|
890
|
+
if (!optionalText(node.value, 8e3))
|
|
891
|
+
return false;
|
|
892
|
+
if (node.type === "input")
|
|
893
|
+
return optionalBoolean(node.multiline) && (node.maxLength === void 0 || Number.isSafeInteger(node.maxLength) && node.maxLength > 0 && node.maxLength <= 8e3);
|
|
894
|
+
if (!Array.isArray(node.options) || !node.options.length || node.options.length > 200)
|
|
895
|
+
return false;
|
|
896
|
+
const options = /* @__PURE__ */ new Set();
|
|
897
|
+
return node.options.every((o) => {
|
|
898
|
+
if (!object(o) || !text(o.value, 256) || !text(o.label) || !optionalBoolean(o.disabled) || options.has(o.value))
|
|
899
|
+
return false;
|
|
900
|
+
options.add(o.value);
|
|
901
|
+
return true;
|
|
902
|
+
}) && (node.value === void 0 || node.options.some((o) => o.value === node.value && !o.disabled));
|
|
903
|
+
});
|
|
904
|
+
};
|
|
905
|
+
if (!nodes(value.content, 0) || !Array.isArray(value.actions) || !value.actions.length || value.actions.length > 3)
|
|
906
|
+
return null;
|
|
907
|
+
const actionIds = /* @__PURE__ */ new Set();
|
|
908
|
+
if (!value.actions.every((a) => {
|
|
909
|
+
if (!object(a) || !text(a.id, 64) || !namePattern.test(a.id) || actionIds.has(a.id) || !text(a.label) || !["submit", "cancel", "reset"].includes(a.kind) || !optionalBoolean(a.primary))
|
|
910
|
+
return false;
|
|
911
|
+
actionIds.add(a.id);
|
|
912
|
+
return true;
|
|
913
|
+
}))
|
|
914
|
+
return null;
|
|
915
|
+
const definition = JSON.parse(JSON.stringify(value));
|
|
916
|
+
if (value.resetValues !== void 0 && (!object(value.resetValues) || !validSheetValues(definition, value.resetValues, false)))
|
|
917
|
+
return null;
|
|
918
|
+
return definition;
|
|
919
|
+
}
|
|
920
|
+
function sheetFields(definition) {
|
|
921
|
+
const result = [];
|
|
922
|
+
const visit = (nodes) => nodes.forEach((node) => {
|
|
923
|
+
if (node.type === "section")
|
|
924
|
+
visit(node.children);
|
|
925
|
+
else if ("name" in node)
|
|
926
|
+
result.push(node);
|
|
927
|
+
});
|
|
928
|
+
visit(definition.content);
|
|
929
|
+
return result;
|
|
930
|
+
}
|
|
931
|
+
function validSheetValues(definition, values, required = true) {
|
|
932
|
+
if (!object(values))
|
|
933
|
+
return false;
|
|
934
|
+
const fields = sheetFields(definition);
|
|
935
|
+
if (Object.keys(values).some((key2) => !fields.some((field) => field.name === key2)))
|
|
936
|
+
return false;
|
|
937
|
+
return fields.every((field) => {
|
|
938
|
+
const value = values[field.name];
|
|
939
|
+
if (value === void 0)
|
|
940
|
+
return !required;
|
|
941
|
+
if (field.type === "toggle")
|
|
942
|
+
return typeof value === "boolean" && (!field.disabled || value === (field.value ?? false));
|
|
943
|
+
if (!text(value, field.type === "input" ? field.maxLength ?? 8e3 : 256) || required && field.required && !value.trim())
|
|
944
|
+
return false;
|
|
945
|
+
if (field.disabled && value !== (field.value ?? ""))
|
|
946
|
+
return false;
|
|
947
|
+
return field.type !== "select" || value === "" && (!required || !field.required) || field.options.some((o) => o.value === value && !o.disabled);
|
|
948
|
+
});
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
// src/sheet-component.js
|
|
952
|
+
function sheetComponents({ Component, contextFor: contextFor2, mobile }) {
|
|
953
|
+
class Sheet extends Component {
|
|
954
|
+
constructor() {
|
|
955
|
+
super("<style>:host{display:contents}</style><slot></slot>");
|
|
956
|
+
this.dialog = this.ownerDocument.createElement("s24-dialog");
|
|
957
|
+
this.dialog.addEventListener("s24-close", (event) => {
|
|
958
|
+
event.stopPropagation();
|
|
959
|
+
if (!this._settled && this._resolve) this._finish({ supported: true, cancelled: true });
|
|
960
|
+
});
|
|
961
|
+
}
|
|
962
|
+
connectedCallback() {
|
|
963
|
+
if (!this.dialog.parentNode) this.append(this.dialog);
|
|
964
|
+
}
|
|
965
|
+
disconnectedCallback() {
|
|
966
|
+
this.close();
|
|
967
|
+
}
|
|
968
|
+
async show(definition) {
|
|
969
|
+
if (this._resolve) throw new Error("Sheet is already open");
|
|
970
|
+
const parsed = parseSheetDefinition(definition);
|
|
971
|
+
if (!parsed) throw new TypeError("Invalid sheet definition version 1");
|
|
972
|
+
this._definition = parsed;
|
|
973
|
+
this._values = {};
|
|
974
|
+
this._fields = [];
|
|
975
|
+
const visit = (nodes) => nodes.forEach((node) => {
|
|
976
|
+
if (node.type === "section") visit(node.children);
|
|
977
|
+
else if (node.name) {
|
|
978
|
+
this._fields.push(node);
|
|
979
|
+
this._values[node.name] = node.value ?? (node.type === "toggle" ? false : "");
|
|
980
|
+
}
|
|
981
|
+
});
|
|
982
|
+
visit(this._definition.content);
|
|
983
|
+
this._settled = false;
|
|
984
|
+
const result = new Promise((resolve) => {
|
|
985
|
+
this._resolve = resolve;
|
|
986
|
+
});
|
|
987
|
+
const sdk = contextFor2(this)?.sdk;
|
|
988
|
+
if (mobile(this) && sdk?.getCapabilities?.().nativeSheet === 1 && sdk.openSheet) {
|
|
989
|
+
const id = "sheet_" + (globalThis.crypto?.randomUUID?.() ?? Math.random().toString(36).slice(2));
|
|
990
|
+
this._native = { sdk, id };
|
|
991
|
+
Promise.resolve(sdk.openSheet(this._definition, { id })).then((reply) => {
|
|
992
|
+
if (this._native?.id !== id) return;
|
|
993
|
+
if (reply.supported === false) {
|
|
994
|
+
this._native = null;
|
|
995
|
+
this._renderWeb();
|
|
996
|
+
} else this._finish(reply);
|
|
997
|
+
}).catch((error) => {
|
|
998
|
+
if (this._native?.id !== id) return;
|
|
999
|
+
this._finish({ supported: true, cancelled: true });
|
|
1000
|
+
this.event("s24-error", { message: error.message });
|
|
1001
|
+
});
|
|
1002
|
+
} else this._renderWeb();
|
|
1003
|
+
return result;
|
|
1004
|
+
}
|
|
1005
|
+
_renderWeb() {
|
|
1006
|
+
const doc = this.ownerDocument, definition = this._definition;
|
|
1007
|
+
this.dialog.replaceChildren();
|
|
1008
|
+
this.dialog.setAttribute("heading", definition.title);
|
|
1009
|
+
if (definition.description) this.dialog.setAttribute("description", definition.description);
|
|
1010
|
+
else this.dialog.removeAttribute("description");
|
|
1011
|
+
const render = (nodes, parent) => {
|
|
1012
|
+
for (const node of nodes) {
|
|
1013
|
+
let element;
|
|
1014
|
+
if (node.type === "section") {
|
|
1015
|
+
element = doc.createElement("s24-stack");
|
|
1016
|
+
const title = doc.createElement("s24-text");
|
|
1017
|
+
title.setAttribute("bold", "");
|
|
1018
|
+
title.textContent = node.title;
|
|
1019
|
+
element.append(title);
|
|
1020
|
+
if (node.description) {
|
|
1021
|
+
const description = doc.createElement("s24-text");
|
|
1022
|
+
description.setAttribute("muted", "");
|
|
1023
|
+
description.textContent = node.description;
|
|
1024
|
+
element.append(description);
|
|
1025
|
+
}
|
|
1026
|
+
render(node.children, element);
|
|
1027
|
+
} else if (node.type === "text") {
|
|
1028
|
+
element = doc.createElement("s24-text");
|
|
1029
|
+
element.textContent = node.text;
|
|
1030
|
+
if (node.tone === "secondary") element.setAttribute("muted", "");
|
|
1031
|
+
} else if (node.type === "divider") element = doc.createElement("s24-divider");
|
|
1032
|
+
else {
|
|
1033
|
+
element = doc.createElement(node.type === "select" ? "s24-select" : node.type === "toggle" ? "s24-switch" : node.multiline ? "s24-textarea" : "s24-input");
|
|
1034
|
+
for (const attr of ["label", "description", "placeholder"]) if (node[attr]) element.setAttribute(attr, node[attr]);
|
|
1035
|
+
for (const attr of ["disabled", "required"]) if (node[attr]) element.setAttribute(attr, "");
|
|
1036
|
+
if (node.maxLength) element.setAttribute("maxlength", String(node.maxLength));
|
|
1037
|
+
if (node.type === "select") element.options = node.options;
|
|
1038
|
+
if (node.type === "toggle") element.checked = this._values[node.name];
|
|
1039
|
+
else element.value = this._values[node.name];
|
|
1040
|
+
element.dataset.sheetField = node.name;
|
|
1041
|
+
element.addEventListener(node.type === "input" ? "s24-input" : "s24-change", (event) => {
|
|
1042
|
+
this._values[node.name] = node.type === "toggle" ? event.detail.checked : event.detail.value;
|
|
1043
|
+
element.removeAttribute("error");
|
|
1044
|
+
});
|
|
1045
|
+
}
|
|
1046
|
+
parent.append(element);
|
|
1047
|
+
}
|
|
1048
|
+
};
|
|
1049
|
+
const stack = doc.createElement("s24-stack");
|
|
1050
|
+
render(definition.content, stack);
|
|
1051
|
+
this.dialog.append(stack);
|
|
1052
|
+
for (const action of definition.actions) {
|
|
1053
|
+
const button = doc.createElement("s24-button");
|
|
1054
|
+
button.slot = "footer";
|
|
1055
|
+
button.textContent = action.label;
|
|
1056
|
+
button.setAttribute("variant", action.primary ? "primary" : "secondary");
|
|
1057
|
+
button.addEventListener("click", () => {
|
|
1058
|
+
if (action.kind === "cancel") {
|
|
1059
|
+
this.close();
|
|
1060
|
+
return;
|
|
1061
|
+
}
|
|
1062
|
+
if (action.kind === "reset") {
|
|
1063
|
+
for (const field of this._fields) this._values[field.name] = field.disabled ? field.value ?? (field.type === "toggle" ? false : "") : definition.resetValues?.[field.name] ?? field.value ?? (field.type === "toggle" ? false : "");
|
|
1064
|
+
this._renderWeb();
|
|
1065
|
+
return;
|
|
1066
|
+
}
|
|
1067
|
+
let valid = true;
|
|
1068
|
+
for (const field of this._fields) if (field.required && !String(this._values[field.name] ?? "").trim()) {
|
|
1069
|
+
[...this.dialog.querySelectorAll("[data-sheet-field]")].find((el) => el.dataset.sheetField === field.name)?.setAttribute("error", "\u0417\u0430\u043F\u043E\u043B\u043D\u0438\u0442\u0435 \u043F\u043E\u043B\u0435");
|
|
1070
|
+
valid = false;
|
|
1071
|
+
}
|
|
1072
|
+
if (valid) this._finish({ supported: true, cancelled: false, action: action.id, values: { ...this._values } });
|
|
1073
|
+
});
|
|
1074
|
+
this.dialog.append(button);
|
|
1075
|
+
}
|
|
1076
|
+
this.dialog.showModal();
|
|
1077
|
+
}
|
|
1078
|
+
_finish(result) {
|
|
1079
|
+
if (!this._resolve || this._settled) return;
|
|
1080
|
+
this._settled = true;
|
|
1081
|
+
const resolve = this._resolve;
|
|
1082
|
+
this._resolve = null;
|
|
1083
|
+
this._native = null;
|
|
1084
|
+
this.dialog.close();
|
|
1085
|
+
if (!result.cancelled) this.event("s24-submit", result);
|
|
1086
|
+
this.event("s24-close", result);
|
|
1087
|
+
resolve(result);
|
|
1088
|
+
}
|
|
1089
|
+
close() {
|
|
1090
|
+
if (this._native) this._native.sdk.closeSheet?.(this._native.id).catch(() => {
|
|
1091
|
+
});
|
|
1092
|
+
if (this._resolve) this._finish({ supported: true, cancelled: true });
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
return { "s24-sheet": Sheet };
|
|
1096
|
+
}
|
|
1097
|
+
|
|
856
1098
|
// src/widget-styles.js
|
|
857
1099
|
var widgetStyles = `
|
|
858
1100
|
:host(:not([data-mobile=true])) .employee-chips>[data-add]{display:none}
|
|
@@ -1148,16 +1390,16 @@ function widgetComponents({ Component, contextFor: contextFor2, mobile, coreSVG:
|
|
|
1148
1390
|
img.alt = "";
|
|
1149
1391
|
avatar.replaceChildren(img);
|
|
1150
1392
|
}
|
|
1151
|
-
const
|
|
1152
|
-
|
|
1393
|
+
const text2 = document.createElement("span");
|
|
1394
|
+
text2.className = "employee-copy";
|
|
1153
1395
|
const title = document.createElement("strong");
|
|
1154
1396
|
const parts = name.split(/\s+/);
|
|
1155
1397
|
title.textContent = native && this._value.length === 1 && parts.length >= 2 ? `${parts[0]} ${parts.slice(1, 3).map((p) => p[0] + ".").join("")}` : name;
|
|
1156
1398
|
const position = document.createElement("small");
|
|
1157
1399
|
position.textContent = person?.position || "";
|
|
1158
|
-
|
|
1159
|
-
if (native && this._value.length !== 1)
|
|
1160
|
-
chip.append(avatar,
|
|
1400
|
+
text2.append(title, position);
|
|
1401
|
+
if (native && this._value.length !== 1) text2.hidden = true;
|
|
1402
|
+
chip.append(avatar, text2);
|
|
1161
1403
|
chips.append(chip);
|
|
1162
1404
|
}
|
|
1163
1405
|
if (native && this._value.length > 5) {
|
|
@@ -1889,7 +2131,7 @@ function coreSVG(name, cls = "") {
|
|
|
1889
2131
|
}
|
|
1890
2132
|
|
|
1891
2133
|
// src/index.js
|
|
1892
|
-
var version = "0.
|
|
2134
|
+
var version = "0.3.0";
|
|
1893
2135
|
var sessions = /* @__PURE__ */ new WeakMap();
|
|
1894
2136
|
var contextKey = /* @__PURE__ */ Symbol.for("synchra24.ui.context.v1");
|
|
1895
2137
|
function contextFor(element) {
|
|
@@ -2494,10 +2736,10 @@ function defineComponents(registry = globalThis.customElements) {
|
|
|
2494
2736
|
if (!this.control) return;
|
|
2495
2737
|
this.labels();
|
|
2496
2738
|
this.control.disabled = this.disabled;
|
|
2497
|
-
const
|
|
2498
|
-
this.text(".selected",
|
|
2739
|
+
const text2 = this.displayValue();
|
|
2740
|
+
this.text(".selected", text2);
|
|
2499
2741
|
const label = this.getAttribute("label") || this.getAttribute("aria-label") || (this.kind === "date" ? "\u0414\u0430\u0442\u0430" : "\u0412\u0440\u0435\u043C\u044F");
|
|
2500
|
-
this.control.setAttribute("aria-label", `${label}: ${
|
|
2742
|
+
this.control.setAttribute("aria-label", `${label}: ${text2}`);
|
|
2501
2743
|
this.control.setAttribute(
|
|
2502
2744
|
"aria-invalid",
|
|
2503
2745
|
String(Boolean(this.getAttribute("error")))
|
|
@@ -2522,10 +2764,10 @@ function defineComponents(registry = globalThis.customElements) {
|
|
|
2522
2764
|
this.value = value;
|
|
2523
2765
|
this.event("s24-change", { value: this.value });
|
|
2524
2766
|
}
|
|
2525
|
-
button(
|
|
2767
|
+
button(text2, fn, attrs = {}) {
|
|
2526
2768
|
const b = this.ownerDocument.createElement("button");
|
|
2527
2769
|
b.type = "button";
|
|
2528
|
-
b.textContent =
|
|
2770
|
+
b.textContent = text2;
|
|
2529
2771
|
for (const [k, v] of Object.entries(attrs)) b.setAttribute(k, String(v));
|
|
2530
2772
|
b.addEventListener("click", fn);
|
|
2531
2773
|
return b;
|
|
@@ -2882,9 +3124,9 @@ function defineComponents(registry = globalThis.customElements) {
|
|
|
2882
3124
|
formatter = new Intl.NumberFormat("ru-RU");
|
|
2883
3125
|
}
|
|
2884
3126
|
const format = (v) => formatter.format(v) + (this.getAttribute("suffix") || "");
|
|
2885
|
-
const
|
|
2886
|
-
this.control.setAttribute("aria-valuetext",
|
|
2887
|
-
this.text("output",
|
|
3127
|
+
const text2 = format(this.valueAsNumber);
|
|
3128
|
+
this.control.setAttribute("aria-valuetext", text2);
|
|
3129
|
+
this.text("output", text2);
|
|
2888
3130
|
const scale = this.shadowRoot.querySelectorAll(".slider-scale span");
|
|
2889
3131
|
scale[0].textContent = this.getAttribute("start-label") ?? format(Number(this.control.min));
|
|
2890
3132
|
scale[1].textContent = this.getAttribute("middle-label") || "";
|
|
@@ -3443,10 +3685,10 @@ function defineComponents(registry = globalThis.customElements) {
|
|
|
3443
3685
|
const list = this.hasAttribute("list-item");
|
|
3444
3686
|
this.shadowRoot.querySelector(".content").className = `content ${list ? "list" : ""}`;
|
|
3445
3687
|
this.shadowRoot.querySelector(".dot").hidden = !list;
|
|
3446
|
-
const
|
|
3447
|
-
this.shadowRoot.querySelector(".plain").hidden =
|
|
3448
|
-
this.shadowRoot.querySelector(".plain").textContent =
|
|
3449
|
-
this.shadowRoot.querySelector("slot").hidden =
|
|
3688
|
+
const text2 = this.getAttribute("text");
|
|
3689
|
+
this.shadowRoot.querySelector(".plain").hidden = text2 === null;
|
|
3690
|
+
this.shadowRoot.querySelector(".plain").textContent = text2 || "";
|
|
3691
|
+
this.shadowRoot.querySelector("slot").hidden = text2 !== null;
|
|
3450
3692
|
}
|
|
3451
3693
|
}
|
|
3452
3694
|
class Text extends Typography {
|
|
@@ -3793,16 +4035,16 @@ function defineComponents(registry = globalThis.customElements) {
|
|
|
3793
4035
|
b.setAttribute("role", "option");
|
|
3794
4036
|
b.setAttribute("aria-selected", String(item.value === this.value));
|
|
3795
4037
|
b.disabled = Boolean(item.disabled);
|
|
3796
|
-
const
|
|
4038
|
+
const text2 = this.ownerDocument.createElement("span");
|
|
3797
4039
|
const label = this.ownerDocument.createElement("span");
|
|
3798
4040
|
label.className = "option-label";
|
|
3799
4041
|
label.textContent = item.label;
|
|
3800
|
-
|
|
3801
|
-
b.append(
|
|
4042
|
+
text2.append(label);
|
|
4043
|
+
b.append(text2);
|
|
3802
4044
|
if (item.description) {
|
|
3803
4045
|
const small = this.ownerDocument.createElement("small");
|
|
3804
4046
|
small.textContent = item.description;
|
|
3805
|
-
|
|
4047
|
+
text2.append(small);
|
|
3806
4048
|
}
|
|
3807
4049
|
list.append(b);
|
|
3808
4050
|
}
|
|
@@ -3875,6 +4117,7 @@ function defineComponents(registry = globalThis.customElements) {
|
|
|
3875
4117
|
const components = {
|
|
3876
4118
|
...widgetComponents({ Component, contextFor, mobile, coreSVG }),
|
|
3877
4119
|
...feedbackComponents({ Component, contextFor, mobile }),
|
|
4120
|
+
...sheetComponents({ Component, contextFor, mobile }),
|
|
3878
4121
|
...editorComponents({ Component, contextFor, mobile }),
|
|
3879
4122
|
"s24-icon": Icon,
|
|
3880
4123
|
"s24-typography": Typography,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
export type SheetValues = Record<string, string | boolean>;
|
|
2
|
+
export type SheetNode =
|
|
3
|
+
| { type: 'text'; text: string; tone?: 'default' | 'secondary' }
|
|
4
|
+
| { type: 'divider' }
|
|
5
|
+
| { type: 'section'; title: string; description?: string; children: SheetNode[] }
|
|
6
|
+
| { type: 'input'; name: string; label: string; description?: string; placeholder?: string; value?: string; required?: boolean; disabled?: boolean; multiline?: boolean; maxLength?: number }
|
|
7
|
+
| { type: 'select'; name: string; label: string; description?: string; placeholder?: string; value?: string; required?: boolean; disabled?: boolean; options: { value: string; label: string; disabled?: boolean }[] }
|
|
8
|
+
| { type: 'toggle'; name: string; label: string; description?: string; value?: boolean; disabled?: boolean };
|
|
9
|
+
export interface SheetDefinition {
|
|
10
|
+
version: 1;
|
|
11
|
+
title: string;
|
|
12
|
+
description?: string;
|
|
13
|
+
content: SheetNode[];
|
|
14
|
+
actions: { id: string; label: string; kind: 'submit' | 'cancel' | 'reset'; primary?: boolean }[];
|
|
15
|
+
resetValues?: SheetValues;
|
|
16
|
+
}
|
|
17
|
+
export interface SheetResult { supported: boolean; cancelled?: boolean; action?: string; values?: SheetValues; sheet_id?: string }
|
|
18
|
+
export interface SheetElement extends HTMLElement {
|
|
19
|
+
show(definition: SheetDefinition): Promise<SheetResult>;
|
|
20
|
+
close(): void;
|
|
21
|
+
}
|
|
22
|
+
|
|
1
23
|
export const version: string;
|
|
2
24
|
export type Runtime = "web" | "mobile";
|
|
3
25
|
export interface Theme {
|
|
@@ -21,8 +43,11 @@ export interface SDK {
|
|
|
21
43
|
inputEditor?: number;
|
|
22
44
|
nativePickers?: number;
|
|
23
45
|
nativeSelect?: number;
|
|
46
|
+
nativeSheet?: number;
|
|
24
47
|
serviceWidgets?: number;
|
|
25
48
|
};
|
|
49
|
+
openSheet?(definition: SheetDefinition, options?: { id?: string }): Promise<SheetResult>;
|
|
50
|
+
closeSheet?(id: string): Promise<{ supported: boolean; closed?: boolean }>;
|
|
26
51
|
selectOption?(options: {
|
|
27
52
|
value?: string;
|
|
28
53
|
label?: string;
|
|
@@ -129,6 +154,7 @@ declare global {
|
|
|
129
154
|
"s24-time-picker": PickerElement;
|
|
130
155
|
"s24-slider": SliderElement;
|
|
131
156
|
"s24-dialog": DialogElement;
|
|
157
|
+
"s24-sheet": SheetElement;
|
|
132
158
|
"s24-tabs": TabsElement;
|
|
133
159
|
"s24-tab": HTMLElement;
|
|
134
160
|
"s24-island": HTMLElement;
|
|
@@ -173,6 +199,8 @@ export interface WidgetResult {
|
|
|
173
199
|
items?: AttachmentItem[];
|
|
174
200
|
}
|
|
175
201
|
export interface SDK {
|
|
202
|
+
setNavigationState?(state: { canGoBack: boolean; title?: string }): Promise<{ supported: boolean }>;
|
|
203
|
+
onBack?(callback: () => void | Promise<void>): () => void;
|
|
176
204
|
selectEmployees?(options?: {
|
|
177
205
|
profile_ids?: number[];
|
|
178
206
|
all_users?: boolean;
|