@manifest-editor/projects 1.0.2
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/LICENSE +21 -0
- package/dist/index.cjs +1301 -0
- package/dist/index.d.cts +219 -0
- package/dist/index.d.ts +219 -0
- package/dist/index.js +1291 -0
- package/package.json +75 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1291 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __publicField = (obj, key, value) => {
|
|
28
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
29
|
+
return value;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// ../../node_modules/.pnpm/shallowequal@1.1.0/node_modules/shallowequal/index.js
|
|
33
|
+
var require_shallowequal = __commonJS({
|
|
34
|
+
"../../node_modules/.pnpm/shallowequal@1.1.0/node_modules/shallowequal/index.js"(exports, module) {
|
|
35
|
+
"use strict";
|
|
36
|
+
module.exports = function shallowEqual2(objA, objB, compare, compareContext) {
|
|
37
|
+
var ret = compare ? compare.call(compareContext, objA, objB) : void 0;
|
|
38
|
+
if (ret !== void 0) {
|
|
39
|
+
return !!ret;
|
|
40
|
+
}
|
|
41
|
+
if (objA === objB) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
if (typeof objA !== "object" || !objA || typeof objB !== "object" || !objB) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
var keysA = Object.keys(objA);
|
|
48
|
+
var keysB = Object.keys(objB);
|
|
49
|
+
if (keysA.length !== keysB.length) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
var bHasOwnProperty = Object.prototype.hasOwnProperty.bind(objB);
|
|
53
|
+
for (var idx = 0; idx < keysA.length; idx++) {
|
|
54
|
+
var key = keysA[idx];
|
|
55
|
+
if (!bHasOwnProperty(key)) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
var valueA = objA[key];
|
|
59
|
+
var valueB = objB[key];
|
|
60
|
+
ret = compare ? compare.call(compareContext, valueA, valueB, key) : void 0;
|
|
61
|
+
if (ret === false || ret === void 0 && valueA !== valueB) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return true;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// ../../node_modules/.pnpm/slugify@1.6.6/node_modules/slugify/slugify.js
|
|
71
|
+
var require_slugify = __commonJS({
|
|
72
|
+
"../../node_modules/.pnpm/slugify@1.6.6/node_modules/slugify/slugify.js"(exports, module) {
|
|
73
|
+
"use strict";
|
|
74
|
+
(function(name, root, factory) {
|
|
75
|
+
if (typeof exports === "object") {
|
|
76
|
+
module.exports = factory();
|
|
77
|
+
module.exports["default"] = factory();
|
|
78
|
+
} else if (typeof define === "function" && define.amd) {
|
|
79
|
+
define(factory);
|
|
80
|
+
} else {
|
|
81
|
+
root[name] = factory();
|
|
82
|
+
}
|
|
83
|
+
})("slugify", exports, function() {
|
|
84
|
+
var charMap = JSON.parse(`{"$":"dollar","%":"percent","&":"and","<":"less",">":"greater","|":"or","\xA2":"cent","\xA3":"pound","\xA4":"currency","\xA5":"yen","\xA9":"(c)","\xAA":"a","\xAE":"(r)","\xBA":"o","\xC0":"A","\xC1":"A","\xC2":"A","\xC3":"A","\xC4":"A","\xC5":"A","\xC6":"AE","\xC7":"C","\xC8":"E","\xC9":"E","\xCA":"E","\xCB":"E","\xCC":"I","\xCD":"I","\xCE":"I","\xCF":"I","\xD0":"D","\xD1":"N","\xD2":"O","\xD3":"O","\xD4":"O","\xD5":"O","\xD6":"O","\xD8":"O","\xD9":"U","\xDA":"U","\xDB":"U","\xDC":"U","\xDD":"Y","\xDE":"TH","\xDF":"ss","\xE0":"a","\xE1":"a","\xE2":"a","\xE3":"a","\xE4":"a","\xE5":"a","\xE6":"ae","\xE7":"c","\xE8":"e","\xE9":"e","\xEA":"e","\xEB":"e","\xEC":"i","\xED":"i","\xEE":"i","\xEF":"i","\xF0":"d","\xF1":"n","\xF2":"o","\xF3":"o","\xF4":"o","\xF5":"o","\xF6":"o","\xF8":"o","\xF9":"u","\xFA":"u","\xFB":"u","\xFC":"u","\xFD":"y","\xFE":"th","\xFF":"y","\u0100":"A","\u0101":"a","\u0102":"A","\u0103":"a","\u0104":"A","\u0105":"a","\u0106":"C","\u0107":"c","\u010C":"C","\u010D":"c","\u010E":"D","\u010F":"d","\u0110":"DJ","\u0111":"dj","\u0112":"E","\u0113":"e","\u0116":"E","\u0117":"e","\u0118":"e","\u0119":"e","\u011A":"E","\u011B":"e","\u011E":"G","\u011F":"g","\u0122":"G","\u0123":"g","\u0128":"I","\u0129":"i","\u012A":"i","\u012B":"i","\u012E":"I","\u012F":"i","\u0130":"I","\u0131":"i","\u0136":"k","\u0137":"k","\u013B":"L","\u013C":"l","\u013D":"L","\u013E":"l","\u0141":"L","\u0142":"l","\u0143":"N","\u0144":"n","\u0145":"N","\u0146":"n","\u0147":"N","\u0148":"n","\u014C":"O","\u014D":"o","\u0150":"O","\u0151":"o","\u0152":"OE","\u0153":"oe","\u0154":"R","\u0155":"r","\u0158":"R","\u0159":"r","\u015A":"S","\u015B":"s","\u015E":"S","\u015F":"s","\u0160":"S","\u0161":"s","\u0162":"T","\u0163":"t","\u0164":"T","\u0165":"t","\u0168":"U","\u0169":"u","\u016A":"u","\u016B":"u","\u016E":"U","\u016F":"u","\u0170":"U","\u0171":"u","\u0172":"U","\u0173":"u","\u0174":"W","\u0175":"w","\u0176":"Y","\u0177":"y","\u0178":"Y","\u0179":"Z","\u017A":"z","\u017B":"Z","\u017C":"z","\u017D":"Z","\u017E":"z","\u018F":"E","\u0192":"f","\u01A0":"O","\u01A1":"o","\u01AF":"U","\u01B0":"u","\u01C8":"LJ","\u01C9":"lj","\u01CB":"NJ","\u01CC":"nj","\u0218":"S","\u0219":"s","\u021A":"T","\u021B":"t","\u0259":"e","\u02DA":"o","\u0386":"A","\u0388":"E","\u0389":"H","\u038A":"I","\u038C":"O","\u038E":"Y","\u038F":"W","\u0390":"i","\u0391":"A","\u0392":"B","\u0393":"G","\u0394":"D","\u0395":"E","\u0396":"Z","\u0397":"H","\u0398":"8","\u0399":"I","\u039A":"K","\u039B":"L","\u039C":"M","\u039D":"N","\u039E":"3","\u039F":"O","\u03A0":"P","\u03A1":"R","\u03A3":"S","\u03A4":"T","\u03A5":"Y","\u03A6":"F","\u03A7":"X","\u03A8":"PS","\u03A9":"W","\u03AA":"I","\u03AB":"Y","\u03AC":"a","\u03AD":"e","\u03AE":"h","\u03AF":"i","\u03B0":"y","\u03B1":"a","\u03B2":"b","\u03B3":"g","\u03B4":"d","\u03B5":"e","\u03B6":"z","\u03B7":"h","\u03B8":"8","\u03B9":"i","\u03BA":"k","\u03BB":"l","\u03BC":"m","\u03BD":"n","\u03BE":"3","\u03BF":"o","\u03C0":"p","\u03C1":"r","\u03C2":"s","\u03C3":"s","\u03C4":"t","\u03C5":"y","\u03C6":"f","\u03C7":"x","\u03C8":"ps","\u03C9":"w","\u03CA":"i","\u03CB":"y","\u03CC":"o","\u03CD":"y","\u03CE":"w","\u0401":"Yo","\u0402":"DJ","\u0404":"Ye","\u0406":"I","\u0407":"Yi","\u0408":"J","\u0409":"LJ","\u040A":"NJ","\u040B":"C","\u040F":"DZ","\u0410":"A","\u0411":"B","\u0412":"V","\u0413":"G","\u0414":"D","\u0415":"E","\u0416":"Zh","\u0417":"Z","\u0418":"I","\u0419":"J","\u041A":"K","\u041B":"L","\u041C":"M","\u041D":"N","\u041E":"O","\u041F":"P","\u0420":"R","\u0421":"S","\u0422":"T","\u0423":"U","\u0424":"F","\u0425":"H","\u0426":"C","\u0427":"Ch","\u0428":"Sh","\u0429":"Sh","\u042A":"U","\u042B":"Y","\u042C":"","\u042D":"E","\u042E":"Yu","\u042F":"Ya","\u0430":"a","\u0431":"b","\u0432":"v","\u0433":"g","\u0434":"d","\u0435":"e","\u0436":"zh","\u0437":"z","\u0438":"i","\u0439":"j","\u043A":"k","\u043B":"l","\u043C":"m","\u043D":"n","\u043E":"o","\u043F":"p","\u0440":"r","\u0441":"s","\u0442":"t","\u0443":"u","\u0444":"f","\u0445":"h","\u0446":"c","\u0447":"ch","\u0448":"sh","\u0449":"sh","\u044A":"u","\u044B":"y","\u044C":"","\u044D":"e","\u044E":"yu","\u044F":"ya","\u0451":"yo","\u0452":"dj","\u0454":"ye","\u0456":"i","\u0457":"yi","\u0458":"j","\u0459":"lj","\u045A":"nj","\u045B":"c","\u045D":"u","\u045F":"dz","\u0490":"G","\u0491":"g","\u0492":"GH","\u0493":"gh","\u049A":"KH","\u049B":"kh","\u04A2":"NG","\u04A3":"ng","\u04AE":"UE","\u04AF":"ue","\u04B0":"U","\u04B1":"u","\u04BA":"H","\u04BB":"h","\u04D8":"AE","\u04D9":"ae","\u04E8":"OE","\u04E9":"oe","\u0531":"A","\u0532":"B","\u0533":"G","\u0534":"D","\u0535":"E","\u0536":"Z","\u0537":"E'","\u0538":"Y'","\u0539":"T'","\u053A":"JH","\u053B":"I","\u053C":"L","\u053D":"X","\u053E":"C'","\u053F":"K","\u0540":"H","\u0541":"D'","\u0542":"GH","\u0543":"TW","\u0544":"M","\u0545":"Y","\u0546":"N","\u0547":"SH","\u0549":"CH","\u054A":"P","\u054B":"J","\u054C":"R'","\u054D":"S","\u054E":"V","\u054F":"T","\u0550":"R","\u0551":"C","\u0553":"P'","\u0554":"Q'","\u0555":"O''","\u0556":"F","\u0587":"EV","\u0621":"a","\u0622":"aa","\u0623":"a","\u0624":"u","\u0625":"i","\u0626":"e","\u0627":"a","\u0628":"b","\u0629":"h","\u062A":"t","\u062B":"th","\u062C":"j","\u062D":"h","\u062E":"kh","\u062F":"d","\u0630":"th","\u0631":"r","\u0632":"z","\u0633":"s","\u0634":"sh","\u0635":"s","\u0636":"dh","\u0637":"t","\u0638":"z","\u0639":"a","\u063A":"gh","\u0641":"f","\u0642":"q","\u0643":"k","\u0644":"l","\u0645":"m","\u0646":"n","\u0647":"h","\u0648":"w","\u0649":"a","\u064A":"y","\u064B":"an","\u064C":"on","\u064D":"en","\u064E":"a","\u064F":"u","\u0650":"e","\u0652":"","\u0660":"0","\u0661":"1","\u0662":"2","\u0663":"3","\u0664":"4","\u0665":"5","\u0666":"6","\u0667":"7","\u0668":"8","\u0669":"9","\u067E":"p","\u0686":"ch","\u0698":"zh","\u06A9":"k","\u06AF":"g","\u06CC":"y","\u06F0":"0","\u06F1":"1","\u06F2":"2","\u06F3":"3","\u06F4":"4","\u06F5":"5","\u06F6":"6","\u06F7":"7","\u06F8":"8","\u06F9":"9","\u0E3F":"baht","\u10D0":"a","\u10D1":"b","\u10D2":"g","\u10D3":"d","\u10D4":"e","\u10D5":"v","\u10D6":"z","\u10D7":"t","\u10D8":"i","\u10D9":"k","\u10DA":"l","\u10DB":"m","\u10DC":"n","\u10DD":"o","\u10DE":"p","\u10DF":"zh","\u10E0":"r","\u10E1":"s","\u10E2":"t","\u10E3":"u","\u10E4":"f","\u10E5":"k","\u10E6":"gh","\u10E7":"q","\u10E8":"sh","\u10E9":"ch","\u10EA":"ts","\u10EB":"dz","\u10EC":"ts","\u10ED":"ch","\u10EE":"kh","\u10EF":"j","\u10F0":"h","\u1E62":"S","\u1E63":"s","\u1E80":"W","\u1E81":"w","\u1E82":"W","\u1E83":"w","\u1E84":"W","\u1E85":"w","\u1E9E":"SS","\u1EA0":"A","\u1EA1":"a","\u1EA2":"A","\u1EA3":"a","\u1EA4":"A","\u1EA5":"a","\u1EA6":"A","\u1EA7":"a","\u1EA8":"A","\u1EA9":"a","\u1EAA":"A","\u1EAB":"a","\u1EAC":"A","\u1EAD":"a","\u1EAE":"A","\u1EAF":"a","\u1EB0":"A","\u1EB1":"a","\u1EB2":"A","\u1EB3":"a","\u1EB4":"A","\u1EB5":"a","\u1EB6":"A","\u1EB7":"a","\u1EB8":"E","\u1EB9":"e","\u1EBA":"E","\u1EBB":"e","\u1EBC":"E","\u1EBD":"e","\u1EBE":"E","\u1EBF":"e","\u1EC0":"E","\u1EC1":"e","\u1EC2":"E","\u1EC3":"e","\u1EC4":"E","\u1EC5":"e","\u1EC6":"E","\u1EC7":"e","\u1EC8":"I","\u1EC9":"i","\u1ECA":"I","\u1ECB":"i","\u1ECC":"O","\u1ECD":"o","\u1ECE":"O","\u1ECF":"o","\u1ED0":"O","\u1ED1":"o","\u1ED2":"O","\u1ED3":"o","\u1ED4":"O","\u1ED5":"o","\u1ED6":"O","\u1ED7":"o","\u1ED8":"O","\u1ED9":"o","\u1EDA":"O","\u1EDB":"o","\u1EDC":"O","\u1EDD":"o","\u1EDE":"O","\u1EDF":"o","\u1EE0":"O","\u1EE1":"o","\u1EE2":"O","\u1EE3":"o","\u1EE4":"U","\u1EE5":"u","\u1EE6":"U","\u1EE7":"u","\u1EE8":"U","\u1EE9":"u","\u1EEA":"U","\u1EEB":"u","\u1EEC":"U","\u1EED":"u","\u1EEE":"U","\u1EEF":"u","\u1EF0":"U","\u1EF1":"u","\u1EF2":"Y","\u1EF3":"y","\u1EF4":"Y","\u1EF5":"y","\u1EF6":"Y","\u1EF7":"y","\u1EF8":"Y","\u1EF9":"y","\u2013":"-","\u2018":"'","\u2019":"'","\u201C":"\\"","\u201D":"\\"","\u201E":"\\"","\u2020":"+","\u2022":"*","\u2026":"...","\u20A0":"ecu","\u20A2":"cruzeiro","\u20A3":"french franc","\u20A4":"lira","\u20A5":"mill","\u20A6":"naira","\u20A7":"peseta","\u20A8":"rupee","\u20A9":"won","\u20AA":"new shequel","\u20AB":"dong","\u20AC":"euro","\u20AD":"kip","\u20AE":"tugrik","\u20AF":"drachma","\u20B0":"penny","\u20B1":"peso","\u20B2":"guarani","\u20B3":"austral","\u20B4":"hryvnia","\u20B5":"cedi","\u20B8":"kazakhstani tenge","\u20B9":"indian rupee","\u20BA":"turkish lira","\u20BD":"russian ruble","\u20BF":"bitcoin","\u2120":"sm","\u2122":"tm","\u2202":"d","\u2206":"delta","\u2211":"sum","\u221E":"infinity","\u2665":"love","\u5143":"yuan","\u5186":"yen","\uFDFC":"rial","\uFEF5":"laa","\uFEF7":"laa","\uFEF9":"lai","\uFEFB":"la"}`);
|
|
85
|
+
var locales = JSON.parse('{"bg":{"\u0419":"Y","\u0426":"Ts","\u0429":"Sht","\u042A":"A","\u042C":"Y","\u0439":"y","\u0446":"ts","\u0449":"sht","\u044A":"a","\u044C":"y"},"de":{"\xC4":"AE","\xE4":"ae","\xD6":"OE","\xF6":"oe","\xDC":"UE","\xFC":"ue","\xDF":"ss","%":"prozent","&":"und","|":"oder","\u2211":"summe","\u221E":"unendlich","\u2665":"liebe"},"es":{"%":"por ciento","&":"y","<":"menor que",">":"mayor que","|":"o","\xA2":"centavos","\xA3":"libras","\xA4":"moneda","\u20A3":"francos","\u2211":"suma","\u221E":"infinito","\u2665":"amor"},"fr":{"%":"pourcent","&":"et","<":"plus petit",">":"plus grand","|":"ou","\xA2":"centime","\xA3":"livre","\xA4":"devise","\u20A3":"franc","\u2211":"somme","\u221E":"infini","\u2665":"amour"},"pt":{"%":"porcento","&":"e","<":"menor",">":"maior","|":"ou","\xA2":"centavo","\u2211":"soma","\xA3":"libra","\u221E":"infinito","\u2665":"amor"},"uk":{"\u0418":"Y","\u0438":"y","\u0419":"Y","\u0439":"y","\u0426":"Ts","\u0446":"ts","\u0425":"Kh","\u0445":"kh","\u0429":"Shch","\u0449":"shch","\u0413":"H","\u0433":"h"},"vi":{"\u0110":"D","\u0111":"d"},"da":{"\xD8":"OE","\xF8":"oe","\xC5":"AA","\xE5":"aa","%":"procent","&":"og","|":"eller","$":"dollar","<":"mindre end",">":"st\xF8rre end"},"nb":{"&":"og","\xC5":"AA","\xC6":"AE","\xD8":"OE","\xE5":"aa","\xE6":"ae","\xF8":"oe"},"it":{"&":"e"},"nl":{"&":"en"},"sv":{"&":"och","\xC5":"AA","\xC4":"AE","\xD6":"OE","\xE5":"aa","\xE4":"ae","\xF6":"oe"}}');
|
|
86
|
+
function replace(string, options) {
|
|
87
|
+
if (typeof string !== "string") {
|
|
88
|
+
throw new Error("slugify: string argument expected");
|
|
89
|
+
}
|
|
90
|
+
options = typeof options === "string" ? { replacement: options } : options || {};
|
|
91
|
+
var locale = locales[options.locale] || {};
|
|
92
|
+
var replacement = options.replacement === void 0 ? "-" : options.replacement;
|
|
93
|
+
var trim = options.trim === void 0 ? true : options.trim;
|
|
94
|
+
var slug = string.normalize().split("").reduce(function(result, ch) {
|
|
95
|
+
var appendChar = locale[ch];
|
|
96
|
+
if (appendChar === void 0)
|
|
97
|
+
appendChar = charMap[ch];
|
|
98
|
+
if (appendChar === void 0)
|
|
99
|
+
appendChar = ch;
|
|
100
|
+
if (appendChar === replacement)
|
|
101
|
+
appendChar = " ";
|
|
102
|
+
return result + appendChar.replace(options.remove || /[^\w\s$*_+~.()'"!\-:@]+/g, "");
|
|
103
|
+
}, "");
|
|
104
|
+
if (options.strict) {
|
|
105
|
+
slug = slug.replace(/[^A-Za-z0-9\s]/g, "");
|
|
106
|
+
}
|
|
107
|
+
if (trim) {
|
|
108
|
+
slug = slug.trim();
|
|
109
|
+
}
|
|
110
|
+
slug = slug.replace(/\s+/g, replacement);
|
|
111
|
+
if (options.lower) {
|
|
112
|
+
slug = slug.toLowerCase();
|
|
113
|
+
}
|
|
114
|
+
return slug;
|
|
115
|
+
}
|
|
116
|
+
replace.extend = function(customMap) {
|
|
117
|
+
Object.assign(charMap, customMap);
|
|
118
|
+
};
|
|
119
|
+
return replace;
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// src/ProjectContext.tsx
|
|
125
|
+
import { createContext, useContext } from "react";
|
|
126
|
+
|
|
127
|
+
// ../../node_modules/.pnpm/tiny-invariant@1.3.3/node_modules/tiny-invariant/dist/esm/tiny-invariant.js
|
|
128
|
+
var isProduction = false;
|
|
129
|
+
var prefix = "Invariant failed";
|
|
130
|
+
function invariant(condition, message) {
|
|
131
|
+
if (condition) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (isProduction) {
|
|
135
|
+
throw new Error(prefix);
|
|
136
|
+
}
|
|
137
|
+
var provided = typeof message === "function" ? message() : message;
|
|
138
|
+
var value = provided ? "".concat(prefix, ": ").concat(provided) : prefix;
|
|
139
|
+
throw new Error(value);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// src/ProjectContext.tsx
|
|
143
|
+
var ProjectReactContext = createContext(null);
|
|
144
|
+
var ProjectLoadingReactContext = createContext({
|
|
145
|
+
error: void 0,
|
|
146
|
+
isError: false,
|
|
147
|
+
isLoading: false
|
|
148
|
+
});
|
|
149
|
+
function useProjectLoading() {
|
|
150
|
+
return useContext(ProjectLoadingReactContext);
|
|
151
|
+
}
|
|
152
|
+
function useProjectContext() {
|
|
153
|
+
const ctx = useContext(ProjectReactContext);
|
|
154
|
+
invariant(ctx, "useProjectContext can only be called from inside <ProjectProvider />");
|
|
155
|
+
return ctx;
|
|
156
|
+
}
|
|
157
|
+
function useCurrentProject() {
|
|
158
|
+
const current = useProjectContext().current;
|
|
159
|
+
invariant(current, "No current project");
|
|
160
|
+
return current;
|
|
161
|
+
}
|
|
162
|
+
function useOptionalCurrentProject() {
|
|
163
|
+
const current = useProjectContext().current;
|
|
164
|
+
return current || null;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// src/ProjectContext.hooks.ts
|
|
168
|
+
var import_shallowequal = __toESM(require_shallowequal(), 1);
|
|
169
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
170
|
+
import { useDebounce } from "tiny-use-debounce";
|
|
171
|
+
|
|
172
|
+
// src/helpers/project-from-manifest.ts
|
|
173
|
+
var import_slugify = __toESM(require_slugify(), 1);
|
|
174
|
+
import { getValue } from "@iiif/helpers";
|
|
175
|
+
function randomId() {
|
|
176
|
+
return `${Math.random().toString(36).substr(2)}-${Date.now().toString(36)}`;
|
|
177
|
+
}
|
|
178
|
+
function projectFromManifest(manifest, details = {}) {
|
|
179
|
+
const name = getValue(manifest.label) || "Untitled manifest";
|
|
180
|
+
return {
|
|
181
|
+
id: `manifest-editor://project/${randomId()}`,
|
|
182
|
+
filename: (0, import_slugify.default)(name, { lower: true }),
|
|
183
|
+
name,
|
|
184
|
+
metadata: {
|
|
185
|
+
created: Date.now(),
|
|
186
|
+
modified: Date.now()
|
|
187
|
+
},
|
|
188
|
+
resource: {
|
|
189
|
+
id: manifest.id,
|
|
190
|
+
type: "Manifest"
|
|
191
|
+
},
|
|
192
|
+
publications: [],
|
|
193
|
+
previews: [],
|
|
194
|
+
settings: {},
|
|
195
|
+
storage: {
|
|
196
|
+
type: "manifest-storage",
|
|
197
|
+
data: manifest
|
|
198
|
+
},
|
|
199
|
+
...details
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// src/ProjectContext.hooks.ts
|
|
204
|
+
import { convertPresentation2 } from "@iiif/parser/presentation-2";
|
|
205
|
+
|
|
206
|
+
// src/helpers/ensure-unique-filename.ts
|
|
207
|
+
var import_slugify2 = __toESM(require_slugify(), 1);
|
|
208
|
+
function ensureUniqueFilename(project, existing) {
|
|
209
|
+
const filenames = existing.map((project2) => project2.filename);
|
|
210
|
+
const name = (project.name || project.filename || "Untitled project").toLowerCase();
|
|
211
|
+
if (project.filename && filenames.indexOf(project.filename) !== -1) {
|
|
212
|
+
project.filename = void 0;
|
|
213
|
+
}
|
|
214
|
+
if (!project.filename) {
|
|
215
|
+
let counter = 0;
|
|
216
|
+
while (!project.filename) {
|
|
217
|
+
const potentialFilename = `${(0, import_slugify2.default)(name, { lower: true })}${counter ? ` (${counter})` : ""}`;
|
|
218
|
+
if (filenames.indexOf(potentialFilename) === -1) {
|
|
219
|
+
project.filename = potentialFilename;
|
|
220
|
+
project.name = `${project.name} (${counter})`;
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
counter++;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// src/helpers/project-from-collection.ts
|
|
229
|
+
var import_slugify3 = __toESM(require_slugify(), 1);
|
|
230
|
+
import { getValue as getValue2 } from "@iiif/helpers";
|
|
231
|
+
|
|
232
|
+
// src/helpers/random-id.ts
|
|
233
|
+
function randomId2() {
|
|
234
|
+
return `${Math.random().toString(36).substr(2)}-${Date.now().toString(36)}`;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// src/helpers/project-from-collection.ts
|
|
238
|
+
function projectFromCollection(collection, details = {}) {
|
|
239
|
+
const name = getValue2(collection.label) || "Untitled collection";
|
|
240
|
+
return {
|
|
241
|
+
id: `manifest-editor://project/${randomId2()}`,
|
|
242
|
+
filename: (0, import_slugify3.default)(name, { lower: true }),
|
|
243
|
+
name,
|
|
244
|
+
metadata: {
|
|
245
|
+
created: Date.now(),
|
|
246
|
+
modified: Date.now()
|
|
247
|
+
},
|
|
248
|
+
resource: {
|
|
249
|
+
id: collection.id,
|
|
250
|
+
type: "Collection"
|
|
251
|
+
},
|
|
252
|
+
publications: [],
|
|
253
|
+
previews: [],
|
|
254
|
+
settings: {},
|
|
255
|
+
storage: {
|
|
256
|
+
type: "collection-storage",
|
|
257
|
+
data: collection
|
|
258
|
+
},
|
|
259
|
+
...details
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// src/ProjectContext.hooks.ts
|
|
264
|
+
import { ClientVault } from "@manifest-editor/client-vault";
|
|
265
|
+
import { getManifestNomalized } from "@manifest-editor/shell";
|
|
266
|
+
function useProjectActionsWithBackend(dispatch, backend, storage) {
|
|
267
|
+
async function createProject(payload) {
|
|
268
|
+
const allProjects = await backend.getAllProjects(true);
|
|
269
|
+
const project = { ...payload };
|
|
270
|
+
ensureUniqueFilename(project, allProjects);
|
|
271
|
+
if (!storage.canCreate()) {
|
|
272
|
+
throw new Error("Cannot create project with this storage backend");
|
|
273
|
+
}
|
|
274
|
+
const backendStorage = await storage.create(project, project.storage.data);
|
|
275
|
+
const createdProject = { ...project, storage: backendStorage };
|
|
276
|
+
await backend.createProject(createdProject);
|
|
277
|
+
dispatch({ type: "createProject", payload: createdProject });
|
|
278
|
+
switchProject(project.id);
|
|
279
|
+
}
|
|
280
|
+
function deleteProject(payload) {
|
|
281
|
+
if (backend.canDelete()) {
|
|
282
|
+
dispatch({ type: "deleteProject", payload });
|
|
283
|
+
backend.deleteProject(payload).then(() => {
|
|
284
|
+
console.log("Loader: project deleted");
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
function switchProject(payload) {
|
|
289
|
+
dispatch({ type: "switchProject", payload });
|
|
290
|
+
backend.setLastProject(payload).then(() => {
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
function deselectProject(payload) {
|
|
294
|
+
dispatch({ type: "deselectProject", payload });
|
|
295
|
+
}
|
|
296
|
+
function forkProject(payload) {
|
|
297
|
+
dispatch({ type: "forkProject", payload });
|
|
298
|
+
throw new Error("Not implemented yet");
|
|
299
|
+
}
|
|
300
|
+
function setLoadingStatus(payload) {
|
|
301
|
+
dispatch({ type: "setLoadingStatus", payload });
|
|
302
|
+
}
|
|
303
|
+
function saveProject(project) {
|
|
304
|
+
console.log("trying to save project...");
|
|
305
|
+
dispatch({ type: "saveProject", payload: project });
|
|
306
|
+
Promise.all([
|
|
307
|
+
//
|
|
308
|
+
backend.updateProject(project),
|
|
309
|
+
storage.saveStorage(project.storage)
|
|
310
|
+
]).then(() => {
|
|
311
|
+
console.log("Loader: project saved");
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
function updateDetails(payload) {
|
|
315
|
+
dispatch({ type: "updateDetails", payload });
|
|
316
|
+
}
|
|
317
|
+
function createPublication(payload) {
|
|
318
|
+
dispatch({ type: "createPublication", payload });
|
|
319
|
+
}
|
|
320
|
+
function updatePublication(payload) {
|
|
321
|
+
dispatch({ type: "updatePublication", payload });
|
|
322
|
+
}
|
|
323
|
+
function removePublication(payload) {
|
|
324
|
+
dispatch({ type: "removePublication", payload });
|
|
325
|
+
}
|
|
326
|
+
function updateSettings(payload) {
|
|
327
|
+
dispatch({ type: "updateSettings", payload });
|
|
328
|
+
}
|
|
329
|
+
function updateThumbnail(payload) {
|
|
330
|
+
dispatch({ type: "updateThumbnail", payload });
|
|
331
|
+
}
|
|
332
|
+
function updateStorage(payload) {
|
|
333
|
+
dispatch({ type: "updateStorage", payload });
|
|
334
|
+
}
|
|
335
|
+
function load(payload) {
|
|
336
|
+
dispatch({ type: "load", payload });
|
|
337
|
+
}
|
|
338
|
+
function setPreview(publication) {
|
|
339
|
+
dispatch({ type: "setPreview", payload: publication });
|
|
340
|
+
}
|
|
341
|
+
function removePreview(id) {
|
|
342
|
+
dispatch({ type: "removePreview", payload: id });
|
|
343
|
+
}
|
|
344
|
+
return useMemo(
|
|
345
|
+
() => ({
|
|
346
|
+
createProject,
|
|
347
|
+
deleteProject,
|
|
348
|
+
switchProject,
|
|
349
|
+
deselectProject,
|
|
350
|
+
forkProject,
|
|
351
|
+
saveProject,
|
|
352
|
+
setLoadingStatus,
|
|
353
|
+
load,
|
|
354
|
+
updateDetails,
|
|
355
|
+
createPublication,
|
|
356
|
+
updatePublication,
|
|
357
|
+
removePublication,
|
|
358
|
+
updateSettings,
|
|
359
|
+
updateThumbnail,
|
|
360
|
+
updateStorage,
|
|
361
|
+
setPreview,
|
|
362
|
+
removePreview
|
|
363
|
+
}),
|
|
364
|
+
// Dispatch always stable.
|
|
365
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
366
|
+
[]
|
|
367
|
+
);
|
|
368
|
+
}
|
|
369
|
+
function useProjectBackend({ actions, current }, backend) {
|
|
370
|
+
useEffect(() => {
|
|
371
|
+
actions.setLoadingStatus({ loading: true, lastLoaded: 0, loaded: false });
|
|
372
|
+
backend.getAllProjects().then(async (allProjects) => {
|
|
373
|
+
const lastId = await backend.getLastProject();
|
|
374
|
+
const lastValid = allProjects.find((s) => s.id === lastId);
|
|
375
|
+
actions.load({
|
|
376
|
+
allProjects,
|
|
377
|
+
current: lastValid || null,
|
|
378
|
+
loadingStatus: {
|
|
379
|
+
loaded: true,
|
|
380
|
+
loading: false,
|
|
381
|
+
lastLoaded: Date.now()
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
});
|
|
385
|
+
}, []);
|
|
386
|
+
}
|
|
387
|
+
function useProjectLoader({ actions, current }, storage) {
|
|
388
|
+
const currentRef = useRef(null);
|
|
389
|
+
const [ready, setIsReady] = useState(false);
|
|
390
|
+
const [error, setError] = useState("");
|
|
391
|
+
const saveChanges = useCallback(() => {
|
|
392
|
+
const project = currentRef.current;
|
|
393
|
+
if (project) {
|
|
394
|
+
storage.saveStorage(project.storage).then(() => {
|
|
395
|
+
const newStorage = storage.getBackendStorage(project);
|
|
396
|
+
if (!(0, import_shallowequal.default)(newStorage, project.storage)) {
|
|
397
|
+
actions.saveProject({
|
|
398
|
+
...project,
|
|
399
|
+
storage: newStorage
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
}, [actions, storage]);
|
|
405
|
+
const debounceSaveChanges = useDebounce(saveChanges, storage.saveInterval);
|
|
406
|
+
const currentId = current?.id;
|
|
407
|
+
useEffect(() => {
|
|
408
|
+
currentRef.current = current;
|
|
409
|
+
}, [current]);
|
|
410
|
+
const { vault, promise } = useMemo(() => {
|
|
411
|
+
if (current) {
|
|
412
|
+
const [vault2, promise2] = storage.createVaultInstance(current);
|
|
413
|
+
return {
|
|
414
|
+
vault: vault2,
|
|
415
|
+
promise: promise2
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
return { vault: null, promise: null };
|
|
419
|
+
}, [storage, currentId]);
|
|
420
|
+
useEffect(() => {
|
|
421
|
+
const currentStorage = storage;
|
|
422
|
+
const currentProject = current;
|
|
423
|
+
const currentVault = vault;
|
|
424
|
+
return () => {
|
|
425
|
+
if (currentVault && currentProject) {
|
|
426
|
+
currentStorage.closeVaultInstance(currentProject, currentVault);
|
|
427
|
+
} else if (currentVault instanceof ClientVault) {
|
|
428
|
+
currentVault.ws.close();
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
}, [storage, current, vault]);
|
|
432
|
+
useEffect(() => {
|
|
433
|
+
setIsReady(false);
|
|
434
|
+
let cancelled = false;
|
|
435
|
+
if (promise) {
|
|
436
|
+
promise.then(() => {
|
|
437
|
+
if (!cancelled) {
|
|
438
|
+
setIsReady(true);
|
|
439
|
+
}
|
|
440
|
+
}).catch((e) => {
|
|
441
|
+
setError(e.message);
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
return () => {
|
|
445
|
+
cancelled = true;
|
|
446
|
+
};
|
|
447
|
+
}, [promise]);
|
|
448
|
+
useEffect(() => {
|
|
449
|
+
window.addEventListener("beforeunload", saveChanges, false);
|
|
450
|
+
return () => {
|
|
451
|
+
window.removeEventListener("beforeunload", saveChanges);
|
|
452
|
+
};
|
|
453
|
+
}, [saveChanges]);
|
|
454
|
+
useEffect(() => {
|
|
455
|
+
return () => {
|
|
456
|
+
saveChanges();
|
|
457
|
+
};
|
|
458
|
+
}, [saveChanges, currentId]);
|
|
459
|
+
useEffect(() => {
|
|
460
|
+
if (vault && storage.shouldUpdateWithVault()) {
|
|
461
|
+
return vault.subscribe(debounceSaveChanges, true);
|
|
462
|
+
}
|
|
463
|
+
}, [debounceSaveChanges, storage, vault]);
|
|
464
|
+
return {
|
|
465
|
+
vault,
|
|
466
|
+
ready,
|
|
467
|
+
error
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
function useProjectCreators() {
|
|
471
|
+
const { actions } = useProjectContext();
|
|
472
|
+
const createBlankManifest = useCallback(function createBlankManifest2() {
|
|
473
|
+
actions.createProject(
|
|
474
|
+
projectFromManifest({
|
|
475
|
+
"@context": "http://iiif.io/api/presentation/3/context.json",
|
|
476
|
+
id: `https://example.org/${randomId2()}`,
|
|
477
|
+
type: "Manifest",
|
|
478
|
+
label: {
|
|
479
|
+
en: ["Blank Manifest"]
|
|
480
|
+
},
|
|
481
|
+
items: []
|
|
482
|
+
})
|
|
483
|
+
);
|
|
484
|
+
}, []);
|
|
485
|
+
const createProjectFromManifestId = useCallback(
|
|
486
|
+
async function createProjectFromManifestId2(id) {
|
|
487
|
+
let full = await getManifestNomalized(id);
|
|
488
|
+
if (full) {
|
|
489
|
+
if (full["@id"]) {
|
|
490
|
+
full = convertPresentation2(full);
|
|
491
|
+
}
|
|
492
|
+
if (full) {
|
|
493
|
+
actions.createProject(projectFromManifest(full));
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
},
|
|
497
|
+
// Actions are stable.
|
|
498
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
499
|
+
[]
|
|
500
|
+
);
|
|
501
|
+
const createProjectFromCollectionId = useCallback(
|
|
502
|
+
async function createProjectFromCollectionId2(id) {
|
|
503
|
+
let full = await getManifestNomalized(id);
|
|
504
|
+
if (full) {
|
|
505
|
+
if (full["@id"]) {
|
|
506
|
+
full = convertPresentation2(full);
|
|
507
|
+
}
|
|
508
|
+
if (full) {
|
|
509
|
+
actions.createProject(projectFromCollection(full));
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
},
|
|
513
|
+
// Actions are stable.
|
|
514
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
515
|
+
[]
|
|
516
|
+
);
|
|
517
|
+
const createProjectFromManifestJson = useCallback(
|
|
518
|
+
async function createProjectFromManifestId2(json) {
|
|
519
|
+
let full = JSON.parse(json);
|
|
520
|
+
if (full) {
|
|
521
|
+
if (full["@id"]) {
|
|
522
|
+
full = convertPresentation2(full);
|
|
523
|
+
}
|
|
524
|
+
if (full) {
|
|
525
|
+
actions.createProject(projectFromManifest(full));
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
},
|
|
529
|
+
// Actions are stable.
|
|
530
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
531
|
+
[]
|
|
532
|
+
);
|
|
533
|
+
return {
|
|
534
|
+
createProjectFromManifestJson,
|
|
535
|
+
createProjectFromManifestId,
|
|
536
|
+
createProjectFromCollectionId,
|
|
537
|
+
createBlankManifest
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
// src/ProjectContext.internal.tsx
|
|
542
|
+
import { useEffect as useEffect2, useMemo as useMemo2, useReducer } from "react";
|
|
543
|
+
import { useApps, AppResourceProvider, AppResourceInstanceProvider } from "@manifest-editor/shell";
|
|
544
|
+
|
|
545
|
+
// src/ProjectContext.reducer.ts
|
|
546
|
+
import { produce } from "immer";
|
|
547
|
+
var projectContextReducer = produce(function projectContextReducer2(state, action) {
|
|
548
|
+
if (state.current) {
|
|
549
|
+
switch (action.type) {
|
|
550
|
+
case "removePublication":
|
|
551
|
+
state.current.publications = state.current.publications.filter((p) => p.id !== action.payload);
|
|
552
|
+
break;
|
|
553
|
+
case "saveProject":
|
|
554
|
+
state.current.metadata.modified = Date.now();
|
|
555
|
+
break;
|
|
556
|
+
case "updateDetails":
|
|
557
|
+
state.current.name = action.payload.name;
|
|
558
|
+
state.current.filename = action.payload.filename;
|
|
559
|
+
break;
|
|
560
|
+
case "updateStorage":
|
|
561
|
+
state.current.storage = action.payload;
|
|
562
|
+
break;
|
|
563
|
+
case "createPublication": {
|
|
564
|
+
if (!state.current.publications.find((s) => s.id === action.payload.id)) {
|
|
565
|
+
state.current.publications.push(action.payload);
|
|
566
|
+
}
|
|
567
|
+
break;
|
|
568
|
+
}
|
|
569
|
+
case "updateThumbnail":
|
|
570
|
+
state.current.thumbnail = action.payload;
|
|
571
|
+
break;
|
|
572
|
+
case "updateSettings":
|
|
573
|
+
state.current.settings = action.payload;
|
|
574
|
+
break;
|
|
575
|
+
case "updatePublication": {
|
|
576
|
+
const found = state.current.publications.find((s) => s.id === action.payload.id);
|
|
577
|
+
if (found) {
|
|
578
|
+
found.config = action.payload.config;
|
|
579
|
+
}
|
|
580
|
+
break;
|
|
581
|
+
}
|
|
582
|
+
case "removePreview": {
|
|
583
|
+
const existing = state.current.previews?.findIndex((p) => p.id === action.payload);
|
|
584
|
+
if (existing !== -1) {
|
|
585
|
+
state.current.previews.splice(existing, 1);
|
|
586
|
+
}
|
|
587
|
+
break;
|
|
588
|
+
}
|
|
589
|
+
case "setPreview": {
|
|
590
|
+
const existing = state.current.previews?.findIndex((p) => p.id === action.payload.id);
|
|
591
|
+
if (existing !== -1) {
|
|
592
|
+
state.current.previews.splice(existing, 1, action.payload);
|
|
593
|
+
} else {
|
|
594
|
+
state.current.previews.push(action.payload);
|
|
595
|
+
}
|
|
596
|
+
break;
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
switch (action.type) {
|
|
601
|
+
case "load": {
|
|
602
|
+
state.allProjects = action.payload.allProjects;
|
|
603
|
+
state.current = action.payload.current;
|
|
604
|
+
state.loadingStatus = action.payload.loadingStatus;
|
|
605
|
+
break;
|
|
606
|
+
}
|
|
607
|
+
case "forkProject":
|
|
608
|
+
break;
|
|
609
|
+
case "deleteProject":
|
|
610
|
+
state.allProjects = state.allProjects.filter((p) => p.id !== action.payload);
|
|
611
|
+
if (state.current && state.current.id === action.payload) {
|
|
612
|
+
state.current = null;
|
|
613
|
+
}
|
|
614
|
+
break;
|
|
615
|
+
case "deselectProject":
|
|
616
|
+
state.current = null;
|
|
617
|
+
break;
|
|
618
|
+
case "createProject":
|
|
619
|
+
state.allProjects.push(action.payload);
|
|
620
|
+
state.current = action.payload;
|
|
621
|
+
break;
|
|
622
|
+
case "switchProject":
|
|
623
|
+
state.current = state.allProjects.find((p) => p.id === action.payload) || null;
|
|
624
|
+
break;
|
|
625
|
+
case "setLoadingStatus":
|
|
626
|
+
state.loadingStatus = action.payload;
|
|
627
|
+
break;
|
|
628
|
+
}
|
|
629
|
+
});
|
|
630
|
+
function getDefaultProjectContextState(status = {
|
|
631
|
+
loading: false,
|
|
632
|
+
loaded: true,
|
|
633
|
+
lastLoaded: 0
|
|
634
|
+
}) {
|
|
635
|
+
return {
|
|
636
|
+
allProjects: [],
|
|
637
|
+
current: null,
|
|
638
|
+
loadingStatus: status
|
|
639
|
+
};
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
// src/backend/LocalStorageBackend.ts
|
|
643
|
+
import * as localforage from "localforage";
|
|
644
|
+
var LocalStorageBackend = class {
|
|
645
|
+
constructor(settings) {
|
|
646
|
+
__publicField(this, "namespace");
|
|
647
|
+
__publicField(this, "saveInterval");
|
|
648
|
+
__publicField(this, "storage");
|
|
649
|
+
this.namespace = settings?.namespace || "default-v1.1";
|
|
650
|
+
this.saveInterval = 5e3;
|
|
651
|
+
this.storage = localforage.createInstance({
|
|
652
|
+
name: "manifest-editor-projects"
|
|
653
|
+
});
|
|
654
|
+
}
|
|
655
|
+
async deleteProject(id) {
|
|
656
|
+
await this.storage.removeItem(`${this.namespace}/projects/${id}`);
|
|
657
|
+
}
|
|
658
|
+
async createProject(project) {
|
|
659
|
+
const index = await this.getProjectIndex();
|
|
660
|
+
await this.storage.setItem(`${this.namespace}/projects/${project.id}`, JSON.stringify(project));
|
|
661
|
+
if (index.indexOf(project.id) === -1) {
|
|
662
|
+
index.push(project.id);
|
|
663
|
+
await this.saveProjectIndex(index);
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
canDelete() {
|
|
667
|
+
return true;
|
|
668
|
+
}
|
|
669
|
+
async getAllProjects() {
|
|
670
|
+
try {
|
|
671
|
+
const index = await this.getProjectIndex();
|
|
672
|
+
const projects = [];
|
|
673
|
+
for (const item of index) {
|
|
674
|
+
if (item === "_index") {
|
|
675
|
+
continue;
|
|
676
|
+
}
|
|
677
|
+
const loaded = await this.storage.getItem(`${this.namespace}/projects/${item}`);
|
|
678
|
+
if (loaded) {
|
|
679
|
+
try {
|
|
680
|
+
projects.push(JSON.parse(loaded));
|
|
681
|
+
} catch (e) {
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
return projects;
|
|
686
|
+
} catch (e) {
|
|
687
|
+
console.error("Error loading from localstorage", e);
|
|
688
|
+
return [];
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
async getLastProject() {
|
|
692
|
+
return this.storage.getItem(`${this.namespace}/last`);
|
|
693
|
+
}
|
|
694
|
+
async setLastProject(id) {
|
|
695
|
+
await this.storage.setItem(`${this.namespace}/last`, id);
|
|
696
|
+
}
|
|
697
|
+
async updateProject(project) {
|
|
698
|
+
await this.storage.setItem(`${this.namespace}/projects/${project.id}`, JSON.stringify(project));
|
|
699
|
+
}
|
|
700
|
+
async saveProjectIndex(index) {
|
|
701
|
+
await this.storage.setItem(`${this.namespace}/_index`, JSON.stringify(index));
|
|
702
|
+
}
|
|
703
|
+
async getProjectIndex() {
|
|
704
|
+
const json = await this.storage.getItem(`${this.namespace}/_index`);
|
|
705
|
+
if (!json) {
|
|
706
|
+
return [];
|
|
707
|
+
}
|
|
708
|
+
const index = JSON.parse(json);
|
|
709
|
+
if (!Array.isArray(index)) {
|
|
710
|
+
return [];
|
|
711
|
+
}
|
|
712
|
+
return index;
|
|
713
|
+
}
|
|
714
|
+
};
|
|
715
|
+
|
|
716
|
+
// src/storage/AbstractVaultLoader.ts
|
|
717
|
+
import { Vault } from "@iiif/helpers/vault";
|
|
718
|
+
var AbstractVaultLoader = class {
|
|
719
|
+
constructor(config = {}) {
|
|
720
|
+
__publicField(this, "vaults", {});
|
|
721
|
+
__publicField(this, "saveInterval");
|
|
722
|
+
this.saveInterval = config.saveInterval || 5e3;
|
|
723
|
+
}
|
|
724
|
+
shouldUpdateWithVault() {
|
|
725
|
+
return true;
|
|
726
|
+
}
|
|
727
|
+
canCreate() {
|
|
728
|
+
return true;
|
|
729
|
+
}
|
|
730
|
+
canDelete() {
|
|
731
|
+
return true;
|
|
732
|
+
}
|
|
733
|
+
createVaultInstance(project) {
|
|
734
|
+
const foundVault = this.vaults[project.storage.data.key];
|
|
735
|
+
if (foundVault) {
|
|
736
|
+
return [foundVault, Promise.resolve()];
|
|
737
|
+
}
|
|
738
|
+
const vault = new Vault();
|
|
739
|
+
const promise = async () => {
|
|
740
|
+
const data = await this.getStorage(project.storage);
|
|
741
|
+
await vault.loadManifest(project.resource.id, JSON.parse(JSON.stringify(data?.data)));
|
|
742
|
+
this.vaults[project.storage.data.key] = vault;
|
|
743
|
+
};
|
|
744
|
+
return [vault, promise()];
|
|
745
|
+
}
|
|
746
|
+
closeVaultInstance(project, vault) {
|
|
747
|
+
}
|
|
748
|
+
async saveStorage(storage) {
|
|
749
|
+
const vault = this.vaults[storage.data.key];
|
|
750
|
+
const manifestRef = {
|
|
751
|
+
id: storage.data.id,
|
|
752
|
+
type: storage.data.type
|
|
753
|
+
};
|
|
754
|
+
if (vault) {
|
|
755
|
+
const data = vault.toPresentation3(manifestRef);
|
|
756
|
+
const stored = data.type === "Collection" ? {
|
|
757
|
+
type: "collection-storage",
|
|
758
|
+
data
|
|
759
|
+
} : {
|
|
760
|
+
type: "manifest-storage",
|
|
761
|
+
data
|
|
762
|
+
};
|
|
763
|
+
await this.saveStorageData(stored, storage);
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
};
|
|
767
|
+
|
|
768
|
+
// src/storage/LocalStorageLoader.ts
|
|
769
|
+
import localforage2 from "localforage";
|
|
770
|
+
var LocalStorageLoader = class extends AbstractVaultLoader {
|
|
771
|
+
constructor(settings) {
|
|
772
|
+
super({ saveInterval: 5e3 });
|
|
773
|
+
__publicField(this, "type", "local-storage");
|
|
774
|
+
__publicField(this, "namespace");
|
|
775
|
+
__publicField(this, "storage");
|
|
776
|
+
__publicField(this, "vaults", {});
|
|
777
|
+
this.namespace = settings?.namespace || "default";
|
|
778
|
+
this.storage = localforage2.createInstance({
|
|
779
|
+
name: "local-storage-resource-loader"
|
|
780
|
+
});
|
|
781
|
+
}
|
|
782
|
+
shouldUpdateWithVault() {
|
|
783
|
+
return true;
|
|
784
|
+
}
|
|
785
|
+
async create(project, data) {
|
|
786
|
+
const key = randomId2();
|
|
787
|
+
await localStorage.setItem(`${this.namespace}/store/${key}`, JSON.stringify(data));
|
|
788
|
+
return {
|
|
789
|
+
type: "resource-keyed-storage",
|
|
790
|
+
data: {
|
|
791
|
+
id: data.id,
|
|
792
|
+
type: data.type,
|
|
793
|
+
key
|
|
794
|
+
}
|
|
795
|
+
};
|
|
796
|
+
}
|
|
797
|
+
async getStorage(storage) {
|
|
798
|
+
try {
|
|
799
|
+
const item = await localStorage.getItem(`${this.namespace}/store/${storage.data.key}`);
|
|
800
|
+
const manifest = item ? JSON.parse(item) : null;
|
|
801
|
+
invariant(manifest, "Resource not found");
|
|
802
|
+
if (manifest.type === "Collection") {
|
|
803
|
+
return {
|
|
804
|
+
type: "collection-storage",
|
|
805
|
+
data: manifest
|
|
806
|
+
};
|
|
807
|
+
}
|
|
808
|
+
return {
|
|
809
|
+
type: "manifest-storage",
|
|
810
|
+
data: manifest
|
|
811
|
+
};
|
|
812
|
+
} catch (e) {
|
|
813
|
+
return null;
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
async saveStorageData(manifestStorage, storage) {
|
|
817
|
+
await localStorage.setItem(`${this.namespace}/store/${storage.data.key}`, JSON.stringify(manifestStorage.data));
|
|
818
|
+
}
|
|
819
|
+
async deleteStorage(storage) {
|
|
820
|
+
this.vaults[storage.data.key] = null;
|
|
821
|
+
await localStorage.removeItem(`${this.namespace}/store/${storage.data.key}`);
|
|
822
|
+
}
|
|
823
|
+
getBackendStorage(project) {
|
|
824
|
+
return project.storage;
|
|
825
|
+
}
|
|
826
|
+
};
|
|
827
|
+
|
|
828
|
+
// src/ProjectContext.internal.tsx
|
|
829
|
+
import { VaultProvider } from "react-iiif-vault";
|
|
830
|
+
import { jsx } from "react/jsx-runtime";
|
|
831
|
+
function ProjectProvider(props) {
|
|
832
|
+
const { currentApp, changeApp } = useApps();
|
|
833
|
+
const backend = useMemo2(() => props.backend || new LocalStorageBackend(), []);
|
|
834
|
+
const storage = useMemo2(() => props.storage || new LocalStorageLoader(), []);
|
|
835
|
+
const [state, dispatch] = useReducer(
|
|
836
|
+
projectContextReducer,
|
|
837
|
+
void 0,
|
|
838
|
+
props.initialState || getDefaultProjectContextState
|
|
839
|
+
);
|
|
840
|
+
const actions = useProjectActionsWithBackend(dispatch, backend, storage);
|
|
841
|
+
const context = useMemo2(
|
|
842
|
+
() => ({ actions, canDelete: backend.canDelete(), ...state }),
|
|
843
|
+
[actions, backend, state]
|
|
844
|
+
);
|
|
845
|
+
const { vault, ready, error } = useProjectLoader(context, storage);
|
|
846
|
+
const manifestOrCollection = context.current?.resource;
|
|
847
|
+
const loadingStatus = useMemo2(() => {
|
|
848
|
+
return { isLoading: !ready, isError: !!error, error };
|
|
849
|
+
}, [ready, error]);
|
|
850
|
+
useProjectBackend(context, backend);
|
|
851
|
+
useEffect2(() => {
|
|
852
|
+
if (state.loadingStatus && state.loadingStatus.loaded && ready && (!vault || !manifestOrCollection) && currentApp?.id !== (props.defaultApp || "splash")) {
|
|
853
|
+
changeApp({ id: props.defaultApp || "splash" });
|
|
854
|
+
}
|
|
855
|
+
}, []);
|
|
856
|
+
if (state.loadingStatus && state.loadingStatus.loading || context.current && !manifestOrCollection) {
|
|
857
|
+
return /* @__PURE__ */ jsx("div", { children: "Loading..." });
|
|
858
|
+
}
|
|
859
|
+
return /* @__PURE__ */ jsx(ProjectLoadingReactContext.Provider, { value: loadingStatus, children: /* @__PURE__ */ jsx(ProjectReactContext.Provider, { value: context, children: /* @__PURE__ */ jsx(VaultProvider, { vault: vault || void 0, children: /* @__PURE__ */ jsx(AppResourceInstanceProvider, { id: context.current?.id, children: /* @__PURE__ */ jsx(AppResourceProvider, { resource: manifestOrCollection, children: props.children }) }) }, state.current?.id) }) });
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
// ../ui/icons/MenuIcon.tsx
|
|
863
|
+
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
864
|
+
var MenuIcon = () => /* @__PURE__ */ jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", height: "1rem", viewBox: "0 0 24 24", width: "24px", fill: "#000000", children: [
|
|
865
|
+
/* @__PURE__ */ jsx2("path", { d: "M0 0h24v24H0z", fill: "none" }),
|
|
866
|
+
/* @__PURE__ */ jsx2("path", { d: "M3 18h18v-2H3v2zm0-5h18v-2H3v2zm0-7v2h18V6H3z" })
|
|
867
|
+
] });
|
|
868
|
+
|
|
869
|
+
// ../ui/atoms/Dropdown.tsx
|
|
870
|
+
import styled2, { css } from "styled-components";
|
|
871
|
+
|
|
872
|
+
// ../ui/atoms/Button.tsx
|
|
873
|
+
import styled from "styled-components";
|
|
874
|
+
var ButtonReset = styled.button`
|
|
875
|
+
border: none;
|
|
876
|
+
outline: none;
|
|
877
|
+
background-color: transparent;
|
|
878
|
+
margin: 0;
|
|
879
|
+
padding: 0;
|
|
880
|
+
font-size: inherit;
|
|
881
|
+
color: inherit;
|
|
882
|
+
cursor: pointer;
|
|
883
|
+
&:hover {
|
|
884
|
+
color: inherit;
|
|
885
|
+
}
|
|
886
|
+
`;
|
|
887
|
+
var Button = styled.button`
|
|
888
|
+
padding: 0.5rem 1rem;
|
|
889
|
+
color: ${(props) => props.theme.color.main || "none"};
|
|
890
|
+
background-color: ${(props) => props.theme.color.white || "white"};
|
|
891
|
+
border-radius: inherit;
|
|
892
|
+
border: none;
|
|
893
|
+
cursor: pointer;
|
|
894
|
+
display: flex;
|
|
895
|
+
align-items: center;
|
|
896
|
+
font-size: 0.85em;
|
|
897
|
+
:disabled {
|
|
898
|
+
opacity: 0.65;
|
|
899
|
+
cursor: not-allowed;
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
&:hover {
|
|
903
|
+
background: #eee;
|
|
904
|
+
}
|
|
905
|
+
`;
|
|
906
|
+
var SmallButton = styled(Button)`
|
|
907
|
+
padding: 0.25em ${(props) => props.theme.padding.xs || "0.4em"};
|
|
908
|
+
height: unset;
|
|
909
|
+
background: none;
|
|
910
|
+
`;
|
|
911
|
+
var SecondaryButton = styled(Button)`
|
|
912
|
+
{
|
|
913
|
+
padding: 0 ${(props) => props.theme.padding.medium || "1rem"};
|
|
914
|
+
color: ${(props) => props.theme.color.main || "#B84C74;"};
|
|
915
|
+
background-color: ${(props) => props.theme.color.white || "white"};
|
|
916
|
+
border: 1px solid ${(props) => props.theme.color.main || "#B84C74;"};
|
|
917
|
+
border-radius: 0.25rem;
|
|
918
|
+
cursor: pointer;
|
|
919
|
+
height: 2rem;
|
|
920
|
+
display: flex;
|
|
921
|
+
align-items: center;
|
|
922
|
+
white-space: nowrap;
|
|
923
|
+
font-size: 0.75rem;
|
|
924
|
+
|
|
925
|
+
:disabled {
|
|
926
|
+
opacity: 0.65;
|
|
927
|
+
cursor: not-allowed;
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
`;
|
|
931
|
+
var CalltoButton = styled(Button)`
|
|
932
|
+
padding: 0 ${(props) => props.theme.padding.medium || "1rem"};
|
|
933
|
+
color: ${(props) => props.theme.color.white || "white"};
|
|
934
|
+
background-color: ${(props) => props.theme.color.main || "#B84C74;"};
|
|
935
|
+
border: 1px solid #eee;
|
|
936
|
+
border-radius: 0.25rem;
|
|
937
|
+
cursor: pointer;
|
|
938
|
+
justify-content: center;
|
|
939
|
+
display: flex;
|
|
940
|
+
align-items: center;
|
|
941
|
+
&:hover {
|
|
942
|
+
background-color: ${(props) => props.theme.color.mainHover || "#B84C74;"};
|
|
943
|
+
}
|
|
944
|
+
`;
|
|
945
|
+
var ButtonGroup = styled.div`
|
|
946
|
+
display: flex;
|
|
947
|
+
flex-direction: row;
|
|
948
|
+
flex-wrap: wrap;
|
|
949
|
+
align-items: flex-start;
|
|
950
|
+
justify-content: ${(props) => props.$right ? "flex-end" : "flex-start"};
|
|
951
|
+
`;
|
|
952
|
+
|
|
953
|
+
// ../ui/atoms/Dropdown.tsx
|
|
954
|
+
var Dropdown = styled2.div`
|
|
955
|
+
position: relative;
|
|
956
|
+
display: inline-block;
|
|
957
|
+
`;
|
|
958
|
+
var DropdownContent = styled2.div`
|
|
959
|
+
display: flex;
|
|
960
|
+
flex-direction: column;
|
|
961
|
+
position: absolute;
|
|
962
|
+
background-color: ${(props) => props.theme.color.white || "white"};
|
|
963
|
+
color: ${(props) => props.theme.color.black || " black"};
|
|
964
|
+
font-size: 0.75rem;
|
|
965
|
+
min-width: 160px;
|
|
966
|
+
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
|
|
967
|
+
z-index: 150;
|
|
968
|
+
button {
|
|
969
|
+
&:hover {
|
|
970
|
+
background-color: ${(props) => props.theme.color.lightgrey || "lightgrey"};
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
`;
|
|
974
|
+
var DropdownItem = styled2.button`
|
|
975
|
+
padding: 0 ${(props) => props.theme.padding.small || "0.5rem"};
|
|
976
|
+
color: ${(props) => props.theme.color.main || "none"};
|
|
977
|
+
background-color: ${(props) => props.theme.color.white || "white"};
|
|
978
|
+
border-radius: 0;
|
|
979
|
+
border: none;
|
|
980
|
+
cursor: pointer;
|
|
981
|
+
display: flex;
|
|
982
|
+
padding: 0.65em 1em;
|
|
983
|
+
align-items: center;
|
|
984
|
+
:disabled {
|
|
985
|
+
opacity: 0.65;
|
|
986
|
+
cursor: not-allowed;
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
&:hover {
|
|
990
|
+
background-color: ${(props) => props.theme.color.lightgrey || "lightgrey"};
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
${(props) => props.$active && css`
|
|
994
|
+
background: #b84c74;
|
|
995
|
+
color: #fff;
|
|
996
|
+
&:hover {
|
|
997
|
+
background: #b84c74;
|
|
998
|
+
color: #fff;
|
|
999
|
+
}
|
|
1000
|
+
`}
|
|
1001
|
+
`;
|
|
1002
|
+
var DropdownMenu = styled2.div`
|
|
1003
|
+
display: none;
|
|
1004
|
+
flex-direction: column;
|
|
1005
|
+
position: absolute;
|
|
1006
|
+
background: #fff;
|
|
1007
|
+
color: ${(props) => props.theme.color.black || " black"};
|
|
1008
|
+
font-size: 0.75rem;
|
|
1009
|
+
min-width: 190px;
|
|
1010
|
+
top: calc(100% + 0.5em);
|
|
1011
|
+
box-shadow:
|
|
1012
|
+
0 4px 15px 0 rgba(0, 0, 0, 0.18),
|
|
1013
|
+
0 0px 0px 1px rgba(0, 0, 0, 0.15),
|
|
1014
|
+
inset 0 0 0 1px rgba(255, 255, 255, 0.2);
|
|
1015
|
+
border-radius: 3px;
|
|
1016
|
+
z-index: 150;
|
|
1017
|
+
overflow: hidden;
|
|
1018
|
+
padding-bottom: 3px;
|
|
1019
|
+
|
|
1020
|
+
${Button} {
|
|
1021
|
+
&:hover {
|
|
1022
|
+
background-color: ${(props) => props.theme.color.lightgrey || "lightgrey"};
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
${(props) => props.$open && css`
|
|
1027
|
+
display: flex;
|
|
1028
|
+
`}
|
|
1029
|
+
`;
|
|
1030
|
+
var DropdownLabel = styled2.div`
|
|
1031
|
+
color: #999;
|
|
1032
|
+
text-transform: uppercase;
|
|
1033
|
+
font-weight: 600;
|
|
1034
|
+
padding: 0.7em;
|
|
1035
|
+
font-size: 0.875em;
|
|
1036
|
+
`;
|
|
1037
|
+
var DropdownDivider = styled2.div`
|
|
1038
|
+
height: 1px;
|
|
1039
|
+
margin: 0 0.5em;
|
|
1040
|
+
background: #eee;
|
|
1041
|
+
`;
|
|
1042
|
+
|
|
1043
|
+
// ../ui/madoc/use-local-storage.ts
|
|
1044
|
+
import { useEffect as useEffect3, useRef as useRef2, useState as useState2 } from "react";
|
|
1045
|
+
|
|
1046
|
+
// ../../node_modules/.pnpm/mitt@3.0.1/node_modules/mitt/dist/mitt.mjs
|
|
1047
|
+
function mitt_default(n) {
|
|
1048
|
+
return { all: n = n || /* @__PURE__ */ new Map(), on: function(t, e) {
|
|
1049
|
+
var i = n.get(t);
|
|
1050
|
+
i ? i.push(e) : n.set(t, [e]);
|
|
1051
|
+
}, off: function(t, e) {
|
|
1052
|
+
var i = n.get(t);
|
|
1053
|
+
i && (e ? i.splice(i.indexOf(e) >>> 0, 1) : n.set(t, []));
|
|
1054
|
+
}, emit: function(t, e) {
|
|
1055
|
+
var i = n.get(t);
|
|
1056
|
+
i && i.slice().map(function(n2) {
|
|
1057
|
+
n2(e);
|
|
1058
|
+
}), (i = n.get("*")) && i.slice().map(function(n2) {
|
|
1059
|
+
n2(t, e);
|
|
1060
|
+
});
|
|
1061
|
+
} };
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
// ../ui/madoc/use-local-storage.ts
|
|
1065
|
+
globalThis.MS_LS_EMITTER = globalThis.MS_LS_EMITTER || mitt_default();
|
|
1066
|
+
var lsEmitter = globalThis.MS_LS_EMITTER;
|
|
1067
|
+
function useLocalStorage(key, initialValue) {
|
|
1068
|
+
const lastStoredValue = useRef2();
|
|
1069
|
+
if (!lastStoredValue.current && initialValue) {
|
|
1070
|
+
lastStoredValue.current = JSON.stringify(initialValue);
|
|
1071
|
+
}
|
|
1072
|
+
const [storedValue, setStoredValue] = useState2(() => {
|
|
1073
|
+
try {
|
|
1074
|
+
if (typeof window === "undefined" || typeof window.localStorage === "undefined") {
|
|
1075
|
+
return initialValue;
|
|
1076
|
+
}
|
|
1077
|
+
const item = window.localStorage.getItem(key);
|
|
1078
|
+
if (item) {
|
|
1079
|
+
lastStoredValue.current = item;
|
|
1080
|
+
}
|
|
1081
|
+
return item ? JSON.parse(item) : initialValue;
|
|
1082
|
+
} catch (error) {
|
|
1083
|
+
console.log(error);
|
|
1084
|
+
return initialValue;
|
|
1085
|
+
}
|
|
1086
|
+
});
|
|
1087
|
+
const setValue = (value) => {
|
|
1088
|
+
try {
|
|
1089
|
+
if (typeof window !== "undefined" && typeof window.localStorage !== "undefined") {
|
|
1090
|
+
let prev = initialValue;
|
|
1091
|
+
try {
|
|
1092
|
+
prev = typeof lastStoredValue.current === "undefined" ? initialValue : JSON.parse(lastStoredValue.current);
|
|
1093
|
+
} catch (e) {
|
|
1094
|
+
}
|
|
1095
|
+
const valueToStore = value instanceof Function ? value(prev) : value;
|
|
1096
|
+
setStoredValue(valueToStore);
|
|
1097
|
+
const valueJson = JSON.stringify(valueToStore);
|
|
1098
|
+
window.localStorage.setItem(key, valueJson);
|
|
1099
|
+
if (valueJson !== lastStoredValue.current) {
|
|
1100
|
+
lastStoredValue.current = valueJson;
|
|
1101
|
+
lsEmitter.emit(`change:${key}`, { valueJson });
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
} catch (error) {
|
|
1105
|
+
console.log(error);
|
|
1106
|
+
}
|
|
1107
|
+
};
|
|
1108
|
+
useEffect3(() => {
|
|
1109
|
+
const listener = ({ valueJson }) => {
|
|
1110
|
+
if (valueJson && valueJson !== lastStoredValue.current) {
|
|
1111
|
+
try {
|
|
1112
|
+
setStoredValue(JSON.parse(valueJson));
|
|
1113
|
+
lastStoredValue.current = valueJson;
|
|
1114
|
+
} catch (e) {
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
};
|
|
1118
|
+
lsEmitter.on(`change:${key}`, listener);
|
|
1119
|
+
return () => {
|
|
1120
|
+
lsEmitter.off(`change:${key}`, listener);
|
|
1121
|
+
};
|
|
1122
|
+
}, [key]);
|
|
1123
|
+
return [storedValue, setValue, lastStoredValue];
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
// src/components/AppMenu.tsx
|
|
1127
|
+
import useDropdownMenu from "react-accessible-dropdown-menu-hook";
|
|
1128
|
+
import { useApps as useApps2 } from "@manifest-editor/shell";
|
|
1129
|
+
import styled3 from "styled-components";
|
|
1130
|
+
import { Fragment, jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
1131
|
+
var IconButton = styled3.button`
|
|
1132
|
+
height: 1.75em;
|
|
1133
|
+
width: 1.75em;
|
|
1134
|
+
background: #e9e9e9;
|
|
1135
|
+
border-radius: 3px;
|
|
1136
|
+
display: flex;
|
|
1137
|
+
text-align: center;
|
|
1138
|
+
align-items: center;
|
|
1139
|
+
font-size: 1.1em;
|
|
1140
|
+
border: none;
|
|
1141
|
+
justify-content: center;
|
|
1142
|
+
|
|
1143
|
+
&:focus {
|
|
1144
|
+
background: #e94581;
|
|
1145
|
+
color: #fff;
|
|
1146
|
+
svg {
|
|
1147
|
+
fill: #fff;
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
`;
|
|
1151
|
+
function AppMenu(props) {
|
|
1152
|
+
const { current: currentProject } = useProjectContext();
|
|
1153
|
+
const [isMenuHidden, setIsMenuHidden] = useLocalStorage("menu-hidden");
|
|
1154
|
+
const { apps, changeApp } = useApps2();
|
|
1155
|
+
const type = currentProject?.resource.type;
|
|
1156
|
+
const filteredApps = Object.values(apps).filter((app) => {
|
|
1157
|
+
if (app.metadata.project && app.metadata.projectType !== type) {
|
|
1158
|
+
return false;
|
|
1159
|
+
}
|
|
1160
|
+
if (!currentProject && app.metadata.project) {
|
|
1161
|
+
return false;
|
|
1162
|
+
}
|
|
1163
|
+
if (app.metadata.type === "launcher") {
|
|
1164
|
+
return false;
|
|
1165
|
+
}
|
|
1166
|
+
return true;
|
|
1167
|
+
});
|
|
1168
|
+
const { itemProps, buttonProps, isOpen, setIsOpen } = useDropdownMenu(filteredApps.length + 1);
|
|
1169
|
+
return /* @__PURE__ */ jsxs2(Dropdown, { children: [
|
|
1170
|
+
/* @__PURE__ */ jsx3(IconButton, { ...buttonProps, children: /* @__PURE__ */ jsx3(MenuIcon, {}) }),
|
|
1171
|
+
/* @__PURE__ */ jsxs2(DropdownMenu, { $open: isOpen, children: [
|
|
1172
|
+
/* @__PURE__ */ jsx3(DropdownLabel, { children: "Apps" }),
|
|
1173
|
+
/* @__PURE__ */ jsx3(DropdownDivider, {}),
|
|
1174
|
+
filteredApps.map((app, key) => /* @__PURE__ */ jsx3(
|
|
1175
|
+
Button,
|
|
1176
|
+
{
|
|
1177
|
+
...itemProps[key],
|
|
1178
|
+
onClick: () => {
|
|
1179
|
+
changeApp({ id: app.metadata.id });
|
|
1180
|
+
setIsOpen(false);
|
|
1181
|
+
},
|
|
1182
|
+
children: app.metadata.title
|
|
1183
|
+
},
|
|
1184
|
+
app.metadata.id
|
|
1185
|
+
)),
|
|
1186
|
+
props.hideMenu ? null : /* @__PURE__ */ jsxs2(Fragment, { children: [
|
|
1187
|
+
/* @__PURE__ */ jsx3(DropdownLabel, { children: "Quick Settings" }),
|
|
1188
|
+
/* @__PURE__ */ jsx3(DropdownDivider, {}),
|
|
1189
|
+
/* @__PURE__ */ jsx3(Button, { ...itemProps[filteredApps.length + 0], onClick: () => setIsMenuHidden(!isMenuHidden), children: isMenuHidden ? "Show menu" : "Hide menu" })
|
|
1190
|
+
] })
|
|
1191
|
+
] })
|
|
1192
|
+
] });
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
// src/components/DraftTitleEditor.tsx
|
|
1196
|
+
import { useState as useState3 } from "react";
|
|
1197
|
+
import { flushSync } from "react-dom";
|
|
1198
|
+
import styled4 from "styled-components";
|
|
1199
|
+
import { Fragment as Fragment2, jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
1200
|
+
var Draft = styled4.div`
|
|
1201
|
+
display: flex;
|
|
1202
|
+
flex-direction: row;
|
|
1203
|
+
flex: 1;
|
|
1204
|
+
padding: 0.28em;
|
|
1205
|
+
padding-left: 0.5em;
|
|
1206
|
+
align-items: center;
|
|
1207
|
+
overflow: hidden;
|
|
1208
|
+
`;
|
|
1209
|
+
var DraftsText = styled4.div`
|
|
1210
|
+
color: #828282;
|
|
1211
|
+
padding-right: 1em;
|
|
1212
|
+
`;
|
|
1213
|
+
var DraftTitleEdit = styled4.form`
|
|
1214
|
+
margin: 0;
|
|
1215
|
+
padding: 0;
|
|
1216
|
+
display: flex;
|
|
1217
|
+
flex: 1;
|
|
1218
|
+
`;
|
|
1219
|
+
var DraftTitleEditInput = styled4.input`
|
|
1220
|
+
font-size: 1em;
|
|
1221
|
+
flex: 1;
|
|
1222
|
+
border: 1px solid #999;
|
|
1223
|
+
padding: 0.2em;
|
|
1224
|
+
margin: -0.2em 0;
|
|
1225
|
+
`;
|
|
1226
|
+
var DraftTitleEditButton = styled4(SmallButton)`
|
|
1227
|
+
font-size: 1em;
|
|
1228
|
+
display: inline-block;
|
|
1229
|
+
`;
|
|
1230
|
+
var DraftTitle = styled4.div`
|
|
1231
|
+
color: #333;
|
|
1232
|
+
flex: 1;
|
|
1233
|
+
text-overflow: ellipsis;
|
|
1234
|
+
white-space: nowrap;
|
|
1235
|
+
overflow: hidden;
|
|
1236
|
+
`;
|
|
1237
|
+
function DraftTitleEditor() {
|
|
1238
|
+
const { actions, current } = useProjectContext();
|
|
1239
|
+
const [editingTitle, setIsEditingTitle] = useState3(false);
|
|
1240
|
+
return /* @__PURE__ */ jsxs3(Draft, { children: [
|
|
1241
|
+
/* @__PURE__ */ jsx4(DraftsText, { children: "Drafts" }),
|
|
1242
|
+
current ? /* @__PURE__ */ jsx4(Fragment2, { children: editingTitle ? /* @__PURE__ */ jsxs3(
|
|
1243
|
+
DraftTitleEdit,
|
|
1244
|
+
{
|
|
1245
|
+
onSubmit: (e) => {
|
|
1246
|
+
const form = new FormData(e.target);
|
|
1247
|
+
const data = Object.fromEntries(form.entries());
|
|
1248
|
+
actions.updateDetails(data);
|
|
1249
|
+
setIsEditingTitle(false);
|
|
1250
|
+
},
|
|
1251
|
+
children: [
|
|
1252
|
+
/* @__PURE__ */ jsx4(DraftTitleEditInput, { id: "project-title", defaultValue: current.name, name: "name" }),
|
|
1253
|
+
/* @__PURE__ */ jsx4(DraftTitleEditButton, { children: "Save" })
|
|
1254
|
+
]
|
|
1255
|
+
}
|
|
1256
|
+
) : /* @__PURE__ */ jsx4(
|
|
1257
|
+
DraftTitle,
|
|
1258
|
+
{
|
|
1259
|
+
onClick: () => {
|
|
1260
|
+
flushSync(() => {
|
|
1261
|
+
setIsEditingTitle(true);
|
|
1262
|
+
});
|
|
1263
|
+
document.getElementById("project-title")?.focus();
|
|
1264
|
+
},
|
|
1265
|
+
children: current.name || "Untitled project"
|
|
1266
|
+
}
|
|
1267
|
+
) }) : null
|
|
1268
|
+
] });
|
|
1269
|
+
}
|
|
1270
|
+
export {
|
|
1271
|
+
AppMenu,
|
|
1272
|
+
Draft,
|
|
1273
|
+
DraftTitle,
|
|
1274
|
+
DraftTitleEdit,
|
|
1275
|
+
DraftTitleEditButton,
|
|
1276
|
+
DraftTitleEditInput,
|
|
1277
|
+
DraftTitleEditor,
|
|
1278
|
+
DraftsText,
|
|
1279
|
+
IconButton,
|
|
1280
|
+
ProjectLoadingReactContext,
|
|
1281
|
+
ProjectProvider,
|
|
1282
|
+
ProjectReactContext,
|
|
1283
|
+
useCurrentProject,
|
|
1284
|
+
useOptionalCurrentProject,
|
|
1285
|
+
useProjectActionsWithBackend,
|
|
1286
|
+
useProjectBackend,
|
|
1287
|
+
useProjectContext,
|
|
1288
|
+
useProjectCreators,
|
|
1289
|
+
useProjectLoader,
|
|
1290
|
+
useProjectLoading
|
|
1291
|
+
};
|