@lesjoursfr/edith 2.1.0 → 2.1.3

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 (58) hide show
  1. package/build/edith.css +1 -0
  2. package/build/edith.js +1 -0
  3. package/dist/core/dom.d.ts +224 -0
  4. package/dist/core/dom.js +480 -0
  5. package/dist/core/edit.d.ts +36 -0
  6. package/dist/core/edit.js +255 -0
  7. package/dist/core/events.d.ts +47 -0
  8. package/dist/core/events.js +100 -0
  9. package/dist/core/history.d.ts +14 -0
  10. package/dist/core/history.js +24 -0
  11. package/dist/core/index.d.ts +7 -0
  12. package/dist/core/index.js +7 -0
  13. package/dist/core/mode.d.ts +4 -0
  14. package/dist/core/mode.js +5 -0
  15. package/dist/core/range.d.ts +45 -0
  16. package/dist/core/range.js +86 -0
  17. package/dist/core/throttle.d.ts +53 -0
  18. package/dist/core/throttle.js +139 -0
  19. package/dist/edith-options.d.ts +17 -0
  20. package/dist/edith-options.js +56 -0
  21. package/dist/edith.d.ts +30 -0
  22. package/dist/edith.js +76 -0
  23. package/dist/index.d.ts +1 -0
  24. package/dist/index.js +1 -0
  25. package/dist/ui/button.d.ts +25 -0
  26. package/dist/ui/button.js +165 -0
  27. package/dist/ui/editor.d.ts +37 -0
  28. package/dist/ui/editor.js +322 -0
  29. package/dist/ui/index.d.ts +3 -0
  30. package/dist/ui/index.js +3 -0
  31. package/dist/ui/modal.d.ts +32 -0
  32. package/dist/ui/modal.js +145 -0
  33. package/package.json +49 -32
  34. package/src/core/dom.ts +584 -0
  35. package/src/core/{edit.js → edit.ts} +59 -40
  36. package/src/core/events.ts +148 -0
  37. package/src/core/history.ts +28 -0
  38. package/src/core/index.ts +7 -0
  39. package/src/core/mode.ts +4 -0
  40. package/src/core/{range.js → range.ts} +32 -22
  41. package/src/core/{throttle.js → throttle.ts} +37 -23
  42. package/src/css/edith.scss +283 -0
  43. package/src/edith-options.ts +75 -0
  44. package/src/edith.ts +98 -0
  45. package/src/index.ts +1 -0
  46. package/src/ui/button.ts +197 -0
  47. package/src/ui/editor.ts +403 -0
  48. package/src/ui/index.ts +3 -0
  49. package/src/ui/modal.ts +180 -0
  50. package/src/core/dom.js +0 -353
  51. package/src/core/event.js +0 -4
  52. package/src/core/history.js +0 -27
  53. package/src/core/mode.js +0 -4
  54. package/src/index.js +0 -90
  55. package/src/ui/button.js +0 -200
  56. package/src/ui/editor.js +0 -392
  57. package/src/ui/modal.js +0 -151
  58. /package/{src/css/main.scss → dist/css/edith.scss} +0 -0
package/src/ui/modal.js DELETED
@@ -1,151 +0,0 @@
1
- const EdithModalFieldType = Object.freeze({
2
- input: 1,
3
- checkbox: 2,
4
- });
5
-
6
- function EdithModal(ctx, options) {
7
- this.ctx = ctx;
8
- this.title = options.title;
9
- this.fields = options.fields || [];
10
- this.callback = options.callback;
11
- }
12
-
13
- EdithModal.prototype.cancel = function (event) {
14
- event.preventDefault();
15
-
16
- // Call the callback with a null value
17
- this.callback(null);
18
-
19
- // Close the modal
20
- this.close();
21
- };
22
-
23
- EdithModal.prototype.submit = function (event) {
24
- event.preventDefault();
25
-
26
- // Call the callback with the input & checkboxes values
27
- const payload = {};
28
- for (const el of this.el.querySelectorAll("input")) {
29
- payload[el.getAttribute("name")] = el.getAttribute("type") === "checkbox" ? el.checked : el.value;
30
- }
31
- this.callback(payload);
32
-
33
- // Close the modal
34
- this.close();
35
- };
36
-
37
- EdithModal.prototype.close = function () {
38
- // Remove the element from the dom
39
- this.el.remove();
40
- };
41
-
42
- EdithModal.prototype.show = function () {
43
- // Create the modal
44
- this.el = document.createElement("div");
45
- this.el.setAttribute("class", "edith-modal");
46
-
47
- // Create the header
48
- const header = document.createElement("div");
49
- header.setAttribute("class", "edith-modal-header");
50
- const title = document.createElement("span");
51
- title.setAttribute("class", "edith-modal-title");
52
- title.textContent = this.title;
53
- header.append(title);
54
-
55
- // Create the content
56
- const content = document.createElement("div");
57
- content.setAttribute("class", "edith-modal-content");
58
- for (const field of this.fields) {
59
- switch (field.fieldType) {
60
- case EdithModalFieldType.input:
61
- content.append(renderInputModalField(field));
62
- break;
63
- case EdithModalFieldType.checkbox:
64
- content.append(renderCheckboxModalField(field));
65
- break;
66
- default:
67
- throw new Error(`Unknown fieldType ${field.fieldType}`);
68
- }
69
- }
70
-
71
- // Create the footer
72
- const footer = document.createElement("div");
73
- footer.setAttribute("class", "edith-modal-footer");
74
- const cancel = document.createElement("button");
75
- cancel.setAttribute("class", "edith-modal-cancel");
76
- cancel.setAttribute("type", "button");
77
- cancel.textContent = "Annuler";
78
- footer.append(cancel);
79
- const submit = document.createElement("button");
80
- submit.setAttribute("class", "edith-modal-submit");
81
- submit.setAttribute("type", "button");
82
- submit.textContent = "Valider";
83
- footer.append(submit);
84
-
85
- // Append everything
86
- this.el.append(header);
87
- this.el.append(content);
88
- this.el.append(footer);
89
-
90
- // Add the modal to the editor
91
- this.ctx.modals.append(this.el);
92
-
93
- // Bind events
94
- cancel.onclick = this.cancel.bind(this);
95
- submit.onclick = this.submit.bind(this);
96
-
97
- // Return the modal
98
- return this.el;
99
- };
100
-
101
- function createInputModalField(label, name, initialValue = null) {
102
- return {
103
- fieldType: EdithModalFieldType.input,
104
- label,
105
- name,
106
- initialValue,
107
- };
108
- }
109
-
110
- function renderInputModalField(field) {
111
- const el = document.createElement("div");
112
- el.setAttribute("class", "edith-modal-input");
113
- const label = document.createElement("label");
114
- label.textContent = field.label;
115
- const input = document.createElement("input");
116
- input.setAttribute("name", field.name);
117
- input.setAttribute("type", "text");
118
- if (field.initialValue !== null) {
119
- input.value = field.initialValue;
120
- }
121
- el.append(label);
122
- el.append(input);
123
- return el;
124
- }
125
-
126
- function createCheckboxModalField(label, name, initialState = false) {
127
- return {
128
- fieldType: EdithModalFieldType.checkbox,
129
- label,
130
- name,
131
- initialState,
132
- };
133
- }
134
-
135
- function renderCheckboxModalField(field) {
136
- const el = document.createElement("div");
137
- el.setAttribute("class", "edith-modal-checkbox");
138
- const label = document.createElement("label");
139
- label.textContent = field.label;
140
- const input = document.createElement("input");
141
- input.setAttribute("name", field.name);
142
- input.setAttribute("type", "checkbox");
143
- if (field.initialState) {
144
- input.checked = true;
145
- }
146
- label.prepend(input);
147
- el.append(label);
148
- return el;
149
- }
150
-
151
- export { EdithModal, createInputModalField, createCheckboxModalField };
File without changes