@selfhelp/shared 1.0.3 → 1.0.5

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.
@@ -20,14 +20,22 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/registry/index.ts
21
21
  var registry_exports = {};
22
22
  __export(registry_exports, {
23
+ BASE_STYLE_REGISTRY: () => BASE_STYLE_REGISTRY,
23
24
  STYLE_REGISTRY: () => STYLE_REGISTRY,
25
+ _resetPluginStyleRegistry: () => _resetPluginStyleRegistry,
26
+ extendStyleRegistry: () => extendStyleRegistry,
27
+ getMergedStyleRegistry: () => getMergedStyleRegistry,
28
+ getPluginStyleRegistry: () => getPluginStyleRegistry,
24
29
  getRegistryEntry: () => getRegistryEntry,
25
- isKnownStyleName: () => isKnownStyleName
30
+ getRegistryEntryAny: () => getRegistryEntryAny,
31
+ getStylePluginId: () => getStylePluginId,
32
+ isKnownStyleName: () => isKnownStyleName,
33
+ isRegisteredStyleName: () => isRegisteredStyleName
26
34
  });
27
35
  module.exports = __toCommonJS(registry_exports);
28
36
 
29
37
  // src/registry/styles.registry.ts
30
- var STYLE_REGISTRY = {
38
+ var BASE_STYLE_REGISTRY = {
31
39
  // ===== auth =====
32
40
  login: { description: "User login form", category: "auth", frontendOnly: true, canHaveChildren: false },
33
41
  register: { description: "User registration form", category: "auth", frontendOnly: true, canHaveChildren: false },
@@ -118,17 +126,98 @@ var STYLE_REGISTRY = {
118
126
  entryRecordDelete: { description: "Inline delete confirmation for an entry", category: "composite", frontendOnly: true, canHaveChildren: false },
119
127
  loop: { description: "Loop / repeater over backend-provided rows", category: "composite", frontendOnly: true, canHaveChildren: true }
120
128
  };
129
+ var STYLE_REGISTRY = BASE_STYLE_REGISTRY;
130
+ var PLUGIN_STYLE_REGISTRY = {};
131
+ var REGISTERED_PLUGIN_KEYS = /* @__PURE__ */ new Map();
132
+ function extendStyleRegistry(entries, options) {
133
+ const { pluginId, pluginVersion } = options;
134
+ const ownedKeys = REGISTERED_PLUGIN_KEYS.get(pluginId) ?? /* @__PURE__ */ new Set();
135
+ const addedKeys = [];
136
+ for (const [name, entry] of Object.entries(entries)) {
137
+ if (Object.prototype.hasOwnProperty.call(BASE_STYLE_REGISTRY, name)) {
138
+ throw new Error(
139
+ `[shared/registry] plugin '${pluginId}' tried to register core style '${name}'.`
140
+ );
141
+ }
142
+ const existing = PLUGIN_STYLE_REGISTRY[name];
143
+ if (existing && existing.pluginId !== pluginId) {
144
+ throw new Error(
145
+ `[shared/registry] plugin '${pluginId}' tried to register style '${name}' already owned by '${existing.pluginId}'.`
146
+ );
147
+ }
148
+ PLUGIN_STYLE_REGISTRY[name] = {
149
+ ...entry,
150
+ pluginId,
151
+ pluginVersion
152
+ };
153
+ ownedKeys.add(name);
154
+ addedKeys.push(name);
155
+ }
156
+ REGISTERED_PLUGIN_KEYS.set(pluginId, ownedKeys);
157
+ return function dispose() {
158
+ for (const key of addedKeys) {
159
+ const existing = PLUGIN_STYLE_REGISTRY[key];
160
+ if (existing && existing.pluginId === pluginId) {
161
+ delete PLUGIN_STYLE_REGISTRY[key];
162
+ ownedKeys.delete(key);
163
+ }
164
+ }
165
+ if (ownedKeys.size === 0) {
166
+ REGISTERED_PLUGIN_KEYS.delete(pluginId);
167
+ }
168
+ };
169
+ }
170
+ function getMergedStyleRegistry() {
171
+ return {
172
+ ...BASE_STYLE_REGISTRY,
173
+ ...PLUGIN_STYLE_REGISTRY
174
+ };
175
+ }
176
+ function getPluginStyleRegistry() {
177
+ return { ...PLUGIN_STYLE_REGISTRY };
178
+ }
179
+ function _resetPluginStyleRegistry() {
180
+ for (const key of Object.keys(PLUGIN_STYLE_REGISTRY)) {
181
+ delete PLUGIN_STYLE_REGISTRY[key];
182
+ }
183
+ REGISTERED_PLUGIN_KEYS.clear();
184
+ }
121
185
 
122
186
  // src/registry/index.ts
123
187
  function getRegistryEntry(name) {
124
- return STYLE_REGISTRY[name];
188
+ if (Object.prototype.hasOwnProperty.call(BASE_STYLE_REGISTRY, name)) {
189
+ return BASE_STYLE_REGISTRY[name];
190
+ }
191
+ return void 0;
192
+ }
193
+ function getRegistryEntryAny(name) {
194
+ const merged = getMergedStyleRegistry();
195
+ return merged[name];
125
196
  }
126
197
  function isKnownStyleName(name) {
127
- return Object.prototype.hasOwnProperty.call(STYLE_REGISTRY, name);
198
+ return Object.prototype.hasOwnProperty.call(BASE_STYLE_REGISTRY, name);
199
+ }
200
+ function isRegisteredStyleName(name) {
201
+ if (Object.prototype.hasOwnProperty.call(BASE_STYLE_REGISTRY, name)) {
202
+ return true;
203
+ }
204
+ return Object.prototype.hasOwnProperty.call(getPluginStyleRegistry(), name);
205
+ }
206
+ function getStylePluginId(name) {
207
+ const plugin = getPluginStyleRegistry()[name];
208
+ return plugin?.pluginId;
128
209
  }
129
210
  // Annotate the CommonJS export names for ESM import in node:
130
211
  0 && (module.exports = {
212
+ BASE_STYLE_REGISTRY,
131
213
  STYLE_REGISTRY,
214
+ _resetPluginStyleRegistry,
215
+ extendStyleRegistry,
216
+ getMergedStyleRegistry,
217
+ getPluginStyleRegistry,
132
218
  getRegistryEntry,
133
- isKnownStyleName
219
+ getRegistryEntryAny,
220
+ getStylePluginId,
221
+ isKnownStyleName,
222
+ isRegisteredStyleName
134
223
  });
@@ -1,5 +1,5 @@
1
1
  // src/registry/styles.registry.ts
2
- var STYLE_REGISTRY = {
2
+ var BASE_STYLE_REGISTRY = {
3
3
  // ===== auth =====
4
4
  login: { description: "User login form", category: "auth", frontendOnly: true, canHaveChildren: false },
5
5
  register: { description: "User registration form", category: "auth", frontendOnly: true, canHaveChildren: false },
@@ -90,16 +90,97 @@ var STYLE_REGISTRY = {
90
90
  entryRecordDelete: { description: "Inline delete confirmation for an entry", category: "composite", frontendOnly: true, canHaveChildren: false },
91
91
  loop: { description: "Loop / repeater over backend-provided rows", category: "composite", frontendOnly: true, canHaveChildren: true }
92
92
  };
93
+ var STYLE_REGISTRY = BASE_STYLE_REGISTRY;
94
+ var PLUGIN_STYLE_REGISTRY = {};
95
+ var REGISTERED_PLUGIN_KEYS = /* @__PURE__ */ new Map();
96
+ function extendStyleRegistry(entries, options) {
97
+ const { pluginId, pluginVersion } = options;
98
+ const ownedKeys = REGISTERED_PLUGIN_KEYS.get(pluginId) ?? /* @__PURE__ */ new Set();
99
+ const addedKeys = [];
100
+ for (const [name, entry] of Object.entries(entries)) {
101
+ if (Object.prototype.hasOwnProperty.call(BASE_STYLE_REGISTRY, name)) {
102
+ throw new Error(
103
+ `[shared/registry] plugin '${pluginId}' tried to register core style '${name}'.`
104
+ );
105
+ }
106
+ const existing = PLUGIN_STYLE_REGISTRY[name];
107
+ if (existing && existing.pluginId !== pluginId) {
108
+ throw new Error(
109
+ `[shared/registry] plugin '${pluginId}' tried to register style '${name}' already owned by '${existing.pluginId}'.`
110
+ );
111
+ }
112
+ PLUGIN_STYLE_REGISTRY[name] = {
113
+ ...entry,
114
+ pluginId,
115
+ pluginVersion
116
+ };
117
+ ownedKeys.add(name);
118
+ addedKeys.push(name);
119
+ }
120
+ REGISTERED_PLUGIN_KEYS.set(pluginId, ownedKeys);
121
+ return function dispose() {
122
+ for (const key of addedKeys) {
123
+ const existing = PLUGIN_STYLE_REGISTRY[key];
124
+ if (existing && existing.pluginId === pluginId) {
125
+ delete PLUGIN_STYLE_REGISTRY[key];
126
+ ownedKeys.delete(key);
127
+ }
128
+ }
129
+ if (ownedKeys.size === 0) {
130
+ REGISTERED_PLUGIN_KEYS.delete(pluginId);
131
+ }
132
+ };
133
+ }
134
+ function getMergedStyleRegistry() {
135
+ return {
136
+ ...BASE_STYLE_REGISTRY,
137
+ ...PLUGIN_STYLE_REGISTRY
138
+ };
139
+ }
140
+ function getPluginStyleRegistry() {
141
+ return { ...PLUGIN_STYLE_REGISTRY };
142
+ }
143
+ function _resetPluginStyleRegistry() {
144
+ for (const key of Object.keys(PLUGIN_STYLE_REGISTRY)) {
145
+ delete PLUGIN_STYLE_REGISTRY[key];
146
+ }
147
+ REGISTERED_PLUGIN_KEYS.clear();
148
+ }
93
149
 
94
150
  // src/registry/index.ts
95
151
  function getRegistryEntry(name) {
96
- return STYLE_REGISTRY[name];
152
+ if (Object.prototype.hasOwnProperty.call(BASE_STYLE_REGISTRY, name)) {
153
+ return BASE_STYLE_REGISTRY[name];
154
+ }
155
+ return void 0;
156
+ }
157
+ function getRegistryEntryAny(name) {
158
+ const merged = getMergedStyleRegistry();
159
+ return merged[name];
97
160
  }
98
161
  function isKnownStyleName(name) {
99
- return Object.prototype.hasOwnProperty.call(STYLE_REGISTRY, name);
162
+ return Object.prototype.hasOwnProperty.call(BASE_STYLE_REGISTRY, name);
163
+ }
164
+ function isRegisteredStyleName(name) {
165
+ if (Object.prototype.hasOwnProperty.call(BASE_STYLE_REGISTRY, name)) {
166
+ return true;
167
+ }
168
+ return Object.prototype.hasOwnProperty.call(getPluginStyleRegistry(), name);
169
+ }
170
+ function getStylePluginId(name) {
171
+ const plugin = getPluginStyleRegistry()[name];
172
+ return plugin?.pluginId;
100
173
  }
101
174
  export {
175
+ BASE_STYLE_REGISTRY,
102
176
  STYLE_REGISTRY,
177
+ _resetPluginStyleRegistry,
178
+ extendStyleRegistry,
179
+ getMergedStyleRegistry,
180
+ getPluginStyleRegistry,
103
181
  getRegistryEntry,
104
- isKnownStyleName
182
+ getRegistryEntryAny,
183
+ getStylePluginId,
184
+ isKnownStyleName,
185
+ isRegisteredStyleName
105
186
  };